@@ -54,7 +54,10 @@ function createPriorityPreprocessor (config, preprocessorPriority, basePath, inj
54
54
return
55
55
}
56
56
57
- let p
57
+ let p = instances [ name ]
58
+ if ( p ) {
59
+ return p
60
+ }
58
61
59
62
try {
60
63
p = injector . get ( 'preprocessor:' + name )
@@ -68,6 +71,14 @@ function createPriorityPreprocessor (config, preprocessorPriority, basePath, inj
68
71
emitter . emit ( 'load_error' , 'preprocessor' , name )
69
72
}
70
73
74
+ if ( ! p && ! alreadyDisplayedErrors [ name ] ) {
75
+ alreadyDisplayedErrors [ name ] = true
76
+ log . error ( `Failed to instantiate preprocessor ${ name } ` )
77
+ emitter . emit ( 'load_error' , 'preprocessor' , name )
78
+ } else {
79
+ instances [ name ] = p
80
+ }
81
+
71
82
return p
72
83
}
73
84
@@ -107,31 +118,20 @@ function createPriorityPreprocessor (config, preprocessorPriority, basePath, inj
107
118
} )
108
119
109
120
// Apply preprocessor priority.
110
- let sortedPreprocessorNames = preprocessorNames
121
+ const preprocessors = preprocessorNames
111
122
. map ( ( name ) => [ name , preprocessorPriority [ name ] || 0 ] )
112
123
. sort ( ( a , b ) => b [ 1 ] - a [ 1 ] )
113
124
. map ( ( duo ) => duo [ 0 ] )
125
+ . reduce ( ( res , name ) => {
126
+ const p = instantiatePreprocessor ( name )
114
127
115
- let preprocessors = [ ]
116
- sortedPreprocessorNames . forEach ( ( name ) => {
117
- const p = instances [ name ] || instantiatePreprocessor ( name )
118
-
119
- if ( p == null ) {
120
- if ( ! alreadyDisplayedErrors [ name ] ) {
121
- alreadyDisplayedErrors [ name ] = true
122
- log . error ( `Failed to instantiate preprocessor ${ name } ` )
123
- emitter . emit ( 'load_error' , 'preprocessor' , name )
128
+ if ( ! isBinary || ( p && p . handleBinaryFiles ) ) {
129
+ res . push ( p )
130
+ } else {
131
+ log . warn ( `Ignored preprocessing ${ file . originalPath } because ${ name } has handleBinaryFiles=false.` )
124
132
}
125
- return
126
- }
127
-
128
- instances [ name ] = p
129
- if ( ! isBinary || p . handleBinaryFiles ) {
130
- preprocessors . push ( p )
131
- } else {
132
- log . warn ( `Ignored preprocessing ${ file . originalPath } because ${ name } has handleBinaryFiles=false.` )
133
- }
134
- } )
133
+ return res
134
+ } , [ ] )
135
135
136
136
runProcessors ( preprocessors , file , isBinary ? buffer : buffer . toString ( ) ) . then ( done , done )
137
137
} )
0 commit comments