From 05b9b975a964d00557c0ce3e682be414ef7b3e4c Mon Sep 17 00:00:00 2001 From: Lucas Azzola Date: Wed, 14 Jun 2017 00:45:49 +1000 Subject: [PATCH 1/2] New: Support TypeScript 2.4 (fixes #321) (#322) --- README.md | 2 +- lib/ast-node-types.js | 1 + lib/convert.js | 6 + package.json | 2 +- .../dynamic-import.src.js | 1 + tests/lib/__snapshots__/ecma-features.js.snap | 350 ++++++++++++++++++ 6 files changed, 360 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/ecma-features/experimentalDynamicImport/dynamic-import.src.js diff --git a/README.md b/README.md index 9d80318..8d3cd4d 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A parser that converts TypeScript into an [ESTree](https://github.com/estree/est We will always endeavor to support the latest stable version of TypeScript. -The version of TypeScript currently supported by this parser is `~2.3.2`. This is reflected in the `devDependency` requirement within the package.json file, and it is what the tests will be run against. We have an open `peerDependency` requirement in order to allow for experimentation on newer/beta versions of TypeScript. +The version of TypeScript currently supported by this parser is `~2.4.0`. This is reflected in the `devDependency` requirement within the package.json file, and it is what the tests will be run against. We have an open `peerDependency` requirement in order to allow for experimentation on newer/beta versions of TypeScript. If you use a non-supported version of TypeScript, the parser will log a warning to the console. diff --git a/lib/ast-node-types.js b/lib/ast-node-types.js index 629bc8d..66de023 100644 --- a/lib/ast-node-types.js +++ b/lib/ast-node-types.js @@ -56,6 +56,7 @@ module.exports = { GenericTypeAnnotation: "GenericTypeAnnotation", Identifier: "Identifier", IfStatement: "IfStatement", + Import: "Import", ImportDeclaration: "ImportDeclaration", ImportDefaultSpecifier: "ImportDefaultSpecifier", ImportNamespaceSpecifier: "ImportNamespaceSpecifier", diff --git a/lib/convert.js b/lib/convert.js index 8f881ee..dcec596 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -1604,6 +1604,12 @@ module.exports = function convert(config) { break; } + case SyntaxKind.ImportKeyword: + Object.assign(result, { + type: AST_NODE_TYPES.Import + }); + break; + case SyntaxKind.EmptyStatement: case SyntaxKind.DebuggerStatement: simplyCopy(); diff --git a/package.json b/package.json index 790cfed..d691132 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "npm-license": "0.3.3", "shelljs": "0.7.7", "shelljs-nodecli": "0.1.1", - "typescript": "~2.3.2" + "typescript": "~2.4.0" }, "keywords": [ "ast", diff --git a/tests/fixtures/ecma-features/experimentalDynamicImport/dynamic-import.src.js b/tests/fixtures/ecma-features/experimentalDynamicImport/dynamic-import.src.js new file mode 100644 index 0000000..18dff34 --- /dev/null +++ b/tests/fixtures/ecma-features/experimentalDynamicImport/dynamic-import.src.js @@ -0,0 +1 @@ +import('foo').then(main); diff --git a/tests/lib/__snapshots__/ecma-features.js.snap b/tests/lib/__snapshots__/ecma-features.js.snap index 27aaffe..cd9b390 100644 --- a/tests/lib/__snapshots__/ecma-features.js.snap +++ b/tests/lib/__snapshots__/ecma-features.js.snap @@ -56575,6 +56575,356 @@ Object { } `; +exports[`ecmaFeatures fixtures/experimentalDynamicImport/dynamic-import.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "arguments": Array [ + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 19, + "line": 1, + }, + }, + "name": "main", + "range": Array [ + 19, + 23, + ], + "type": "Identifier", + }, + ], + "callee": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "object": Object { + "arguments": Array [ + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 12, + ], + "raw": "'foo'", + "type": "Literal", + "value": "foo", + }, + ], + "callee": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Import", + }, + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 13, + ], + "type": "CallExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "name": "then", + "range": Array [ + 14, + 18, + ], + "type": "Identifier", + }, + "range": Array [ + 0, + 18, + ], + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 24, + ], + "type": "CallExpression", + }, + "loc": Object { + "end": Object { + "column": 25, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 25, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 25, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 25, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Keyword", + "value": "import", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 7, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 12, + ], + "type": "String", + "value": "'foo'", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, + 13, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 18, + ], + "type": "Identifier", + "value": "then", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 19, + "line": 1, + }, + }, + "range": Array [ + 19, + 23, + ], + "type": "Identifier", + "value": "main", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "range": Array [ + 23, + 24, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 1, + }, + "start": Object { + "column": 24, + "line": 1, + }, + }, + "range": Array [ + 24, + 25, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`ecmaFeatures fixtures/experimentalObjectRestSpread/arg-spread.src 1`] = ` Object { "body": Array [ From 479b592c0ad84a6ec5170fbe1821ed5ca90c4ee1 Mon Sep 17 00:00:00 2001 From: James Henry Date: Wed, 14 Jun 2017 17:20:15 +0100 Subject: [PATCH 2/2] Fix: JSDocComments no longer return tokens from getChildren() --- tests/lib/__snapshots__/typescript.js.snap | 378 --------------------- 1 file changed, 378 deletions(-) diff --git a/tests/lib/__snapshots__/typescript.js.snap b/tests/lib/__snapshots__/typescript.js.snap index 2068b4e..1deb6ab 100644 --- a/tests/lib/__snapshots__/typescript.js.snap +++ b/tests/lib/__snapshots__/typescript.js.snap @@ -32238,384 +32238,6 @@ Object { "type": "Punctuator", "value": "{", }, - Object { - "loc": Object { - "end": Object { - "column": 5, - "line": 2, - }, - "start": Object { - "column": 4, - "line": 6, - }, - }, - "range": Array [ - 76, - 22, - ], - "type": "Identifier", - "value": "", - }, - Object { - "loc": Object { - "end": Object { - "column": 6, - "line": 2, - }, - "start": Object { - "column": 5, - "line": 2, - }, - }, - "range": Array [ - 22, - 23, - ], - "type": "Punctuator", - "value": "*", - }, - Object { - "loc": Object { - "end": Object { - "column": 7, - "line": 2, - }, - "start": Object { - "column": 6, - "line": 2, - }, - }, - "range": Array [ - 23, - 24, - ], - "type": "Punctuator", - "value": "*", - }, - Object { - "loc": Object { - "end": Object { - "column": 0, - "line": 3, - }, - "start": Object { - "column": 5, - "line": 3, - }, - }, - "range": Array [ - 30, - 25, - ], - "type": "Identifier", - "value": "", - }, - Object { - "loc": Object { - "end": Object { - "column": 5, - "line": 3, - }, - "start": Object { - "column": 5, - "line": 3, - }, - }, - "range": Array [ - 30, - 30, - ], - "type": "Identifier", - "value": "", - }, - Object { - "loc": Object { - "end": Object { - "column": 6, - "line": 3, - }, - "start": Object { - "column": 5, - "line": 3, - }, - }, - "range": Array [ - 30, - 31, - ], - "type": "Punctuator", - "value": "*", - }, - Object { - "loc": Object { - "end": Object { - "column": 7, - "line": 3, - }, - "start": Object { - "column": 7, - "line": 3, - }, - }, - "range": Array [ - 32, - 32, - ], - "type": "Identifier", - "value": "", - }, - Object { - "loc": Object { - "end": Object { - "column": 14, - "line": 3, - }, - "start": Object { - "column": 7, - "line": 3, - }, - }, - "range": Array [ - 32, - 39, - ], - "type": "Identifier", - "value": "Comment", - }, - Object { - "loc": Object { - "end": Object { - "column": 15, - "line": 3, - }, - "start": Object { - "column": 15, - "line": 3, - }, - }, - "range": Array [ - 40, - 40, - ], - "type": "Identifier", - "value": "", - }, - Object { - "loc": Object { - "end": Object { - "column": 19, - "line": 3, - }, - "start": Object { - "column": 15, - "line": 3, - }, - }, - "range": Array [ - 40, - 44, - ], - "type": "Identifier", - "value": "Line", - }, - Object { - "loc": Object { - "end": Object { - "column": 20, - "line": 3, - }, - "start": Object { - "column": 20, - "line": 3, - }, - }, - "range": Array [ - 45, - 45, - ], - "type": "Identifier", - "value": "", - }, - Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 3, - }, - "start": Object { - "column": 20, - "line": 3, - }, - }, - "range": Array [ - 45, - 46, - ], - "type": "Identifier", - "value": "1", - }, - Object { - "loc": Object { - "end": Object { - "column": 0, - "line": 4, - }, - "start": Object { - "column": 5, - "line": 4, - }, - }, - "range": Array [ - 52, - 47, - ], - "type": "Identifier", - "value": "", - }, - Object { - "loc": Object { - "end": Object { - "column": 5, - "line": 4, - }, - "start": Object { - "column": 5, - "line": 4, - }, - }, - "range": Array [ - 52, - 52, - ], - "type": "Identifier", - "value": "", - }, - Object { - "loc": Object { - "end": Object { - "column": 6, - "line": 4, - }, - "start": Object { - "column": 5, - "line": 4, - }, - }, - "range": Array [ - 52, - 53, - ], - "type": "Punctuator", - "value": "*", - }, - Object { - "loc": Object { - "end": Object { - "column": 7, - "line": 4, - }, - "start": Object { - "column": 7, - "line": 4, - }, - }, - "range": Array [ - 54, - 54, - ], - "type": "Identifier", - "value": "", - }, - Object { - "loc": Object { - "end": Object { - "column": 8, - "line": 4, - }, - "start": Object { - "column": 7, - "line": 4, - }, - }, - "range": Array [ - 54, - 55, - ], - "type": "Punctuator", - "value": "@", - }, - Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 4, - }, - "start": Object { - "column": 8, - "line": 4, - }, - }, - "range": Array [ - 55, - 58, - ], - "type": "Identifier", - "value": "baz", - }, - Object { - "loc": Object { - "end": Object { - "column": 15, - "line": 4, - }, - "start": Object { - "column": 12, - "line": 4, - }, - }, - "range": Array [ - 59, - 62, - ], - "type": "Identifier", - "value": "bar", - }, - Object { - "loc": Object { - "end": Object { - "column": 6, - "line": 5, - }, - "start": Object { - "column": 5, - "line": 5, - }, - }, - "range": Array [ - 69, - 70, - ], - "type": "Punctuator", - "value": "*", - }, - Object { - "loc": Object { - "end": Object { - "column": 7, - "line": 5, - }, - "start": Object { - "column": 6, - "line": 5, - }, - }, - "range": Array [ - 70, - 71, - ], - "type": "Punctuator", - "value": "/", - }, Object { "loc": Object { "end": Object {