mirror of https://github.com/webpack/webpack.git
fixed #627
This commit is contained in:
parent
0e21e6ec0b
commit
9d5113827f
|
|
@ -37,15 +37,22 @@ CommonJsRequireDependencyParserPlugin.prototype.apply = function(parser) {
|
|||
var localModule;
|
||||
var param = this.evaluateExpression(expr.arguments[0]);
|
||||
if(param.isConditional()) {
|
||||
var isExpression = false;
|
||||
var prevLength = this.state.current.dependencies.length;
|
||||
this.state.current.addDependency(new RequireHeaderDependency(expr.callee.range));
|
||||
param.options.forEach(function(param) {
|
||||
var result = this.applyPluginsBailResult("call require:commonjs:item", expr, param);
|
||||
if(result === undefined) {
|
||||
throw new Error("Cannot convert options with mixed known and unknown stuff");
|
||||
isExpression = true;
|
||||
}
|
||||
}, this);
|
||||
return true;
|
||||
} else if(param.isString() && (localModule = LocalModulesHelpers.getLocalModule(this.state, param.string))) {
|
||||
if(isExpression) {
|
||||
this.state.current.dependencies.length = prevLength;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(param.isString() && (localModule = LocalModulesHelpers.getLocalModule(this.state, param.string))) {
|
||||
var dep = new LocalModuleDependency(localModule, expr.range);
|
||||
dep.loc = expr.loc;
|
||||
this.state.current.addDependency(dep);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
(function() {
|
||||
var expr1 = "a", expr2 = "b";
|
||||
require(Math.random() < 0.5 ? expr1 : expr2);
|
||||
}).should.throw();
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
it("should compile expr in ?: operator", function() {
|
||||
require("./dir/test");
|
||||
});
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = [
|
||||
[/Critical dependencies/]
|
||||
];
|
||||
Loading…
Reference in New Issue