diff --git a/src/parser/expression.js b/src/parser/expression.js index 2f00e5d1a5..6159d306f6 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -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)) { + if (isStrict && param.type !== "Identifier") { + this.raise(param.start, "Non-simple parameter in strict mode"); + } this.checkLVal(param, true, nameHash); } this.state.strict = oldStrict; diff --git a/test/fixtures/es2016/simple-parameter-list/array-pattern-default/actual.js b/test/fixtures/es2016/simple-parameter-list/array-pattern-default/actual.js new file mode 100644 index 0000000000..ed9b603687 --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/array-pattern-default/actual.js @@ -0,0 +1,3 @@ +function a([ option1, option2 ] = []) { + "use strict"; +} diff --git a/test/fixtures/es2016/simple-parameter-list/array-pattern-default/options.json b/test/fixtures/es2016/simple-parameter-list/array-pattern-default/options.json new file mode 100644 index 0000000000..5a257f4e5d --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/array-pattern-default/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Non-simple parameter in strict mode (1:11)" +} diff --git a/test/fixtures/es2016/simple-parameter-list/array-pattern/actual.js b/test/fixtures/es2016/simple-parameter-list/array-pattern/actual.js new file mode 100644 index 0000000000..2d5d9ede78 --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/array-pattern/actual.js @@ -0,0 +1,3 @@ +function a([ option1, option2 ]) { + "use strict"; +} diff --git a/test/fixtures/es2016/simple-parameter-list/array-pattern/options.json b/test/fixtures/es2016/simple-parameter-list/array-pattern/options.json new file mode 100644 index 0000000000..5a257f4e5d --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/array-pattern/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Non-simple parameter in strict mode (1:11)" +} diff --git a/test/fixtures/es2016/simple-parameter-list/arrow-function-concise-body/actual.js b/test/fixtures/es2016/simple-parameter-list/arrow-function-concise-body/actual.js new file mode 100644 index 0000000000..770cce6026 --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/arrow-function-concise-body/actual.js @@ -0,0 +1 @@ +var a = (options = {}) => options; diff --git a/test/fixtures/es2016/simple-parameter-list/arrow-function-concise-body/expected.json b/test/fixtures/es2016/simple-parameter-list/arrow-function-concise-body/expected.json new file mode 100644 index 0000000000..647180b64a --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/arrow-function-concise-body/expected.json @@ -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": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2016/simple-parameter-list/arrow-function/actual.js b/test/fixtures/es2016/simple-parameter-list/arrow-function/actual.js new file mode 100644 index 0000000000..eecf8d53da --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/arrow-function/actual.js @@ -0,0 +1,3 @@ +var a = (options = {}) => { + "use strict"; +}; diff --git a/test/fixtures/es2016/simple-parameter-list/arrow-function/options.json b/test/fixtures/es2016/simple-parameter-list/arrow-function/options.json new file mode 100644 index 0000000000..2e6ae0771c --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/arrow-function/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Non-simple parameter in strict mode (1:9)" +} diff --git a/test/fixtures/es2016/simple-parameter-list/async-arrow-function-concise-body/actual.js b/test/fixtures/es2016/simple-parameter-list/async-arrow-function-concise-body/actual.js new file mode 100644 index 0000000000..4c592c16b6 --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/async-arrow-function-concise-body/actual.js @@ -0,0 +1 @@ +var a = async (options = {}) => options; diff --git a/test/fixtures/es2016/simple-parameter-list/async-arrow-function-concise-body/expected.json b/test/fixtures/es2016/simple-parameter-list/async-arrow-function-concise-body/expected.json new file mode 100644 index 0000000000..419b4797ef --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/async-arrow-function-concise-body/expected.json @@ -0,0 +1,170 @@ +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "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": 39, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "id": null, + "generator": false, + "expression": true, + "async": true, + "params": [ + { + "type": "AssignmentPattern", + "start": 15, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "left": { + "type": "Identifier", + "start": 15, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 22 + }, + "identifierName": "options" + }, + "name": "options" + }, + "right": { + "type": "ObjectExpression", + "start": 25, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "properties": [] + } + } + ], + "body": { + "type": "Identifier", + "start": 32, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 39 + }, + "identifierName": "options" + }, + "name": "options" + } + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2016/simple-parameter-list/async-arrow-function/actual.js b/test/fixtures/es2016/simple-parameter-list/async-arrow-function/actual.js new file mode 100644 index 0000000000..a36e097d8e --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/async-arrow-function/actual.js @@ -0,0 +1,3 @@ +var a = async (options = {}) => { + "use strict"; +}; diff --git a/test/fixtures/es2016/simple-parameter-list/async-arrow-function/options.json b/test/fixtures/es2016/simple-parameter-list/async-arrow-function/options.json new file mode 100644 index 0000000000..0c31636171 --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/async-arrow-function/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Non-simple parameter in strict mode (1:15)" +} diff --git a/test/fixtures/es2016/simple-parameter-list/async-function/actual.js b/test/fixtures/es2016/simple-parameter-list/async-function/actual.js new file mode 100644 index 0000000000..639b9e9289 --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/async-function/actual.js @@ -0,0 +1,3 @@ +async function a(options = {}) { + "use strict"; +} diff --git a/test/fixtures/es2016/simple-parameter-list/async-function/options.json b/test/fixtures/es2016/simple-parameter-list/async-function/options.json new file mode 100644 index 0000000000..ff8a46ae1a --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/async-function/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Non-simple parameter in strict mode (1:17)" +} diff --git a/test/fixtures/es2016/simple-parameter-list/default/actual.js b/test/fixtures/es2016/simple-parameter-list/default/actual.js new file mode 100644 index 0000000000..067bc955d5 --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/default/actual.js @@ -0,0 +1,3 @@ +function a(options = {}) { + "use strict"; +} diff --git a/test/fixtures/es2016/simple-parameter-list/default/options.json b/test/fixtures/es2016/simple-parameter-list/default/options.json new file mode 100644 index 0000000000..5a257f4e5d --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/default/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Non-simple parameter in strict mode (1:11)" +} diff --git a/test/fixtures/es2016/simple-parameter-list/generator-function/actual.js b/test/fixtures/es2016/simple-parameter-list/generator-function/actual.js new file mode 100644 index 0000000000..c63c64a049 --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/generator-function/actual.js @@ -0,0 +1,3 @@ +function* a(options = {}) { + "use strict"; +} diff --git a/test/fixtures/es2016/simple-parameter-list/generator-function/options.json b/test/fixtures/es2016/simple-parameter-list/generator-function/options.json new file mode 100644 index 0000000000..65ff709b5f --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/generator-function/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Non-simple parameter in strict mode (1:12)" +} diff --git a/test/fixtures/es2016/simple-parameter-list/generator-method/actual.js b/test/fixtures/es2016/simple-parameter-list/generator-method/actual.js new file mode 100644 index 0000000000..1f34608a28 --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/generator-method/actual.js @@ -0,0 +1,5 @@ +var obj = { + * a(options = {}) { + "use strict"; + } +}; diff --git a/test/fixtures/es2016/simple-parameter-list/generator-method/options.json b/test/fixtures/es2016/simple-parameter-list/generator-method/options.json new file mode 100644 index 0000000000..dd467e6578 --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/generator-method/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Non-simple parameter in strict mode (2:6)" +} diff --git a/test/fixtures/es2016/simple-parameter-list/method/actual.js b/test/fixtures/es2016/simple-parameter-list/method/actual.js new file mode 100644 index 0000000000..2090882ad4 --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/method/actual.js @@ -0,0 +1,5 @@ +var obj = { + a(options = {}) { + "use strict"; + } +}; diff --git a/test/fixtures/es2016/simple-parameter-list/method/options.json b/test/fixtures/es2016/simple-parameter-list/method/options.json new file mode 100644 index 0000000000..ac620235e9 --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/method/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Non-simple parameter in strict mode (2:4)" +} diff --git a/test/fixtures/es2016/simple-parameter-list/object-pattern-default/actual.js b/test/fixtures/es2016/simple-parameter-list/object-pattern-default/actual.js new file mode 100644 index 0000000000..236c9a3043 --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/object-pattern-default/actual.js @@ -0,0 +1,3 @@ +function a({ option1, option2 } = {}) { + "use strict"; +} diff --git a/test/fixtures/es2016/simple-parameter-list/object-pattern-default/options.json b/test/fixtures/es2016/simple-parameter-list/object-pattern-default/options.json new file mode 100644 index 0000000000..5a257f4e5d --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/object-pattern-default/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Non-simple parameter in strict mode (1:11)" +} diff --git a/test/fixtures/es2016/simple-parameter-list/object-pattern/actual.js b/test/fixtures/es2016/simple-parameter-list/object-pattern/actual.js new file mode 100644 index 0000000000..103c5af584 --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/object-pattern/actual.js @@ -0,0 +1,3 @@ +function a({ option1, option2 }) { + "use strict"; +} diff --git a/test/fixtures/es2016/simple-parameter-list/object-pattern/options.json b/test/fixtures/es2016/simple-parameter-list/object-pattern/options.json new file mode 100644 index 0000000000..5a257f4e5d --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/object-pattern/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Non-simple parameter in strict mode (1:11)" +} diff --git a/test/fixtures/es2016/simple-parameter-list/rest/actual.js b/test/fixtures/es2016/simple-parameter-list/rest/actual.js new file mode 100644 index 0000000000..f1ddd04a7d --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/rest/actual.js @@ -0,0 +1,3 @@ +function a(...options) { + "use strict"; +} diff --git a/test/fixtures/es2016/simple-parameter-list/rest/options.json b/test/fixtures/es2016/simple-parameter-list/rest/options.json new file mode 100644 index 0000000000..5a257f4e5d --- /dev/null +++ b/test/fixtures/es2016/simple-parameter-list/rest/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Non-simple parameter in strict mode (1:11)" +} diff --git a/test/fixtures/esprima/declaration-function/empty-param/actual.js b/test/fixtures/esprima/declaration-function/empty-param/actual.js deleted file mode 100644 index 860cafa480..0000000000 --- a/test/fixtures/esprima/declaration-function/empty-param/actual.js +++ /dev/null @@ -1 +0,0 @@ -function a([], []) {'use strict';} diff --git a/test/fixtures/esprima/declaration-function/empty-param/expected.json b/test/fixtures/esprima/declaration-function/empty-param/expected.json deleted file mode 100644 index 554eee01b4..0000000000 --- a/test/fixtures/esprima/declaration-function/empty-param/expected.json +++ /dev/null @@ -1,154 +0,0 @@ -{ - "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": "FunctionDeclaration", - "start": 0, - "end": 34, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 34 - } - }, - "id": { - "type": "Identifier", - "start": 9, - "end": 10, - "loc": { - "start": { - "line": 1, - "column": 9 - }, - "end": { - "line": 1, - "column": 10 - } - }, - "name": "a" - }, - "generator": false, - "expression": false, - "params": [ - { - "type": "ArrayPattern", - "start": 11, - "end": 13, - "loc": { - "start": { - "line": 1, - "column": 11 - }, - "end": { - "line": 1, - "column": 13 - } - }, - "elements": [] - }, - { - "type": "ArrayPattern", - "start": 15, - "end": 17, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 17 - } - }, - "elements": [] - } - ], - "body": { - "type": "BlockStatement", - "start": 19, - "end": 34, - "loc": { - "start": { - "line": 1, - "column": 19 - }, - "end": { - "line": 1, - "column": 34 - } - }, - "body": [], - "directives": [ - { - "type": "Directive", - "start": 20, - "end": 33, - "loc": { - "start": { - "line": 1, - "column": 20 - }, - "end": { - "line": 1, - "column": 33 - } - }, - "value": { - "type": "DirectiveLiteral", - "start": 20, - "end": 32, - "loc": { - "start": { - "line": 1, - "column": 20 - }, - "end": { - "line": 1, - "column": 32 - } - }, - "value": "use strict", - "extra": { - "raw": "'use strict'", - "rawValue": "use strict" - } - } - } - ] - } - } - ], - "directives": [] - } -} \ No newline at end of file