mirror of https://github.com/webpack/webpack.git
split out noParse check for modules
This commit is contained in:
parent
93377f7bc4
commit
1e4d9297b4
|
|
@ -197,6 +197,43 @@ class NormalModule extends Module {
|
|||
}
|
||||
}
|
||||
|
||||
applyNoParseRule(rule, request) {
|
||||
// must start with "rule" if rule is a string
|
||||
if(typeof rule === "string") {
|
||||
return request.indexOf(rule) === 0;
|
||||
}
|
||||
// we assume rule is a regexp
|
||||
return rule.test(request);
|
||||
}
|
||||
|
||||
// check if module should not be parsed
|
||||
// returns "true" if the module should !not! be parsed
|
||||
// returns "false" if the module !must! be parsed
|
||||
preventParsing(noParseRule, request) {
|
||||
// if no noParseRule exists, return false
|
||||
// the module !must! be parsed.
|
||||
if(!noParseRule) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// we only have one rule to check
|
||||
if(!Array.isArray(noParseRule)) {
|
||||
// returns "true" if the module is !not! to be parsed
|
||||
return this.applyNoParseRule(noParseRule, request);
|
||||
}
|
||||
|
||||
for(let i = 0; i < noParseRule.length; i++) {
|
||||
const rule = noParseRule[i];
|
||||
// early exit on first truthy match
|
||||
// this module is !not! to be parsed
|
||||
if(this.applyNoParseRule(rule, request)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// no match found, so this module !should! be parsed
|
||||
return false;
|
||||
}
|
||||
|
||||
build(options, compilation, resolver, fs, callback) {
|
||||
this.buildTimestamp = new Date().getTime();
|
||||
this.built = true;
|
||||
|
|
@ -211,23 +248,20 @@ class NormalModule extends Module {
|
|||
this.variables.length = 0;
|
||||
this.blocks.length = 0;
|
||||
this._cachedSource = null;
|
||||
|
||||
// if we have an error mark module as failed and exit
|
||||
if(err) {
|
||||
this.markModuleAsErrored();
|
||||
return callback();
|
||||
}
|
||||
if(options.module && options.module.noParse) {
|
||||
const testRegExp = function testRegExp(regExp) {
|
||||
return typeof regExp === "string" ?
|
||||
this.request.indexOf(regExp) === 0 :
|
||||
regExp.test(this.request);
|
||||
};
|
||||
if(Array.isArray(options.module.noParse)) {
|
||||
if(options.module.noParse.some(testRegExp, this))
|
||||
return callback();
|
||||
} else if(testRegExp.call(this, options.module.noParse)) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
// check if this module should !not! be parsed.
|
||||
// if so, exit here;
|
||||
const noParseRule = options.module && options.module.noParse;
|
||||
if(this.preventParsing(noParseRule, this.request)) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
try {
|
||||
this.parser.parse(this._source.source(), {
|
||||
current: this,
|
||||
|
|
|
|||
Loading…
Reference in New Issue