@@ -197,6 +197,43 @@ class NormalModule extends Module {
197197 }
198198 }
199199
200+ applyNoParseRule ( rule , request ) {
201+ // must start with "rule" if rule is a string
202+ if ( typeof rule === "string" ) {
203+ return request . indexOf ( rule ) === 0 ;
204+ }
205+ // we assume rule is a regexp
206+ return rule . test ( request ) ;
207+ }
208+
209+ // check if module should not be parsed
210+ // returns "true" if the module should !not! be parsed
211+ // returns "false" if the module !must! be parsed
212+ preventParsing ( noParseRule , request ) {
213+ // if no noParseRule exists, return false
214+ // the module !must! be parsed.
215+ if ( ! noParseRule ) {
216+ return false ;
217+ }
218+
219+ // we only have one rule to check
220+ if ( ! Array . isArray ( noParseRule ) ) {
221+ // returns "true" if the module is !not! to be parsed
222+ return this . applyNoParseRule ( noParseRule , request ) ;
223+ }
224+
225+ for ( let i = 0 ; i < noParseRule . length ; i ++ ) {
226+ const rule = noParseRule [ i ] ;
227+ // early exit on first truthy match
228+ // this module is !not! to be parsed
229+ if ( this . applyNoParseRule ( rule , request ) ) {
230+ return true ;
231+ }
232+ }
233+ // no match found, so this module !should! be parsed
234+ return false ;
235+ }
236+
200237 build ( options , compilation , resolver , fs , callback ) {
201238 this . buildTimestamp = new Date ( ) . getTime ( ) ;
202239 this . built = true ;
@@ -211,23 +248,20 @@ class NormalModule extends Module {
211248 this . variables . length = 0 ;
212249 this . blocks . length = 0 ;
213250 this . _cachedSource = null ;
251+
252+ // if we have an error mark module as failed and exit
214253 if ( err ) {
215254 this . markModuleAsErrored ( ) ;
216255 return callback ( ) ;
217256 }
218- if ( options . module && options . module . noParse ) {
219- const testRegExp = function testRegExp ( regExp ) {
220- return typeof regExp === "string" ?
221- this . request . indexOf ( regExp ) === 0 :
222- regExp . test ( this . request ) ;
223- } ;
224- if ( Array . isArray ( options . module . noParse ) ) {
225- if ( options . module . noParse . some ( testRegExp , this ) )
226- return callback ( ) ;
227- } else if ( testRegExp . call ( this , options . module . noParse ) ) {
228- return callback ( ) ;
229- }
257+
258+ // check if this module should !not! be parsed.
259+ // if so, exit here;
260+ const noParseRule = options . module && options . module . noParse ;
261+ if ( this . preventParsing ( noParseRule , this . request ) ) {
262+ return callback ( ) ;
230263 }
264+
231265 try {
232266 this . parser . parse ( this . _source . source ( ) , {
233267 current : this ,
0 commit comments