Skip to content

Commit 2caec48

Browse files
fix(parser): check called function expressions for reserved binding names
1 parent c0d8599 commit 2caec48

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

lib/javascript/JavascriptParser.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4379,6 +4379,16 @@ class JavascriptParser extends Parser {
43794379
};
43804380
const { params, type } = functionExpression;
43814381
const arrow = type === "ArrowFunctionExpression";
4382+
// the walk skips walkFunctionExpression for a called function expression
4383+
if (this._strictInModuleOutput) {
4384+
this._checkStrictModeParams(params);
4385+
if (type === "FunctionExpression" && functionExpression.id) {
4386+
this._checkStrictModeBinding(
4387+
functionExpression.id.name,
4388+
functionExpression.id
4389+
);
4390+
}
4391+
}
43824392
const renameThis = currentThis ? getVarInfo(currentThis) : null;
43834393
const varInfoForArgs = options.map(getVarInfo);
43844394
const wasTopLevel = this.scope.topLevelScope;

test/configCases/parsing/strict-mode-module-output-bindings/mod.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ function awaitParam(await) {
4040
// A named class expression binds its name, same as a declaration.
4141
var namedClass = class await {};
4242

43+
// A called function expression is walked as an IIFE, not through
44+
// walkFunctionExpression.
45+
var iifeName = (function yield() {
46+
return 1;
47+
})();
48+
var iifeParam = (function (static) {
49+
return static;
50+
})(1);
51+
4352
// Unaffected: reserved words are valid as property and method names.
4453
var properties = { static: 1, public: 2, await: 3 };
4554
var readsProperty = properties.static + properties.public;
@@ -60,6 +69,8 @@ module.exports = {
6069
arrowParam,
6170
awaitParam,
6271
namedClass,
72+
iifeName,
73+
iifeParam,
6374
readsProperty,
6475
normalBinding
6576
};

test/configCases/parsing/strict-mode-module-output-bindings/warnings.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,17 @@ module.exports = [
3636
}
3737
],
3838
[{ message: /"await" is not allowed as a parameter name/ }],
39-
[{ message: /"await" is not allowed as a binding name/ }]
39+
[{ message: /"await" is not allowed as a binding name/ }],
40+
[
41+
{
42+
message:
43+
/"yield" is a reserved word in strict mode and is not allowed as a binding name/
44+
}
45+
],
46+
[
47+
{
48+
message:
49+
/"static" is a reserved word in strict mode and is not allowed as a parameter name/
50+
}
51+
]
4052
];

0 commit comments

Comments
 (0)
Sponsor
SponsoredKunjungi sekarang
Promo