1
+ /* eslint-disable
2
+ import/order,
3
+ import/first,
4
+ no-shadow,
5
+ no-param-reassign
6
+ */
1
7
import schema from './options.json' ;
2
8
import { getOptions } from 'loader-utils' ;
3
9
import validateOptions from 'schema-utils' ;
@@ -18,11 +24,7 @@ const defaults = {
18
24
19
25
export default function loader ( html , map , meta ) {
20
26
// Loader Options
21
- const options = Object . assign (
22
- { } ,
23
- defaults ,
24
- getOptions ( this )
25
- ) ;
27
+ const options = Object . assign ( { } , defaults , getOptions ( this ) ) ;
26
28
27
29
validateOptions ( schema , options , 'HTML Loader' ) ;
28
30
// Make the loader async
@@ -39,7 +41,7 @@ export default function loader(html, map, meta) {
39
41
if ( options . url ) {
40
42
plugins . push ( urls ( options ) ) ;
41
43
}
42
-
44
+
43
45
// HTML IMPORT Plugin
44
46
if ( options . import ) {
45
47
plugins . push ( imports ( options ) ) ;
@@ -53,10 +55,10 @@ export default function loader(html, map, meta) {
53
55
54
56
// Reuse HTML AST (PostHTML AST)
55
57
// (e.g posthtml-loader) to avoid HTML reparsing
56
- if ( meta ) {
58
+ if ( meta ) {
57
59
if ( meta . ast && meta . ast . type === 'posthtml' ) {
58
- const { ast } = meta . ast ;
59
-
60
+ const { ast } = meta . ast ;
61
+
60
62
html = ast . root ;
61
63
}
62
64
}
@@ -65,45 +67,41 @@ export default function loader(html, map, meta) {
65
67
. process ( html , { from : file , to : file } )
66
68
. then ( ( { html, messages } ) => {
67
69
if ( meta && meta . messages ) {
68
- messages = messages . concat ( meta . messages )
70
+ messages = messages . concat ( meta . messages ) ;
69
71
}
70
-
72
+
71
73
const imports = messages
72
- . filter ( ( msg ) => msg . type === 'import' ? msg : false )
74
+ . filter ( ( msg ) => ( msg . type === 'import' ? msg : false ) )
73
75
. reduce ( ( imports , msg ) => {
74
76
try {
75
- msg = typeof msg . import === 'function'
76
- ? msg . import ( )
77
- : msg . import
77
+ msg = typeof msg . import === 'function' ? msg . import ( ) : msg . import ;
78
78
79
- imports += msg ;
79
+ imports += msg ;
80
80
} catch ( err ) {
81
81
// TODO(michael-ciniawsky)
82
82
// revisit HTMLImportError
83
- this . emitError ( err )
83
+ this . emitError ( err ) ;
84
84
}
85
85
86
- return imports
87
- } , '' )
86
+ return imports ;
87
+ } , '' ) ;
88
88
89
89
const exports = messages
90
- . filter ( ( msg ) => msg . type === 'export' ? msg : false )
91
- . reduce ( ( exports , msg ) => {
92
- try {
93
- msg = typeof msg . export === 'function'
94
- ? msg . import ( )
95
- : msg . import
90
+ . filter ( ( msg ) => ( msg . type === 'export' ? msg : false ) )
91
+ . reduce ( ( exports , msg ) => {
92
+ try {
93
+ msg = typeof msg . export === 'function' ? msg . import ( ) : msg . import ;
96
94
97
95
exports += msg ;
98
96
} catch ( err ) {
99
97
// TODO(michael-ciniawsky)
100
98
// revisit HTMLExportError
101
- this . emitError ( err )
99
+ this . emitError ( err ) ;
102
100
}
103
101
104
102
return exports ;
105
- } , '' )
106
-
103
+ } , '' ) ;
104
+
107
105
// TODO(michael-ciniawsky)
108
106
// HACK Ensure to cleanup/reset messages between files
109
107
// @see https://github.com/posthtml/posthtml/pull/250
0 commit comments