mirror of https://github.com/webpack/webpack.git
add simple returnTrue helper, less function definitions
This commit is contained in:
parent
82eec175af
commit
58e7a2f30b
|
@ -41,7 +41,7 @@ class APIPlugin {
|
|||
parser.plugin(`evaluate typeof ${key}`, ParserHelpers.evaluateToString(REPLACEMENT_TYPES[key]));
|
||||
});
|
||||
IGNORES.forEach(key => {
|
||||
parser.plugin(key, () => true);
|
||||
parser.plugin(key, ParserHelpers.returnTrue);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -54,7 +54,7 @@ class DefinePlugin {
|
|||
const splittedKey = key.split(".");
|
||||
splittedKey.slice(1).forEach((_, i) => {
|
||||
const fullKey = prefix + splittedKey.slice(0, i + 1).join(".");
|
||||
parser.plugin("can-rename " + fullKey, () => true);
|
||||
parser.plugin("can-rename " + fullKey, ParserHelpers.returnTrue);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ class DefinePlugin {
|
|||
let recurseTypeof = false;
|
||||
code = toCode(code);
|
||||
if(!isTypeof) {
|
||||
parser.plugin("can-rename " + key, () => true);
|
||||
parser.plugin("can-rename " + key, ParserHelpers.returnTrue);
|
||||
parser.plugin("evaluate Identifier " + key, (expr) => {
|
||||
if(recurse) return;
|
||||
let res = parser.evaluate(code);
|
||||
|
@ -92,7 +92,7 @@ class DefinePlugin {
|
|||
|
||||
function applyObjectDefine(key, obj) {
|
||||
let code = stringifyObj(obj);
|
||||
parser.plugin("can-rename " + key, () => true);
|
||||
parser.plugin("can-rename " + key, ParserHelpers.returnTrue);
|
||||
parser.plugin("evaluate Identifier " + key, (expr) => new BasicEvaluatedExpression().setRange(expr.range));
|
||||
parser.plugin("evaluate typeof " + key, ParserHelpers.evaluateToString("object"));
|
||||
parser.plugin("expression " + key, ParserHelpers.toConstantDependency(code));
|
||||
|
|
|
@ -252,9 +252,7 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
|
|||
}.bind(this));
|
||||
}
|
||||
});
|
||||
parser.plugin("expression module.hot", function() {
|
||||
return true;
|
||||
});
|
||||
parser.plugin("expression module.hot", ParserHelpers.returnTrue);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -56,3 +56,7 @@ ParserHelpers.expressionIsUnsupported = function expressionIsUnsupported(message
|
|||
return true;
|
||||
};
|
||||
};
|
||||
|
||||
ParserHelpers.returnTrue = function returnTrue() {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -23,9 +23,7 @@ ProvidePlugin.prototype.apply = function(compiler) {
|
|||
if(splittedName.length > 0) {
|
||||
splittedName.slice(1).forEach(function(_, i) {
|
||||
var name = splittedName.slice(0, i + 1).join(".");
|
||||
parser.plugin("can-rename " + name, function() {
|
||||
return true;
|
||||
});
|
||||
parser.plugin("can-rename " + name, ParserHelpers.returnTrue);
|
||||
});
|
||||
}
|
||||
parser.plugin("expression " + name, function(expr) {
|
||||
|
|
|
@ -85,9 +85,7 @@ AMDPlugin.prototype.apply = function(compiler) {
|
|||
parser.plugin("evaluate Identifier require.amd", ParserHelpers.evaluateToBoolean(true));
|
||||
parser.plugin("typeof define", ParserHelpers.toConstantDependency(JSON.stringify("function")));
|
||||
parser.plugin("evaluate typeof define", ParserHelpers.evaluateToString("function"));
|
||||
parser.plugin("can-rename define", function() {
|
||||
return true;
|
||||
});
|
||||
parser.plugin("can-rename define", ParserHelpers.returnTrue);
|
||||
parser.plugin("rename define", function(expr) {
|
||||
var dep = new AMDRequireItemDependency("!!webpack amd define", expr.range);
|
||||
dep.userRequest = "define";
|
||||
|
|
|
@ -68,9 +68,7 @@ CommonJsPlugin.prototype.apply = function(compiler) {
|
|||
this.scope.definitions.push("require");
|
||||
return true;
|
||||
});
|
||||
parser.plugin("can-rename require", function() {
|
||||
return true;
|
||||
});
|
||||
parser.plugin("can-rename require", ParserHelpers.returnTrue);
|
||||
parser.plugin("rename require", function(expr) {
|
||||
// define the require variable. It's still undefined, but not "not defined".
|
||||
var dep = new ConstDependency("var require;", 0);
|
||||
|
@ -78,9 +76,7 @@ CommonJsPlugin.prototype.apply = function(compiler) {
|
|||
this.state.current.addDependency(dep);
|
||||
return false;
|
||||
});
|
||||
parser.plugin("typeof module", function() {
|
||||
return true;
|
||||
});
|
||||
parser.plugin("typeof module", ParserHelpers.returnTrue);
|
||||
parser.plugin("evaluate typeof exports", ParserHelpers.evaluateToString("object"));
|
||||
parser.apply(
|
||||
new CommonJsRequireDependencyParserPlugin(options),
|
||||
|
|
Loading…
Reference in New Issue