Adjusted Object Rest/Spread syntax handling to the latest spec (#670)

This commit is contained in:
Mateusz Burzyński 2017-08-25 01:31:50 +02:00 committed by Brian Ng
parent 5df1139567
commit 5d83e2692f
30 changed files with 58 additions and 835 deletions

View File

@ -1532,5 +1532,3 @@ language/statements/try/optional-catch-binding-throws.js(default)
language/statements/try/optional-catch-binding-throws.js(strict mode)
language/statements/try/optional-catch-binding.js(default)
language/statements/try/optional-catch-binding.js(strict mode)

View File

@ -1118,8 +1118,9 @@ export default class ExpressionParser extends LValParser {
if (this.hasPlugin("objectRestSpread") && this.match(tt.ellipsis)) {
prop = this.parseSpread(isPattern ? { start: 0 } : undefined);
prop.type = isPattern ? "RestElement" : "SpreadElement";
if (isPattern) this.toAssignable(prop.argument, true, "object pattern");
if (isPattern) {
this.toAssignable(prop, true, "object pattern");
}
node.properties.push(prop);
if (isPattern) {
const position = this.state.start;

View File

@ -84,6 +84,8 @@ export default class LValParser extends NodeUtils {
break;
case "SpreadElement":
this.checkToRestConversion(node);
node.type = "RestElement";
const arg = node.argument;
this.toAssignable(arg, isBinding, contextDescription);
@ -378,4 +380,14 @@ export default class LValParser extends NodeUtils {
}
}
}
checkToRestConversion(node: SpreadElement): void {
const validArgumentTypes = ["Identifier", "MemberExpression"];
if (validArgumentTypes.indexOf(node.argument.type) !== -1) {
return;
}
this.raise(node.argument.start, "Invalid rest operator's argument");
}
}

View File

@ -1 +0,0 @@
({ x, ...{ y, z } } = o)

View File

@ -1,300 +0,0 @@
{
"type": "File",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"program": {
"type": "Program",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"sourceType": "script",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 24
}
},
"expression": {
"type": "AssignmentExpression",
"start": 1,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 23
}
},
"operator": "=",
"left": {
"type": "ObjectPattern",
"start": 1,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 19
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 3,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 4
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 3,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 4
},
"identifierName": "x"
},
"name": "x"
},
"shorthand": true,
"value": {
"type": "Identifier",
"start": 3,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 4
},
"identifierName": "x"
},
"name": "x"
},
"extra": {
"shorthand": true
}
},
{
"type": "RestElement",
"start": 6,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 17
}
},
"argument": {
"type": "ObjectPattern",
"start": 9,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 17
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
},
"identifierName": "y"
},
"name": "y"
},
"shorthand": true,
"value": {
"type": "Identifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
},
"identifierName": "y"
},
"name": "y"
},
"extra": {
"shorthand": true
}
},
{
"type": "ObjectProperty",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
},
"identifierName": "z"
},
"name": "z"
},
"shorthand": true,
"value": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
},
"identifierName": "z"
},
"name": "z"
},
"extra": {
"shorthand": true
}
}
]
}
}
]
},
"right": {
"type": "Identifier",
"start": 22,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 22
},
"end": {
"line": 1,
"column": 23
},
"identifierName": "o"
},
"name": "o"
},
"extra": {
"parenthesized": true,
"parenStart": 0
}
}
}
],
"directives": []
}
}

View File

@ -1,3 +0,0 @@
{
"plugins": ["objectRestSpread"]
}

View File

@ -1,243 +0,0 @@
{
"type": "File",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"program": {
"type": "Program",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"sourceType": "script",
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 23
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 4,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 22
}
},
"id": {
"type": "ObjectPattern",
"start": 4,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 12
}
},
"properties": [
{
"type": "RestElement",
"start": 5,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 11
}
},
"argument": {
"type": "ObjectPattern",
"start": 8,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 11
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 9,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 9,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
},
"identifierName": "z"
},
"name": "z"
},
"shorthand": true,
"value": {
"type": "Identifier",
"start": 9,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
},
"identifierName": "z"
},
"name": "z"
},
"extra": {
"shorthand": true
}
}
]
}
}
]
},
"init": {
"type": "ObjectExpression",
"start": 15,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 22
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 17,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 21
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 17,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 18
},
"identifierName": "z"
},
"name": "z"
},
"shorthand": false,
"value": {
"type": "NumericLiteral",
"start": 20,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 20
},
"end": {
"line": 1,
"column": 21
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
}
}
]
}
}
],
"kind": "var"
}
],
"directives": []
}
}

View File

@ -0,0 +1,3 @@
{
"throws": "Invalid rest operator's argument (1:8)"
}

View File

@ -1,278 +0,0 @@
{
"type": "File",
"start": 0,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 31
}
},
"program": {
"type": "Program",
"start": 0,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 31
}
},
"sourceType": "script",
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 31
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 4,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 30
}
},
"id": {
"type": "ObjectPattern",
"start": 4,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 20
}
},
"properties": [
{
"type": "RestElement",
"start": 6,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 18
}
},
"argument": {
"type": "ObjectPattern",
"start": 9,
"end": 18,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 18
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 11,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 16
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
},
"identifierName": "x"
},
"name": "x"
},
"shorthand": true,
"value": {
"type": "AssignmentPattern",
"start": 11,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 16
}
},
"left": {
"type": "Identifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
},
"identifierName": "x"
},
"name": "x"
},
"right": {
"type": "NumericLiteral",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 16
}
},
"extra": {
"rawValue": 5,
"raw": "5"
},
"value": 5
}
},
"extra": {
"shorthand": true
}
}
]
}
}
]
},
"init": {
"type": "ObjectExpression",
"start": 23,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 23
},
"end": {
"line": 1,
"column": 30
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 24,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 24
},
"end": {
"line": 1,
"column": 29
}
},
"method": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 24,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 24
},
"end": {
"line": 1,
"column": 25
},
"identifierName": "x"
},
"name": "x"
},
"shorthand": false,
"value": {
"type": "NumericLiteral",
"start": 28,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 28
},
"end": {
"line": 1,
"column": 29
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
}
}
]
}
}
],
"kind": "var"
}
],
"directives": []
}
}

View File

@ -0,0 +1,3 @@
{
"throws": "Invalid rest operator's argument (1:9)"
}

View File

@ -0,0 +1 @@
({...{}} = {})

View File

@ -0,0 +1,3 @@
{
"throws": "Invalid rest operator's argument (1:5)"
}

View File

@ -0,0 +1 @@
function test({...{}}) {}

View File

@ -0,0 +1,3 @@
{
"throws": "Invalid rest operator's argument (1:18)"
}

View File

@ -0,0 +1 @@
function test({...{a}}) {}

View File

@ -0,0 +1,3 @@
{
"throws": "Invalid rest operator's argument (1:18)"
}

View File

@ -0,0 +1 @@
({...x = 1} = {})

View File

@ -0,0 +1,3 @@
{
"throws": "Invalid rest operator's argument (1:5)"
}

View File

@ -0,0 +1 @@
var {...x = 1} = {}

View File

@ -0,0 +1,3 @@
{
"throws": "Invalid rest operator's argument (1:8)"
}

View File

@ -0,0 +1 @@
function test({...x = 1}) {}

View File

@ -0,0 +1,3 @@
{
"throws": "Invalid rest operator's argument (1:18)"
}

View File

@ -0,0 +1 @@
({...[]} = {})

View File

@ -0,0 +1,3 @@
{
"throws": "Invalid rest operator's argument (1:5)"
}

View File

@ -0,0 +1 @@
var {...[]} = {}

View File

@ -0,0 +1,3 @@
{
"throws": "Invalid rest operator's argument (1:8)"
}

View File

@ -0,0 +1 @@
function test({...[]}) {}

View File

@ -0,0 +1,3 @@
{
"throws": "Invalid rest operator's argument (1:18)"
}

View File

@ -74,7 +74,6 @@ function runTest(test, parseFunction) {
}
let ast;
try {
ast = parseFunction(test.actual.code, opts);
} catch (err) {

View File

@ -3054,7 +3054,7 @@ minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.4:
dependencies:
brace-expansion "^1.1.7"
minimist@0.0.8:
minimist@0.0.8, minimist@~0.0.1:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
@ -3062,10 +3062,6 @@ minimist@^1.1.3, minimist@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
minimist@~0.0.1:
version "0.0.10"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"
"mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"