diff --git a/.travis.yml b/.travis.yml index 44a75f7..cd7025c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: node_js sudo: false node_js: - - "4" - - "5" - "6" - "7" - "8" diff --git a/README.md b/README.md index 4cdb249..cf903fd 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A parser that converts TypeScript source code into an [ESTree](https://github.co We will always endeavor to support the latest stable version of TypeScript. -The version of TypeScript currently supported by this parser is `~2.6.1`. 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.7.1`. 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 42884d4..809404d 100644 --- a/lib/ast-node-types.js +++ b/lib/ast-node-types.js @@ -141,6 +141,7 @@ module.exports = { TSSymbolKeyword: "TSSymbolKeyword", TSTypeAnnotation: "TSTypeAnnotation", TSTypeLiteral: "TSTypeLiteral", + TSTypeOperator: "TSTypeOperator", TSTypeParameter: "TSTypeParameter", TSTypeParameterDeclaration: "TSTypeParameterDeclaration", TSTypeParameterInstantiation: "TSTypeParameterInstantiation", diff --git a/lib/convert.js b/lib/convert.js index d8f8215..3dcb3f9 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -1573,6 +1573,14 @@ module.exports = function convert(config) { }); break; + case SyntaxKind.TypeOperator: + Object.assign(result, { + type: AST_NODE_TYPES.TSTypeOperator, + operator: nodeUtils.getTextForTokenKind(node.operator), + typeAnnotation: convertChild(node.type) + }); + break; + // Binary Operations case SyntaxKind.BinaryExpression: diff --git a/lib/node-utils.js b/lib/node-utils.js index 928ff14..957daed 100644 --- a/lib/node-utils.js +++ b/lib/node-utils.js @@ -97,6 +97,8 @@ TOKEN_TO_TEXT[SyntaxKind.BarEqualsToken] = "|="; TOKEN_TO_TEXT[SyntaxKind.CaretEqualsToken] = "^="; TOKEN_TO_TEXT[SyntaxKind.AtToken] = "@"; TOKEN_TO_TEXT[SyntaxKind.InKeyword] = "in"; +TOKEN_TO_TEXT[SyntaxKind.UniqueKeyword] = "unique"; +TOKEN_TO_TEXT[SyntaxKind.KeyOfKeyword] = "keyof"; /** * Find the first matching child based on the given sourceFile and predicate function. diff --git a/package.json b/package.json index cb24a59..82af8e1 100644 --- a/package.json +++ b/package.json @@ -19,19 +19,19 @@ "license": "BSD-2-Clause", "devDependencies": { "babel-code-frame": "6.26.0", - "babylon": "7.0.0-beta.34", + "babylon": "7.0.0-beta.39", "dedent": "0.7.0", - "eslint": "4.13.1", + "eslint": "4.17.0", "eslint-config-eslint": "4.0.0", - "eslint-plugin-node": "5.2.1", + "eslint-plugin-node": "6.0.0", "eslint-release": "0.10.3", "glob": "7.1.2", - "jest": "21.2.1", + "jest": "22.2.1", "lodash.isplainobject": "4.0.6", "npm-license": "0.3.3", - "shelljs": "0.7.8", + "shelljs": "0.8.1", "shelljs-nodecli": "0.1.1", - "typescript": "~2.6.1" + "typescript": "~2.7.1" }, "keywords": [ "ast", @@ -56,7 +56,7 @@ }, "dependencies": { "lodash.unescape": "4.0.1", - "semver": "5.4.1" + "semver": "5.5.0" }, "peerDependencies": { "typescript": "*" diff --git a/tests/ast-alignment/fixtures-to-test.js b/tests/ast-alignment/fixtures-to-test.js index e368c94..944f621 100644 --- a/tests/ast-alignment/fixtures-to-test.js +++ b/tests/ast-alignment/fixtures-to-test.js @@ -399,6 +399,8 @@ let fixturePatternConfigsToTest = [ "export-type-class-declaration", "abstract-interface", "export-type-alias-declaration", + "unique-symbol", + "keyof-operator", /** * tsep bug - Program.body[0].expression.left.properties[0].value.right is currently showing up * as `ArrayPattern`, babylon, acorn and espree say it should be `ArrayExpression` diff --git a/tests/fixtures/typescript/basics/keyof-operator.src.ts b/tests/fixtures/typescript/basics/keyof-operator.src.ts new file mode 100644 index 0000000..d4cf1df --- /dev/null +++ b/tests/fixtures/typescript/basics/keyof-operator.src.ts @@ -0,0 +1 @@ +type x = keyof foo; diff --git a/tests/fixtures/typescript/basics/unique-symbol.src.ts b/tests/fixtures/typescript/basics/unique-symbol.src.ts new file mode 100644 index 0000000..6d1be98 --- /dev/null +++ b/tests/fixtures/typescript/basics/unique-symbol.src.ts @@ -0,0 +1 @@ +type A = unique symbol; diff --git a/tests/lib/__snapshots__/typescript.js.snap b/tests/lib/__snapshots__/typescript.js.snap index 6eeed6c..f2ac97e 100644 --- a/tests/lib/__snapshots__/typescript.js.snap +++ b/tests/lib/__snapshots__/typescript.js.snap @@ -34908,6 +34908,247 @@ Object { } `; +exports[`typescript fixtures/basics/keyof-operator.src 1`] = ` +Object { + "body": Array [ + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "name": "x", + "range": Array [ + 5, + 6, + ], + "type": "Identifier", + }, + "init": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "operator": "keyof", + "range": Array [ + 9, + 18, + ], + "type": "TSTypeOperator", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 18, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 15, + 18, + ], + "type": "Identifier", + }, + }, + }, + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 19, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "type", + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 19, + ], + "type": "VariableDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 20, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 4, + ], + "type": "Identifier", + "value": "type", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 6, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 8, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 14, + ], + "type": "Identifier", + "value": "keyof", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 18, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`typescript fixtures/basics/nested-type-arguments.src 1`] = ` Object { "body": Array [ @@ -42862,6 +43103,229 @@ Object { } `; +exports[`typescript fixtures/basics/unique-symbol.src 1`] = ` +Object { + "body": Array [ + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "name": "A", + "range": Array [ + 5, + 6, + ], + "type": "Identifier", + }, + "init": Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "operator": "unique", + "range": Array [ + 9, + 22, + ], + "type": "TSTypeOperator", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 22, + ], + "type": "TSSymbolKeyword", + }, + }, + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 23, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "type", + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 23, + ], + "type": "VariableDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 24, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 4, + ], + "type": "Identifier", + "value": "type", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 6, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 8, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 15, + ], + "type": "Identifier", + "value": "unique", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 22, + ], + "type": "Identifier", + "value": "symbol", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "range": Array [ + 22, + 23, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`typescript fixtures/basics/var-with-dotted-type.src 1`] = ` Object { "body": Array [