Implement ES2016 check for simple parameter list in strict mode (#106)
* Slightly simplify logic * Implement ES2016 check for simple parameter list in strict mode See e.g. ECMA-262 7.0 14.1.2: > It is a Syntax Error if ContainsUseStrict of FunctionBody is true and > IsSimpleParameterList of FormalParameters is false. Similar clauses cover arrow functions, generator functions, methods, and generator methods, as well as async functions and async arrow functions.
This commit is contained in:
committed by
Daniel Tschinder
parent
64145b07e3
commit
643d3f37a4
@@ -885,7 +885,6 @@ pp.parseFunctionBody = function (node, allowExpression) {
|
||||
// are not repeated, and it does not try to bind the words `eval`
|
||||
// or `arguments`.
|
||||
let checkLVal = this.state.strict;
|
||||
let checkLValStrict = false;
|
||||
let isStrict = false;
|
||||
|
||||
// arrow function
|
||||
@@ -897,7 +896,6 @@ pp.parseFunctionBody = function (node, allowExpression) {
|
||||
if (directive.value.value === "use strict") {
|
||||
isStrict = true;
|
||||
checkLVal = true;
|
||||
checkLValStrict = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -911,11 +909,14 @@ pp.parseFunctionBody = function (node, allowExpression) {
|
||||
if (checkLVal) {
|
||||
let nameHash = Object.create(null);
|
||||
let oldStrict = this.state.strict;
|
||||
if (checkLValStrict) this.state.strict = true;
|
||||
if (isStrict) this.state.strict = true;
|
||||
if (node.id) {
|
||||
this.checkLVal(node.id, true);
|
||||
}
|
||||
for (let param of (node.params: Array<Object>)) {
|
||||
if (isStrict && param.type !== "Identifier") {
|
||||
this.raise(param.start, "Non-simple parameter in strict mode");
|
||||
}
|
||||
this.checkLVal(param, true, nameHash);
|
||||
}
|
||||
this.state.strict = oldStrict;
|
||||
|
||||
Reference in New Issue
Block a user