@@ -40,45 +40,45 @@ class Watching {
4040 }
4141
4242 _go ( ) {
43- const self = this ;
44- self . startTime = Date . now ( ) ;
45- self . running = true ;
46- self . invalid = false ;
47- self . compiler . applyPluginsAsync ( "watch-run" , self , err => {
48- if ( err ) return self . _done ( err ) ;
49- self . compiler . compile ( function onCompiled ( err , compilation ) {
50- if ( err ) return self . _done ( err ) ;
51- if ( self . invalid ) return self . _done ( ) ;
52-
53- if ( self . compiler . applyPluginsBailResult ( "should-emit" , compilation ) === false ) {
54- return self . _done ( null , compilation ) ;
43+ this . startTime = Date . now ( ) ;
44+ this . running = true ;
45+ this . invalid = false ;
46+ this . compiler . applyPluginsAsync ( "watch-run" , this , err => {
47+ if ( err ) return this . _done ( err ) ;
48+ const onCompiled = ( err , compilation ) => {
49+ if ( err ) return this . _done ( err ) ;
50+ if ( this . invalid ) return this . _done ( ) ;
51+
52+ if ( this . compiler . applyPluginsBailResult ( "should-emit" , compilation ) === false ) {
53+ return this . _done ( null , compilation ) ;
5554 }
5655
57- self . compiler . emitAssets ( compilation , err => {
58- if ( err ) return self . _done ( err ) ;
59- if ( self . invalid ) return self . _done ( ) ;
56+ this . compiler . emitAssets ( compilation , err => {
57+ if ( err ) return this . _done ( err ) ;
58+ if ( this . invalid ) return this . _done ( ) ;
6059
61- self . compiler . emitRecords ( err => {
62- if ( err ) return self . _done ( err ) ;
60+ this . compiler . emitRecords ( err => {
61+ if ( err ) return this . _done ( err ) ;
6362
6463 if ( compilation . applyPluginsBailResult ( "need-additional-pass" ) ) {
6564 compilation . needAdditionalPass = true ;
6665
6766 const stats = new Stats ( compilation ) ;
68- stats . startTime = self . startTime ;
67+ stats . startTime = this . startTime ;
6968 stats . endTime = Date . now ( ) ;
70- self . compiler . applyPlugins ( "done" , stats ) ;
69+ this . compiler . applyPlugins ( "done" , stats ) ;
7170
72- self . compiler . applyPluginsAsync ( "additional-pass" , err => {
73- if ( err ) return self . _done ( err ) ;
74- self . compiler . compiler ( onCompiled ) ;
71+ this . compiler . applyPluginsAsync ( "additional-pass" , err => {
72+ if ( err ) return this . _done ( err ) ;
73+ this . compiler . compiler ( onCompiled ) ;
7574 } ) ;
7675 return ;
7776 }
78- return self . _done ( null , compilation ) ;
77+ return this . _done ( null , compilation ) ;
7978 } ) ;
8079 } ) ;
81- } ) ;
80+ } ;
81+ this . compiler . compile ( onCompiled ) ;
8282 } ) ;
8383 }
8484
@@ -226,58 +226,59 @@ module.exports = class Compiler extends Tapable {
226226 }
227227
228228 run ( callback ) {
229- const self = this ;
230229 const startTime = Date . now ( ) ;
231230
232- self . applyPluginsAsync ( "before-run" , self , err => {
231+ const onCompiled = ( err , compilation ) => {
233232 if ( err ) return callback ( err ) ;
234233
235- self . applyPluginsAsync ( "run" , self , err => {
234+ if ( this . applyPluginsBailResult ( "should-emit" , compilation ) === false ) {
235+ const stats = new Stats ( compilation ) ;
236+ stats . startTime = startTime ;
237+ stats . endTime = Date . now ( ) ;
238+ this . applyPlugins ( "done" , stats ) ;
239+ return callback ( null , stats ) ;
240+ }
241+
242+ this . emitAssets ( compilation , err => {
236243 if ( err ) return callback ( err ) ;
237244
238- self . readRecords ( err => {
239- if ( err ) return callback ( err ) ;
245+ if ( compilation . applyPluginsBailResult ( "need-additional-pass" ) ) {
246+ compilation . needAdditionalPass = true ;
240247
241- self . compile ( function onCompiled ( err , compilation ) {
242- if ( err ) return callback ( err ) ;
248+ const stats = new Stats ( compilation ) ;
249+ stats . startTime = startTime ;
250+ stats . endTime = Date . now ( ) ;
251+ this . applyPlugins ( "done" , stats ) ;
243252
244- if ( self . applyPluginsBailResult ( "should-emit" , compilation ) === false ) {
245- const stats = new Stats ( compilation ) ;
246- stats . startTime = startTime ;
247- stats . endTime = Date . now ( ) ;
248- self . applyPlugins ( "done" , stats ) ;
249- return callback ( null , stats ) ;
250- }
253+ this . applyPluginsAsync ( "additional-pass" , err => {
254+ if ( err ) return callback ( err ) ;
255+ this . compile ( onCompiled ) ;
256+ } ) ;
257+ return ;
258+ }
251259
252- self . emitAssets ( compilation , err => {
253- if ( err ) return callback ( err ) ;
260+ this . emitRecords ( err => {
261+ if ( err ) return callback ( err ) ;
254262
255- if ( compilation . applyPluginsBailResult ( "need-additional-pass" ) ) {
256- compilation . needAdditionalPass = true ;
263+ const stats = new Stats ( compilation ) ;
264+ stats . startTime = startTime ;
265+ stats . endTime = Date . now ( ) ;
266+ this . applyPlugins ( "done" , stats ) ;
267+ return callback ( null , stats ) ;
268+ } ) ;
269+ } ) ;
270+ } ;
257271
258- const stats = new Stats ( compilation ) ;
259- stats . startTime = startTime ;
260- stats . endTime = Date . now ( ) ;
261- self . applyPlugins ( "done" , stats ) ;
272+ this . applyPluginsAsync ( "before-run" , this , err => {
273+ if ( err ) return callback ( err ) ;
262274
263- self . applyPluginsAsync ( "additional-pass" , err => {
264- if ( err ) return callback ( err ) ;
265- self . compile ( onCompiled ) ;
266- } ) ;
267- return ;
268- }
275+ this . applyPluginsAsync ( "run" , this , err => {
276+ if ( err ) return callback ( err ) ;
269277
270- self . emitRecords ( err => {
271- if ( err ) return callback ( err ) ;
278+ this . readRecords ( err => {
279+ if ( err ) return callback ( err ) ;
272280
273- const stats = new Stats ( compilation ) ;
274- stats . startTime = startTime ;
275- stats . endTime = Date . now ( ) ;
276- self . applyPlugins ( "done" , stats ) ;
277- return callback ( null , stats ) ;
278- } ) ;
279- } ) ;
280- } ) ;
281+ this . compile ( onCompiled ) ;
281282 } ) ;
282283 } ) ;
283284 } ) ;
@@ -387,21 +388,20 @@ module.exports = class Compiler extends Tapable {
387388 }
388389
389390 readRecords ( callback ) {
390- const self = this ;
391- if ( ! self . recordsInputPath ) {
392- self . records = { } ;
391+ if ( ! this . recordsInputPath ) {
392+ this . records = { } ;
393393 return callback ( ) ;
394394 }
395- self . inputFileSystem . stat ( self . recordsInputPath , err => {
395+ this . inputFileSystem . stat ( this . recordsInputPath , err => {
396396 // It doesn't exist
397- // We can ignore self .
397+ // We can ignore this .
398398 if ( err ) return callback ( ) ;
399399
400- self . inputFileSystem . readFile ( self . recordsInputPath , ( err , content ) => {
400+ this . inputFileSystem . readFile ( this . recordsInputPath , ( err , content ) => {
401401 if ( err ) return callback ( err ) ;
402402
403403 try {
404- self . records = JSON . parse ( content . toString ( "utf-8" ) ) ;
404+ this . records = JSON . parse ( content . toString ( "utf-8" ) ) ;
405405 } catch ( e ) {
406406 e . message = "Cannot parse records: " + e . message ;
407407 return callback ( e ) ;
@@ -496,24 +496,23 @@ module.exports = class Compiler extends Tapable {
496496 }
497497
498498 compile ( callback ) {
499- const self = this ;
500- const params = self . newCompilationParams ( ) ;
501- self . applyPluginsAsync ( "before-compile" , params , err => {
499+ const params = this . newCompilationParams ( ) ;
500+ this . applyPluginsAsync ( "before-compile" , params , err => {
502501 if ( err ) return callback ( err ) ;
503502
504- self . applyPlugins ( "compile" , params ) ;
503+ this . applyPlugins ( "compile" , params ) ;
505504
506- const compilation = self . newCompilation ( params ) ;
505+ const compilation = this . newCompilation ( params ) ;
507506
508- self . applyPluginsParallel ( "make" , compilation , err => {
507+ this . applyPluginsParallel ( "make" , compilation , err => {
509508 if ( err ) return callback ( err ) ;
510509
511510 compilation . finish ( ) ;
512511
513512 compilation . seal ( err => {
514513 if ( err ) return callback ( err ) ;
515514
516- self . applyPluginsAsync ( "after-compile" , compilation , err => {
515+ this . applyPluginsAsync ( "after-compile" , compilation , err => {
517516 if ( err ) return callback ( err ) ;
518517
519518 return callback ( null , compilation ) ;
0 commit comments