diff --git a/lib/convert.js b/lib/convert.js index 083c278..eee1e37 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -930,17 +930,26 @@ module.exports = function convert(config) { } else { return arrayItem; } - } else { + } else if (parent.kind === SyntaxKind.ObjectBindingPattern) { - Object.assign(result, { - type: AST_NODE_TYPES.Property, - key: convertChild(node.propertyName || node.name), - value: convertChild(node.name), - computed: false, - method: false, - shorthand: !node.propertyName, - kind: "init" - }); + if (node.dotDotDotToken) { + Object.assign(result, { + type: AST_NODE_TYPES.ExperimentalRestProperty, + argument: convertChild(node.propertyName || node.name), + computed: Boolean(node.propertyName && node.propertyName.kind === SyntaxKind.ComputedPropertyName), + shorthand: !node.propertyName + }); + } else { + Object.assign(result, { + type: AST_NODE_TYPES.Property, + key: convertChild(node.propertyName || node.name), + value: convertChild(node.name), + computed: Boolean(node.propertyName && node.propertyName.kind === SyntaxKind.ComputedPropertyName), + method: false, + shorthand: !node.propertyName, + kind: "init" + }); + } if (node.initializer) { result.value = { @@ -951,7 +960,6 @@ module.exports = function convert(config) { loc: nodeUtils.getLocFor(node.name.getStart(), node.initializer.end, ast) }; } - } break; @@ -1053,12 +1061,30 @@ module.exports = function convert(config) { // Patterns case SyntaxKind.SpreadElement: - case SyntaxKind.SpreadAssignment: Object.assign(result, { type: AST_NODE_TYPES.SpreadElement, argument: convertChild(node.expression) }); break; + case SyntaxKind.SpreadAssignment: { + let type = AST_NODE_TYPES.ExperimentalSpreadProperty; + + if (node.parent && + node.parent.parent.kind === SyntaxKind.BinaryExpression + ) { + if (node.parent.parent.right === node.parent) { + type = AST_NODE_TYPES.ExperimentalSpreadProperty; + } else if (node.parent.parent.left === node.parent) { + type = AST_NODE_TYPES.ExperimentalRestProperty; + } + } + + Object.assign(result, { + type, + argument: convertChild(node.expression) + }); + break; + } case SyntaxKind.Parameter: { let parameter; diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/arg-spread.result.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/arg-spread.result.js new file mode 100644 index 0000000..ca29de6 --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/arg-spread.result.js @@ -0,0 +1,409 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "range": [ + 0, + 24 + ], + "body": [ + { + "type": "FunctionDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "range": [ + 0, + 24 + ], + "id": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ], + "name": "c" + }, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "range": [ + 11, + 20 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 12, + 13 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 12, + 13 + ], + "name": "a" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 12, + 13 + ], + "name": "a" + } + }, + { + "type": "ExperimentalRestProperty", + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "range": [ + 15, + 19 + ], + "argument": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "range": [ + 18, + 19 + ], + "name": "b" + }, + "shorthand": true, + "computed": false, + } + ] + } + ], + "body": { + "type": "BlockStatement", + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "range": [ + 22, + 24 + ], + "body": [] + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "function", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 0, + 8 + ] + }, + { + "type": "Identifier", + "value": "c", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ] + }, + { + "type": "Punctuator", + "value": "(", + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 10, + 11 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 11, + 12 + ] + }, + { + "type": "Identifier", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 12, + 13 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 13, + 14 + ] + }, + { + "type": "Punctuator", + "value": "...", + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 15, + 18 + ] + }, + { + "type": "Identifier", + "value": "b", + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "range": [ + 18, + 19 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "range": [ + 19, + 20 + ] + }, + { + "type": "Punctuator", + "value": ")", + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "range": [ + 20, + 21 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "range": [ + 22, + 23 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "range": [ + 23, + 24 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/arg-spread.src.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/arg-spread.src.js new file mode 100644 index 0000000..99da0c5 --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/arg-spread.src.js @@ -0,0 +1 @@ +function c({a, ...b}) {} diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/destructuring-assign-mirror.result.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/destructuring-assign-mirror.result.js new file mode 100644 index 0000000..49acb2b --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/destructuring-assign-mirror.result.js @@ -0,0 +1,549 @@ +module.exports = { + "type": "Program", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "a", + "range": [ + 2, + 3 + ], + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "value": { + "type": "Identifier", + "name": "a", + "range": [ + 2, + 3 + ], + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "kind": "init", + "method": false, + "shorthand": true, + "computed": false, + "range": [ + 2, + 3 + ], + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ExperimentalRestProperty", + "argument": { + "type": "Identifier", + "name": "b", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + } + }, + "range": [ + 5, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 9 + } + } + } + ], + "range": [ + 1, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 10 + } + } + }, + "right": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "a", + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + } + }, + "value": { + "type": "Identifier", + "name": "a", + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + } + }, + "kind": "init", + "method": false, + "shorthand": true, + "computed": false, + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + } + }, + { + "type": "ExperimentalSpreadProperty", + "argument": { + "type": "Identifier", + "name": "b", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + } + }, + "range": [ + 17, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 21 + } + } + } + ], + "range": [ + 13, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 22 + } + } + }, + "range": [ + 1, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 22 + } + } + }, + "range": [ + 0, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + } + } + ], + "sourceType": "script", + "range": [ + 0, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "tokens": [ + { + "type": "Punctuator", + "value": "(", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 1, + 2 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + } + } + }, + { + "type": "Identifier", + "value": "a", + "range": [ + 2, + 3 + ], + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 3, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + { + "type": "Punctuator", + "value": "...", + "range": [ + 5, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + { + "type": "Identifier", + "value": "b", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 11, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "a", + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "...", + "range": [ + 17, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 20 + } + } + }, + { + "type": "Identifier", + "value": "b", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 21, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 22, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 23 + } + } + } + ] +}; diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/destructuring-assign-mirror.src.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/destructuring-assign-mirror.src.js new file mode 100644 index 0000000..0caa3fa --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/destructuring-assign-mirror.src.js @@ -0,0 +1 @@ +({a, ...b} = {a, ...b}) diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/function-parameter-object-spread.result.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/function-parameter-object-spread.result.js new file mode 100644 index 0000000..23c70b6 --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/function-parameter-object-spread.result.js @@ -0,0 +1,316 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "body": [ + { + "type": "FunctionDeclaration", + "range": [ + 0, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "id": { + "type": "Identifier", + "range": [ + 9, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "name": "foo" + }, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "range": [ + 13, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "properties": [ + { + "type": "ExperimentalRestProperty", + "range": [ + 14, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "argument": { + "type": "Identifier", + "range": [ + 17, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "name": "bar" + }, + "computed": false, + "shorthand": true + } + ] + } + ], + "body": { + "type": "BlockStatement", + "range": [ + 23, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "body": [] + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "function", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + { + "type": "Identifier", + "value": "foo", + "range": [ + 9, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "...", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 17 + } + } + }, + { + "type": "Identifier", + "value": "bar", + "range": [ + 17, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 21, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + } + } + ] +}; diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/function-parameter-object-spread.src.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/function-parameter-object-spread.src.js new file mode 100644 index 0000000..29fda8e --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/function-parameter-object-spread.src.js @@ -0,0 +1 @@ +function foo({...bar}) { } diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/invalid-rest-trailing-comma.result.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/invalid-rest-trailing-comma.result.js new file mode 100644 index 0000000..741ae54 --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/invalid-rest-trailing-comma.result.js @@ -0,0 +1,6 @@ +module.exports = { + index: 16, + lineNumber: 1, + column: 17, + message: "Unexpected trailing comma after rest property" +}; diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/invalid-rest-trailing-comma.src.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/invalid-rest-trailing-comma.src.js new file mode 100644 index 0000000..39ef542 --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/invalid-rest-trailing-comma.src.js @@ -0,0 +1 @@ +var { x, y, ...z, } = foo; diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/invalid-rest.result.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/invalid-rest.result.js new file mode 100644 index 0000000..c18a2de --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/invalid-rest.result.js @@ -0,0 +1,6 @@ +module.exports = { + "index": 18, + "lineNumber": 1, + "column": 19, + "message": "Unexpected token ." +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/invalid-rest.src.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/invalid-rest.src.js new file mode 100644 index 0000000..a38d92c --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/invalid-rest.src.js @@ -0,0 +1 @@ +var { x, y, ...foo.bar } = { x: 1, y: 2, a: 3, b: 4 }; diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/object-rest.result.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/object-rest.result.js new file mode 100644 index 0000000..8ee8eae --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/object-rest.result.js @@ -0,0 +1,984 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 48 + } + }, + "range": [ + 0, + 48 + ], + "body": [ + { + "type": "VariableDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 48 + } + }, + "range": [ + 0, + 48 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 47 + } + }, + "range": [ + 4, + 47 + ], + "id": { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 4, + 18 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ], + "name": "x" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ], + "name": "x" + } + }, + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ], + "name": "y" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ], + "name": "y" + } + }, + { + "type": "ExperimentalRestProperty", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 12, + 16 + ], + "argument": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 15, + 16 + ], + "name": "z" + }, + "shorthand": true, + "computed": false, + } + ] + }, + "init": { + "type": "ObjectExpression", + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 47 + } + }, + "range": [ + 21, + 47 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "range": [ + 23, + 27 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "range": [ + 23, + 24 + ], + "name": "x" + }, + "value": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "range": [ + 26, + 27 + ], + "value": 1, + "raw": "1" + }, + "kind": "init" + }, + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "range": [ + 29, + 33 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "range": [ + 29, + 30 + ], + "name": "y" + }, + "value": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "range": [ + 32, + 33 + ], + "value": 2, + "raw": "2" + }, + "kind": "init" + }, + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "range": [ + 35, + 39 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "range": [ + 35, + 36 + ], + "name": "a" + }, + "value": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "range": [ + 38, + 39 + ], + "value": 3, + "raw": "3" + }, + "kind": "init" + }, + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 41 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "range": [ + 41, + 45 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 41 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "range": [ + 41, + 42 + ], + "name": "b" + }, + "value": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 44 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "range": [ + 44, + 45 + ], + "value": 4, + "raw": "4" + }, + "kind": "init" + } + ] + } + } + ], + "kind": "var" + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "var", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 0, + 3 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 4, + 5 + ] + }, + { + "type": "Identifier", + "value": "x", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ] + }, + { + "type": "Identifier", + "value": "y", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 10, + 11 + ] + }, + { + "type": "Punctuator", + "value": "...", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 12, + 15 + ] + }, + { + "type": "Identifier", + "value": "z", + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 15, + 16 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 17, + 18 + ] + }, + { + "type": "Punctuator", + "value": "=", + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "range": [ + 19, + 20 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "range": [ + 21, + 22 + ] + }, + { + "type": "Identifier", + "value": "x", + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "range": [ + 23, + 24 + ] + }, + { + "type": "Punctuator", + "value": ":", + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 24, + 25 + ] + }, + { + "type": "Numeric", + "value": "1", + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "range": [ + 26, + 27 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "range": [ + 27, + 28 + ] + }, + { + "type": "Identifier", + "value": "y", + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "range": [ + 29, + 30 + ] + }, + { + "type": "Punctuator", + "value": ":", + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "range": [ + 30, + 31 + ] + }, + { + "type": "Numeric", + "value": "2", + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "range": [ + 32, + 33 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "range": [ + 33, + 34 + ] + }, + { + "type": "Identifier", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "range": [ + 35, + 36 + ] + }, + { + "type": "Punctuator", + "value": ":", + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "range": [ + 36, + 37 + ] + }, + { + "type": "Numeric", + "value": "3", + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "range": [ + 38, + 39 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "range": [ + 39, + 40 + ] + }, + { + "type": "Identifier", + "value": "b", + "loc": { + "start": { + "line": 1, + "column": 41 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "range": [ + 41, + 42 + ] + }, + { + "type": "Punctuator", + "value": ":", + "loc": { + "start": { + "line": 1, + "column": 42 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "range": [ + 42, + 43 + ] + }, + { + "type": "Numeric", + "value": "4", + "loc": { + "start": { + "line": 1, + "column": 44 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "range": [ + 44, + 45 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 1, + "column": 46 + }, + "end": { + "line": 1, + "column": 47 + } + }, + "range": [ + 46, + 47 + ] + }, + { + "type": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 1, + "column": 47 + }, + "end": { + "line": 1, + "column": 48 + } + }, + "range": [ + 47, + 48 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/object-rest.src.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/object-rest.src.js new file mode 100644 index 0000000..4d73379 --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/object-rest.src.js @@ -0,0 +1 @@ +var { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 }; diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/property-spread.result.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/property-spread.result.js index 8895201..25637c8 100644 --- a/tests/fixtures/ecma-features/experimentalObjectRestSpread/property-spread.result.js +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/property-spread.result.js @@ -326,7 +326,7 @@ module.exports = { "kind": "init" }, { - "type": "SpreadElement", + "type": "ExperimentalSpreadProperty", "loc": { "start": { "line": 8, @@ -856,4 +856,4 @@ module.exports = { ] } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-method-args.result.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-method-args.result.js new file mode 100644 index 0000000..35e97e3 --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-method-args.result.js @@ -0,0 +1,629 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "range": [0, 108], + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "expression": { + "type": "ObjectExpression", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "method": true, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "name": "initialize", + "range": [ + 7, + 17 + ], + }, + "kind": "init", + "value": { + "type": "FunctionExpression", + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "id": null, + "async": false, + "generator": false, + "expression": false, + "params": [ + { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 46 + } + }, + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "name": "someVar", + "range": [ + 19, + 26 + ], + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "name": "someVar", + "range": [ + 19, + 26 + ], + }, + "range": [ + 19, + 26 + ], + }, + { + "type": "Property", + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "name": "otherVar", + "range": [ + 28, + 36 + ], + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "name": "otherVar", + "range": [ + 28, + 36 + ], + }, + "range": [ + 28, + 36 + ], + }, + { + "type": "ExperimentalRestProperty", + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "argument": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "name": "options", + "range": [ + 41, + 48 + ], + }, + "shorthand": true, + "computed": false, + "range": [ + 38, + 48 + ] + } + ], + "range": [ + 18, + 49 + ], + } + ], + "body": { + "type": "BlockStatement", + "loc": { + "start": { + "line": 2, + "column": 48 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "body": [], + "range": [ + 51, + 104 + ], + }, + "range": [ + 17, + 104 + ], + }, + "range": [ + 7, + 104 + ], + } + ], + "range": [ + 1, + 106 + ], + }, + "range": [ + 0, + 108 + ], + } + ], + "tokens": [ + { + "type": "Punctuator", + "value": "(", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "range": [ + 0, + 1 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "range": [ + 1, + 2 + ] + }, + { + "type": "Identifier", + "value": "initialize", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "range": [ + 7, + 17 + ] + }, + { + "type": "Punctuator", + "value": "(", + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "range": [ + 17, + 18 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "range": [ + 18, + 19 + ] + }, + { + "type": "Identifier", + "value": "someVar", + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 19, + 26 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "range": [ + 26, + 27 + ] + }, + { + "type": "Identifier", + "value": "otherVar", + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "range": [ + 28, + 36 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "range": [ + 36, + 37 + ] + }, + { + "type": "Punctuator", + "value": "...", + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "range": [ + 38, + 41 + ] + }, + { + "type": "Identifier", + "value": "options", + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "range": [ + 41, + 48 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 46 + } + }, + "range": [ + 48, + 49 + ] + }, + { + "type": "Punctuator", + "value": ")", + "loc": { + "start": { + "line": 2, + "column": 46 + }, + "end": { + "line": 2, + "column": 47 + } + }, + "range": [ + 49, + 50 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 2, + "column": 48 + }, + "end": { + "line": 2, + "column": 49 + } + }, + "range": [ + 51, + 52 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "range": [ + 103, + 104 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "range": [ + 105, + 106 + ] + }, + { + "type": "Punctuator", + "value": ")", + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "range": [ + 106, + 107 + ] + }, + { + "type": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "range": [ + 107, + 108 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-method-args.src.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-method-args.src.js new file mode 100644 index 0000000..4247e4a --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-method-args.src.js @@ -0,0 +1,5 @@ +({ + initialize({someVar, otherVar, ...options}) { + // ... do some stuff with options ... + } +}); diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-methods.result.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-methods.result.js new file mode 100644 index 0000000..ce598f4 --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-methods.result.js @@ -0,0 +1,688 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "range": [ + 0, + 114 + ], + "body": [ + { + "type": "VariableDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "range": [ + 0, + 114 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "range": [ + 4, + 113 + ], + "id": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 4, + 5 + ], + "name": "x" + }, + "init": { + "type": "ObjectExpression", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "range": [ + 8, + 113 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "range": [ + 14, + 111 + ], + "method": true, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "range": [ + 14, + 24 + ], + "name": "initialize" + }, + "kind": "init", + "value": { + "type": "FunctionExpression", + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "range": [ + 24, + 111 + ], + "id": null, + "async": false, + "generator": false, + "expression": false, + "params": [ + { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 46 + } + }, + "range": [ + 25, + 56 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 26, + 33 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 26, + 33 + ], + "name": "someVar" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 26, + 33 + ], + "name": "someVar" + } + }, + { + "type": "Property", + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "range": [ + 35, + 43 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "range": [ + 35, + 43 + ], + "name": "otherVar" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "range": [ + 35, + 43 + ], + "name": "otherVar" + } + }, + { + "type": "ExperimentalRestProperty", + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "range": [ + 45, + 55 + ], + "argument": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "range": [ + 48, + 55 + ], + "name": "options" + }, + "shorthand": true, + "computed": false, + } + ] + } + ], + "body": { + "type": "BlockStatement", + "loc": { + "start": { + "line": 2, + "column": 48 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "range": [ + 58, + 111 + ], + "body": [] + } + } + } + ] + } + } + ], + "kind": "var" + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "var", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 0, + 3 + ] + }, + { + "type": "Identifier", + "value": "x", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 4, + 5 + ] + }, + { + "type": "Punctuator", + "value": "=", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ] + }, + { + "type": "Identifier", + "value": "initialize", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "range": [ + 14, + 24 + ] + }, + { + "type": "Punctuator", + "value": "(", + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "range": [ + 24, + 25 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "range": [ + 25, + 26 + ] + }, + { + "type": "Identifier", + "value": "someVar", + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 26, + 33 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "range": [ + 33, + 34 + ] + }, + { + "type": "Identifier", + "value": "otherVar", + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "range": [ + 35, + 43 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "range": [ + 43, + 44 + ] + }, + { + "type": "Punctuator", + "value": "...", + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "range": [ + 45, + 48 + ] + }, + { + "type": "Identifier", + "value": "options", + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "range": [ + 48, + 55 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 46 + } + }, + "range": [ + 55, + 56 + ] + }, + { + "type": "Punctuator", + "value": ")", + "loc": { + "start": { + "line": 2, + "column": 46 + }, + "end": { + "line": 2, + "column": 47 + } + }, + "range": [ + 56, + 57 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 2, + "column": 48 + }, + "end": { + "line": 2, + "column": 49 + } + }, + "range": [ + 58, + 59 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "range": [ + 110, + 111 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "range": [ + 112, + 113 + ] + }, + { + "type": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "range": [ + 113, + 114 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-methods.src.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-methods.src.js new file mode 100644 index 0000000..2eb0d18 --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-methods.src.js @@ -0,0 +1,5 @@ +var x = { + initialize({someVar, otherVar, ...options}) { + // ... do some stuff with options ... + } +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-properties.result.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-properties.result.js new file mode 100644 index 0000000..9b861af --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-properties.result.js @@ -0,0 +1,715 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "range": [ + 0, + 69 + ], + "body": [ + { + "type": "VariableDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "range": [ + 0, + 26 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 4, + 7 + ], + "id": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 4, + 7 + ], + "name": "foo" + }, + "init": null + }, + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "range": [ + 13, + 16 + ], + "id": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "range": [ + 13, + 16 + ], + "name": "get" + }, + "init": null + }, + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "range": [ + 22, + 25 + ], + "id": { + "type": "Identifier", + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "range": [ + 22, + 25 + ], + "name": "set" + }, + "init": null + } + ], + "kind": "var" + }, + { + "type": "VariableDeclaration", + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "range": [ + 28, + 69 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "range": [ + 32, + 68 + ], + "id": { + "type": "Identifier", + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "range": [ + 32, + 33 + ], + "name": "x" + }, + "init": { + "type": "ObjectExpression", + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "range": [ + 36, + 68 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "range": [ + 42, + 45 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "range": [ + 42, + 45 + ], + "name": "foo" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "range": [ + 42, + 45 + ], + "name": "foo" + } + }, + { + "type": "Property", + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "range": [ + 51, + 54 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "range": [ + 51, + 54 + ], + "name": "get" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "range": [ + 51, + 54 + ], + "name": "get" + } + }, + { + "type": "ExperimentalSpreadProperty", + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "range": [ + 60, + 66 + ], + "argument": { + "type": "Identifier", + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "range": [ + 63, + 66 + ], + "name": "set" + } + } + ] + } + } + ], + "kind": "var" + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "var", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 0, + 3 + ] + }, + { + "type": "Identifier", + "value": "foo", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 4, + 7 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ] + }, + { + "type": "Identifier", + "value": "get", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "range": [ + 13, + 16 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "range": [ + 16, + 17 + ] + }, + { + "type": "Identifier", + "value": "set", + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "range": [ + 22, + 25 + ] + }, + { + "type": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "range": [ + 25, + 26 + ] + }, + { + "type": "Keyword", + "value": "var", + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "range": [ + 28, + 31 + ] + }, + { + "type": "Identifier", + "value": "x", + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "range": [ + 32, + 33 + ] + }, + { + "type": "Punctuator", + "value": "=", + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "range": [ + 34, + 35 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "range": [ + 36, + 37 + ] + }, + { + "type": "Identifier", + "value": "foo", + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "range": [ + 42, + 45 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 8 + } + }, + "range": [ + 45, + 46 + ] + }, + { + "type": "Identifier", + "value": "get", + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 7 + } + }, + "range": [ + 51, + 54 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 8 + } + }, + "range": [ + 54, + 55 + ] + }, + { + "type": "Punctuator", + "value": "...", + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "range": [ + 60, + 63 + ] + }, + { + "type": "Identifier", + "value": "set", + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "range": [ + 63, + 66 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "range": [ + 67, + 68 + ] + }, + { + "type": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "range": [ + 68, + 69 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-properties.src.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-properties.src.js new file mode 100644 index 0000000..11d8c39 --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-properties.src.js @@ -0,0 +1,9 @@ +var foo, + get, + set; + +var x = { + foo, + get, + ...set +}; diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/single-spread.result.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/single-spread.result.js index 573b616..f2afb48 100644 --- a/tests/fixtures/ecma-features/experimentalObjectRestSpread/single-spread.result.js +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/single-spread.result.js @@ -326,7 +326,7 @@ module.exports = { "kind": "init" }, { - "type": "SpreadElement", + "type": "ExperimentalSpreadProperty", "loc": { "start": { "line": 8, @@ -784,4 +784,4 @@ module.exports = { ] } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/spread-trailing-comma.result.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/spread-trailing-comma.result.js new file mode 100644 index 0000000..b882e2b --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/spread-trailing-comma.result.js @@ -0,0 +1,405 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 0, + 17 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 0, + 17 + ], + "expression": { + "type": "ObjectExpression", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 1, + 16 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "range": [ + 3, + 4 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "range": [ + 3, + 4 + ], + "name": "a" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "range": [ + 3, + 4 + ], + "name": "a" + } + }, + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ], + "name": "b" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ], + "name": "b" + } + }, + { + "type": "ExperimentalSpreadProperty", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 9, + 13 + ], + "argument": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 12, + 13 + ], + "name": "c" + } + } + ] + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Punctuator", + "value": "(", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "range": [ + 0, + 1 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "range": [ + 1, + 2 + ] + }, + { + "type": "Identifier", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "range": [ + 3, + 4 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 4, + 5 + ] + }, + { + "type": "Identifier", + "value": "b", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ] + }, + { + "type": "Punctuator", + "value": "...", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 9, + 12 + ] + }, + { + "type": "Identifier", + "value": "c", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 12, + 13 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 13, + 14 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 15, + 16 + ] + }, + { + "type": "Punctuator", + "value": ")", + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 16, + 17 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/spread-trailing-comma.src.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/spread-trailing-comma.src.js new file mode 100644 index 0000000..a2841df --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/spread-trailing-comma.src.js @@ -0,0 +1 @@ +({ a, b, ...c, }) diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/two-spread.result.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/two-spread.result.js index 28044a0..15a0234 100644 --- a/tests/fixtures/ecma-features/experimentalObjectRestSpread/two-spread.result.js +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/two-spread.result.js @@ -269,7 +269,7 @@ module.exports = { "kind": "init" }, { - "type": "SpreadElement", + "type": "ExperimentalSpreadProperty", "loc": { "start": { "line": 7, @@ -304,7 +304,7 @@ module.exports = { } }, { - "type": "SpreadElement", + "type": "ExperimentalSpreadProperty", "loc": { "start": { "line": 8, @@ -744,4 +744,4 @@ module.exports = { ] } ] -}; +}; \ No newline at end of file