Skip to content

Commit f5e6c6b

Browse files
committed
make AMD require work without fn expr
1 parent 3e7fc1c commit f5e6c6b

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ module.exports = AbstractPlugin.create({
5959
case 2:
6060
var param = this.evaluateExpression(expr.arguments[0]);
6161
if(!param.isArray()) return;
62-
if(expr.arguments[1].type !== "FunctionExpression") return;
6362
var dep = new AMDRequireDependenciesBlock(expr, param.range, expr.arguments[1].range);
6463
dep.loc = expr.loc;
6564
var old = this.state.current;
@@ -73,14 +72,16 @@ module.exports = AbstractPlugin.create({
7372
}
7473
}, this);
7574
}.bind(this));
76-
this.inScope(expr.arguments[1].params.filter(function(i) {
77-
return ["require", "module", "exports"].indexOf(i.name) < 0;
78-
}), function() {
79-
if(expr.arguments[1].body.type === "BlockStatement")
80-
this.walkStatement(expr.arguments[1].body);
81-
else
82-
this.walkExpression(expr.arguments[1].body);
83-
}.bind(this));
75+
if(expr.arguments[1].type === "FunctionExpression") {
76+
this.inScope(expr.arguments[1].params.filter(function(i) {
77+
return ["require", "module", "exports"].indexOf(i.name) < 0;
78+
}), function() {
79+
if(expr.arguments[1].body.type === "BlockStatement")
80+
this.walkStatement(expr.arguments[1].body);
81+
else
82+
this.walkExpression(expr.arguments[1].body);
83+
}.bind(this));
84+
}
8485
} finally {
8586
this.state.current = old;
8687
this.state.current.addBlock(dep);

test/browsertest/lib/index.web.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,16 @@ describe("main", function() {
407407
it("should not crash on require.js require only with array", function() {
408408
require(["./circular"]);
409409
});
410+
it("should be able to use AMD require without function expression (empty array)", function(done) {
411+
require([], done);
412+
});
413+
it("should be able to use AMD require without function expression", function(done) {
414+
require(["./circular"], fn);
415+
function fn(c) {
416+
c.should.be.eql(1);
417+
done();
418+
}
419+
});
410420
it("should create a chunk for require.js require", function(done) {
411421
var sameTick = true;
412422
require(["./c"], function(c) {

0 commit comments

Comments
 (0)