Skip to content

Commit 158f35b

Browse files
committed
parser should not crash if to many arguments are passed to an IIFE
fixes webpack#284
1 parent 2b6bfde commit 158f35b

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/Parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ Parser.prototype.walkExpression = function walkExpression(expression) {
597597
}), function() {
598598
args.forEach(function(arg, idx) {
599599
if(!arg) return;
600-
if(params[idx].type !== "Identifier") return;
600+
if(!params[idx] || params[idx].type !== "Identifier") return;
601601
this.scope.renames["$"+params[idx].name] = arg;
602602
}, this);
603603
if(functionExpression.body.type === "BlockStatement")

test/cases/parsing/renaming/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ it("should be able to rename stuff by IIFE call", function() {
5555
require);
5656
});
5757

58+
it("should accept less parameters in a IIFE call", function() {
59+
(function(r, require) {
60+
r("./file").should.be.eql("ok");
61+
(typeof require).should.be.eql("undefined");
62+
}(require));
63+
});
64+
65+
it("should accept more parameters in a IIFE call", function() {
66+
(function() {
67+
}(require));
68+
});
69+
5870
it("should be able to rename stuff by IIFE call", function() {
5971
(function(_exports, _module, _define, _require) {
6072
_define(function(R, E, M) {

0 commit comments

Comments
 (0)