diff --git a/lib/convert.js b/lib/convert.js index fe4bdb2..104c990 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -570,6 +570,8 @@ module.exports = function convert(config) { case SyntaxKind.ArrayLiteralExpression: { const arrayAssignNode = nodeUtils.findAncestorOfKind(node, SyntaxKind.BinaryExpression); + const arrayIsInForOf = node.parent && node.parent.kind === SyntaxKind.ForOfStatement; + const arrayIsInForIn = node.parent && node.parent.kind === SyntaxKind.ForInStatement; let arrayIsInAssignment; if (arrayAssignNode) { @@ -581,7 +583,7 @@ module.exports = function convert(config) { } // TypeScript uses ArrayLiteralExpression in destructuring assignment, too - if (arrayIsInAssignment) { + if (arrayIsInAssignment || arrayIsInForOf || arrayIsInForIn) { Object.assign(result, { type: AST_NODE_TYPES.ArrayPattern, elements: node.elements.map(convertChild) @@ -925,6 +927,11 @@ module.exports = function convert(config) { left: arrayItem, right: convertChild(node.initializer) }); + } else if (node.dotDotDotToken) { + Object.assign(result, { + type: AST_NODE_TYPES.RestElement, + argument: arrayItem + }); } else { return arrayItem; } @@ -1058,16 +1065,31 @@ module.exports = function convert(config) { // Patterns - case SyntaxKind.SpreadElement: + case SyntaxKind.SpreadElement: { + let type = AST_NODE_TYPES.SpreadElement; + + if (node.parent && + node.parent.parent && + node.parent.parent.kind === SyntaxKind.BinaryExpression + ) { + if (node.parent.parent.left === node.parent) { + type = AST_NODE_TYPES.RestElement; + } else if (node.parent.parent.right === node.parent) { + type = AST_NODE_TYPES.SpreadElement; + } + } + Object.assign(result, { - type: AST_NODE_TYPES.SpreadElement, + type, argument: convertChild(node.expression) }); break; + } case SyntaxKind.SpreadAssignment: { let type = AST_NODE_TYPES.ExperimentalSpreadProperty; if (node.parent && + node.parent.parent && node.parent.parent.kind === SyntaxKind.BinaryExpression ) { if (node.parent.parent.right === node.parent) { diff --git a/lib/node-utils.js b/lib/node-utils.js index 64d2551..28f1e4a 100644 --- a/lib/node-utils.js +++ b/lib/node-utils.js @@ -112,6 +112,11 @@ function findFirstMatchingChild(node, sourceFile, predicate) { if (child && predicate(child)) { return child; } + + const grandChild = findFirstMatchingChild(child, sourceFile, predicate); + if (grandChild) { + return grandChild; + } } return undefined; } diff --git a/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-array.result.js b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-array.result.js new file mode 100644 index 0000000..d546423 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-array.result.js @@ -0,0 +1,261 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 0, + 11 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 0, + 11 + ], + "expression": { + "type": "ArrowFunctionExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 0, + 10 + ], + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "range": [ + 1, + 4 + ], + "elements": [ + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ], + "name": "y" + } + ] + } + ], + "body": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ], + "name": "x" + } + } + } + ], + "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": "y", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ] + }, + { + "type": "Punctuator", + "value": "]", + "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": "Punctuator", + "value": "=>", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 6, + 8 + ] + }, + { + "type": "Identifier", + "value": "x", + "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 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-array.src.js b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-array.src.js new file mode 100644 index 0000000..c2f3872 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-array.src.js @@ -0,0 +1 @@ +([y]) => x; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-array.result.js b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-array.result.js new file mode 100644 index 0000000..c75245c --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-array.result.js @@ -0,0 +1,370 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 0, + 16 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 0, + 16 + ], + "expression": { + "type": "ArrowFunctionExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 0, + 15 + ], + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 1, + 9 + ], + "elements": [ + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ], + "name": "y" + }, + { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 5, + 8 + ], + "elements": [ + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ], + "name": "x" + } + ] + } + ] + } + ], + "body": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ], + "name": "x" + } + } + } + ], + "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": "y", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "range": [ + 3, + 4 + ] + }, + { + "type": "Punctuator", + "value": "[", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ] + }, + { + "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": "Punctuator", + "value": "]", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ] + }, + { + "type": "Punctuator", + "value": ")", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ] + }, + { + "type": "Punctuator", + "value": "=>", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 11, + 13 + ] + }, + { + "type": "Identifier", + "value": "x", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ] + }, + { + "type": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 15, + 16 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-array.src.js b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-array.src.js new file mode 100644 index 0000000..75bb19b --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-array.src.js @@ -0,0 +1 @@ +([y, [x]]) => x; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-object-named.result.js b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-object-named.result.js new file mode 100644 index 0000000..380c7ec --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-object-named.result.js @@ -0,0 +1,595 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "range": [ + 0, + 28 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "range": [ + 0, + 28 + ], + "expression": { + "type": "ArrowFunctionExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "range": [ + 0, + 27 + ], + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "range": [ + 1, + 21 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 2, + 8 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 2, + 5 + ], + "name": "foo" + }, + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ], + "name": "y" + }, + "kind": "init" + }, + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "range": [ + 10, + 20 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 10, + 11 + ], + "name": "a" + }, + "value": { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "range": [ + 12, + 20 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "range": [ + 13, + 19 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 13, + 16 + ], + "name": "bar" + }, + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "range": [ + 18, + 19 + ], + "name": "x" + }, + "kind": "init" + } + ] + }, + "kind": "init" + } + ] + } + ], + "body": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "range": [ + 26, + 27 + ], + "name": "x" + } + } + } + ], + "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": "foo", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 2, + 5 + ] + }, + { + "type": "Punctuator", + "value": ":", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ] + }, + { + "type": "Identifier", + "value": "y", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ] + }, + { + "type": "Identifier", + "value": "a", + "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": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 12, + 13 + ] + }, + { + "type": "Identifier", + "value": "bar", + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 13, + 16 + ] + }, + { + "type": "Punctuator", + "value": ":", + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 16, + 17 + ] + }, + { + "type": "Identifier", + "value": "x", + "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": 21 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "range": [ + 21, + 22 + ] + }, + { + "type": "Punctuator", + "value": "=>", + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 23, + 25 + ] + }, + { + "type": "Identifier", + "value": "x", + "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 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-object-named.src.js b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-object-named.src.js new file mode 100644 index 0000000..c2a809e --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-object-named.src.js @@ -0,0 +1 @@ +({foo: y, a:{bar: x}}) => x; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-object.result.js b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-object.result.js new file mode 100644 index 0000000..e195323 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-object.result.js @@ -0,0 +1,523 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 0, + 18 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 0, + 18 + ], + "expression": { + "type": "ArrowFunctionExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 0, + 17 + ], + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 1, + 11 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ], + "name": "y" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ], + "name": "y" + } + }, + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 5, + 10 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ], + "name": "a" + }, + "value": { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 7, + 10 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ], + "name": "x" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ], + "name": "x" + } + } + ] + }, + "kind": "init" + } + ] + } + ], + "body": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 16, + 17 + ], + "name": "x" + } + } + } + ], + "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": "y", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "range": [ + 3, + 4 + ] + }, + { + "type": "Identifier", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ] + }, + { + "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": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ] + }, + { + "type": "Identifier", + "value": "x", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ] + }, + { + "type": "Punctuator", + "value": "}", + "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": "Punctuator", + "value": "=>", + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 13, + 15 + ] + }, + { + "type": "Identifier", + "value": "x", + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 16, + 17 + ] + }, + { + "type": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 17, + 18 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-object.src.js b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-object.src.js new file mode 100644 index 0000000..177cd72 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-nested-object.src.js @@ -0,0 +1 @@ +({y, a:{x}}) => x; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-object.result.js b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-object.result.js new file mode 100644 index 0000000..52e0075 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-object.result.js @@ -0,0 +1,300 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 0, + 11 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 0, + 11 + ], + "expression": { + "type": "ArrowFunctionExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 0, + 10 + ], + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "range": [ + 1, + 4 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ], + "name": "y" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ], + "name": "y" + } + } + ] + } + ], + "body": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ], + "name": "x" + } + } + } + ], + "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": "y", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ] + }, + { + "type": "Punctuator", + "value": "}", + "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": "Punctuator", + "value": "=>", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 6, + 8 + ] + }, + { + "type": "Identifier", + "value": "x", + "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 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-object.src.js b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-object.src.js new file mode 100644 index 0000000..7f6a1fb --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/arrow-param-object.src.js @@ -0,0 +1 @@ +({y}) => x; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-array.result.js b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-array.result.js new file mode 100644 index 0000000..914227a --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-array.result.js @@ -0,0 +1,315 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 0, + 15 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 0, + 15 + ], + "expression": { + "type": "ArrowFunctionExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 0, + 15 + ], + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 1, + 9 + ], + "elements": [ + { + "type": "AssignmentPattern", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 2, + 8 + ], + "left": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ], + "name": "x" + }, + "right": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 6, + 8 + ], + "value": 10, + "raw": "10" + } + } + ] + } + ], + "body": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ], + "name": "x" + } + } + } + ], + "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": "x", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ] + }, + { + "type": "Punctuator", + "value": "=", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 4, + 5 + ] + }, + { + "type": "Numeric", + "value": "10", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 6, + 8 + ] + }, + { + "type": "Punctuator", + "value": "]", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ] + }, + { + "type": "Punctuator", + "value": ")", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ] + }, + { + "type": "Punctuator", + "value": "=>", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 11, + 13 + ] + }, + { + "type": "Identifier", + "value": "x", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-array.src.js b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-array.src.js new file mode 100644 index 0000000..7fa2d19 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-array.src.js @@ -0,0 +1 @@ +([x = 10]) => x \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-object-nested.result.js b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-object-nested.result.js new file mode 100644 index 0000000..e78410a --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-object-nested.result.js @@ -0,0 +1,758 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "range": [ + 0, + 35 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "range": [ + 0, + 35 + ], + "expression": { + "type": "ArrowFunctionExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "range": [ + 0, + 35 + ], + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "range": [ + 1, + 24 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 2, + 8 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ], + "name": "x" + }, + "kind": "init", + "value": { + "type": "AssignmentPattern", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 2, + 8 + ], + "left": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ], + "name": "x" + }, + "right": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 6, + 8 + ], + "value": 10, + "raw": "10" + } + } + }, + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "range": [ + 10, + 23 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 10, + 11 + ], + "name": "y" + }, + "value": { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "range": [ + 13, + 23 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "range": [ + 15, + 21 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 15, + 16 + ], + "name": "z" + }, + "kind": "init", + "value": { + "type": "AssignmentPattern", + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "range": [ + 15, + 21 + ], + "left": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 15, + 16 + ], + "name": "z" + }, + "right": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "range": [ + 19, + 21 + ], + "value": 10, + "raw": "10" + } + } + } + ] + }, + "kind": "init" + } + ] + } + ], + "body": { + "type": "ArrayExpression", + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "range": [ + 29, + 35 + ], + "elements": [ + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "range": [ + 30, + 31 + ], + "name": "x" + }, + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "range": [ + 33, + 34 + ], + "name": "z" + } + ] + } + } + } + ], + "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": "x", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ] + }, + { + "type": "Punctuator", + "value": "=", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 4, + 5 + ] + }, + { + "type": "Numeric", + "value": "10", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 6, + 8 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ] + }, + { + "type": "Identifier", + "value": "y", + "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": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 13, + 14 + ] + }, + { + "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": "Numeric", + "value": "10", + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "range": [ + 19, + 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 + ] + }, + { + "type": "Punctuator", + "value": ")", + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 24, + 25 + ] + }, + { + "type": "Punctuator", + "value": "=>", + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "range": [ + 26, + 28 + ] + }, + { + "type": "Punctuator", + "value": "[", + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "range": [ + 29, + 30 + ] + }, + { + "type": "Identifier", + "value": "x", + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "range": [ + 30, + 31 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "range": [ + 31, + 32 + ] + }, + { + "type": "Identifier", + "value": "z", + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "range": [ + 33, + 34 + ] + }, + { + "type": "Punctuator", + "value": "]", + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "range": [ + 34, + 35 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-object-nested.src.js b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-object-nested.src.js new file mode 100644 index 0000000..410eed8 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-object-nested.src.js @@ -0,0 +1 @@ +({x = 10, y: { z = 10 }}) => [x, z] \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-object.result.js b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-object.result.js new file mode 100644 index 0000000..136e0c3 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-object.result.js @@ -0,0 +1,354 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 0, + 15 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 0, + 15 + ], + "expression": { + "type": "ArrowFunctionExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 0, + 15 + ], + "id": null, + "generator": false, + "expression": true, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 1, + 9 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 2, + 8 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ], + "name": "x" + }, + "kind": "init", + "value": { + "type": "AssignmentPattern", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 2, + 8 + ], + "left": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ], + "name": "x" + }, + "right": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 6, + 8 + ], + "value": 10, + "raw": "10" + } + } + } + ] + } + ], + "body": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ], + "name": "x" + } + } + } + ], + "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": "x", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ] + }, + { + "type": "Punctuator", + "value": "=", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 4, + 5 + ] + }, + { + "type": "Numeric", + "value": "10", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 6, + 8 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ] + }, + { + "type": "Punctuator", + "value": ")", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ] + }, + { + "type": "Punctuator", + "value": "=>", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 11, + 13 + ] + }, + { + "type": "Identifier", + "value": "x", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-object.src.js b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-object.src.js new file mode 100644 index 0000000..c6b4037 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-arrowFunctions/param-defaults-object.src.js @@ -0,0 +1 @@ +({x = 10}) => x \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-blockBindings/array-const-undefined.result.js b/tests/fixtures/ecma-features/destructuring-and-blockBindings/array-const-undefined.result.js new file mode 100644 index 0000000..91f9310 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-blockBindings/array-const-undefined.result.js @@ -0,0 +1,258 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 0, + 15 + ], + "body": [ + { + "type": "VariableDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 0, + 15 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 6, + 14 + ], + "id": { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 6, + 9 + ], + "elements": [ + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ], + "name": "a" + } + ] + }, + "init": { + "type": "ArrayExpression", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 12, + 14 + ], + "elements": [] + } + } + ], + "kind": "const" + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "const", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 0, + 5 + ] + }, + { + "type": "Punctuator", + "value": "[", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ] + }, + { + "type": "Identifier", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ] + }, + { + "type": "Punctuator", + "value": "]", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ] + }, + { + "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": 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": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-blockBindings/array-const-undefined.src.js b/tests/fixtures/ecma-features/destructuring-and-blockBindings/array-const-undefined.src.js new file mode 100644 index 0000000..0ff51d0 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-blockBindings/array-const-undefined.src.js @@ -0,0 +1 @@ +const [a] = []; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-blockBindings/array-let-undefined.result.js b/tests/fixtures/ecma-features/destructuring-and-blockBindings/array-let-undefined.result.js new file mode 100644 index 0000000..6fd4ac7 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-blockBindings/array-let-undefined.result.js @@ -0,0 +1,258 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 0, + 13 + ], + "body": [ + { + "type": "VariableDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 0, + 13 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 4, + 12 + ], + "id": { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 4, + 7 + ], + "elements": [ + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ], + "name": "a" + } + ] + }, + "init": { + "type": "ArrayExpression", + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 10, + 12 + ], + "elements": [] + } + } + ], + "kind": "let" + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "let", + "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": "a", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ] + }, + { + "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": "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": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 12, + 13 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-blockBindings/array-let-undefined.src.js b/tests/fixtures/ecma-features/destructuring-and-blockBindings/array-let-undefined.src.js new file mode 100644 index 0000000..c705f58 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-blockBindings/array-let-undefined.src.js @@ -0,0 +1 @@ +let [a] = []; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-const-named.result.js b/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-const-named.result.js new file mode 100644 index 0000000..d927cb0 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-const-named.result.js @@ -0,0 +1,333 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 0, + 17 + ], + "body": [ + { + "type": "VariableDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 0, + 17 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 6, + 16 + ], + "id": { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 6, + 11 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 7, + 10 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ], + "name": "a" + }, + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ], + "name": "b" + }, + "kind": "init" + } + ] + }, + "init": { + "type": "ObjectExpression", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 14, + 16 + ], + "properties": [] + } + } + ], + "kind": "const" + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "const", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 0, + 5 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ] + }, + { + "type": "Identifier", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ] + }, + { + "type": "Punctuator", + "value": ":", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ] + }, + { + "type": "Identifier", + "value": "b", + "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": 13 + } + }, + "range": [ + 12, + 13 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ] + }, + { + "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 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-const-named.src.js b/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-const-named.src.js new file mode 100644 index 0000000..67a0d1a --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-const-named.src.js @@ -0,0 +1 @@ +const {a:b} = {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-const-undefined.result.js b/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-const-undefined.result.js new file mode 100644 index 0000000..b28b4f1 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-const-undefined.result.js @@ -0,0 +1,297 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 0, + 15 + ], + "body": [ + { + "type": "VariableDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 0, + 15 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 6, + 14 + ], + "id": { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 6, + 9 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ], + "name": "a" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ], + "name": "a" + } + } + ] + }, + "init": { + "type": "ObjectExpression", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 12, + 14 + ], + "properties": [] + } + } + ], + "kind": "const" + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "const", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 0, + 5 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ] + }, + { + "type": "Identifier", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ] + }, + { + "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": 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": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-const-undefined.src.js b/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-const-undefined.src.js new file mode 100644 index 0000000..80b78cb --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-const-undefined.src.js @@ -0,0 +1 @@ +const {a} = {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-let-named.result.js b/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-let-named.result.js new file mode 100644 index 0000000..4409bcd --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-let-named.result.js @@ -0,0 +1,333 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 0, + 15 + ], + "body": [ + { + "type": "VariableDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 0, + 15 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 4, + 14 + ], + "id": { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 4, + 9 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 5, + 8 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ], + "name": "a" + }, + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ], + "name": "b" + }, + "kind": "init" + } + ] + }, + "init": { + "type": "ObjectExpression", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 12, + 14 + ], + "properties": [] + } + } + ], + "kind": "let" + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "let", + "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": "a", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ] + }, + { + "type": "Punctuator", + "value": ":", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ] + }, + { + "type": "Identifier", + "value": "b", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ] + }, + { + "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": 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": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-let-named.src.js b/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-let-named.src.js new file mode 100644 index 0000000..53b1654 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-let-named.src.js @@ -0,0 +1 @@ +let {a:b} = {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-let-undefined.result.js b/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-let-undefined.result.js new file mode 100644 index 0000000..1b70558 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-let-undefined.result.js @@ -0,0 +1,297 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 0, + 13 + ], + "body": [ + { + "type": "VariableDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 0, + 13 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 4, + 12 + ], + "id": { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 4, + 7 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ], + "name": "a" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ], + "name": "a" + } + } + ] + }, + "init": { + "type": "ObjectExpression", + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 10, + 12 + ], + "properties": [] + } + } + ], + "kind": "let" + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "let", + "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": "a", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ] + }, + { + "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": "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": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 12, + 13 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-let-undefined.src.js b/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-let-undefined.src.js new file mode 100644 index 0000000..51c02f8 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-blockBindings/object-let-undefined.src.js @@ -0,0 +1 @@ +let {a} = {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-array.result.js b/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-array.result.js new file mode 100644 index 0000000..47a9f6b --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-array.result.js @@ -0,0 +1,441 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 0, + 25 + ], + "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": "f" + }, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "AssignmentPattern", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "range": [ + 11, + 20 + ], + "left": { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 11, + 14 + ], + "elements": [ + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 12, + 13 + ], + "name": "x" + } + ] + }, + "right": { + "type": "ArrayExpression", + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "range": [ + 17, + 20 + ], + "elements": [ + { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "range": [ + 18, + 19 + ], + "value": 1, + "raw": "1" + } + ] + } + } + ], + "body": { + "type": "BlockStatement", + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "range": [ + 22, + 24 + ], + "body": [] + } + }, + { + "type": "EmptyStatement", + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 24, + 25 + ] + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "function", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 0, + 8 + ] + }, + { + "type": "Identifier", + "value": "f", + "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": "x", + "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": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 17, + 18 + ] + }, + { + "type": "Numeric", + "value": "1", + "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 + ] + }, + { + "type": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 24, + 25 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-array.src.js b/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-array.src.js new file mode 100644 index 0000000..b233ca5 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-array.src.js @@ -0,0 +1 @@ +function f([x] = [1]) {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-object-short.result.js b/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-object-short.result.js new file mode 100644 index 0000000..648d9c7 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-object-short.result.js @@ -0,0 +1,650 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "range": [ + 0, + 24 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "range": [ + 0, + 24 + ], + "expression": { + "type": "ObjectExpression", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "range": [ + 1, + 22 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "range": [ + 2, + 21 + ], + "method": true, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ], + "name": "f" + }, + "kind": "init", + "value": { + "type": "FunctionExpression", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "range": [ + 3, + 21 + ], + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "AssignmentPattern", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 4, + 17 + ], + "left": { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 4, + 7 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ], + "name": "x" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ], + "name": "x" + } + } + ] + }, + "right": { + "type": "ObjectExpression", + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 10, + 17 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 11, + 16 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 11, + 12 + ], + "name": "x" + }, + "value": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 14, + 16 + ], + "value": 10, + "raw": "10" + }, + "kind": "init" + } + ] + } + } + ], + "body": { + "type": "BlockStatement", + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "range": [ + 19, + 21 + ], + "body": [] + } + } + } + ] + } + } + ], + "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": "f", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ] + }, + { + "type": "Punctuator", + "value": "(", + "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": "x", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ] + }, + { + "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": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 10, + 11 + ] + }, + { + "type": "Identifier", + "value": "x", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 11, + 12 + ] + }, + { + "type": "Punctuator", + "value": ":", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 12, + 13 + ] + }, + { + "type": "Numeric", + "value": "10", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 14, + 16 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 16, + 17 + ] + }, + { + "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": 20 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "range": [ + 20, + 21 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "range": [ + 21, + 22 + ] + }, + { + "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/destructuring-and-defaultParams/param-object-short.src.js b/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-object-short.src.js new file mode 100644 index 0000000..0821397 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-object-short.src.js @@ -0,0 +1 @@ +({f({x} = {x: 10}) {}}); \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-object-wrapped.result.js b/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-object-wrapped.result.js new file mode 100644 index 0000000..f7e1f37 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-object-wrapped.result.js @@ -0,0 +1,141 @@ +module.exports = { + "type": "Program", + "body": [ + { + type: 'ExpressionStatement', + expression: { + type: 'ObjectExpression', + properties: [{ + type: 'Property', + key: { + type: 'Identifier', + name: 'f', + range: [2, 3], + loc: { + start: { line: 1, column: 2 }, + end: { line: 1, column: 3 } + } + }, + value: { + type: 'FunctionExpression', + id: null, + params: [{ + type: 'ObjectPattern', + properties: [{ + type: 'Property', + key: { + type: 'Identifier', + name: 'x', + range: [15, 16], + loc: { + start: { line: 1, column: 15 }, + end: { line: 1, column: 16 } + } + }, + value: { + type: 'Identifier', + name: 'x', + range: [15, 16], + loc: { + start: { line: 1, column: 15 }, + end: { line: 1, column: 16 } + } + }, + kind: 'init', + method: false, + shorthand: true, + computed: false, + range: [15, 16], + loc: { + start: { line: 1, column: 15 }, + end: { line: 1, column: 16 } + } + }], + range: [14, 17], + loc: { + start: { line: 1, column: 14 }, + end: { line: 1, column: 17 } + } + }], + defaults: [{ + type: 'ObjectExpression', + properties: [{ + type: 'Property', + key: { + type: 'Identifier', + name: 'x', + range: [21, 22], + loc: { + start: { line: 1, column: 21 }, + end: { line: 1, column: 22 } + } + }, + value: { + type: 'Literal', + value: 10, + raw: '10', + range: [24, 26], + loc: { + start: { line: 1, column: 24 }, + end: { line: 1, column: 26 } + } + }, + kind: 'init', + method: false, + shorthand: false, + computed: false, + range: [21, 26], + loc: { + start: { line: 1, column: 21 }, + end: { line: 1, column: 26 } + } + }], + range: [20, 27], + loc: { + start: { line: 1, column: 20 }, + end: { line: 1, column: 27 } + } + }], + body: { + type: 'BlockStatement', + body: [], + range: [29, 31], + loc: { + start: { line: 1, column: 29 }, + end: { line: 1, column: 31 } + } + }, + rest: null, + generator: false, + expression: false, + async: false, + range: [5, 31], + loc: { + start: { line: 1, column: 5 }, + end: { line: 1, column: 31 } + } + }, + kind: 'init', + method: false, + shorthand: false, + computed: false, + range: [2, 31], + loc: { + start: { line: 1, column: 2 }, + end: { line: 1, column: 31 } + } + }], + range: [1, 32], + loc: { + start: { line: 1, column: 1 }, + end: { line: 1, column: 32 } + } + }, + range: [0, 33], + loc: { + start: { line: 1, column: 0 }, + end: { line: 1, column: 33 } + } + } + ] +} diff --git a/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-object-wrapped.src.xjs b/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-object-wrapped.src.xjs new file mode 100644 index 0000000..1740302 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-object-wrapped.src.xjs @@ -0,0 +1 @@ +({f: function({x} = {x: 10}) {}}); \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-object.result.js b/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-object.result.js new file mode 100644 index 0000000..be4e7ab --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-object.result.js @@ -0,0 +1,592 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "range": [ + 0, + 31 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "range": [ + 0, + 31 + ], + "expression": { + "type": "AssignmentExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "range": [ + 0, + 30 + ], + "operator": "=", + "left": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "range": [ + 0, + 1 + ], + "name": "f" + }, + "right": { + "type": "FunctionExpression", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "range": [ + 4, + 30 + ], + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "AssignmentPattern", + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "range": [ + 13, + 26 + ], + "left": { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 13, + 16 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ], + "name": "x" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ], + "name": "x" + } + } + ] + }, + "right": { + "type": "ObjectExpression", + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "range": [ + 19, + 26 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 20, + 25 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "range": [ + 20, + 21 + ], + "name": "x" + }, + "value": { + "type": "Literal", + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 23, + 25 + ], + "value": 10, + "raw": "10" + }, + "kind": "init" + } + ] + } + } + ], + "body": { + "type": "BlockStatement", + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "range": [ + 28, + 30 + ], + "body": [] + } + } + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Identifier", + "value": "f", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "range": [ + 0, + 1 + ] + }, + { + "type": "Punctuator", + "value": "=", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ] + }, + { + "type": "Keyword", + "value": "function", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 4, + 12 + ] + }, + { + "type": "Punctuator", + "value": "(", + "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": "Identifier", + "value": "x", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ] + }, + { + "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": 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": "Identifier", + "value": "x", + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "range": [ + 20, + 21 + ] + }, + { + "type": "Punctuator", + "value": ":", + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "range": [ + 21, + 22 + ] + }, + { + "type": "Numeric", + "value": "10", + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 23, + 25 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "range": [ + 25, + 26 + ] + }, + { + "type": "Punctuator", + "value": ")", + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "range": [ + 26, + 27 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "range": [ + 28, + 29 + ] + }, + { + "type": "Punctuator", + "value": "}", + "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 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-object.src.js b/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-object.src.js new file mode 100644 index 0000000..753d7b4 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-defaultParams/param-object.src.js @@ -0,0 +1 @@ +f = function({x} = {x: 10}) {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-forOf/loop.result.js b/tests/fixtures/ecma-features/destructuring-and-forOf/loop.result.js new file mode 100644 index 0000000..af1e17a --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-forOf/loop.result.js @@ -0,0 +1,273 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 0, + 17 + ], + "body": [ + { + "type": "ForOfStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 0, + 17 + ], + "left": { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 5, + 8 + ], + "elements": [ + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ], + "name": "a" + } + ] + }, + "right": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 12, + 15 + ], + "name": "foo" + }, + "body": { + "type": "EmptyStatement", + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 16, + 17 + ] + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "for", + "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": "Punctuator", + "value": "[", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ] + }, + { + "type": "Identifier", + "value": "a", + "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": "of", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 9, + 11 + ] + }, + { + "type": "Identifier", + "value": "foo", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 12, + 15 + ] + }, + { + "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 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-forOf/loop.src.js b/tests/fixtures/ecma-features/destructuring-and-forOf/loop.src.js new file mode 100644 index 0000000..7751aed --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-forOf/loop.src.js @@ -0,0 +1 @@ +for ([a] of foo); diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/complex-destructured.result.js b/tests/fixtures/ecma-features/destructuring-and-spread/complex-destructured.result.js new file mode 100644 index 0000000..0e76969 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/complex-destructured.result.js @@ -0,0 +1,496 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "range": [ + 0, + 21 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "range": [ + 0, + 21 + ], + "expression": { + "type": "AssignmentExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "range": [ + 0, + 20 + ], + "operator": "=", + "left": { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 0, + 16 + ], + "elements": [ + { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 1, + 9 + ], + "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": "RestElement", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 11, + 15 + ], + "argument": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ], + "name": "c" + } + } + ] + }, + "right": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "range": [ + 19, + 20 + ], + "name": "d" + } + } + } + ], + "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": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ] + }, + { + "type": "Punctuator", + "value": "...", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 11, + 14 + ] + }, + { + "type": "Identifier", + "value": "c", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ] + }, + { + "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": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 17, + 18 + ] + }, + { + "type": "Identifier", + "value": "d", + "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 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/complex-destructured.src.js b/tests/fixtures/ecma-features/destructuring-and-spread/complex-destructured.src.js new file mode 100644 index 0000000..a14d109 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/complex-destructured.src.js @@ -0,0 +1 @@ +[{ a, b }, ...c] = d; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/destructured-array-literal.result.js b/tests/fixtures/ecma-features/destructuring-and-spread/destructured-array-literal.result.js new file mode 100644 index 0000000..0a7da17 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/destructured-array-literal.result.js @@ -0,0 +1,418 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "range": [ + 0, + 19 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "range": [ + 0, + 19 + ], + "expression": { + "type": "AssignmentExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 0, + 18 + ], + "operator": "=", + "left": { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 0, + 14 + ], + "elements": [ + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "range": [ + 1, + 2 + ], + "name": "a" + }, + { + "type": "RestElement", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 4, + 13 + ], + "argument": { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 7, + 13 + ], + "elements": [ + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ], + "name": "b" + }, + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 11, + 12 + ], + "name": "c" + } + ] + } + } + ] + }, + "right": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 17, + 18 + ], + "name": "d" + } + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Punctuator", + "value": "[", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "range": [ + 0, + 1 + ] + }, + { + "type": "Identifier", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "range": [ + 1, + 2 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ] + }, + { + "type": "Punctuator", + "value": "...", + "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": "b", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ] + }, + { + "type": "Identifier", + "value": "c", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 11, + 12 + ] + }, + { + "type": "Punctuator", + "value": "]", + "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": "Identifier", + "value": "d", + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 17, + 18 + ] + }, + { + "type": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "range": [ + 18, + 19 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/destructured-array-literal.src.js b/tests/fixtures/ecma-features/destructuring-and-spread/destructured-array-literal.src.js new file mode 100644 index 0000000..aa3e6be --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/destructured-array-literal.src.js @@ -0,0 +1 @@ +[a, ...[b, c]] = d; diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/destructuring-param.result.js b/tests/fixtures/ecma-features/destructuring-and-spread/destructuring-param.result.js new file mode 100644 index 0000000..8b9c1f7 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/destructuring-param.result.js @@ -0,0 +1,512 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "range": [ + 0, + 31 + ], + "body": [ + { + "type": "FunctionDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "range": [ + 0, + 30 + ], + "id": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ], + "name": "a" + }, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "range": [ + 11, + 26 + ], + "elements": [ + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 12, + 13 + ], + "name": "a" + }, + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 15, + 16 + ], + "name": "b" + }, + { + "type": "RestElement", + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 18, + 25 + ], + "argument": { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 21, + 25 + ], + "elements": [ + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "range": [ + 22, + 24 + ], + "name": "ok" + } + ] + } + } + ] + } + ], + "body": { + "type": "BlockStatement", + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "range": [ + 28, + 30 + ], + "body": [] + } + }, + { + "type": "EmptyStatement", + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "range": [ + 30, + 31 + ] + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "function", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 0, + 8 + ] + }, + { + "type": "Identifier", + "value": "a", + "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": "Identifier", + "value": "b", + "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 + ] + }, + { + "type": "Punctuator", + "value": "...", + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "range": [ + 18, + 21 + ] + }, + { + "type": "Punctuator", + "value": "[", + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "range": [ + 21, + 22 + ] + }, + { + "type": "Identifier", + "value": "ok", + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "range": [ + 22, + 24 + ] + }, + { + "type": "Punctuator", + "value": "]", + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 24, + 25 + ] + }, + { + "type": "Punctuator", + "value": "]", + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "range": [ + 25, + 26 + ] + }, + { + "type": "Punctuator", + "value": ")", + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "range": [ + 26, + 27 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "range": [ + 28, + 29 + ] + }, + { + "type": "Punctuator", + "value": "}", + "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 + ] + } + ] +}; diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/destructuring-param.src.js b/tests/fixtures/ecma-features/destructuring-and-spread/destructuring-param.src.js new file mode 100644 index 0000000..28bec5e --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/destructuring-param.src.js @@ -0,0 +1 @@ +function a([a, b, ...[ok]]) {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/error-complex-destructured-spread-first.result.js b/tests/fixtures/ecma-features/destructuring-and-spread/error-complex-destructured-spread-first.result.js new file mode 100644 index 0000000..5c1edf7 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/error-complex-destructured-spread-first.result.js @@ -0,0 +1,6 @@ +module.exports = { + "index": 5, + "lineNumber": 1, + "column": 6, + "message": "Comma is not permitted after the rest element" +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/error-complex-destructured-spread-first.src.js b/tests/fixtures/ecma-features/destructuring-and-spread/error-complex-destructured-spread-first.src.js new file mode 100644 index 0000000..eee9879 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/error-complex-destructured-spread-first.src.js @@ -0,0 +1 @@ +[...c, { a, b }] = d; diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/invalid-not-final-array-empty.result.js b/tests/fixtures/ecma-features/destructuring-and-spread/invalid-not-final-array-empty.result.js new file mode 100644 index 0000000..5c1edf7 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/invalid-not-final-array-empty.result.js @@ -0,0 +1,6 @@ +module.exports = { + "index": 5, + "lineNumber": 1, + "column": 6, + "message": "Comma is not permitted after the rest element" +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/invalid-not-final-array-empty.src.xjs b/tests/fixtures/ecma-features/destructuring-and-spread/invalid-not-final-array-empty.src.xjs new file mode 100644 index 0000000..6154cfe --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/invalid-not-final-array-empty.src.xjs @@ -0,0 +1 @@ +[...a, ] = b; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/multi-destructured.result.js b/tests/fixtures/ecma-features/destructuring-and-spread/multi-destructured.result.js new file mode 100644 index 0000000..e46fa0a --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/multi-destructured.result.js @@ -0,0 +1,309 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 0, + 14 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 0, + 14 + ], + "expression": { + "type": "AssignmentExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 0, + 13 + ], + "operator": "=", + "left": { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 0, + 9 + ], + "elements": [ + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "range": [ + 1, + 2 + ], + "name": "a" + }, + { + "type": "RestElement", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 4, + 8 + ], + "argument": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ], + "name": "b" + } + } + ] + }, + "right": { + "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": "Identifier", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "range": [ + 1, + 2 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 2, + 3 + ] + }, + { + "type": "Punctuator", + "value": "...", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 4, + 7 + ] + }, + { + "type": "Identifier", + "value": "b", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ] + }, + { + "type": "Punctuator", + "value": "]", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ] + }, + { + "type": "Punctuator", + "value": "=", + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 10, + 11 + ] + }, + { + "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 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/multi-destructured.src.js b/tests/fixtures/ecma-features/destructuring-and-spread/multi-destructured.src.js new file mode 100644 index 0000000..c7f6aa9 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/multi-destructured.src.js @@ -0,0 +1 @@ +[a, ...b] = c; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/not-final-array.result.js b/tests/fixtures/ecma-features/destructuring-and-spread/not-final-array.result.js new file mode 100644 index 0000000..5c1edf7 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/not-final-array.result.js @@ -0,0 +1,6 @@ +module.exports = { + "index": 5, + "lineNumber": 1, + "column": 6, + "message": "Comma is not permitted after the rest element" +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/not-final-array.src.xjs b/tests/fixtures/ecma-features/destructuring-and-spread/not-final-array.src.xjs new file mode 100644 index 0000000..cb9a2a1 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/not-final-array.src.xjs @@ -0,0 +1 @@ +[...a, b] = c; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/single-destructured.result.js b/tests/fixtures/ecma-features/destructuring-and-spread/single-destructured.result.js new file mode 100644 index 0000000..8d4b931 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/single-destructured.result.js @@ -0,0 +1,255 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 0, + 11 + ], + "body": [ + { + "type": "ExpressionStatement", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 0, + 11 + ], + "expression": { + "type": "AssignmentExpression", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 0, + 10 + ], + "operator": "=", + "left": { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 0, + 6 + ], + "elements": [ + { + "type": "RestElement", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 1, + 5 + ], + "argument": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 4, + 5 + ], + "name": "a" + } + } + ] + }, + "right": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ], + "name": "b" + } + } + } + ], + "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": 4 + } + }, + "range": [ + 1, + 4 + ] + }, + { + "type": "Identifier", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 4, + 5 + ] + }, + { + "type": "Punctuator", + "value": "]", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ] + }, + { + "type": "Punctuator", + "value": "=", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ] + }, + { + "type": "Identifier", + "value": "b", + "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 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/single-destructured.src.js b/tests/fixtures/ecma-features/destructuring-and-spread/single-destructured.src.js new file mode 100644 index 0000000..0be6e5d --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/single-destructured.src.js @@ -0,0 +1 @@ +[...a] = b; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/var-complex-destructured.result.js b/tests/fixtures/ecma-features/destructuring-and-spread/var-complex-destructured.result.js new file mode 100644 index 0000000..085d47f --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/var-complex-destructured.result.js @@ -0,0 +1,516 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 0, + 25 + ], + "body": [ + { + "type": "VariableDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 0, + 25 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "range": [ + 4, + 24 + ], + "id": { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "range": [ + 4, + 20 + ], + "elements": [ + { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 5, + 13 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ], + "name": "a" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ], + "name": "a" + } + }, + { + "type": "Property", + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 10, + 11 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 10, + 11 + ], + "name": "b" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "range": [ + 10, + 11 + ], + "name": "b" + } + } + ] + }, + { + "type": "RestElement", + "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": "c" + } + } + ] + }, + "init": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "range": [ + 23, + 24 + ], + "name": "d" + } + } + ], + "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": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ] + }, + { + "type": "Identifier", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 7, + 8 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ] + }, + { + "type": "Identifier", + "value": "b", + "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": 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": "c", + "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": 21 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "range": [ + 21, + 22 + ] + }, + { + "type": "Identifier", + "value": "d", + "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 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/var-complex-destructured.src.js b/tests/fixtures/ecma-features/destructuring-and-spread/var-complex-destructured.src.js new file mode 100644 index 0000000..dabf00d --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/var-complex-destructured.src.js @@ -0,0 +1 @@ +var [{ a, b }, ...c] = d; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/var-destructured-array-literal.result.js b/tests/fixtures/ecma-features/destructuring-and-spread/var-destructured-array-literal.result.js new file mode 100644 index 0000000..7610b6e --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/var-destructured-array-literal.result.js @@ -0,0 +1,438 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "range": [ + 0, + 23 + ], + "body": [ + { + "type": "VariableDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "range": [ + 0, + 23 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "range": [ + 4, + 22 + ], + "id": { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 4, + 18 + ], + "elements": [ + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ], + "name": "a" + }, + { + "type": "RestElement", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 8, + 17 + ], + "argument": { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 11, + 17 + ], + "elements": [ + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 12, + 13 + ], + "name": "b" + }, + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "range": [ + 15, + 16 + ], + "name": "c" + } + ] + } + } + ] + }, + "init": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "range": [ + 21, + 22 + ], + "name": "d" + } + } + ], + "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": "a", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ] + }, + { + "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": 11 + } + }, + "range": [ + 8, + 11 + ] + }, + { + "type": "Punctuator", + "value": "[", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 11, + 12 + ] + }, + { + "type": "Identifier", + "value": "b", + "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": "Identifier", + "value": "c", + "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 + ] + }, + { + "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": "Identifier", + "value": "d", + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "range": [ + 21, + 22 + ] + }, + { + "type": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "range": [ + 22, + 23 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/var-destructured-array-literal.src.js b/tests/fixtures/ecma-features/destructuring-and-spread/var-destructured-array-literal.src.js new file mode 100644 index 0000000..ed56a20 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/var-destructured-array-literal.src.js @@ -0,0 +1 @@ +var [a, ...[b, c]] = d; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/var-multi-destructured.result.js b/tests/fixtures/ecma-features/destructuring-and-spread/var-multi-destructured.result.js new file mode 100644 index 0000000..bf92133 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/var-multi-destructured.result.js @@ -0,0 +1,329 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 0, + 18 + ], + "body": [ + { + "type": "VariableDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 0, + 18 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 4, + 17 + ], + "id": { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 4, + 13 + ], + "elements": [ + { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ], + "name": "a" + }, + { + "type": "RestElement", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 8, + 12 + ], + "argument": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 11, + 12 + ], + "name": "b" + } + } + ] + }, + "init": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 16, + 17 + ], + "name": "c" + } + } + ], + "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": "a", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "range": [ + 5, + 6 + ] + }, + { + "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": 11 + } + }, + "range": [ + 8, + 11 + ] + }, + { + "type": "Identifier", + "value": "b", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 11, + 12 + ] + }, + { + "type": "Punctuator", + "value": "]", + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "range": [ + 12, + 13 + ] + }, + { + "type": "Punctuator", + "value": "=", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ] + }, + { + "type": "Identifier", + "value": "c", + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "range": [ + 16, + 17 + ] + }, + { + "type": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 17, + 18 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/var-multi-destructured.src.js b/tests/fixtures/ecma-features/destructuring-and-spread/var-multi-destructured.src.js new file mode 100644 index 0000000..897bcba --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/var-multi-destructured.src.js @@ -0,0 +1 @@ +var [a, ...b] = c; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/var-single-destructured.result.js b/tests/fixtures/ecma-features/destructuring-and-spread/var-single-destructured.result.js new file mode 100644 index 0000000..cd58c3a --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/var-single-destructured.result.js @@ -0,0 +1,275 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 0, + 15 + ], + "body": [ + { + "type": "VariableDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 0, + 15 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 4, + 14 + ], + "id": { + "type": "ArrayPattern", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 4, + 10 + ], + "elements": [ + { + "type": "RestElement", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 5, + 9 + ], + "argument": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ], + "name": "a" + } + } + ] + }, + "init": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 13, + 14 + ], + "name": "b" + } + } + ], + "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": "Punctuator", + "value": "...", + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "range": [ + 5, + 8 + ] + }, + { + "type": "Identifier", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ] + }, + { + "type": "Punctuator", + "value": "]", + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "range": [ + 9, + 10 + ] + }, + { + "type": "Punctuator", + "value": "=", + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "range": [ + 11, + 12 + ] + }, + { + "type": "Identifier", + "value": "b", + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "range": [ + 13, + 14 + ] + }, + { + "type": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "range": [ + 14, + 15 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/destructuring-and-spread/var-single-destructured.src.js b/tests/fixtures/ecma-features/destructuring-and-spread/var-single-destructured.src.js new file mode 100644 index 0000000..e6dc8d6 --- /dev/null +++ b/tests/fixtures/ecma-features/destructuring-and-spread/var-single-destructured.src.js @@ -0,0 +1 @@ +var [...a] = b; \ No newline at end of file diff --git a/tests/lib/ecma-features.js b/tests/lib/ecma-features.js index eda1883..b5f9609 100644 --- a/tests/lib/ecma-features.js +++ b/tests/lib/ecma-features.js @@ -70,7 +70,7 @@ describe("ecmaFeatures", () => { const feature = path.dirname(filename), code = shelljs.cat(`${path.resolve(FIXTURES_DIR, filename)}.src.js`); - it(`should parse correctly when ${feature} is true`, () => { + it(`should parse correctly when ${feature} is true ${filename}`, () => { config.ecmaFeatures[feature] = true; let expected = null;