Skip to content

Commit 9d51138

Browse files
committed
fixed webpack#627
1 parent 0e21e6e commit 9d51138

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

‎lib/dependencies/CommonJsRequireDependencyParserPlugin.js‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,22 @@ CommonJsRequireDependencyParserPlugin.prototype.apply = function(parser) {
3737
var localModule;
3838
var param = this.evaluateExpression(expr.arguments[0]);
3939
if(param.isConditional()) {
40+
var isExpression = false;
41+
var prevLength = this.state.current.dependencies.length;
4042
this.state.current.addDependency(new RequireHeaderDependency(expr.callee.range));
4143
param.options.forEach(function(param) {
4244
var result = this.applyPluginsBailResult("call require:commonjs:item", expr, param);
4345
if(result === undefined) {
44-
throw new Error("Cannot convert options with mixed known and unknown stuff");
46+
isExpression = true;
4547
}
4648
}, this);
47-
return true;
48-
} else if(param.isString() && (localModule = LocalModulesHelpers.getLocalModule(this.state, param.string))) {
49+
if(isExpression) {
50+
this.state.current.dependencies.length = prevLength;
51+
} else {
52+
return true;
53+
}
54+
}
55+
if(param.isString() && (localModule = LocalModulesHelpers.getLocalModule(this.state, param.string))) {
4956
var dep = new LocalModuleDependency(localModule, expr.range);
5057
dep.loc = expr.loc;
5158
this.state.current.addDependency(dep);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(function() {
2+
var expr1 = "a", expr2 = "b";
3+
require(Math.random() < 0.5 ? expr1 : expr2);
4+
}).should.throw();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
it("should compile expr in ?: operator", function() {
2+
require("./dir/test");
3+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = [
2+
[/Critical dependencies/]
3+
];

0 commit comments

Comments
 (0)