@@ -37,7 +37,7 @@ module.exports = function loader (html, map, meta) {
3737 // Loader Options
3838 const options = loaderUtils . getOptions ( this ) || { }
3939
40- validateOptions ( schema , options , 'PostHTML Loader' )
40+ validateOptions ( schema , options , { name : 'PostHTML Loader' , baseDataPath : 'options' } )
4141
4242 // Make the loader async
4343 const cb = this . async ( )
@@ -84,80 +84,80 @@ module.exports = function loader (html, map, meta) {
8484
8585 return posthtmlrc ( rc . ctx , rc . path , { argv : false } )
8686 } )
87- . then ( ( config ) => {
88- if ( ! config ) config = { }
87+ . then ( ( config ) => {
88+ if ( ! config ) config = { }
8989
90- if ( config . file ) this . addDependency ( config . file )
90+ if ( config . file ) this . addDependency ( config . file )
9191
92- if ( config . options ) {
92+ if ( config . options ) {
9393 // Disable overriding `options.to` (`posthtml.config.js`)
94- if ( config . options . to ) delete config . options . to
95- // Disable overriding `options.from` (`posthtml.config.js`)
96- if ( config . options . from ) delete config . options . from
97- }
94+ if ( config . options . to ) delete config . options . to
95+ // Disable overriding `options.from` (`posthtml.config.js`)
96+ if ( config . options . from ) delete config . options . from
97+ }
9898
99- let plugins = config . plugins || [ ]
100- let options = Object . assign (
101- { from : file , to : file } ,
102- config . options
103- )
99+ const plugins = config . plugins || [ ]
100+ const options = Object . assign (
101+ { from : file , to : file } ,
102+ config . options
103+ )
104104
105- if ( typeof options . parser === 'string' ) {
106- options . parser = require ( options . parser ) ( )
107- }
105+ if ( typeof options . parser === 'string' ) {
106+ options . parser = require ( options . parser ) ( )
107+ }
108108
109- // TODO(michael-ciniawsky) enable if when custom renderer available
110- // if (typeof options.render === 'string') {
111- // options.render = require(options.render)()
112- // }
113-
114- return posthtml ( plugins )
115- . process ( html , options )
116- . then ( ( result ) => {
117- if ( result . messages ) {
118- result . messages . forEach ( ( msg ) => {
119- switch ( msg . type ) {
120- case 'error' :
121- this . emitError ( msg . message )
122-
123- break
124- case 'warning' :
125- this . emitWarning ( msg . message )
126-
127- break
128- case 'dependency' :
129- this . addDependency ( msg . file )
130-
131- break
132- default :
133- break
134- }
135- } )
136- }
109+ // TODO(michael-ciniawsky) enable if when custom renderer available
110+ // if (typeof options.render === 'string') {
111+ // options.render = require(options.render)()
112+ // }
137113
138- html = result . html
114+ return posthtml ( plugins )
115+ . process ( html , options )
116+ . then ( ( result ) => {
117+ if ( result . messages ) {
118+ result . messages . forEach ( ( msg ) => {
119+ switch ( msg . type ) {
120+ case 'error' :
121+ this . emitError ( msg . message )
139122
140- if ( this . loaderIndex === 0 ) {
141- html = `export default \`${ html } \``
123+ break
124+ case 'warning' :
125+ this . emitWarning ( msg . message )
142126
143- cb ( null , html )
127+ break
128+ case 'dependency' :
129+ this . addDependency ( msg . file )
144130
145- return null
146- }
131+ break
132+ default :
133+ break
134+ }
135+ } )
136+ }
147137
148- if ( ! meta ) meta = { }
138+ html = result . html
149139
150- meta . ast = { type : 'posthtml' , root : result . tree }
151- meta . messages = result . messages
140+ if ( this . loaderIndex === 0 ) {
141+ html = `export default \` ${ html } \``
152142
153- cb ( null , html , map , meta )
143+ cb ( null , html )
154144
155- return null
156- } )
157- } )
158- . catch ( ( err ) => {
159- cb ( new LoaderError ( err ) )
145+ return null
146+ }
160147
161- return null
162- } )
148+ if ( ! meta ) meta = { }
149+
150+ meta . ast = { type : 'posthtml' , root : result . tree }
151+ meta . messages = result . messages
152+
153+ cb ( null , html , map , meta )
154+
155+ return null
156+ } )
157+ } )
158+ . catch ( ( err ) => {
159+ cb ( new LoaderError ( err ) )
160+
161+ return null
162+ } )
163163}
0 commit comments