Skip to content

Commit 58e7a2f

Browse files
committed
add simple returnTrue helper, less function definitions
1 parent 82eec17 commit 58e7a2f

File tree

7 files changed

+13
-19
lines changed

7 files changed

+13
-19
lines changed

lib/APIPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class APIPlugin {
4141
parser.plugin(`evaluate typeof ${key}`, ParserHelpers.evaluateToString(REPLACEMENT_TYPES[key]));
4242
});
4343
IGNORES.forEach(key => {
44-
parser.plugin(key, () => true);
44+
parser.plugin(key, ParserHelpers.returnTrue);
4545
});
4646
});
4747
});

lib/DefinePlugin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class DefinePlugin {
5454
const splittedKey = key.split(".");
5555
splittedKey.slice(1).forEach((_, i) => {
5656
const fullKey = prefix + splittedKey.slice(0, i + 1).join(".");
57-
parser.plugin("can-rename " + fullKey, () => true);
57+
parser.plugin("can-rename " + fullKey, ParserHelpers.returnTrue);
5858
});
5959
}
6060

@@ -65,7 +65,7 @@ class DefinePlugin {
6565
let recurseTypeof = false;
6666
code = toCode(code);
6767
if(!isTypeof) {
68-
parser.plugin("can-rename " + key, () => true);
68+
parser.plugin("can-rename " + key, ParserHelpers.returnTrue);
6969
parser.plugin("evaluate Identifier " + key, (expr) => {
7070
if(recurse) return;
7171
let res = parser.evaluate(code);
@@ -92,7 +92,7 @@ class DefinePlugin {
9292

9393
function applyObjectDefine(key, obj) {
9494
let code = stringifyObj(obj);
95-
parser.plugin("can-rename " + key, () => true);
95+
parser.plugin("can-rename " + key, ParserHelpers.returnTrue);
9696
parser.plugin("evaluate Identifier " + key, (expr) => new BasicEvaluatedExpression().setRange(expr.range));
9797
parser.plugin("evaluate typeof " + key, ParserHelpers.evaluateToString("object"));
9898
parser.plugin("expression " + key, ParserHelpers.toConstantDependency(code));

lib/HotModuleReplacementPlugin.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,7 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
252252
}.bind(this));
253253
}
254254
});
255-
parser.plugin("expression module.hot", function() {
256-
return true;
257-
});
255+
parser.plugin("expression module.hot", ParserHelpers.returnTrue);
258256
});
259257
});
260258

lib/ParserHelpers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@ ParserHelpers.expressionIsUnsupported = function expressionIsUnsupported(message
5656
return true;
5757
};
5858
};
59+
60+
ParserHelpers.returnTrue = function returnTrue() {
61+
return true;
62+
}

lib/ProvidePlugin.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ ProvidePlugin.prototype.apply = function(compiler) {
2323
if(splittedName.length > 0) {
2424
splittedName.slice(1).forEach(function(_, i) {
2525
var name = splittedName.slice(0, i + 1).join(".");
26-
parser.plugin("can-rename " + name, function() {
27-
return true;
28-
});
26+
parser.plugin("can-rename " + name, ParserHelpers.returnTrue);
2927
});
3028
}
3129
parser.plugin("expression " + name, function(expr) {

lib/dependencies/AMDPlugin.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ AMDPlugin.prototype.apply = function(compiler) {
8585
parser.plugin("evaluate Identifier require.amd", ParserHelpers.evaluateToBoolean(true));
8686
parser.plugin("typeof define", ParserHelpers.toConstantDependency(JSON.stringify("function")));
8787
parser.plugin("evaluate typeof define", ParserHelpers.evaluateToString("function"));
88-
parser.plugin("can-rename define", function() {
89-
return true;
90-
});
88+
parser.plugin("can-rename define", ParserHelpers.returnTrue);
9189
parser.plugin("rename define", function(expr) {
9290
var dep = new AMDRequireItemDependency("!!webpack amd define", expr.range);
9391
dep.userRequest = "define";

lib/dependencies/CommonJsPlugin.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,15 @@ CommonJsPlugin.prototype.apply = function(compiler) {
6868
this.scope.definitions.push("require");
6969
return true;
7070
});
71-
parser.plugin("can-rename require", function() {
72-
return true;
73-
});
71+
parser.plugin("can-rename require", ParserHelpers.returnTrue);
7472
parser.plugin("rename require", function(expr) {
7573
// define the require variable. It's still undefined, but not "not defined".
7674
var dep = new ConstDependency("var require;", 0);
7775
dep.loc = expr.loc;
7876
this.state.current.addDependency(dep);
7977
return false;
8078
});
81-
parser.plugin("typeof module", function() {
82-
return true;
83-
});
79+
parser.plugin("typeof module", ParserHelpers.returnTrue);
8480
parser.plugin("evaluate typeof exports", ParserHelpers.evaluateToString("object"));
8581
parser.apply(
8682
new CommonJsRequireDependencyParserPlugin(options),

0 commit comments

Comments
 (0)