From 055130bf518b6d44ad3eed775e05f8090882da7f Mon Sep 17 00:00:00 2001 From: Jamund Ferguson Date: Mon, 9 Feb 2015 16:33:41 -0800 Subject: [PATCH] New: Rest Parameter (refs: #10) --- README.md | 3 + espree.js | 83 ++- lib/ast-node-factory.js | 17 +- lib/ast-node-types.js | 1 + lib/features.js | 3 + lib/messages.js | 6 + tests/fixtures/ast/API.json | 1 + .../arrow-rest-multi.config.js | 5 + .../arrow-rest-multi.result.js | 113 ++++ .../arrow-rest-multi.src.js | 1 + .../arrow-rest.config.js | 4 + .../arrow-rest.result.js | 94 ++++ .../arrow-rest.src.js | 1 + .../destructured-arrow-array.config.js | 5 + .../destructured-arrow-array.result.js | 171 ++++++ .../destructured-arrow-array.src.js | 1 + .../destructured-arrow-multi.config.js | 5 + .../destructured-arrow-multi.result.js | 283 ++++++++++ .../destructured-arrow-multi.src.js | 1 + .../destructured-arrow-object.config.js | 5 + .../destructured-arrow-object.result.js | 208 ++++++++ .../destructured-arrow-object.src.js | 1 + .../destructuring.config.js | 5 + .../destructuring.result.js | 148 ++++++ .../destructuring.src.js | 1 + .../shortHand-destructuring-array.config.js | 6 + .../shortHand-destructuring-array.result.js | 189 +++++++ .../shortHand-destructuring-array.src.js | 1 + .../shortHand-multi-destructuring.config.js | 6 + .../shortHand-multi-destructuring.result.js | 493 ++++++++++++++++++ .../shortHand-multi-destructuring.src.js | 1 + .../restParams/basic-rest.result.js | 130 +++++ .../restParams/basic-rest.src.js | 1 + .../restParams/error-no-default.result.js | 6 + .../restParams/error-no-default.src.js | 1 + .../restParams/error-not-last.result.js | 6 + .../restParams/error-not-last.src.js | 1 + .../func-expression-multi.result.js | 151 ++++++ .../restParams/func-expression-multi.src.js | 1 + .../restParams/func-expression.result.js | 132 +++++ .../restParams/func-expression.src.js | 1 + .../restParams/invalid-rest-param.result.js | 6 + .../restParams/invalid-rest-param.src.js | 1 + .../restParams/single-rest.result.js | 111 ++++ .../restParams/single-rest.src.js | 1 + 45 files changed, 2395 insertions(+), 16 deletions(-) create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest-multi.config.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest-multi.result.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest-multi.src.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest.config.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest.result.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest.src.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-array.config.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-array.result.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-array.src.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-multi.config.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-multi.result.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-multi.src.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-object.config.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-object.result.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-object.src.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-destructuring/destructuring.config.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-destructuring/destructuring.result.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-destructuring/destructuring.src.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-destructuring-array.config.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-destructuring-array.result.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-destructuring-array.src.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-multi-destructuring.config.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-multi-destructuring.result.js create mode 100644 tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-multi-destructuring.src.js create mode 100644 tests/fixtures/ecma-features/restParams/basic-rest.result.js create mode 100644 tests/fixtures/ecma-features/restParams/basic-rest.src.js create mode 100644 tests/fixtures/ecma-features/restParams/error-no-default.result.js create mode 100644 tests/fixtures/ecma-features/restParams/error-no-default.src.js create mode 100644 tests/fixtures/ecma-features/restParams/error-not-last.result.js create mode 100644 tests/fixtures/ecma-features/restParams/error-not-last.src.js create mode 100644 tests/fixtures/ecma-features/restParams/func-expression-multi.result.js create mode 100644 tests/fixtures/ecma-features/restParams/func-expression-multi.src.js create mode 100644 tests/fixtures/ecma-features/restParams/func-expression.result.js create mode 100644 tests/fixtures/ecma-features/restParams/func-expression.src.js create mode 100644 tests/fixtures/ecma-features/restParams/invalid-rest-param.result.js create mode 100644 tests/fixtures/ecma-features/restParams/invalid-rest-param.src.js create mode 100644 tests/fixtures/ecma-features/restParams/single-rest.result.js create mode 100644 tests/fixtures/ecma-features/restParams/single-rest.src.js diff --git a/README.md b/README.md index 1b420915..c06c9584 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,9 @@ var ast = espree.parse(code, { // enable parsing of default parameters defaultParams: false, + // enable parsing of rest parameters + restParams: true, + // enable parsing of for-of statement forOf: true, diff --git a/espree.js b/espree.js index e75e6716..a5ee0796 100644 --- a/espree.js +++ b/espree.js @@ -553,7 +553,7 @@ function scanPunctuator() { } // The ... operator only valid in JSX mode for now - if (extra.ecmaFeatures.jsx && state.inJSXSpreadAttribute) { + if (extra.ecmaFeatures.restParams || (extra.ecmaFeatures.jsx && state.inJSXSpreadAttribute)) { if (ch1 === "." && ch2 === "." && ch3 === ".") { index += 3; return { @@ -2860,6 +2860,15 @@ function parseArguments() { return args; } +function parseSpreadOrAssignmentExpression() { + if (match("...")) { + var marker = markerCreate(); + lex(); + return markerApply(marker, astNodeFactory.createSpreadElement(parseAssignmentExpression())); + } + return parseAssignmentExpression(); +} + function parseNonComputedProperty() { var token, marker = markerCreate(); @@ -3218,6 +3227,13 @@ function reinterpretAsCoverFormalsList(expressions) { reinterpretAsDestructuredParameter(options, param); params.push(param); defaults.push(null); + } else if (param.type === astNodeTypes.SpreadElement) { + assert(i === len - 1, "It is guaranteed that SpreadElement is last element by parseExpression"); + if (param.argument.type !== astNodeTypes.Identifier) { + throwError({}, Messages.InvalidLHSInFormalsList); + } + reinterpretAsDestructuredParameter(options, param.argument); + rest = param.argument; } else if (param.type === astNodeTypes.AssignmentExpression) { params.push(param.left); defaults.push(param.right); @@ -3266,7 +3282,13 @@ function parseArrowFunctionExpression(options, marker) { } strict = previousStrict; - return markerApply(marker, astNodeFactory.createArrowFunctionExpression(options.params, options.defaults, body, body.type !== astNodeTypes.BlockStatement)); + return markerApply(marker, astNodeFactory.createArrowFunctionExpression( + options.params, + options.defaults, + body, + options.rest, + body.type !== astNodeTypes.BlockStatement + )); } // 11.13 Assignment Operators @@ -3323,7 +3345,7 @@ function reinterpretAsDestructuredParameter(options, expr) { allowDestructuring = extra.ecmaFeatures.destructuring; if (!allowDestructuring) { - throwUnexpected(lex()); + throwUnexpected(lex()); } if (expr.type === astNodeTypes.ObjectExpression) { @@ -3374,7 +3396,7 @@ function parseAssignmentExpression() { if (match("(")) { token = lookahead2(); - if (token.value === ")" && token.type === Token.Punctuator) { + if ((token.value === ")" && token.type === Token.Punctuator) || token.value === "...") { params = parseParams(); if (!match("=>")) { throwUnexpected(lex()); @@ -3435,26 +3457,37 @@ function parseAssignmentExpression() { // 11.14 Comma Operator function parseExpression() { - var expr, - marker = markerCreate(); - - expr = parseAssignmentExpression(); + var marker = markerCreate(), + expr = parseAssignmentExpression(), + expressions = [ expr ], + sequence, spreadFound; if (match(",")) { - expr = astNodeFactory.createSequenceExpression([ expr ]); - while (index < length) { if (!match(",")) { break; } lex(); - expr.expressions.push(parseAssignmentExpression()); + expr = parseSpreadOrAssignmentExpression(); + expressions.push(expr); + + if (expr.type === astNodeTypes.SpreadElement) { + spreadFound = true; + if (!match(")")) { + throwError({}, Messages.ElementAfterSpreadElement); + } + break; + } } - markerApply(marker, expr); + sequence = markerApply(marker, astNodeFactory.createSequenceExpression(expressions)); } - return expr; + if (spreadFound && lookahead2().value !== "=>") { + throwError({}, Messages.IllegalSpread); + } + + return sequence || expr; } // 12.1 Block @@ -4265,11 +4298,19 @@ function validateParam(options, param, name) { } function parseParam(options) { - var token, param, def, + var token, rest, param, def, + allowRestParams = extra.ecmaFeatures.restParams, allowDestructuring = extra.ecmaFeatures.destructuring, allowDefaultParams = extra.ecmaFeatures.defaultParams; token = lookahead; + if (token.value === "...") { + if (!allowRestParams) { + throwUnexpected(lookahead); + } + token = lex(); + rest = true; + } if (match("[")) { if (!allowDestructuring) { @@ -4278,6 +4319,9 @@ function parseParam(options) { param = parseArrayInitialiser(); reinterpretAsDestructuredParameter(options, param); } else if (match("{")) { + if (rest) { + throwError({}, Messages.ObjectPatternAsRestParameter); + } if (!allowDestructuring) { throwUnexpected(lookahead); } @@ -4289,6 +4333,9 @@ function parseParam(options) { } if (match("=")) { + if (rest) { + throwErrorTolerant(lookahead, Messages.DefaultRestParameter); + } if (!allowDefaultParams) { throwUnexpected(lookahead); } @@ -4297,6 +4344,14 @@ function parseParam(options) { ++options.defaultCount; } + if (rest) { + if (!match(")")) { + throwError({}, Messages.ParameterAfterRestParameter); + } + options.rest = param; + return false; + } + options.params.push(param); options.defaults.push(def ? def : null); // TODO: determine if null or undefined (see: #55) diff --git a/lib/ast-node-factory.js b/lib/ast-node-factory.js index 37cdb31b..06b6930a 100644 --- a/lib/ast-node-factory.js +++ b/lib/ast-node-factory.js @@ -56,19 +56,20 @@ module.exports = { * @param {ASTNode} params The function arguments * @param {ASTNode} defaults Any default arguments * @param {ASTNode} body The function body + * @param {ASTNode} rest The rest parameter * @param {boolean} expression True if the arrow function is created via an expression. * Always false for declarations, but kept here to be in sync with * FunctionExpression objects. * @returns {ASTNode} An ASTNode representing the entire arrow function expression */ - createArrowFunctionExpression: function (params, defaults, body, expression) { + createArrowFunctionExpression: function (params, defaults, body, rest, expression) { return { type: astNodeTypes.ArrowFunctionExpression, id: null, params: params, defaults: defaults, body: body, - rest: null, + rest: rest, generator: false, expression: expression }; @@ -442,6 +443,18 @@ module.exports = { }; }, + /** + * Create an ASTNode representation of a spread element + * @param {ASTNode} argument The array being spread + * @returns {ASTNode} An ASTNode representing a spread element + */ + createSpreadElement: function (argument) { + return { + type: astNodeTypes.SpreadElement, + argument: argument + }; + }, + /** * Create an ASTNode tagged template expression * @param {ASTNode} tag The tag expression diff --git a/lib/ast-node-types.js b/lib/ast-node-types.js index f2343186..58fc3452 100644 --- a/lib/ast-node-types.js +++ b/lib/ast-node-types.js @@ -71,6 +71,7 @@ module.exports = { Property: "Property", ReturnStatement: "ReturnStatement", SequenceExpression: "SequenceExpression", + SpreadElement: "SpreadElement", SwitchCase: "SwitchCase", SwitchStatement: "SwitchStatement", TaggedTemplateExpression: "TaggedTemplateExpression", diff --git a/lib/features.js b/lib/features.js index 667ef77b..c1b24a75 100644 --- a/lib/features.js +++ b/lib/features.js @@ -70,6 +70,9 @@ module.exports = { // enable parsing of default parameters defaultParams: false, + // enable parsing of rest parameters + restParams: false, + // enable parsing of for-of statements forOf: false, diff --git a/lib/messages.js b/lib/messages.js index 112afcff..0d817391 100644 --- a/lib/messages.js +++ b/lib/messages.js @@ -62,11 +62,17 @@ module.exports = { IllegalBreak: "Illegal break statement", IllegalReturn: "Illegal return statement", IllegalYield: "Illegal yield expression", + IllegalSpread: "Illegal spread element", StrictModeWith: "Strict mode code may not include a with statement", StrictCatchVariable: "Catch variable may not be eval or arguments in strict mode", StrictVarName: "Variable name may not be eval or arguments in strict mode", StrictParamName: "Parameter name eval or arguments is not allowed in strict mode", StrictParamDupe: "Strict mode function may not have duplicate parameter names", + ParameterAfterRestParameter: "Rest parameter must be final parameter of an argument list", + DefaultRestParameter: "Rest parameter can not have a default value", + ElementAfterSpreadElement: "Spread must be the final element of an element list", + ObjectPatternAsRestParameter: "Invalid rest parameter", + ObjectPatternAsSpread: "Invalid spread argument", StrictFunctionName: "Function name may not be eval or arguments in strict mode", StrictOctalLiteral: "Octal literals are not allowed in strict mode.", StrictDelete: "Delete of an unqualified identifier in strict mode.", diff --git a/tests/fixtures/ast/API.json b/tests/fixtures/ast/API.json index 4e88ef8c..b9aa8afa 100644 --- a/tests/fixtures/ast/API.json +++ b/tests/fixtures/ast/API.json @@ -182,6 +182,7 @@ "Property": "Property", "ReturnStatement": "ReturnStatement", "SequenceExpression": "SequenceExpression", + "SpreadElement": "SpreadElement", "SwitchCase": "SwitchCase", "SwitchStatement": "SwitchStatement", "TaggedTemplateExpression": "TaggedTemplateExpression", diff --git a/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest-multi.config.js b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest-multi.config.js new file mode 100644 index 00000000..4ef77f98 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest-multi.config.js @@ -0,0 +1,5 @@ +module.exports = { + arrowFunctions: true, + restParams: true, + destructuring: true +}; diff --git a/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest-multi.result.js b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest-multi.result.js new file mode 100644 index 00000000..f9f287aa --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest-multi.result.js @@ -0,0 +1,113 @@ +module.exports = { + "type": "Program", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "ArrowFunctionExpression", + "id": null, + "params": [ + { + "type": "Identifier", + "name": "a", + "range": [ + 1, + 2 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + } + } + } + ], + "defaults": [], + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 13, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 15 + } + } + }, + "rest": { + "type": "Identifier", + "name": "b", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + "generator": false, + "expression": false, + "range": [ + 0, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + } + }, + "range": [ + 0, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + } + } + ], + "range": [ + 0, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest-multi.src.js b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest-multi.src.js new file mode 100644 index 00000000..09ec648a --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest-multi.src.js @@ -0,0 +1 @@ +(a, ...b) => {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest.config.js b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest.config.js new file mode 100644 index 00000000..37664407 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest.config.js @@ -0,0 +1,4 @@ +module.exports = { + arrowFunctions: true, + restParams: true +}; diff --git a/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest.result.js b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest.result.js new file mode 100644 index 00000000..8e949999 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest.result.js @@ -0,0 +1,94 @@ +module.exports = { + "type": "Program", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "ArrowFunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 10, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + "rest": { + "type": "Identifier", + "name": "a", + "range": [ + 4, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + } + }, + "generator": false, + "expression": false, + "range": [ + 0, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + "range": [ + 0, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + } + } + ], + "range": [ + 0, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest.src.js b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest.src.js new file mode 100644 index 00000000..fae03351 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/arrow-rest.src.js @@ -0,0 +1 @@ +(...a) => {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-array.config.js b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-array.config.js new file mode 100644 index 00000000..4ef77f98 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-array.config.js @@ -0,0 +1,5 @@ +module.exports = { + arrowFunctions: true, + restParams: true, + destructuring: true +}; diff --git a/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-array.result.js b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-array.result.js new file mode 100644 index 00000000..8a7f5a77 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-array.result.js @@ -0,0 +1,171 @@ +module.exports = { + "type": "Program", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "ArrowFunctionExpression", + "id": null, + "params": [ + { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "a", + "range": [ + 3, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + "value": { + "type": "Identifier", + "name": "a", + "range": [ + 3, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + "kind": "init", + "method": false, + "shorthand": true, + "computed": false, + "range": [ + 3, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + } + } + ], + "range": [ + 1, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 6 + } + } + } + ], + "defaults": [], + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 17, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + "rest": { + "type": "Identifier", + "name": "b", + "range": [ + 11, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + "generator": false, + "expression": false, + "range": [ + 0, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + "range": [ + 0, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + } + } + ], + "range": [ + 0, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-array.src.js b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-array.src.js new file mode 100644 index 00000000..9c56a46d --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-array.src.js @@ -0,0 +1 @@ +({ a }, ...b) => {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-multi.config.js b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-multi.config.js new file mode 100644 index 00000000..4ef77f98 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-multi.config.js @@ -0,0 +1,5 @@ +module.exports = { + arrowFunctions: true, + restParams: true, + destructuring: true +}; diff --git a/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-multi.result.js b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-multi.result.js new file mode 100644 index 00000000..482ff54d --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-multi.result.js @@ -0,0 +1,283 @@ +module.exports = { + "type": "Program", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "ArrowFunctionExpression", + "id": null, + "params": [ + { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "a", + "range": [ + 3, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + "value": { + "type": "Identifier", + "name": "b", + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false, + "range": [ + 3, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "c", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + } + }, + "value": { + "type": "Identifier", + "name": "c", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + } + }, + "kind": "init", + "method": false, + "shorthand": true, + "computed": false, + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + } + } + ], + "range": [ + 1, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + { + "type": "ArrayPattern", + "elements": [ + { + "type": "Identifier", + "name": "d", + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + { + "type": "Identifier", + "name": "e", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + } + } + ], + "range": [ + 14, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 20 + } + } + } + ], + "defaults": [], + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 31, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 33 + } + } + }, + "rest": { + "type": "Identifier", + "name": "f", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + "generator": false, + "expression": false, + "range": [ + 0, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + } + }, + "range": [ + 0, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + } + } + ], + "range": [ + 0, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-multi.src.js b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-multi.src.js new file mode 100644 index 00000000..49f55da3 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-multi.src.js @@ -0,0 +1 @@ +({ a: b, c }, [d, e], ...f) => {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-object.config.js b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-object.config.js new file mode 100644 index 00000000..4ef77f98 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-object.config.js @@ -0,0 +1,5 @@ +module.exports = { + arrowFunctions: true, + restParams: true, + destructuring: true +}; diff --git a/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-object.result.js b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-object.result.js new file mode 100644 index 00000000..20426947 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-object.result.js @@ -0,0 +1,208 @@ +module.exports = { + "type": "Program", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "ArrowFunctionExpression", + "id": null, + "params": [ + { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "a", + "range": [ + 3, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + "value": { + "type": "ArrayPattern", + "elements": [ + { + "type": "Identifier", + "name": "a", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + { + "type": "Identifier", + "name": "b", + "range": [ + 10, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + } + } + ], + "range": [ + 6, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false, + "range": [ + 3, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + } + } + } + ], + "range": [ + 1, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 14 + } + } + } + ], + "defaults": [], + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 25, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 27 + } + } + }, + "rest": { + "type": "Identifier", + "name": "c", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + } + }, + "generator": false, + "expression": false, + "range": [ + 0, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + } + }, + "range": [ + 0, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + } + } + ], + "range": [ + 0, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-object.src.js b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-object.src.js new file mode 100644 index 00000000..0aa03bd8 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-arrowFunctions/destructured-arrow-object.src.js @@ -0,0 +1 @@ +({ a: [a, b] }, ...c) => {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features-mix/restParams-and-destructuring/destructuring.config.js b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/destructuring.config.js new file mode 100644 index 00000000..4ef77f98 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/destructuring.config.js @@ -0,0 +1,5 @@ +module.exports = { + arrowFunctions: true, + restParams: true, + destructuring: true +}; diff --git a/tests/fixtures/ecma-features-mix/restParams-and-destructuring/destructuring.result.js b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/destructuring.result.js new file mode 100644 index 00000000..d0538d86 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/destructuring.result.js @@ -0,0 +1,148 @@ +module.exports = { + "type": "Program", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "FunctionExpression", + "id": { + "type": "Identifier", + "name": "x", + "range": [ + 10, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + } + }, + "params": [], + "defaults": [], + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 24, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + "rest": { + "type": "ArrayPattern", + "elements": [ + { + "type": "Identifier", + "name": "a", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + { + "type": "Identifier", + "name": "b", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + } + } + ], + "range": [ + 15, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 23 + } + } + }, + "generator": false, + "expression": false, + "range": [ + 1, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + "range": [ + 0, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + } + } + ], + "range": [ + 0, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 28 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features-mix/restParams-and-destructuring/destructuring.src.js b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/destructuring.src.js new file mode 100644 index 00000000..097b7b54 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/destructuring.src.js @@ -0,0 +1 @@ +(function x(...[ a, b ]){}); \ No newline at end of file diff --git a/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-destructuring-array.config.js b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-destructuring-array.config.js new file mode 100644 index 00000000..b46e9d26 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-destructuring-array.config.js @@ -0,0 +1,6 @@ +module.exports = { + arrowFunctions: true, + restParams: true, + destructuring: true, + objectLiteralShorthandMethods: true +}; diff --git a/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-destructuring-array.result.js b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-destructuring-array.result.js new file mode 100644 index 00000000..1729aeba --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-destructuring-array.result.js @@ -0,0 +1,189 @@ +module.exports = { + "type": "Program", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "x", + "range": [ + 3, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + "value": { + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 17, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + "rest": { + "type": "ArrayPattern", + "elements": [ + { + "type": "Identifier", + "name": "a", + "range": [ + 10, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + } + }, + { + "type": "Identifier", + "name": "b", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + } + ], + "range": [ + 8, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + "generator": false, + "expression": false, + "range": [ + 17, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + "kind": "init", + "method": true, + "shorthand": false, + "computed": false, + "range": [ + 3, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 19 + } + } + } + ], + "range": [ + 1, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 21 + } + } + }, + "range": [ + 0, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + } + } + ], + "range": [ + 0, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-destructuring-array.src.js b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-destructuring-array.src.js new file mode 100644 index 00000000..3a5a2eb8 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-destructuring-array.src.js @@ -0,0 +1 @@ +({ x(...[ a, b ]){} }); \ No newline at end of file diff --git a/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-multi-destructuring.config.js b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-multi-destructuring.config.js new file mode 100644 index 00000000..b46e9d26 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-multi-destructuring.config.js @@ -0,0 +1,6 @@ +module.exports = { + arrowFunctions: true, + restParams: true, + destructuring: true, + objectLiteralShorthandMethods: true +}; diff --git a/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-multi-destructuring.result.js b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-multi-destructuring.result.js new file mode 100644 index 00000000..d573a8d3 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-multi-destructuring.result.js @@ -0,0 +1,493 @@ +module.exports = { + "type": "Program", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "x", + "range": [ + 3, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + "value": { + "type": "FunctionExpression", + "id": null, + "params": [ + { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "a", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + "value": { + "type": "ObjectPattern", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "w", + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + "value": { + "type": "Identifier", + "name": "w", + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + "kind": "init", + "method": false, + "shorthand": true, + "computed": false, + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + { + "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": [ + 10, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false, + "range": [ + 7, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "b", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + } + }, + "value": { + "type": "ArrayPattern", + "elements": [ + { + "type": "Identifier", + "name": "y", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + } + } + }, + { + "type": "Identifier", + "name": "z", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 28 + } + } + } + ], + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 29 + } + } + }, + "kind": "init", + "method": false, + "shorthand": false, + "computed": false, + "range": [ + 20, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 29 + } + } + } + ], + "range": [ + 5, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 31 + } + } + } + ], + "defaults": [], + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 46, + 48 + ], + "loc": { + "start": { + "line": 1, + "column": 46 + }, + "end": { + "line": 1, + "column": 48 + } + } + }, + "rest": { + "type": "ArrayPattern", + "elements": [ + { + "type": "Identifier", + "name": "a", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 1, + "column": 38 + } + } + }, + { + "type": "Identifier", + "name": "b", + "range": [ + 40, + 41 + ], + "loc": { + "start": { + "line": 1, + "column": 40 + }, + "end": { + "line": 1, + "column": 41 + } + } + }, + { + "type": "Identifier", + "name": "c", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 1, + "column": 43 + }, + "end": { + "line": 1, + "column": 44 + } + } + } + ], + "range": [ + 36, + 45 + ], + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 45 + } + } + }, + "generator": false, + "expression": false, + "range": [ + 46, + 48 + ], + "loc": { + "start": { + "line": 1, + "column": 46 + }, + "end": { + "line": 1, + "column": 48 + } + } + }, + "kind": "init", + "method": true, + "shorthand": false, + "computed": false, + "range": [ + 3, + 48 + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 48 + } + } + } + ], + "range": [ + 1, + 50 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 50 + } + } + }, + "range": [ + 0, + 52 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 52 + } + } + } + ], + "range": [ + 0, + 52 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 52 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-multi-destructuring.src.js b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-multi-destructuring.src.js new file mode 100644 index 00000000..8ced8b49 --- /dev/null +++ b/tests/fixtures/ecma-features-mix/restParams-and-destructuring/shortHand-multi-destructuring.src.js @@ -0,0 +1 @@ +({ x({ a: { w, x }, b: [y, z] }, ...[a, b, c]){} }); \ No newline at end of file diff --git a/tests/fixtures/ecma-features/restParams/basic-rest.result.js b/tests/fixtures/ecma-features/restParams/basic-rest.result.js new file mode 100644 index 00000000..9685845e --- /dev/null +++ b/tests/fixtures/ecma-features/restParams/basic-rest.result.js @@ -0,0 +1,130 @@ +module.exports = { + "type": "Program", + "body": [ + { + "type": "FunctionDeclaration", + "id": { + "type": "Identifier", + "name": "f", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + } + }, + "params": [ + { + "type": "Identifier", + "name": "a", + "range": [ + 11, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + } + } + ], + "defaults": [], + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 20, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 22 + } + } + }, + "rest": { + "type": "Identifier", + "name": "b", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + "generator": false, + "expression": false, + "range": [ + 0, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + } + }, + { + "type": "EmptyStatement", + "range": [ + 22, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 23 + } + } + } + ], + "range": [ + 0, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/restParams/basic-rest.src.js b/tests/fixtures/ecma-features/restParams/basic-rest.src.js new file mode 100644 index 00000000..c7d2b947 --- /dev/null +++ b/tests/fixtures/ecma-features/restParams/basic-rest.src.js @@ -0,0 +1 @@ +function f(a, ...b) {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/restParams/error-no-default.result.js b/tests/fixtures/ecma-features/restParams/error-no-default.result.js new file mode 100644 index 00000000..a97b819b --- /dev/null +++ b/tests/fixtures/ecma-features/restParams/error-no-default.result.js @@ -0,0 +1,6 @@ +module.exports = { + "index": 19, + "lineNumber": 1, + "column": 20, + "description": "Rest parameter can not have a default value" +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/restParams/error-no-default.src.js b/tests/fixtures/ecma-features/restParams/error-no-default.src.js new file mode 100644 index 00000000..6de42c24 --- /dev/null +++ b/tests/fixtures/ecma-features/restParams/error-no-default.src.js @@ -0,0 +1 @@ +function f(a, ...b = 0); \ No newline at end of file diff --git a/tests/fixtures/ecma-features/restParams/error-not-last.result.js b/tests/fixtures/ecma-features/restParams/error-not-last.result.js new file mode 100644 index 00000000..c17169be --- /dev/null +++ b/tests/fixtures/ecma-features/restParams/error-not-last.result.js @@ -0,0 +1,6 @@ +module.exports = { + "index": 18, + "lineNumber": 1, + "column": 19, + "description": "Rest parameter must be final parameter of an argument list" +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/restParams/error-not-last.src.js b/tests/fixtures/ecma-features/restParams/error-not-last.src.js new file mode 100644 index 00000000..309cc757 --- /dev/null +++ b/tests/fixtures/ecma-features/restParams/error-not-last.src.js @@ -0,0 +1 @@ +function f(a, ...b, c); \ No newline at end of file diff --git a/tests/fixtures/ecma-features/restParams/func-expression-multi.result.js b/tests/fixtures/ecma-features/restParams/func-expression-multi.result.js new file mode 100644 index 00000000..87606954 --- /dev/null +++ b/tests/fixtures/ecma-features/restParams/func-expression-multi.result.js @@ -0,0 +1,151 @@ +module.exports = { + "type": "Program", + "body": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x", + "range": [ + 4, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + } + }, + "init": { + "type": "FunctionExpression", + "id": null, + "params": [ + { + "type": "Identifier", + "name": "a", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + } + } + ], + "defaults": [], + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 26, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 28 + } + } + }, + "rest": { + "type": "Identifier", + "name": "b", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + } + }, + "generator": false, + "expression": false, + "range": [ + 8, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 28 + } + } + }, + "range": [ + 4, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 28 + } + } + } + ], + "kind": "var", + "range": [ + 0, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + } + } + ], + "range": [ + 0, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/restParams/func-expression-multi.src.js b/tests/fixtures/ecma-features/restParams/func-expression-multi.src.js new file mode 100644 index 00000000..68f41d81 --- /dev/null +++ b/tests/fixtures/ecma-features/restParams/func-expression-multi.src.js @@ -0,0 +1 @@ +var x = function(a, ...b) {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/restParams/func-expression.result.js b/tests/fixtures/ecma-features/restParams/func-expression.result.js new file mode 100644 index 00000000..238d705e --- /dev/null +++ b/tests/fixtures/ecma-features/restParams/func-expression.result.js @@ -0,0 +1,132 @@ +module.exports = { + "type": "Program", + "body": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x", + "range": [ + 4, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + } + }, + "init": { + "type": "FunctionExpression", + "id": null, + "params": [], + "defaults": [], + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 24, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + "rest": { + "type": "Identifier", + "name": "a", + "range": [ + 21, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + } + }, + "generator": false, + "expression": false, + "range": [ + 8, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + "range": [ + 4, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 26 + } + } + } + ], + "kind": "var", + "range": [ + 0, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + } + } + ], + "range": [ + 0, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/restParams/func-expression.src.js b/tests/fixtures/ecma-features/restParams/func-expression.src.js new file mode 100644 index 00000000..a7984c62 --- /dev/null +++ b/tests/fixtures/ecma-features/restParams/func-expression.src.js @@ -0,0 +1 @@ +var x = function (...a) {}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/restParams/invalid-rest-param.result.js b/tests/fixtures/ecma-features/restParams/invalid-rest-param.result.js new file mode 100644 index 00000000..5416df2c --- /dev/null +++ b/tests/fixtures/ecma-features/restParams/invalid-rest-param.result.js @@ -0,0 +1,6 @@ +module.exports = { + "index": 14, + "lineNumber": 1, + "column": 15, + "description": "Invalid rest parameter" +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/restParams/invalid-rest-param.src.js b/tests/fixtures/ecma-features/restParams/invalid-rest-param.src.js new file mode 100644 index 00000000..49f73ed3 --- /dev/null +++ b/tests/fixtures/ecma-features/restParams/invalid-rest-param.src.js @@ -0,0 +1 @@ +function x(...{ a }){}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/restParams/single-rest.result.js b/tests/fixtures/ecma-features/restParams/single-rest.result.js new file mode 100644 index 00000000..ebb3e67b --- /dev/null +++ b/tests/fixtures/ecma-features/restParams/single-rest.result.js @@ -0,0 +1,111 @@ +module.exports = { + "type": "Program", + "body": [ + { + "type": "FunctionDeclaration", + "id": { + "type": "Identifier", + "name": "f", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + } + }, + "params": [], + "defaults": [], + "body": { + "type": "BlockStatement", + "body": [], + "range": [ + 17, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + "rest": { + "type": "Identifier", + "name": "b", + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + } + }, + "generator": false, + "expression": false, + "range": [ + 0, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + { + "type": "EmptyStatement", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + } + } + ], + "range": [ + 0, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/ecma-features/restParams/single-rest.src.js b/tests/fixtures/ecma-features/restParams/single-rest.src.js new file mode 100644 index 00000000..9c90dd49 --- /dev/null +++ b/tests/fixtures/ecma-features/restParams/single-rest.src.js @@ -0,0 +1 @@ +function f(...b) {}; \ No newline at end of file