Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Implement ES2016 check for simple parameter list in strict mode #106

Merged
merged 2 commits into from
Sep 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,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
Expand All @@ -893,7 +892,6 @@ pp.parseFunctionBody = function (node, allowExpression) {
if (directive.value.value === "use strict") {
isStrict = true;
checkLVal = true;
checkLValStrict = true;
break;
}
}
Expand All @@ -907,11 +905,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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function a([ option1, option2 ] = []) {
"use strict";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Non-simple parameter in strict mode (1:11)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function a([ option1, option2 ]) {
"use strict";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Non-simple parameter in strict mode (1:11)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var a = (options = {}) => options;
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{
"type": "File",
"start": 0,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 34
}
},
"program": {
"type": "Program",
"start": 0,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 34
}
},
"sourceType": "script",
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 34
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 4,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 33
}
},
"id": {
"type": "Identifier",
"start": 4,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 5
},
"identifierName": "a"
},
"name": "a"
},
"init": {
"type": "ArrowFunctionExpression",
"start": 8,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 33
}
},
"id": null,
"generator": false,
"expression": true,
"async": false,
"params": [
{
"type": "AssignmentPattern",
"start": 9,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 21
}
},
"left": {
"type": "Identifier",
"start": 9,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 16
},
"identifierName": "options"
},
"name": "options"
},
"right": {
"type": "ObjectExpression",
"start": 19,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 21
}
},
"properties": []
}
}
],
"body": {
"type": "Identifier",
"start": 26,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 26
},
"end": {
"line": 1,
"column": 33
},
"identifierName": "options"
},
"name": "options"
}
}
}
],
"kind": "var"
}
],
"directives": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var a = (options = {}) => {
"use strict";
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Non-simple parameter in strict mode (1:9)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var a = async (options = {}) => options;
Loading