diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-methods.result.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-methods.result.js new file mode 100644 index 00000000..7590dc13 --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-methods.result.js @@ -0,0 +1,685 @@ +module.exports = { + "type": "Program", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "range": [ + 0, + 114 + ], + "body": [ + { + "type": "VariableDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "range": [ + 0, + 114 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "range": [ + 4, + 113 + ], + "id": { + "type": "Identifier", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 4, + 5 + ], + "name": "x" + }, + "init": { + "type": "ObjectExpression", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "range": [ + 8, + 113 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "range": [ + 14, + 111 + ], + "method": true, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "range": [ + 14, + 24 + ], + "name": "initialize" + }, + "kind": "init", + "value": { + "type": "FunctionExpression", + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "range": [ + 24, + 111 + ], + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "ObjectPattern", + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 46 + } + }, + "range": [ + 25, + 56 + ], + "properties": [ + { + "type": "Property", + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 26, + 33 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 26, + 33 + ], + "name": "someVar" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 26, + 33 + ], + "name": "someVar" + } + }, + { + "type": "Property", + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "range": [ + 35, + 43 + ], + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "range": [ + 35, + 43 + ], + "name": "otherVar" + }, + "kind": "init", + "value": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "range": [ + 35, + 43 + ], + "name": "otherVar" + } + }, + { + "type": "ExperimentalRestProperty", + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "range": [ + 45, + 55 + ], + "argument": { + "type": "Identifier", + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "range": [ + 48, + 55 + ], + "name": "options" + } + } + ] + } + ], + "body": { + "type": "BlockStatement", + "loc": { + "start": { + "line": 2, + "column": 48 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "range": [ + 58, + 111 + ], + "body": [] + } + } + } + ] + } + } + ], + "kind": "var" + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "var", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + } + }, + "range": [ + 0, + 3 + ] + }, + { + "type": "Identifier", + "value": "x", + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "range": [ + 4, + 5 + ] + }, + { + "type": "Punctuator", + "value": "=", + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "range": [ + 6, + 7 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "range": [ + 8, + 9 + ] + }, + { + "type": "Identifier", + "value": "initialize", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "range": [ + 14, + 24 + ] + }, + { + "type": "Punctuator", + "value": "(", + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "range": [ + 24, + 25 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "range": [ + 25, + 26 + ] + }, + { + "type": "Identifier", + "value": "someVar", + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 26, + 33 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "range": [ + 33, + 34 + ] + }, + { + "type": "Identifier", + "value": "otherVar", + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "range": [ + 35, + 43 + ] + }, + { + "type": "Punctuator", + "value": ",", + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "range": [ + 43, + 44 + ] + }, + { + "type": "Punctuator", + "value": "...", + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "range": [ + 45, + 48 + ] + }, + { + "type": "Identifier", + "value": "options", + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "range": [ + 48, + 55 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 46 + } + }, + "range": [ + 55, + 56 + ] + }, + { + "type": "Punctuator", + "value": ")", + "loc": { + "start": { + "line": 2, + "column": 46 + }, + "end": { + "line": 2, + "column": 47 + } + }, + "range": [ + 56, + 57 + ] + }, + { + "type": "Punctuator", + "value": "{", + "loc": { + "start": { + "line": 2, + "column": 48 + }, + "end": { + "line": 2, + "column": 49 + } + }, + "range": [ + 58, + 59 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + }, + "range": [ + 110, + 111 + ] + }, + { + "type": "Punctuator", + "value": "}", + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "range": [ + 112, + 113 + ] + }, + { + "type": "Punctuator", + "value": ";", + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "range": [ + 113, + 114 + ] + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-methods.src.js b/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-methods.src.js new file mode 100644 index 00000000..2eb0d18f --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalObjectRestSpread/shorthand-methods.src.js @@ -0,0 +1,5 @@ +var x = { + initialize({someVar, otherVar, ...options}) { + // ... do some stuff with options ... + } +}; \ No newline at end of file diff --git a/tools/create-test.js b/tools/create-test.js index 32743978..e3ef72a8 100644 --- a/tools/create-test.js +++ b/tools/create-test.js @@ -38,7 +38,7 @@ //------------------------------------------------------------------------------ var shelljs = require("shelljs"), - esprima = require("esprima-fb"), + esprima = require("../espree"), path = require("path"); //------------------------------------------------------------------------------ @@ -94,8 +94,13 @@ code.forEach(function(source, index) { try { result = esprima.parse(sourceCode, { + ecmaVersion: 6, + ecmaFeatures: { + experimentalObjectRestSpread: true + }, loc: true, - range: true + range: true, + tokens: true }); } catch (ex) { result = ex; diff --git a/tools/update-tests.js b/tools/update-tests.js index 6d7e28fd..803a3001 100644 --- a/tools/update-tests.js +++ b/tools/update-tests.js @@ -81,12 +81,12 @@ function outputResult(result, testResultFilename) { //------------------------------------------------------------------------------ var FIXTURES_DIR = "./tests/fixtures/ecma-features", - FIXTURES_MIX_DIR = "./tests/fixtures/ecma-features-mix", + VERSION_DIR = "./tests/fixtures/ecma-version", COMMENTS_DIR = "./tests/fixtures/attach-comments", LIBRARIES_DIR = "./tests/fixtures/libraries"; var testFiles = getTestFilenames(FIXTURES_DIR), - mixFiles = getTestFilenames(FIXTURES_MIX_DIR), + mixFiles = getTestFilenames(VERSION_DIR), commentFiles = getTestFilenames(COMMENTS_DIR), libraryFiles = getLibraryFilenames(LIBRARIES_DIR); @@ -131,6 +131,7 @@ testFiles.forEach(function(filename) { loc: true, range: true, tokens: true, + ecmaVersion: 6, ecmaFeatures: {} }; @@ -141,21 +142,22 @@ testFiles.forEach(function(filename) { outputResult(result, testResultFilename); }); -// update all tests in ecma-features-mix +// update all tests in ecma-version mixFiles.forEach(function(filename) { var feature = path.dirname(filename), - code = shelljs.cat(path.resolve(FIXTURES_MIX_DIR, filename) + ".src.js"), + code = shelljs.cat(path.resolve(VERSION_DIR, filename) + ".src.js"), config = { loc: true, range: true, tokens: true, + ecmaVersion: 6, ecmaFeatures: {} }; - config.ecmaFeatures = require(path.resolve(__dirname, "../", FIXTURES_MIX_DIR, filename) + ".config.js"); + // config.ecmaFeatures = require(path.resolve(__dirname, "../", VERSION_DIR, filename) + ".config.js"); - var testResultFilename = path.resolve(__dirname, "..", FIXTURES_MIX_DIR, filename) + ".result.js", + var testResultFilename = path.resolve(__dirname, "..", VERSION_DIR, filename) + ".result.js", result = getExpectedResult(code, config); outputResult(result, testResultFilename);