From c0a0d59692b7f90e265db2559782e26d498ca2f2 Mon Sep 17 00:00:00 2001 From: Ian MacLeod Date: Wed, 5 Dec 2018 16:50:24 -0800 Subject: [PATCH 01/18] Bump to typescript-estree@6.0.0 and typescript@~3.2.1 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fc21e87..5f51883 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "dependencies": { "eslint-scope": "^4.0.0", "eslint-visitor-keys": "^1.0.0", - "typescript-estree": "5.3.0" + "typescript-estree": "6.0.0" }, "devDependencies": { "eslint": "^4.19.1", @@ -57,7 +57,7 @@ "npm-license": "0.3.3", "shelljs": "0.8.2", "shelljs-nodecli": "0.1.1", - "typescript": "~3.1.1" + "typescript": "~3.2.1" }, "jest": { "testEnvironment": "node", From 3aaa4ad631b52e0d715642b00906b6743d7a4bef Mon Sep 17 00:00:00 2001 From: Ian MacLeod Date: Wed, 5 Dec 2018 16:55:50 -0800 Subject: [PATCH 02/18] Test & snapshot for BigIntLiteral nodes --- .../bigIntLiterals/binary.src.js | 1 + .../bigIntLiterals/decimal.src.js | 1 + .../ecma-features/bigIntLiterals/hex.src.js | 1 + .../ecma-features/bigIntLiterals/octal.src.js | 1 + tests/lib/__snapshots__/ecma-features.js.snap | 392 ++++++++++++++++++ 5 files changed, 396 insertions(+) create mode 100644 tests/fixtures/ecma-features/bigIntLiterals/binary.src.js create mode 100644 tests/fixtures/ecma-features/bigIntLiterals/decimal.src.js create mode 100644 tests/fixtures/ecma-features/bigIntLiterals/hex.src.js create mode 100644 tests/fixtures/ecma-features/bigIntLiterals/octal.src.js diff --git a/tests/fixtures/ecma-features/bigIntLiterals/binary.src.js b/tests/fixtures/ecma-features/bigIntLiterals/binary.src.js new file mode 100644 index 0000000..2b13801 --- /dev/null +++ b/tests/fixtures/ecma-features/bigIntLiterals/binary.src.js @@ -0,0 +1 @@ +0b1n; diff --git a/tests/fixtures/ecma-features/bigIntLiterals/decimal.src.js b/tests/fixtures/ecma-features/bigIntLiterals/decimal.src.js new file mode 100644 index 0000000..fe03424 --- /dev/null +++ b/tests/fixtures/ecma-features/bigIntLiterals/decimal.src.js @@ -0,0 +1 @@ +1n; diff --git a/tests/fixtures/ecma-features/bigIntLiterals/hex.src.js b/tests/fixtures/ecma-features/bigIntLiterals/hex.src.js new file mode 100644 index 0000000..204f239 --- /dev/null +++ b/tests/fixtures/ecma-features/bigIntLiterals/hex.src.js @@ -0,0 +1 @@ +0x1n; diff --git a/tests/fixtures/ecma-features/bigIntLiterals/octal.src.js b/tests/fixtures/ecma-features/bigIntLiterals/octal.src.js new file mode 100644 index 0000000..f2ce84f --- /dev/null +++ b/tests/fixtures/ecma-features/bigIntLiterals/octal.src.js @@ -0,0 +1 @@ +0o1n; diff --git a/tests/lib/__snapshots__/ecma-features.js.snap b/tests/lib/__snapshots__/ecma-features.js.snap index 00a985d..9b4e20c 100644 --- a/tests/lib/__snapshots__/ecma-features.js.snap +++ b/tests/lib/__snapshots__/ecma-features.js.snap @@ -9142,6 +9142,398 @@ Object { } `; +exports[`ecmaFeatures fixtures/bigIntLiterals/binary.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 4, + ], + "raw": "0b1n", + "type": "BigIntLiteral", + "value": "0b1", + }, + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "ExpressionStatement", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "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": "0b1n", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 5, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + +exports[`ecmaFeatures fixtures/bigIntLiterals/decimal.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 2, + ], + "raw": "1n", + "type": "BigIntLiteral", + "value": "1", + }, + "loc": Object { + "end": Object { + "column": 3, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 3, + ], + "type": "ExpressionStatement", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 4, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 2, + ], + "type": "Identifier", + "value": "1n", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 1, + }, + "start": Object { + "column": 2, + "line": 1, + }, + }, + "range": Array [ + 2, + 3, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + +exports[`ecmaFeatures fixtures/bigIntLiterals/hex.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 4, + ], + "raw": "0x1n", + "type": "BigIntLiteral", + "value": "0x1", + }, + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "ExpressionStatement", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "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": "0x1n", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 5, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + +exports[`ecmaFeatures fixtures/bigIntLiterals/octal.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 4, + ], + "raw": "0o1n", + "type": "BigIntLiteral", + "value": "0o1", + }, + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "ExpressionStatement", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "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": "0o1n", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 5, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`ecmaFeatures fixtures/binaryLiterals/invalid.src 1`] = `"';' expected."`; exports[`ecmaFeatures fixtures/binaryLiterals/lowercase.src 1`] = ` From d1c5de30c7ddfe268088097d8c99ab2831edd279 Mon Sep 17 00:00:00 2001 From: Ian MacLeod Date: Thu, 6 Dec 2018 20:46:06 -0800 Subject: [PATCH 03/18] ^ style dependency for typescript-estree. Ref: https://github.com/eslint/typescript-eslint-parser/pull/573#issuecomment-443797291 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5f51883..f24b437 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "dependencies": { "eslint-scope": "^4.0.0", "eslint-visitor-keys": "^1.0.0", - "typescript-estree": "6.0.0" + "typescript-estree": "^6.0.0" }, "devDependencies": { "eslint": "^4.19.1", From 4cfd8c0e91dc46e1dfda56663cd44b12ccb98028 Mon Sep 17 00:00:00 2001 From: Ian MacLeod Date: Thu, 6 Dec 2018 20:52:37 -0800 Subject: [PATCH 04/18] Bump in the readme, too --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f2c4442..97b92d1 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ The following additional configuration options are available by specifying them We will always endeavor to support the latest stable version of TypeScript. -The version of TypeScript currently supported by this parser is `~3.1.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 `~3.2.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. From 65f8cb0585d484f40ce753d68a19aa20aa61bf47 Mon Sep 17 00:00:00 2001 From: Ian MacLeod Date: Thu, 6 Dec 2018 20:53:36 -0800 Subject: [PATCH 05/18] bump integration tests' typescript --- .../declared-empty-body-functions-issue-162/package.json | 4 ++-- tests/integration/jsdoc-indent-issues-344-422/package.json | 4 ++-- tests/integration/method-overloads-issue-389/package.json | 4 ++-- .../no-redeclare-overloaded-functions-issue-402/package.json | 4 ++-- tests/integration/range-error-indent-issue-333/package.json | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/integration/declared-empty-body-functions-issue-162/package.json b/tests/integration/declared-empty-body-functions-issue-162/package.json index 9029571..4944126 100644 --- a/tests/integration/declared-empty-body-functions-issue-162/package.json +++ b/tests/integration/declared-empty-body-functions-issue-162/package.json @@ -8,6 +8,6 @@ "devDependencies": { "eslint": "4.19.1", "jest": "23.1.0", - "typescript": "~3.1.1" + "typescript": "~3.2.1" } -} \ No newline at end of file +} diff --git a/tests/integration/jsdoc-indent-issues-344-422/package.json b/tests/integration/jsdoc-indent-issues-344-422/package.json index 9029571..4944126 100644 --- a/tests/integration/jsdoc-indent-issues-344-422/package.json +++ b/tests/integration/jsdoc-indent-issues-344-422/package.json @@ -8,6 +8,6 @@ "devDependencies": { "eslint": "4.19.1", "jest": "23.1.0", - "typescript": "~3.1.1" + "typescript": "~3.2.1" } -} \ No newline at end of file +} diff --git a/tests/integration/method-overloads-issue-389/package.json b/tests/integration/method-overloads-issue-389/package.json index 9029571..4944126 100644 --- a/tests/integration/method-overloads-issue-389/package.json +++ b/tests/integration/method-overloads-issue-389/package.json @@ -8,6 +8,6 @@ "devDependencies": { "eslint": "4.19.1", "jest": "23.1.0", - "typescript": "~3.1.1" + "typescript": "~3.2.1" } -} \ No newline at end of file +} diff --git a/tests/integration/no-redeclare-overloaded-functions-issue-402/package.json b/tests/integration/no-redeclare-overloaded-functions-issue-402/package.json index 9029571..4944126 100644 --- a/tests/integration/no-redeclare-overloaded-functions-issue-402/package.json +++ b/tests/integration/no-redeclare-overloaded-functions-issue-402/package.json @@ -8,6 +8,6 @@ "devDependencies": { "eslint": "4.19.1", "jest": "23.1.0", - "typescript": "~3.1.1" + "typescript": "~3.2.1" } -} \ No newline at end of file +} diff --git a/tests/integration/range-error-indent-issue-333/package.json b/tests/integration/range-error-indent-issue-333/package.json index 9029571..4944126 100644 --- a/tests/integration/range-error-indent-issue-333/package.json +++ b/tests/integration/range-error-indent-issue-333/package.json @@ -8,6 +8,6 @@ "devDependencies": { "eslint": "4.19.1", "jest": "23.1.0", - "typescript": "~3.1.1" + "typescript": "~3.2.1" } -} \ No newline at end of file +} From d772b0ac843a1a5175dc796e4eca88fde37944c0 Mon Sep 17 00:00:00 2001 From: Ian MacLeod Date: Tue, 11 Dec 2018 11:46:42 -0800 Subject: [PATCH 06/18] Add BigIntLiteral as a node type --- visitor-keys.js | 1 + 1 file changed, 1 insertion(+) diff --git a/visitor-keys.js b/visitor-keys.js index 40a5e49..c036ea6 100644 --- a/visitor-keys.js +++ b/visitor-keys.js @@ -23,6 +23,7 @@ module.exports = Evk.unionWith({ CallExpression: ["callee", "typeParameters", "arguments"], // Additional Nodes. + BigIntLiteral: [], ClassProperty: ["decorators", "key", "typeAnnotation", "value"], Decorator: ["expression"], TSAbstractClassProperty: ["decorators", "key", "typeAnnotation", "value"], From 6aad31d5edf06d25677651446d9a88fdd29ef990 Mon Sep 17 00:00:00 2001 From: Armano Date: Tue, 25 Dec 2018 00:02:46 +0100 Subject: [PATCH 07/18] Upgrade: typescript-estree to 7.0.0 --- .gitignore | 1 + analyze-scope.js | 26 +- package.json | 2 +- parser.js | 4 +- tests/fixtures/scope-analysis/type-alias.ts | 1 + tests/lib/__snapshots__/ecma-features.js.snap | 2 - .../lib/__snapshots__/scope-analysis.js.snap | 25 + tests/lib/__snapshots__/tsx.js.snap | 214 +- tests/lib/__snapshots__/typescript.js.snap | 2982 ++++++++--------- visitor-keys.js | 1 + 10 files changed, 1498 insertions(+), 1760 deletions(-) create mode 100644 tests/fixtures/scope-analysis/type-alias.ts diff --git a/.gitignore b/.gitignore index 5f01791..34a9c5a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ _test.js .vscode yarn.lock .eslint-release-info.json +.idea diff --git a/analyze-scope.js b/analyze-scope.js index a542a22..13c559b 100644 --- a/analyze-scope.js +++ b/analyze-scope.js @@ -239,25 +239,6 @@ class Referencer extends OriginalReferencer { super.MethodDefinition(node); } - /** - * Override. - * Don't make variable if `kind === "type"`. - * It doesn't declare variables but declare types. - * @param {VariableDeclaration} node The VariableDeclaration node to visit. - * @returns {void} - */ - VariableDeclaration(node) { - if (node.kind !== "type") { - super.VariableDeclaration(node); - return; - } - - // To detect typeof. - this.typeMode = true; - this.visitChildren(node); - this.typeMode = false; - } - /** * Don't create the reference object for the key if not computed. * @param {TSEmptyBodyFunctionDeclaration} node The TSEmptyBodyFunctionDeclaration node to visit. @@ -337,6 +318,7 @@ class Referencer extends OriginalReferencer { this.visit(returnType); this.typeMode = upperTypeMode; } + TSEmptyBodyDeclareFunction(node) { this.TSEmptyBodyFunctionDeclaration(node); } @@ -556,6 +538,12 @@ class Referencer extends OriginalReferencer { this.visit(body); } + TSTypeAliasDeclaration(node) { + this.typeMode = true; + this.visitChildren(node); + this.typeMode = false; + } + /** * Process the module block. * @param {TSModuleBlock} node The TSModuleBlock node to visit. diff --git a/package.json b/package.json index f24b437..c16077a 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "dependencies": { "eslint-scope": "^4.0.0", "eslint-visitor-keys": "^1.0.0", - "typescript-estree": "^6.0.0" + "typescript-estree": "^7.0.0" }, "devDependencies": { "eslint": "^4.19.1", diff --git a/parser.js b/parser.js index 59f5836..e59361c 100644 --- a/parser.js +++ b/parser.js @@ -42,9 +42,9 @@ exports.parseForESLint = function parseForESLint(code, options) { enter: node => { switch (node.type) { // Just for backward compatibility. - case "DeclareFunction": + case "TSDeclareFunction": if (!node.body) { - node.type = `TSEmptyBody${node.type}`; + node.type = "TSEmptyBodyDeclareFunction"; } break; diff --git a/tests/fixtures/scope-analysis/type-alias.ts b/tests/fixtures/scope-analysis/type-alias.ts new file mode 100644 index 0000000..188a66b --- /dev/null +++ b/tests/fixtures/scope-analysis/type-alias.ts @@ -0,0 +1 @@ +type foo = string diff --git a/tests/lib/__snapshots__/ecma-features.js.snap b/tests/lib/__snapshots__/ecma-features.js.snap index 9b4e20c..ee9c97b 100644 --- a/tests/lib/__snapshots__/ecma-features.js.snap +++ b/tests/lib/__snapshots__/ecma-features.js.snap @@ -102029,7 +102029,6 @@ Object { "body": Array [ Object { "async": false, - "body": null, "expression": false, "generator": false, "id": Object { @@ -102347,7 +102346,6 @@ Object { "body": Array [ Object { "async": false, - "body": null, "expression": false, "generator": false, "id": Object { diff --git a/tests/lib/__snapshots__/scope-analysis.js.snap b/tests/lib/__snapshots__/scope-analysis.js.snap index 6316b14..0d256f0 100644 --- a/tests/lib/__snapshots__/scope-analysis.js.snap +++ b/tests/lib/__snapshots__/scope-analysis.js.snap @@ -5298,6 +5298,31 @@ Object { } `; +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/type-alias.ts 1`] = ` +Object { + "$id": 0, + "block": Object { + "range": Array [ + 0, + 19, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 0, + }, + "variables": Array [], +} +`; + exports[`TypeScript scope analysis tests/fixtures/scope-analysis/type-annotations.ts 1`] = ` Object { "$id": 7, diff --git a/tests/lib/__snapshots__/tsx.js.snap b/tests/lib/__snapshots__/tsx.js.snap index 4025e7b..2c696e0 100644 --- a/tests/lib/__snapshots__/tsx.js.snap +++ b/tests/lib/__snapshots__/tsx.js.snap @@ -500,148 +500,128 @@ Object { "type": "ImportDeclaration", }, Object { - "declarations": Array [ - Object { - "id": Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 2, - }, - "start": Object { - "column": 5, - "line": 2, + "id": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 5, + "line": 2, + }, + }, + "name": "Props", + "range": Array [ + 36, + 41, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 31, + 63, + ], + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 4, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "members": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, }, + "name": "title", + "range": Array [ + 48, + 53, + ], + "type": "Identifier", }, - "name": "Props", - "range": Array [ - 36, - 41, - ], - "type": "Identifier", - }, - "init": Object { "loc": Object { "end": Object { - "column": 1, - "line": 4, + "column": 15, + "line": 3, }, "start": Object { - "column": 13, - "line": 2, + "column": 2, + "line": 3, }, }, - "members": Array [ - Object { - "computed": false, - "key": Object { - "loc": Object { - "end": Object { - "column": 7, - "line": 3, - }, - "start": Object { - "column": 2, - "line": 3, - }, - }, - "name": "title", - "range": Array [ - 48, - 53, - ], - "type": "Identifier", + "range": Array [ + 48, + 61, + ], + "type": "TSPropertySignature", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 3, }, + "start": Object { + "column": 7, + "line": 3, + }, + }, + "range": Array [ + 53, + 61, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { "loc": Object { "end": Object { "column": 15, "line": 3, }, "start": Object { - "column": 2, + "column": 9, "line": 3, }, }, "range": Array [ - 48, + 55, 61, ], - "type": "TSPropertySignature", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 15, - "line": 3, - }, - "start": Object { - "column": 7, - "line": 3, - }, - }, - "range": Array [ - 53, - 61, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 15, - "line": 3, - }, - "start": Object { - "column": 9, - "line": 3, - }, - }, - "range": Array [ - 55, - 61, - ], - "type": "TSStringKeyword", - }, - }, + "type": "TSStringKeyword", }, - ], - "range": Array [ - 44, - 63, - ], - "type": "TSTypeLiteral", - }, - "loc": Object { - "end": Object { - "column": 1, - "line": 4, - }, - "start": Object { - "column": 5, - "line": 2, }, }, - "range": Array [ - 36, - 63, - ], - "type": "VariableDeclarator", - }, - ], - "kind": "type", - "loc": Object { - "end": Object { - "column": 1, - "line": 4, - }, - "start": Object { - "column": 0, - "line": 2, - }, + ], + "range": Array [ + 44, + 63, + ], + "type": "TSTypeLiteral", }, - "range": Array [ - 31, - 63, - ], - "type": "VariableDeclaration", }, Object { "declaration": Object { diff --git a/tests/lib/__snapshots__/typescript.js.snap b/tests/lib/__snapshots__/typescript.js.snap index dc29543..5703c0c 100644 --- a/tests/lib/__snapshots__/typescript.js.snap +++ b/tests/lib/__snapshots__/typescript.js.snap @@ -10741,7 +10741,6 @@ Object { "type": "ClassDeclaration", }, Object { - "abstract": false, "body": Object { "body": Array [], "loc": Object { @@ -10796,254 +10795,234 @@ Object { "type": "TSInterfaceDeclaration", }, Object { - "declarations": Array [ - Object { - "id": Object { - "loc": Object { - "end": Object { - "column": 16, - "line": 9, - }, - "start": Object { - "column": 5, - "line": 9, - }, - }, - "name": "Constructor", - "range": Array [ - 163, - 174, - ], - "type": "Identifier", + "id": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 9, }, - "init": Object { - "loc": Object { - "end": Object { - "column": 47, - "line": 9, - }, - "start": Object { - "column": 22, - "line": 9, - }, - }, - "parameters": Array [ - Object { - "argument": Object { - "loc": Object { - "end": Object { - "column": 41, - "line": 9, - }, - "start": Object { - "column": 30, - "line": 9, - }, - }, - "name": "args", - "range": Array [ - 188, - 199, - ], - "type": "Identifier", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 41, - "line": 9, - }, - "start": Object { - "column": 34, - "line": 9, - }, - }, - "range": Array [ - 192, - 199, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "elementType": Object { - "loc": Object { - "end": Object { - "column": 39, - "line": 9, - }, - "start": Object { - "column": 36, - "line": 9, - }, - }, - "range": Array [ - 194, - 197, - ], - "type": "TSAnyKeyword", - }, - "loc": Object { - "end": Object { - "column": 41, - "line": 9, - }, - "start": Object { - "column": 36, - "line": 9, - }, - }, - "range": Array [ - 194, - 199, - ], - "type": "TSArrayType", - }, - }, - }, - "loc": Object { - "end": Object { - "column": 41, - "line": 9, - }, - "start": Object { - "column": 27, - "line": 9, - }, - }, - "range": Array [ - 185, - 199, - ], - "type": "RestElement", - }, - ], - "range": Array [ - 180, - 205, - ], - "type": "TSConstructorType", - "typeAnnotation": Object { + "start": Object { + "column": 5, + "line": 9, + }, + }, + "name": "Constructor", + "range": Array [ + 163, + 174, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 48, + "line": 9, + }, + "start": Object { + "column": 0, + "line": 9, + }, + }, + "range": Array [ + 158, + 206, + ], + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 47, + "line": 9, + }, + "start": Object { + "column": 22, + "line": 9, + }, + }, + "parameters": Array [ + Object { + "argument": Object { "loc": Object { "end": Object { - "column": 47, + "column": 41, "line": 9, }, "start": Object { - "column": 44, + "column": 30, "line": 9, }, }, + "name": "args", "range": Array [ - 202, - 205, + 188, + 199, ], - "type": "TSTypeAnnotation", + "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 47, + "column": 41, "line": 9, }, "start": Object { - "column": 46, + "column": 34, "line": 9, }, }, "range": Array [ - 204, - 205, + 192, + 199, ], - "type": "TSTypeReference", - "typeName": Object { + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "elementType": Object { + "loc": Object { + "end": Object { + "column": 39, + "line": 9, + }, + "start": Object { + "column": 36, + "line": 9, + }, + }, + "range": Array [ + 194, + 197, + ], + "type": "TSAnyKeyword", + }, "loc": Object { "end": Object { - "column": 47, + "column": 41, "line": 9, }, "start": Object { - "column": 46, + "column": 36, "line": 9, }, }, - "name": "T", "range": Array [ - 204, - 205, + 194, + 199, ], - "type": "Identifier", + "type": "TSArrayType", }, }, }, - "typeParameters": null, + "loc": Object { + "end": Object { + "column": 41, + "line": 9, + }, + "start": Object { + "column": 27, + "line": 9, + }, + }, + "range": Array [ + 185, + 199, + ], + "type": "RestElement", }, + ], + "range": Array [ + 180, + 205, + ], + "type": "TSConstructorType", + "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 48, + "column": 47, "line": 9, }, "start": Object { - "column": 5, + "column": 44, "line": 9, }, }, "range": Array [ - 163, - 206, + 202, + 205, ], - "type": "VariableDeclarator", - "typeParameters": Object { + "type": "TSTypeAnnotation", + "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 19, + "column": 47, "line": 9, }, "start": Object { - "column": 16, + "column": 46, "line": 9, }, }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 18, - "line": 9, - }, - "start": Object { - "column": 17, - "line": 9, - }, - }, - "name": "T", - "range": Array [ - 175, - 176, - ], - "type": "TSTypeParameter", - }, - ], "range": Array [ - 174, - 177, + 204, + 205, ], - "type": "TSTypeParameterDeclaration", + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 47, + "line": 9, + }, + "start": Object { + "column": 46, + "line": 9, + }, + }, + "name": "T", + "range": Array [ + 204, + 205, + ], + "type": "Identifier", + }, }, }, - ], - "kind": "type", - "loc": Object { - "end": Object { - "column": 48, - "line": 9, - }, - "start": Object { - "column": 0, - "line": 9, + "typeParameters": null, + }, + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 9, + }, + "start": Object { + "column": 16, + "line": 9, + }, }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 9, + }, + "start": Object { + "column": 17, + "line": 9, + }, + }, + "name": "T", + "range": Array [ + 175, + 176, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 174, + 177, + ], + "type": "TSTypeParameterDeclaration", }, - "range": Array [ - 158, - 206, - ], - "type": "VariableDeclaration", }, ], "comments": Array [], @@ -20361,6 +20340,7 @@ Object { ], "type": "ClassBody", }, + "declare": true, "id": Object { "loc": Object { "end": Object { @@ -20640,7 +20620,7 @@ Object { "body": Array [ Object { "async": false, - "body": null, + "declare": true, "expression": false, "generator": false, "id": Object { @@ -23053,112 +23033,92 @@ Object { "body": Array [ Object { "declaration": Object { - "declarations": Array [ - Object { - "id": Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "name": "TestAlias", + "range": Array [ + 12, + 21, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 40, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 40, + ], + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 39, + "line": 1, + }, + "start": Object { + "column": 24, + "line": 1, + }, + }, + "range": Array [ + 24, + 39, + ], + "type": "TSUnionType", + "types": Array [ + Object { "loc": Object { "end": Object { - "column": 21, + "column": 30, "line": 1, }, "start": Object { - "column": 12, + "column": 24, "line": 1, }, }, - "name": "TestAlias", "range": Array [ - 12, - 21, + 24, + 30, ], - "type": "Identifier", + "type": "TSStringKeyword", }, - "init": Object { + Object { "loc": Object { "end": Object { "column": 39, "line": 1, }, "start": Object { - "column": 24, + "column": 33, "line": 1, }, }, "range": Array [ - 24, + 33, 39, ], - "type": "TSUnionType", - "types": Array [ - Object { - "loc": Object { - "end": Object { - "column": 30, - "line": 1, - }, - "start": Object { - "column": 24, - "line": 1, - }, - }, - "range": Array [ - 24, - 30, - ], - "type": "TSStringKeyword", - }, - Object { - "loc": Object { - "end": Object { - "column": 39, - "line": 1, - }, - "start": Object { - "column": 33, - "line": 1, - }, - }, - "range": Array [ - 33, - 39, - ], - "type": "TSNumberKeyword", - }, - ], - }, - "loc": Object { - "end": Object { - "column": 40, - "line": 1, - }, - "start": Object { - "column": 12, - "line": 1, - }, + "type": "TSNumberKeyword", }, - "range": Array [ - 12, - 40, - ], - "type": "VariableDeclarator", - }, - ], - "kind": "type", - "loc": Object { - "end": Object { - "column": 40, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, - }, + ], }, - "range": Array [ - 7, - 40, - ], - "type": "VariableDeclaration", }, "loc": Object { "end": Object { @@ -23350,148 +23310,128 @@ Object { "body": Array [ Object { "declaration": Object { - "declarations": Array [ - Object { - "id": Object { - "loc": Object { - "end": Object { - "column": 26, - "line": 1, - }, - "start": Object { - "column": 12, - "line": 1, + "id": Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "name": "TestClassProps", + "range": Array [ + 12, + 26, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 2, + "line": 3, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 51, + ], + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 29, + "line": 1, + }, + }, + "members": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, }, + "name": "count", + "range": Array [ + 35, + 40, + ], + "type": "Identifier", }, - "name": "TestClassProps", - "range": Array [ - 12, - 26, - ], - "type": "Identifier", - }, - "init": Object { "loc": Object { "end": Object { - "column": 1, - "line": 3, + "column": 17, + "line": 2, }, "start": Object { - "column": 29, - "line": 1, + "column": 4, + "line": 2, }, }, - "members": Array [ - Object { - "computed": false, - "key": Object { - "loc": Object { - "end": Object { - "column": 9, - "line": 2, - }, - "start": Object { - "column": 4, - "line": 2, - }, - }, - "name": "count", - "range": Array [ - 35, - 40, - ], - "type": "Identifier", + "range": Array [ + 35, + 48, + ], + "type": "TSPropertySignature", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, }, + }, + "range": Array [ + 40, + 48, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { "loc": Object { "end": Object { "column": 17, "line": 2, }, "start": Object { - "column": 4, + "column": 11, "line": 2, }, }, "range": Array [ - 35, + 42, 48, ], - "type": "TSPropertySignature", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 2, - }, - "start": Object { - "column": 9, - "line": 2, - }, - }, - "range": Array [ - 40, - 48, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 2, - }, - "start": Object { - "column": 11, - "line": 2, - }, - }, - "range": Array [ - 42, - 48, - ], - "type": "TSNumberKeyword", - }, - }, + "type": "TSNumberKeyword", }, - ], - "range": Array [ - 29, - 50, - ], - "type": "TSTypeLiteral", - }, - "loc": Object { - "end": Object { - "column": 2, - "line": 3, - }, - "start": Object { - "column": 12, - "line": 1, }, }, - "range": Array [ - 12, - 51, - ], - "type": "VariableDeclarator", - }, - ], - "kind": "type", - "loc": Object { - "end": Object { - "column": 2, - "line": 3, - }, - "start": Object { - "column": 7, - "line": 1, - }, + ], + "range": Array [ + 29, + 50, + ], + "type": "TSTypeLiteral", }, - "range": Array [ - 7, - 51, - ], - "type": "VariableDeclaration", }, "loc": Object { "end": Object { @@ -23719,165 +23659,145 @@ Object { "body": Array [ Object { "declaration": Object { - "declarations": Array [ - Object { - "id": Object { - "loc": Object { - "end": Object { - "column": 24, - "line": 1, - }, - "start": Object { - "column": 12, - "line": 1, - }, - }, - "name": "TestCallback", - "range": Array [ - 12, - 24, - ], - "type": "Identifier", + "id": Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "name": "TestCallback", + "range": Array [ + 12, + 24, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 47, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 47, + ], + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 46, + "line": 1, + }, + "start": Object { + "column": 27, + "line": 1, }, - "init": Object { + }, + "parameters": Array [ + Object { "loc": Object { "end": Object { - "column": 46, + "column": 37, "line": 1, }, "start": Object { - "column": 27, + "column": 28, "line": 1, }, }, - "parameters": Array [ - Object { - "loc": Object { - "end": Object { - "column": 37, - "line": 1, - }, - "start": Object { - "column": 28, - "line": 1, - }, - }, - "name": "a", - "range": Array [ - 28, - 37, - ], - "type": "Identifier", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 37, - "line": 1, - }, - "start": Object { - "column": 29, - "line": 1, - }, - }, - "range": Array [ - 29, - 37, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 37, - "line": 1, - }, - "start": Object { - "column": 31, - "line": 1, - }, - }, - "range": Array [ - 31, - 37, - ], - "type": "TSNumberKeyword", - }, - }, - }, - ], + "name": "a", "range": Array [ - 27, - 46, + 28, + 37, ], - "type": "TSFunctionType", + "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 46, + "column": 37, "line": 1, }, "start": Object { - "column": 40, + "column": 29, "line": 1, }, }, "range": Array [ - 40, - 46, + 29, + 37, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 46, + "column": 37, "line": 1, }, "start": Object { - "column": 42, + "column": 31, "line": 1, }, }, "range": Array [ - 42, - 46, + 31, + 37, ], - "type": "TSVoidKeyword", + "type": "TSNumberKeyword", }, }, - "typeParameters": null, }, + ], + "range": Array [ + 27, + 46, + ], + "type": "TSFunctionType", + "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 47, + "column": 46, "line": 1, }, "start": Object { - "column": 12, + "column": 40, "line": 1, }, }, "range": Array [ - 12, - 47, + 40, + 46, ], - "type": "VariableDeclarator", - }, - ], - "kind": "type", - "loc": Object { - "end": Object { - "column": 47, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 46, + "line": 1, + }, + "start": Object { + "column": 42, + "line": 1, + }, + }, + "range": Array [ + 42, + 46, + ], + "type": "TSVoidKeyword", + }, }, + "typeParameters": null, }, - "range": Array [ - 7, - 47, - ], - "type": "VariableDeclaration", }, "loc": Object { "end": Object { @@ -28855,296 +28775,256 @@ exports[`typescript fixtures/basics/import-type.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", + "id": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, }, - "init": Object { - "isTypeOf": true, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "name": "A", + "range": Array [ + 5, + 6, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 28, + ], + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "isTypeOf": true, + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "parameter": Object { + "literal": Object { "loc": Object { "end": Object { - "column": 27, + "column": 26, "line": 1, }, "start": Object { - "column": 9, + "column": 23, "line": 1, }, }, - "parameter": Object { - "literal": Object { - "loc": Object { - "end": Object { - "column": 26, - "line": 1, - }, - "start": Object { - "column": 23, - "line": 1, - }, - }, - "range": Array [ - 23, - 26, - ], - "raw": "'A'", - "type": "Literal", - "value": "A", - }, - "loc": Object { - "end": Object { - "column": 26, - "line": 1, - }, - "start": Object { - "column": 23, - "line": 1, - }, - }, - "range": Array [ - 23, - 26, - ], - "type": "TSLiteralType", - }, - "qualifier": null, "range": Array [ - 9, - 27, + 23, + 26, ], - "type": "TSImportType", - "typeParameters": null, + "raw": "'A'", + "type": "Literal", + "value": "A", }, "loc": Object { "end": Object { - "column": 28, + "column": 26, "line": 1, }, "start": Object { - "column": 5, + "column": 23, "line": 1, }, }, "range": Array [ - 5, - 28, + 23, + 26, ], - "type": "VariableDeclarator", + "type": "TSLiteralType", }, - ], - "kind": "type", + "qualifier": null, + "range": Array [ + 9, + 27, + ], + "type": "TSImportType", + "typeParameters": null, + }, + }, + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 5, + "line": 2, + }, + }, + "name": "B", + "range": Array [ + 34, + 35, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { - "column": 28, - "line": 1, + "column": 26, + "line": 2, }, "start": Object { "column": 0, - "line": 1, + "line": 2, }, }, "range": Array [ - 0, - 28, + 29, + 55, ], - "type": "VariableDeclaration", - }, - Object { - "declarations": Array [ - Object { - "id": Object { + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "isTypeOf": false, + "loc": Object { + "end": Object { + "column": 25, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "parameter": Object { + "literal": Object { "loc": Object { "end": Object { - "column": 6, + "column": 19, "line": 2, }, "start": Object { - "column": 5, + "column": 16, "line": 2, }, }, - "name": "B", "range": Array [ - 34, - 35, + 45, + 48, ], - "type": "Identifier", + "raw": "\\"B\\"", + "type": "Literal", + "value": "B", }, - "init": Object { - "isTypeOf": false, - "loc": Object { - "end": Object { - "column": 25, - "line": 2, - }, - "start": Object { - "column": 9, - "line": 2, - }, + "loc": Object { + "end": Object { + "column": 19, + "line": 2, }, - "parameter": Object { - "literal": Object { - "loc": Object { - "end": Object { - "column": 19, - "line": 2, - }, - "start": Object { - "column": 16, - "line": 2, - }, - }, - "range": Array [ - 45, - 48, - ], - "raw": "\\"B\\"", - "type": "Literal", - "value": "B", - }, - "loc": Object { - "end": Object { - "column": 19, - "line": 2, - }, - "start": Object { - "column": 16, - "line": 2, - }, - }, - "range": Array [ - 45, - 48, - ], - "type": "TSLiteralType", + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 45, + 48, + ], + "type": "TSLiteralType", + }, + "qualifier": Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 2, + }, + "start": Object { + "column": 21, + "line": 2, + }, + }, + "name": "X", + "range": Array [ + 50, + 51, + ], + "type": "Identifier", + }, + "range": Array [ + 38, + 54, + ], + "type": "TSImportType", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 2, }, - "qualifier": Object { + "start": Object { + "column": 22, + "line": 2, + }, + }, + "params": Array [ + Object { "loc": Object { "end": Object { - "column": 22, + "column": 24, "line": 2, }, "start": Object { - "column": 21, + "column": 23, "line": 2, }, }, - "name": "X", "range": Array [ - 50, - 51, + 52, + 53, ], - "type": "Identifier", - }, - "range": Array [ - 38, - 54, - ], - "type": "TSImportType", - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 25, - "line": 2, - }, - "start": Object { - "column": 22, - "line": 2, - }, - }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 24, - "line": 2, - }, - "start": Object { - "column": 23, - "line": 2, - }, + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, }, - "range": Array [ - 52, - 53, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 24, - "line": 2, - }, - "start": Object { - "column": 23, - "line": 2, - }, - }, - "name": "Y", - "range": Array [ - 52, - 53, - ], - "type": "Identifier", + "start": Object { + "column": 23, + "line": 2, }, }, - ], - "range": Array [ - 51, - 54, - ], - "type": "TSTypeParameterInstantiation", + "name": "Y", + "range": Array [ + 52, + 53, + ], + "type": "Identifier", + }, }, - }, - "loc": Object { - "end": Object { - "column": 26, - "line": 2, - }, - "start": Object { - "column": 5, - "line": 2, - }, - }, + ], "range": Array [ - 34, - 55, + 51, + 54, ], - "type": "VariableDeclarator", - }, - ], - "kind": "type", - "loc": Object { - "end": Object { - "column": 26, - "line": 2, - }, - "start": Object { - "column": 0, - "line": 2, + "type": "TSTypeParameterInstantiation", }, }, - "range": Array [ - 29, - 55, - ], - "type": "VariableDeclaration", }, ], "comments": Array [], @@ -29569,221 +29449,201 @@ exports[`typescript fixtures/basics/import-type-with-type-parameters-in-type-ref Object { "body": Array [ Object { - "declarations": Array [ - Object { - "id": Object { - "loc": Object { - "end": Object { - "column": 6, - "line": 1, - }, - "start": Object { - "column": 5, - "line": 1, - }, + "id": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "name": "X", + "range": Array [ + 5, + 6, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 30, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 30, + ], + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 29, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, }, - "name": "X", - "range": Array [ - 5, - 6, - ], - "type": "Identifier", }, - "init": Object { - "loc": Object { - "end": Object { - "column": 29, - "line": 1, - }, - "start": Object { - "column": 9, - "line": 1, - }, + "name": "A", + "range": Array [ + 9, + 10, + ], + "type": "Identifier", + }, + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 1, }, - "range": Array [ - 9, - 29, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 1, - }, - "start": Object { - "column": 9, - "line": 1, - }, - }, - "name": "A", - "range": Array [ - 9, - 10, - ], - "type": "Identifier", + "start": Object { + "column": 10, + "line": 1, }, - "typeParameters": Object { + }, + "params": Array [ + Object { + "isTypeOf": false, "loc": Object { "end": Object { - "column": 29, + "column": 28, "line": 1, }, "start": Object { - "column": 10, + "column": 11, "line": 1, }, }, - "params": Array [ - Object { - "isTypeOf": false, + "parameter": Object { + "literal": Object { "loc": Object { "end": Object { - "column": 28, + "column": 20, "line": 1, }, "start": Object { - "column": 11, + "column": 18, "line": 1, }, }, - "parameter": Object { - "literal": Object { - "loc": Object { - "end": Object { - "column": 20, - "line": 1, - }, - "start": Object { - "column": 18, - "line": 1, - }, - }, - "range": Array [ - 18, - 20, - ], - "raw": "\\"\\"", - "type": "Literal", - "value": "", - }, - "loc": Object { - "end": Object { - "column": 20, - "line": 1, - }, - "start": Object { - "column": 18, - "line": 1, - }, - }, - "range": Array [ - 18, - 20, - ], - "type": "TSLiteralType", - }, - "qualifier": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 1, - }, - "start": Object { - "column": 22, - "line": 1, - }, - }, - "name": "B", - "range": Array [ - 22, - 23, - ], - "type": "Identifier", - }, "range": Array [ - 11, - 28, + 18, + 20, ], - "type": "TSImportType", - "typeParameters": Object { + "raw": "\\"\\"", + "type": "Literal", + "value": "", + }, + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 20, + ], + "type": "TSLiteralType", + }, + "qualifier": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "name": "B", + "range": Array [ + 22, + 23, + ], + "type": "Identifier", + }, + "range": Array [ + 11, + 28, + ], + "type": "TSImportType", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "params": Array [ + Object { "loc": Object { "end": Object { - "column": 28, + "column": 27, "line": 1, }, "start": Object { - "column": 23, + "column": 24, "line": 1, }, }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 1, - }, - "start": Object { - "column": 24, - "line": 1, - }, - }, - "range": Array [ - 24, - 27, - ], - "type": "TSAnyKeyword", - }, - ], "range": Array [ - 23, - 28, + 24, + 27, ], - "type": "TSTypeParameterInstantiation", + "type": "TSAnyKeyword", }, - }, - ], - "range": Array [ - 10, - 29, - ], - "type": "TSTypeParameterInstantiation", - }, - }, - "loc": Object { - "end": Object { - "column": 30, - "line": 1, - }, - "start": Object { - "column": 5, - "line": 1, + ], + "range": Array [ + 23, + 28, + ], + "type": "TSTypeParameterInstantiation", + }, }, - }, + ], "range": Array [ - 5, - 30, + 10, + 29, ], - "type": "VariableDeclarator", - }, - ], - "kind": "type", - "loc": Object { - "end": Object { - "column": 30, - "line": 1, - }, - "start": Object { - "column": 0, - "line": 1, + "type": "TSTypeParameterInstantiation", }, }, - "range": Array [ - 0, - 30, - ], - "type": "VariableDeclaration", }, ], "comments": Array [], @@ -30100,7 +29960,6 @@ exports[`typescript fixtures/basics/interface-extends.src 1`] = ` Object { "body": Array [ Object { - "abstract": false, "body": Object { "body": Array [], "loc": Object { @@ -30325,7 +30184,6 @@ exports[`typescript fixtures/basics/interface-extends-multiple.src 1`] = ` Object { "body": Array [ Object { - "abstract": false, "body": Object { "body": Array [], "loc": Object { @@ -30621,7 +30479,6 @@ exports[`typescript fixtures/basics/interface-type-parameters.src 1`] = ` Object { "body": Array [ Object { - "abstract": false, "body": Object { "body": Array [], "loc": Object { @@ -30865,7 +30722,6 @@ exports[`typescript fixtures/basics/interface-with-all-property-types.src 1`] = Object { "body": Array [ Object { - "abstract": false, "body": Object { "body": Array [ Object { @@ -34165,7 +34021,6 @@ exports[`typescript fixtures/basics/interface-with-construct-signature-with-para Object { "body": Array [ Object { - "abstract": false, "body": Object { "body": Array [ Object { @@ -34573,7 +34428,6 @@ exports[`typescript fixtures/basics/interface-with-extends-type-parameters.src 1 Object { "body": Array [ Object { - "abstract": false, "body": Object { "body": Array [], "loc": Object { @@ -34997,7 +34851,6 @@ exports[`typescript fixtures/basics/interface-with-generic.src 1`] = ` Object { "body": Array [ Object { - "abstract": false, "body": Object { "body": Array [], "loc": Object { @@ -35241,7 +35094,6 @@ exports[`typescript fixtures/basics/interface-with-jsdoc.src 1`] = ` Object { "body": Array [ Object { - "abstract": false, "body": Object { "body": Array [ Object { @@ -35566,7 +35418,6 @@ exports[`typescript fixtures/basics/interface-with-optional-properties.src 1`] = Object { "body": Array [ Object { - "abstract": false, "body": Object { "body": Array [ Object { @@ -36355,7 +36206,6 @@ exports[`typescript fixtures/basics/interface-without-type-annotation.src 1`] = Object { "body": Array [ Object { - "abstract": false, "body": Object { "body": Array [ Object { @@ -36581,97 +36431,24 @@ 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", - }, - }, + "id": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, }, - "loc": Object { - "end": Object { - "column": 19, - "line": 1, - }, - "start": Object { - "column": 5, - "line": 1, - }, + "start": Object { + "column": 5, + "line": 1, }, - "range": Array [ - 5, - 19, - ], - "type": "VariableDeclarator", }, - ], - "kind": "type", + "name": "x", + "range": Array [ + 5, + 6, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { "column": 19, @@ -36686,7 +36463,60 @@ Object { 0, 19, ], - "type": "VariableDeclaration", + "type": "TSTypeAliasDeclaration", + "typeAnnotation": 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", + }, + }, + }, }, ], "comments": Array [], @@ -40623,30 +40453,60 @@ exports[`typescript fixtures/basics/type-alias-declaration.src 1`] = ` Object { "body": Array [ Object { - "declarations": Array [ - Object { - "id": Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 1, - }, - "start": Object { - "column": 5, - "line": 1, - }, - }, - "name": "Result", - "range": Array [ - 5, - 11, - ], - "type": "Identifier", + "id": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, }, - "init": Object { + "start": Object { + "column": 5, + "line": 1, + }, + }, + "name": "Result", + "range": Array [ + 5, + 11, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 37, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 37, + ], + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 37, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 37, + ], + "type": "TSUnionType", + "types": Array [ + Object { "loc": Object { "end": Object { - "column": 37, + "column": 27, "line": 1, }, "start": Object { @@ -40656,206 +40516,156 @@ Object { }, "range": Array [ 17, - 37, + 27, ], - "type": "TSUnionType", - "types": Array [ - Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 1, - }, - "start": Object { - "column": 17, - "line": 1, - }, + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 1, }, - "range": Array [ - 17, - 27, - ], - "type": "TSTypeReference", - "typeName": Object { + "start": Object { + "column": 17, + "line": 1, + }, + }, + "name": "Success", + "range": Array [ + 17, + 24, + ], + "type": "Identifier", + }, + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 24, + "line": 1, + }, + }, + "params": Array [ + Object { "loc": Object { "end": Object { - "column": 24, + "column": 26, "line": 1, }, "start": Object { - "column": 17, + "column": 25, "line": 1, }, }, - "name": "Success", "range": Array [ - 17, - 24, + 25, + 26, ], - "type": "Identifier", - }, - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 1, - }, - "start": Object { - "column": 24, - "line": 1, - }, - }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 26, - "line": 1, - }, - "start": Object { - "column": 25, - "line": 1, - }, + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 1, }, - "range": Array [ - 25, - 26, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 26, - "line": 1, - }, - "start": Object { - "column": 25, - "line": 1, - }, - }, - "name": "T", - "range": Array [ - 25, - 26, - ], - "type": "Identifier", + "start": Object { + "column": 25, + "line": 1, }, }, - ], - "range": Array [ - 24, - 27, - ], - "type": "TSTypeParameterInstantiation", + "name": "T", + "range": Array [ + 25, + 26, + ], + "type": "Identifier", + }, }, + ], + "range": Array [ + 24, + 27, + ], + "type": "TSTypeParameterInstantiation", + }, + }, + Object { + "loc": Object { + "end": Object { + "column": 37, + "line": 1, }, - Object { - "loc": Object { - "end": Object { - "column": 37, - "line": 1, - }, - "start": Object { - "column": 30, - "line": 1, - }, + "start": Object { + "column": 30, + "line": 1, + }, + }, + "range": Array [ + 30, + 37, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 37, + "line": 1, }, - "range": Array [ - 30, - 37, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 37, - "line": 1, - }, - "start": Object { - "column": 30, - "line": 1, - }, - }, - "name": "Failure", - "range": Array [ - 30, - 37, - ], - "type": "Identifier", + "start": Object { + "column": 30, + "line": 1, }, }, - ], - }, - "loc": Object { - "end": Object { - "column": 37, - "line": 1, - }, - "start": Object { - "column": 5, - "line": 1, + "name": "Failure", + "range": Array [ + 30, + 37, + ], + "type": "Identifier", }, }, - "range": Array [ - 5, - 37, - ], - "type": "VariableDeclarator", - "typeParameters": Object { + ], + }, + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "params": Array [ + Object { "loc": Object { "end": Object { - "column": 14, + "column": 13, "line": 1, }, "start": Object { - "column": 11, + "column": 12, "line": 1, }, }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 13, - "line": 1, - }, - "start": Object { - "column": 12, - "line": 1, - }, - }, - "name": "T", - "range": Array [ - 12, - 13, - ], - "type": "TSTypeParameter", - }, - ], + "name": "T", "range": Array [ - 11, - 14, + 12, + 13, ], - "type": "TSTypeParameterDeclaration", + "type": "TSTypeParameter", }, - }, - ], - "kind": "type", - "loc": Object { - "end": Object { - "column": 37, - "line": 1, - }, - "start": Object { - "column": 0, - "line": 1, - }, + ], + "range": Array [ + 11, + 14, + ], + "type": "TSTypeParameterDeclaration", }, - "range": Array [ - 0, - 37, - ], - "type": "VariableDeclaration", }, ], "comments": Array [], @@ -41100,30 +40910,60 @@ exports[`typescript fixtures/basics/type-alias-declaration-with-constrained-type Object { "body": Array [ Object { - "declarations": Array [ - Object { - "id": Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 1, - }, - "start": Object { - "column": 5, - "line": 1, - }, - }, - "name": "Result", - "range": Array [ - 5, - 11, - ], - "type": "Identifier", + "id": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, }, - "init": Object { + "start": Object { + "column": 5, + "line": 1, + }, + }, + "name": "Result", + "range": Array [ + 5, + 11, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 48, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 48, + ], + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 48, + "line": 1, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, + "range": Array [ + 28, + 48, + ], + "type": "TSUnionType", + "types": Array [ + Object { "loc": Object { "end": Object { - "column": 48, + "column": 38, "line": 1, }, "start": Object { @@ -41133,224 +40973,174 @@ Object { }, "range": Array [ 28, - 48, + 38, ], - "type": "TSUnionType", - "types": Array [ - Object { - "loc": Object { - "end": Object { - "column": 38, - "line": 1, - }, - "start": Object { - "column": 28, - "line": 1, - }, + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 1, }, - "range": Array [ - 28, - 38, - ], - "type": "TSTypeReference", - "typeName": Object { + "start": Object { + "column": 28, + "line": 1, + }, + }, + "name": "Success", + "range": Array [ + 28, + 35, + ], + "type": "Identifier", + }, + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 1, + }, + "start": Object { + "column": 35, + "line": 1, + }, + }, + "params": Array [ + Object { "loc": Object { "end": Object { - "column": 35, + "column": 37, "line": 1, }, "start": Object { - "column": 28, + "column": 36, "line": 1, }, }, - "name": "Success", "range": Array [ - 28, - 35, + 36, + 37, ], - "type": "Identifier", - }, - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 38, - "line": 1, - }, - "start": Object { - "column": 35, - "line": 1, - }, - }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 37, - "line": 1, - }, - "start": Object { - "column": 36, - "line": 1, - }, + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 37, + "line": 1, }, - "range": Array [ - 36, - 37, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 37, - "line": 1, - }, - "start": Object { - "column": 36, - "line": 1, - }, - }, - "name": "T", - "range": Array [ - 36, - 37, - ], - "type": "Identifier", + "start": Object { + "column": 36, + "line": 1, }, }, - ], - "range": Array [ - 35, - 38, - ], - "type": "TSTypeParameterInstantiation", - }, - }, - Object { - "loc": Object { - "end": Object { - "column": 48, - "line": 1, - }, - "start": Object { - "column": 41, - "line": 1, - }, - }, - "range": Array [ - 41, - 48, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 48, - "line": 1, - }, - "start": Object { - "column": 41, - "line": 1, - }, + "name": "T", + "range": Array [ + 36, + 37, + ], + "type": "Identifier", }, - "name": "Failure", - "range": Array [ - 41, - 48, - ], - "type": "Identifier", }, - }, - ], - }, - "loc": Object { - "end": Object { - "column": 48, - "line": 1, - }, - "start": Object { - "column": 5, - "line": 1, + ], + "range": Array [ + 35, + 38, + ], + "type": "TSTypeParameterInstantiation", }, }, - "range": Array [ - 5, - 48, - ], - "type": "VariableDeclarator", - "typeParameters": Object { + Object { "loc": Object { "end": Object { - "column": 25, + "column": 48, "line": 1, }, "start": Object { - "column": 11, + "column": 41, "line": 1, }, }, - "params": Array [ - Object { - "constraint": Object { - "loc": Object { - "end": Object { - "column": 24, - "line": 1, - }, - "start": Object { - "column": 22, - "line": 1, - }, - }, - "members": Array [], - "range": Array [ - 22, - 24, - ], - "type": "TSTypeLiteral", + "range": Array [ + 41, + 48, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 48, + "line": 1, }, - "loc": Object { - "end": Object { - "column": 24, - "line": 1, - }, - "start": Object { - "column": 12, - "line": 1, - }, + "start": Object { + "column": 41, + "line": 1, }, - "name": "T", - "range": Array [ - 12, - 24, - ], - "type": "TSTypeParameter", }, - ], + "name": "Failure", + "range": Array [ + 41, + 48, + ], + "type": "Identifier", + }, + }, + ], + }, + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "params": Array [ + Object { + "constraint": Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "members": Array [], + "range": Array [ + 22, + 24, + ], + "type": "TSTypeLiteral", + }, + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "name": "T", "range": Array [ - 11, - 25, + 12, + 24, ], - "type": "TSTypeParameterDeclaration", + "type": "TSTypeParameter", }, - }, - ], - "kind": "type", - "loc": Object { - "end": Object { - "column": 48, - "line": 1, - }, - "start": Object { - "column": 0, - "line": 1, - }, + ], + "range": Array [ + 11, + 25, + ], + "type": "TSTypeParameterDeclaration", }, - "range": Array [ - 0, - 48, - ], - "type": "VariableDeclaration", }, ], "comments": Array [], @@ -41649,184 +41439,164 @@ exports[`typescript fixtures/basics/type-alias-object-without-annotation.src 1`] Object { "body": Array [ Object { - "declarations": Array [ - Object { - "id": Object { - "loc": Object { - "end": Object { - "column": 8, - "line": 1, - }, - "start": Object { - "column": 5, - "line": 1, + "id": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 5, + 8, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 30, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 30, + ], + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "members": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, }, + "name": "bar", + "range": Array [ + 12, + 15, + ], + "type": "Identifier", }, - "name": "foo", - "range": Array [ - 5, - 8, - ], - "type": "Identifier", - }, - "init": Object { "loc": Object { "end": Object { - "column": 29, + "column": 24, "line": 1, }, "start": Object { - "column": 11, + "column": 12, "line": 1, }, }, - "members": Array [ - Object { - "computed": false, - "key": Object { - "loc": Object { - "end": Object { - "column": 15, - "line": 1, - }, - "start": Object { - "column": 12, - "line": 1, - }, - }, - "name": "bar", - "range": Array [ - 12, - 15, - ], - "type": "Identifier", - }, - "loc": Object { - "end": Object { - "column": 24, - "line": 1, - }, - "start": Object { - "column": 12, - "line": 1, - }, + "range": Array [ + 12, + 24, + ], + "type": "TSPropertySignature", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 1, }, - "range": Array [ - 12, - 24, - ], - "type": "TSPropertySignature", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 1, - }, - "start": Object { - "column": 15, - "line": 1, - }, - }, - "range": Array [ - 15, - 23, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 1, - }, - "start": Object { - "column": 17, - "line": 1, - }, - }, - "range": Array [ - 17, - 23, - ], - "type": "TSStringKeyword", - }, + "start": Object { + "column": 15, + "line": 1, }, }, - Object { - "computed": false, - "key": Object { - "loc": Object { - "end": Object { - "column": 28, - "line": 1, - }, - "start": Object { - "column": 25, - "line": 1, - }, - }, - "name": "baz", - "range": Array [ - 25, - 28, - ], - "type": "Identifier", - }, + "range": Array [ + 15, + 23, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 28, + "column": 23, "line": 1, }, "start": Object { - "column": 25, + "column": 17, "line": 1, }, }, "range": Array [ - 25, - 28, + 17, + 23, ], - "type": "TSPropertySignature", + "type": "TSStringKeyword", }, - ], - "range": Array [ - 11, - 29, - ], - "type": "TSTypeLiteral", + }, }, - "loc": Object { - "end": Object { - "column": 30, - "line": 1, + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, + }, + "name": "baz", + "range": Array [ + 25, + 28, + ], + "type": "Identifier", }, - "start": Object { - "column": 5, - "line": 1, + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, }, + "range": Array [ + 25, + 28, + ], + "type": "TSPropertySignature", }, - "range": Array [ - 5, - 30, - ], - "type": "VariableDeclarator", - }, - ], - "kind": "type", - "loc": Object { - "end": Object { - "column": 30, - "line": 1, - }, - "start": Object { - "column": 0, - "line": 1, - }, + ], + "range": Array [ + 11, + 29, + ], + "type": "TSTypeLiteral", }, - "range": Array [ - 0, - 30, - ], - "type": "VariableDeclaration", }, ], "comments": Array [], @@ -44137,7 +43907,6 @@ exports[`typescript fixtures/basics/typed-this.src 1`] = ` Object { "body": Array [ Object { - "abstract": false, "body": Object { "body": Array [ Object { @@ -44918,79 +44687,24 @@ 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", - }, + "id": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, }, - "loc": Object { - "end": Object { - "column": 23, - "line": 1, - }, - "start": Object { - "column": 5, - "line": 1, - }, + "start": Object { + "column": 5, + "line": 1, }, - "range": Array [ - 5, - 23, - ], - "type": "VariableDeclarator", }, - ], - "kind": "type", + "name": "A", + "range": Array [ + 5, + 6, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { "column": 23, @@ -45005,7 +44719,42 @@ Object { 0, 23, ], - "type": "VariableDeclaration", + "type": "TSTypeAliasDeclaration", + "typeAnnotation": 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", + }, + }, }, ], "comments": Array [], @@ -58764,7 +58513,6 @@ exports[`typescript fixtures/errorRecovery/decorator-on-interface-declaration.sr Object { "body": Array [ Object { - "abstract": false, "body": Object { "body": Array [], "loc": Object { @@ -59722,7 +59470,6 @@ exports[`typescript fixtures/errorRecovery/interface-empty-extends.src 1`] = ` Object { "body": Array [ Object { - "abstract": false, "body": Object { "body": Array [], "loc": Object { @@ -59893,7 +59640,6 @@ exports[`typescript fixtures/errorRecovery/interface-property-modifiers.src 1`] Object { "body": Array [ Object { - "abstract": false, "body": Object { "body": Array [ Object { @@ -66117,7 +65863,6 @@ Object { Object { "declaration": Object { "async": false, - "body": null, "expression": false, "generator": false, "id": Object { @@ -67954,7 +67699,6 @@ Object { "body": Array [ Object { "declaration": Object { - "abstract": false, "body": Object { "body": Array [ Object { diff --git a/visitor-keys.js b/visitor-keys.js index c036ea6..1803e8a 100644 --- a/visitor-keys.js +++ b/visitor-keys.js @@ -75,6 +75,7 @@ module.exports = Evk.unionWith({ TSStringKeyword: [], TSSymbolKeyword: [], TSTypeAnnotation: ["typeAnnotation"], + TSTypeAliasDeclaration: ["id", "typeParameters", "typeAnnotation"], TSTypeLiteral: ["members"], TSTypeOperator: ["typeAnnotation"], TSTypeParameter: ["constraint", "default"], From 18598d9bbf003c02bbb55bfb8580560df1fb1e87 Mon Sep 17 00:00:00 2001 From: Armano Date: Tue, 25 Dec 2018 03:54:58 +0100 Subject: [PATCH 08/18] Test: fix eol issue --- tests/lib/__snapshots__/scope-analysis.js.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lib/__snapshots__/scope-analysis.js.snap b/tests/lib/__snapshots__/scope-analysis.js.snap index 0d256f0..8a68450 100644 --- a/tests/lib/__snapshots__/scope-analysis.js.snap +++ b/tests/lib/__snapshots__/scope-analysis.js.snap @@ -5304,7 +5304,7 @@ Object { "block": Object { "range": Array [ 0, - 19, + 18, ], "type": "Program", }, From 34adb5d15256a33a609dc997076d90d9fdcae718 Mon Sep 17 00:00:00 2001 From: Armano Date: Fri, 28 Dec 2018 20:25:04 +0100 Subject: [PATCH 09/18] Upgrade: typescript-estree to 8.1.0 and add new tests --- analyze-scope.js | 105 +- package.json | 2 +- .../scope-analysis/types-array-type.src.ts | 1 + .../types-conditional-with-null.src.ts | 1 + .../scope-analysis/types-conditional.src.ts | 1 + .../scope-analysis/types-indexed.src.ts | 1 + .../types-intersection-type.src.ts | 1 + .../types-mapped-readonly-minus.src.ts | 1 + .../types-mapped-readonly-plus.src.ts | 1 + .../types-mapped-readonly.src.ts | 1 + .../scope-analysis/types-mapped.src.ts | 1 + .../scope-analysis/types-nested-types.src.ts | 1 + .../types-parenthesized-type.src.ts | 1 + .../types-reference-generic-nested.src.ts | 1 + .../types-reference-generic.src.ts | 1 + .../scope-analysis/types-reference.src.ts | 1 + .../scope-analysis/types-tuple-empty.src.ts | 1 + .../types-tuple-optional.src.ts | 1 + .../scope-analysis/types-tuple-rest.src.ts | 1 + .../scope-analysis/types-tuple-type.src.ts | 1 + .../scope-analysis/types-tuple.src.ts | 1 + .../scope-analysis/types-type-literal.src.ts | 1 + .../scope-analysis/types-type-operator.src.ts | 2 + .../scope-analysis/types-typeof.src.ts | 1 + .../types-union-intersection.src.ts | 4 + .../scope-analysis/types-union-type.src.ts | 1 + tests/lib/__snapshots__/ecma-features.js.snap | 17 + .../lib/__snapshots__/scope-analysis.js.snap | 1736 +++++++++++++++++ tests/lib/__snapshots__/typescript.js.snap | 23 +- visitor-keys.js | 8 + 30 files changed, 1897 insertions(+), 22 deletions(-) create mode 100644 tests/fixtures/scope-analysis/types-array-type.src.ts create mode 100644 tests/fixtures/scope-analysis/types-conditional-with-null.src.ts create mode 100644 tests/fixtures/scope-analysis/types-conditional.src.ts create mode 100644 tests/fixtures/scope-analysis/types-indexed.src.ts create mode 100644 tests/fixtures/scope-analysis/types-intersection-type.src.ts create mode 100644 tests/fixtures/scope-analysis/types-mapped-readonly-minus.src.ts create mode 100644 tests/fixtures/scope-analysis/types-mapped-readonly-plus.src.ts create mode 100644 tests/fixtures/scope-analysis/types-mapped-readonly.src.ts create mode 100644 tests/fixtures/scope-analysis/types-mapped.src.ts create mode 100644 tests/fixtures/scope-analysis/types-nested-types.src.ts create mode 100644 tests/fixtures/scope-analysis/types-parenthesized-type.src.ts create mode 100644 tests/fixtures/scope-analysis/types-reference-generic-nested.src.ts create mode 100644 tests/fixtures/scope-analysis/types-reference-generic.src.ts create mode 100644 tests/fixtures/scope-analysis/types-reference.src.ts create mode 100644 tests/fixtures/scope-analysis/types-tuple-empty.src.ts create mode 100644 tests/fixtures/scope-analysis/types-tuple-optional.src.ts create mode 100644 tests/fixtures/scope-analysis/types-tuple-rest.src.ts create mode 100644 tests/fixtures/scope-analysis/types-tuple-type.src.ts create mode 100644 tests/fixtures/scope-analysis/types-tuple.src.ts create mode 100644 tests/fixtures/scope-analysis/types-type-literal.src.ts create mode 100644 tests/fixtures/scope-analysis/types-type-operator.src.ts create mode 100644 tests/fixtures/scope-analysis/types-typeof.src.ts create mode 100644 tests/fixtures/scope-analysis/types-union-intersection.src.ts create mode 100644 tests/fixtures/scope-analysis/types-union-type.src.ts diff --git a/analyze-scope.js b/analyze-scope.js index 13c559b..0248ba1 100644 --- a/analyze-scope.js +++ b/analyze-scope.js @@ -400,9 +400,97 @@ class Referencer extends OriginalReferencer { } } + /** + * @param {TSTypeReference} node The TSTypeReference node to visit. + * @returns {void} + */ + TSTypeReference(node) { + this.visitTypeNodes(node); + } + + /** + * @param {TSTypeLiteral} node The TSTypeLiteral node to visit. + * @returns {void} + */ + TSTypeLiteral(node) { + this.visitTypeNodes(node); + } + + /** + * @param {TSLiteralType} node The TSLiteralType node to visit. + * @returns {void} + */ + TSLiteralType(node) { + this.visitTypeNodes(node); + } + + /** + * @param {TSIntersectionType} node The TSIntersectionType node to visit. + * @returns {void} + */ + TSIntersectionType(node) { + this.visitTypeNodes(node); + } + + /** + * @param {TSConditionalType} node The TSConditionalType node to visit. + * @returns {void} + */ + TSConditionalType(node) { + this.visitTypeNodes(node); + } + + /** + * @param {TSIndexedAccessType} node The TSIndexedAccessType node to visit. + * @returns {void} + */ + TSIndexedAccessType(node) { + this.visitTypeNodes(node); + } + + /** + * @param {TSMappedType} node The TSMappedType node to visit. + * @returns {void} + */ + TSMappedType(node) { + this.visitTypeNodes(node); + } + + /** + * @param {TSOptionalType} node The TSOptionalType node to visit. + * @returns {void} + */ + TSOptionalType(node) { + this.visitTypeNodes(node); + } + + /** + * @param {TSParenthesizedType} node The TSParenthesizedType node to visit. + * @returns {void} + */ + TSParenthesizedType(node) { + this.visitTypeNodes(node); + } + + /** + * @param {TSRestType} node The TSRestType node to visit. + * @returns {void} + */ + TSRestType(node) { + this.visitTypeNodes(node); + } + + /** + * @param {TSTupleType} node The TSTupleType node to visit. + * @returns {void} + */ + TSTupleType(node) { + this.visitTypeNodes(node); + } + /** * Create reference objects for the object part. (This is `obj.prop`) - * @param {TSTypeQuery} node The TSTypeQuery node to visit. + * @param {TSQualifiedName} node The TSQualifiedName node to visit. * @returns {void} */ TSQualifiedName(node) { @@ -616,6 +704,21 @@ class Referencer extends OriginalReferencer { decorators.forEach(this.visit, this); } } + + /** + * Process all child of type nodes + * @param {any} node node to be processed + * @returns {void} + */ + visitTypeNodes(node) { + if (this.typeMode) { + this.visitChildren(node); + } else { + this.typeMode = true; + this.visitChildren(node); + this.typeMode = false; + } + } } module.exports = function(ast, parserOptions, extraOptions) { diff --git a/package.json b/package.json index c16077a..c1f67f7 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "dependencies": { "eslint-scope": "^4.0.0", "eslint-visitor-keys": "^1.0.0", - "typescript-estree": "^7.0.0" + "typescript-estree": "8.1.0" }, "devDependencies": { "eslint": "^4.19.1", diff --git a/tests/fixtures/scope-analysis/types-array-type.src.ts b/tests/fixtures/scope-analysis/types-array-type.src.ts new file mode 100644 index 0000000..5d038fc --- /dev/null +++ b/tests/fixtures/scope-analysis/types-array-type.src.ts @@ -0,0 +1 @@ +type Foo = string[] diff --git a/tests/fixtures/scope-analysis/types-conditional-with-null.src.ts b/tests/fixtures/scope-analysis/types-conditional-with-null.src.ts new file mode 100644 index 0000000..c776486 --- /dev/null +++ b/tests/fixtures/scope-analysis/types-conditional-with-null.src.ts @@ -0,0 +1 @@ +let x: number extends string ? boolean : null; diff --git a/tests/fixtures/scope-analysis/types-conditional.src.ts b/tests/fixtures/scope-analysis/types-conditional.src.ts new file mode 100644 index 0000000..da72fcb --- /dev/null +++ b/tests/fixtures/scope-analysis/types-conditional.src.ts @@ -0,0 +1 @@ +let x: number extends string ? boolean : string; diff --git a/tests/fixtures/scope-analysis/types-indexed.src.ts b/tests/fixtures/scope-analysis/types-indexed.src.ts new file mode 100644 index 0000000..4a5809f --- /dev/null +++ b/tests/fixtures/scope-analysis/types-indexed.src.ts @@ -0,0 +1 @@ +let x: T[K]; diff --git a/tests/fixtures/scope-analysis/types-intersection-type.src.ts b/tests/fixtures/scope-analysis/types-intersection-type.src.ts new file mode 100644 index 0000000..93da940 --- /dev/null +++ b/tests/fixtures/scope-analysis/types-intersection-type.src.ts @@ -0,0 +1 @@ +type LinkedList = T & { next: LinkedList }; diff --git a/tests/fixtures/scope-analysis/types-mapped-readonly-minus.src.ts b/tests/fixtures/scope-analysis/types-mapped-readonly-minus.src.ts new file mode 100644 index 0000000..a7a1183 --- /dev/null +++ b/tests/fixtures/scope-analysis/types-mapped-readonly-minus.src.ts @@ -0,0 +1 @@ +let map: { -readonly [P in string]-?: number }; diff --git a/tests/fixtures/scope-analysis/types-mapped-readonly-plus.src.ts b/tests/fixtures/scope-analysis/types-mapped-readonly-plus.src.ts new file mode 100644 index 0000000..854fb5d --- /dev/null +++ b/tests/fixtures/scope-analysis/types-mapped-readonly-plus.src.ts @@ -0,0 +1 @@ +let map: { +readonly [P in string]+?: number; }; diff --git a/tests/fixtures/scope-analysis/types-mapped-readonly.src.ts b/tests/fixtures/scope-analysis/types-mapped-readonly.src.ts new file mode 100644 index 0000000..ef13a05 --- /dev/null +++ b/tests/fixtures/scope-analysis/types-mapped-readonly.src.ts @@ -0,0 +1 @@ +let map: { readonly [P in string]?: number; }; diff --git a/tests/fixtures/scope-analysis/types-mapped.src.ts b/tests/fixtures/scope-analysis/types-mapped.src.ts new file mode 100644 index 0000000..aca2ba1 --- /dev/null +++ b/tests/fixtures/scope-analysis/types-mapped.src.ts @@ -0,0 +1 @@ +let map: { [P in string]: number; }; diff --git a/tests/fixtures/scope-analysis/types-nested-types.src.ts b/tests/fixtures/scope-analysis/types-nested-types.src.ts new file mode 100644 index 0000000..adaf9a3 --- /dev/null +++ b/tests/fixtures/scope-analysis/types-nested-types.src.ts @@ -0,0 +1 @@ +type Foo = [number, string?, boolean?] | [{}, [number?] | null & boolean[]] & {} diff --git a/tests/fixtures/scope-analysis/types-parenthesized-type.src.ts b/tests/fixtures/scope-analysis/types-parenthesized-type.src.ts new file mode 100644 index 0000000..5a03e27 --- /dev/null +++ b/tests/fixtures/scope-analysis/types-parenthesized-type.src.ts @@ -0,0 +1 @@ +type Foo = (string | number) diff --git a/tests/fixtures/scope-analysis/types-reference-generic-nested.src.ts b/tests/fixtures/scope-analysis/types-reference-generic-nested.src.ts new file mode 100644 index 0000000..e38dfca --- /dev/null +++ b/tests/fixtures/scope-analysis/types-reference-generic-nested.src.ts @@ -0,0 +1 @@ +let x: Array>; diff --git a/tests/fixtures/scope-analysis/types-reference-generic.src.ts b/tests/fixtures/scope-analysis/types-reference-generic.src.ts new file mode 100644 index 0000000..4925bd4 --- /dev/null +++ b/tests/fixtures/scope-analysis/types-reference-generic.src.ts @@ -0,0 +1 @@ +let x: Array; diff --git a/tests/fixtures/scope-analysis/types-reference.src.ts b/tests/fixtures/scope-analysis/types-reference.src.ts new file mode 100644 index 0000000..330fb1d --- /dev/null +++ b/tests/fixtures/scope-analysis/types-reference.src.ts @@ -0,0 +1 @@ +let x: T; diff --git a/tests/fixtures/scope-analysis/types-tuple-empty.src.ts b/tests/fixtures/scope-analysis/types-tuple-empty.src.ts new file mode 100644 index 0000000..f7cd7b5 --- /dev/null +++ b/tests/fixtures/scope-analysis/types-tuple-empty.src.ts @@ -0,0 +1 @@ +let x: []; diff --git a/tests/fixtures/scope-analysis/types-tuple-optional.src.ts b/tests/fixtures/scope-analysis/types-tuple-optional.src.ts new file mode 100644 index 0000000..3b8d21b --- /dev/null +++ b/tests/fixtures/scope-analysis/types-tuple-optional.src.ts @@ -0,0 +1 @@ +let x: [string, number?, (string | number)?] diff --git a/tests/fixtures/scope-analysis/types-tuple-rest.src.ts b/tests/fixtures/scope-analysis/types-tuple-rest.src.ts new file mode 100644 index 0000000..d7719b2 --- /dev/null +++ b/tests/fixtures/scope-analysis/types-tuple-rest.src.ts @@ -0,0 +1 @@ +let x: [string, ...number[]] diff --git a/tests/fixtures/scope-analysis/types-tuple-type.src.ts b/tests/fixtures/scope-analysis/types-tuple-type.src.ts new file mode 100644 index 0000000..75a6d8e --- /dev/null +++ b/tests/fixtures/scope-analysis/types-tuple-type.src.ts @@ -0,0 +1 @@ +type Foo = [string, string?] diff --git a/tests/fixtures/scope-analysis/types-tuple.src.ts b/tests/fixtures/scope-analysis/types-tuple.src.ts new file mode 100644 index 0000000..53c8e72 --- /dev/null +++ b/tests/fixtures/scope-analysis/types-tuple.src.ts @@ -0,0 +1 @@ +let x: [number, number, number]; diff --git a/tests/fixtures/scope-analysis/types-type-literal.src.ts b/tests/fixtures/scope-analysis/types-type-literal.src.ts new file mode 100644 index 0000000..4193f36 --- /dev/null +++ b/tests/fixtures/scope-analysis/types-type-literal.src.ts @@ -0,0 +1 @@ +let obj: { x: number }; diff --git a/tests/fixtures/scope-analysis/types-type-operator.src.ts b/tests/fixtures/scope-analysis/types-type-operator.src.ts new file mode 100644 index 0000000..1d23f96 --- /dev/null +++ b/tests/fixtures/scope-analysis/types-type-operator.src.ts @@ -0,0 +1,2 @@ +let x: keyof T; +let y: unique symbol; diff --git a/tests/fixtures/scope-analysis/types-typeof.src.ts b/tests/fixtures/scope-analysis/types-typeof.src.ts new file mode 100644 index 0000000..eebcd19 --- /dev/null +++ b/tests/fixtures/scope-analysis/types-typeof.src.ts @@ -0,0 +1 @@ +let x: typeof y.z; diff --git a/tests/fixtures/scope-analysis/types-union-intersection.src.ts b/tests/fixtures/scope-analysis/types-union-intersection.src.ts new file mode 100644 index 0000000..93f391f --- /dev/null +++ b/tests/fixtures/scope-analysis/types-union-intersection.src.ts @@ -0,0 +1,4 @@ +let union: number | null | undefined; +let intersection: number & string; +let precedence1: number | string & boolean; +let precedence2: number & string | boolean; diff --git a/tests/fixtures/scope-analysis/types-union-type.src.ts b/tests/fixtures/scope-analysis/types-union-type.src.ts new file mode 100644 index 0000000..a2cfaf9 --- /dev/null +++ b/tests/fixtures/scope-analysis/types-union-type.src.ts @@ -0,0 +1 @@ +type Foo = string & number diff --git a/tests/lib/__snapshots__/ecma-features.js.snap b/tests/lib/__snapshots__/ecma-features.js.snap index ee9c97b..7ff6256 100644 --- a/tests/lib/__snapshots__/ecma-features.js.snap +++ b/tests/lib/__snapshots__/ecma-features.js.snap @@ -2375,6 +2375,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-default-param-eval.sr Object { "body": Array [ Object { + "directive": "use strict", "expression": Object { "loc": Object { "end": Object { @@ -2730,6 +2731,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-dup-params.src 1`] = Object { "body": Array [ Object { + "directive": "use strict", "expression": Object { "loc": Object { "end": Object { @@ -3072,6 +3074,7 @@ Object { "body": Object { "body": Array [ Object { + "directive": "use strict", "expression": Object { "loc": Object { "end": Object { @@ -3404,6 +3407,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-eval-return.src 1`] = Object { "body": Array [ Object { + "directive": "use strict", "expression": Object { "loc": Object { "end": Object { @@ -3669,6 +3673,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-octal.src 1`] = ` Object { "body": Array [ Object { + "directive": "use strict", "expression": Object { "loc": Object { "end": Object { @@ -3952,6 +3957,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-param-arguments.src 1 Object { "body": Array [ Object { + "directive": "use strict", "expression": Object { "loc": Object { "end": Object { @@ -4289,6 +4295,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-param-eval.src 1`] = Object { "body": Array [ Object { + "directive": "use strict", "expression": Object { "loc": Object { "end": Object { @@ -4626,6 +4633,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-param-names.src 1`] = Object { "body": Array [ Object { + "directive": "use strict", "expression": Object { "loc": Object { "end": Object { @@ -4963,6 +4971,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-param-no-paren-argume Object { "body": Array [ Object { + "directive": "use strict", "expression": Object { "loc": Object { "end": Object { @@ -5210,6 +5219,7 @@ exports[`ecmaFeatures fixtures/arrowFunctions/error-strict-param-no-paren-eval.s Object { "body": Array [ Object { + "directive": "use strict", "expression": Object { "loc": Object { "end": Object { @@ -93424,6 +93434,7 @@ exports[`ecmaFeatures fixtures/objectLiteralDuplicateProperties/error-proto-prop Object { "body": Array [ Object { + "directive": "use strict", "expression": Object { "loc": Object { "end": Object { @@ -94125,6 +94136,7 @@ exports[`ecmaFeatures fixtures/objectLiteralDuplicateProperties/error-proto-stri Object { "body": Array [ Object { + "directive": "use strict", "expression": Object { "loc": Object { "end": Object { @@ -94828,6 +94840,7 @@ exports[`ecmaFeatures fixtures/objectLiteralDuplicateProperties/strict-duplicate Object { "body": Array [ Object { + "directive": "use strict", "expression": Object { "loc": Object { "end": Object { @@ -95350,6 +95363,7 @@ exports[`ecmaFeatures fixtures/objectLiteralDuplicateProperties/strict-duplicate Object { "body": Array [ Object { + "directive": "use strict", "expression": Object { "loc": Object { "end": Object { @@ -99632,6 +99646,7 @@ exports[`ecmaFeatures fixtures/octalLiterals/strict-uppercase.src 1`] = ` Object { "body": Array [ Object { + "directive": "use strict", "expression": Object { "loc": Object { "end": Object { @@ -107763,6 +107778,7 @@ exports[`ecmaFeatures fixtures/unicodeCodePointEscapes/basic-string-literal.src Object { "body": Array [ Object { + "directive": "\\\\u{714E}\\\\u{8336}", "expression": Object { "loc": Object { "end": Object { @@ -107861,6 +107877,7 @@ exports[`ecmaFeatures fixtures/unicodeCodePointEscapes/complex-string-literal.sr Object { "body": Array [ Object { + "directive": "\\\\u{20BB7}\\\\u{10FFFF}\\\\u{1}", "expression": Object { "loc": Object { "end": Object { diff --git a/tests/lib/__snapshots__/scope-analysis.js.snap b/tests/lib/__snapshots__/scope-analysis.js.snap index 8a68450..8954a6f 100644 --- a/tests/lib/__snapshots__/scope-analysis.js.snap +++ b/tests/lib/__snapshots__/scope-analysis.js.snap @@ -7085,3 +7085,1739 @@ Object { ], } `; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-array-type.src.ts 1`] = ` +Object { + "$id": 0, + "block": Object { + "range": Array [ + 0, + 20, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 0, + }, + "variables": Array [], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-conditional.src.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 49, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "x": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "x", + "range": Array [ + 4, + 47, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 47, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 48, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "x", + "range": Array [ + 4, + 47, + ], + "type": "Identifier", + }, + ], + "name": "x", + "references": Array [], + "scope": Object { + "$ref": 1, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-conditional-with-null.src.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 47, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "x": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "x", + "range": Array [ + 4, + 45, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 45, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 46, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "x", + "range": Array [ + 4, + 45, + ], + "type": "Identifier", + }, + ], + "name": "x", + "references": Array [], + "scope": Object { + "$ref": 1, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-indexed.src.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 13, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "x": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "x", + "range": Array [ + 4, + 11, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 11, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 12, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "x", + "range": Array [ + 4, + 11, + ], + "type": "Identifier", + }, + ], + "name": "x", + "references": Array [], + "scope": Object { + "$ref": 1, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-intersection-type.src.ts 1`] = ` +Object { + "$id": 0, + "block": Object { + "range": Array [ + 0, + 50, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 0, + }, + "variables": Array [], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-mapped.src.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 37, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "map": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "map", + "range": Array [ + 4, + 35, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 35, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 36, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "map", + "range": Array [ + 4, + 35, + ], + "type": "Identifier", + }, + ], + "name": "map", + "references": Array [], + "scope": Object { + "$ref": 1, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-mapped-readonly.src.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 47, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "map": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "map", + "range": Array [ + 4, + 45, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 45, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 46, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "map", + "range": Array [ + 4, + 45, + ], + "type": "Identifier", + }, + ], + "name": "map", + "references": Array [], + "scope": Object { + "$ref": 1, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-mapped-readonly-minus.src.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 48, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "map": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "map", + "range": Array [ + 4, + 46, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 46, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 47, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "map", + "range": Array [ + 4, + 46, + ], + "type": "Identifier", + }, + ], + "name": "map", + "references": Array [], + "scope": Object { + "$ref": 1, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-mapped-readonly-plus.src.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 49, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "map": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "map", + "range": Array [ + 4, + 47, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 47, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 48, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "map", + "range": Array [ + 4, + 47, + ], + "type": "Identifier", + }, + ], + "name": "map", + "references": Array [], + "scope": Object { + "$ref": 1, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-nested-types.src.ts 1`] = ` +Object { + "$id": 0, + "block": Object { + "range": Array [ + 0, + 81, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 0, + }, + "variables": Array [], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-parenthesized-type.src.ts 1`] = ` +Object { + "$id": 0, + "block": Object { + "range": Array [ + 0, + 29, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 0, + }, + "variables": Array [], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-reference.src.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 10, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "x": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "x", + "range": Array [ + 4, + 8, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 8, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 9, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "x", + "range": Array [ + 4, + 8, + ], + "type": "Identifier", + }, + ], + "name": "x", + "references": Array [], + "scope": Object { + "$ref": 1, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-reference-generic.src.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 22, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "x": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "x", + "range": Array [ + 4, + 20, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 20, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 21, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "x", + "range": Array [ + 4, + 20, + ], + "type": "Identifier", + }, + ], + "name": "x", + "references": Array [], + "scope": Object { + "$ref": 1, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-reference-generic-nested.src.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 29, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "x": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "x", + "range": Array [ + 4, + 27, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 27, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 28, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "x", + "range": Array [ + 4, + 27, + ], + "type": "Identifier", + }, + ], + "name": "x", + "references": Array [], + "scope": Object { + "$ref": 1, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-tuple.src.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 33, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "x": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "x", + "range": Array [ + 4, + 31, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 31, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 32, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "x", + "range": Array [ + 4, + 31, + ], + "type": "Identifier", + }, + ], + "name": "x", + "references": Array [], + "scope": Object { + "$ref": 1, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-tuple-empty.src.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 11, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "x": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "x", + "range": Array [ + 4, + 9, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 9, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 10, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "x", + "range": Array [ + 4, + 9, + ], + "type": "Identifier", + }, + ], + "name": "x", + "references": Array [], + "scope": Object { + "$ref": 1, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-tuple-optional.src.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 45, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "x": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "x", + "range": Array [ + 4, + 44, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 44, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 44, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "x", + "range": Array [ + 4, + 44, + ], + "type": "Identifier", + }, + ], + "name": "x", + "references": Array [], + "scope": Object { + "$ref": 1, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-tuple-rest.src.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 29, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "x": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "x", + "range": Array [ + 4, + 28, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 28, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 28, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "x", + "range": Array [ + 4, + 28, + ], + "type": "Identifier", + }, + ], + "name": "x", + "references": Array [], + "scope": Object { + "$ref": 1, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-tuple-type.src.ts 1`] = ` +Object { + "$id": 0, + "block": Object { + "range": Array [ + 0, + 29, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 0, + }, + "variables": Array [], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-type-literal.src.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 24, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "obj": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "obj", + "range": Array [ + 4, + 22, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 22, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 23, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "obj", + "range": Array [ + 4, + 22, + ], + "type": "Identifier", + }, + ], + "name": "obj", + "references": Array [], + "scope": Object { + "$ref": 1, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-type-operator.src.ts 1`] = ` +Object { + "$id": 2, + "block": Object { + "range": Array [ + 0, + 38, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "x": Object { + "$ref": 0, + }, + "y": Object { + "$ref": 1, + }, + }, + "variableScope": Object { + "$ref": 2, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "x", + "range": Array [ + 4, + 14, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 14, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 15, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "x", + "range": Array [ + 4, + 14, + ], + "type": "Identifier", + }, + ], + "name": "x", + "references": Array [], + "scope": Object { + "$ref": 2, + }, + }, + Object { + "$id": 1, + "defs": Array [ + Object { + "name": Object { + "name": "y", + "range": Array [ + 20, + 36, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 20, + 36, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 16, + 37, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "y", + "range": Array [ + 20, + 36, + ], + "type": "Identifier", + }, + ], + "name": "y", + "references": Array [], + "scope": Object { + "$ref": 2, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-typeof.src.ts 1`] = ` +Object { + "$id": 2, + "block": Object { + "range": Array [ + 0, + 19, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [ + Object { + "$id": 1, + "from": Object { + "$ref": 2, + }, + "identifier": Object { + "name": "y", + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + }, + "kind": "r", + "resolved": null, + "writeExpr": undefined, + }, + ], + "throughReferences": Array [ + Object { + "$ref": 1, + }, + ], + "type": "global", + "upperScope": null, + "variableMap": Object { + "x": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 2, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "x", + "range": Array [ + 4, + 17, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 17, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 18, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "x", + "range": Array [ + 4, + 17, + ], + "type": "Identifier", + }, + ], + "name": "x", + "references": Array [], + "scope": Object { + "$ref": 2, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-union-intersection.src.ts 1`] = ` +Object { + "$id": 4, + "block": Object { + "range": Array [ + 0, + 161, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "intersection": Object { + "$ref": 1, + }, + "precedence1": Object { + "$ref": 2, + }, + "precedence2": Object { + "$ref": 3, + }, + "union": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 4, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "union", + "range": Array [ + 4, + 36, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 4, + 36, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 0, + 37, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "union", + "range": Array [ + 4, + 36, + ], + "type": "Identifier", + }, + ], + "name": "union", + "references": Array [], + "scope": Object { + "$ref": 4, + }, + }, + Object { + "$id": 1, + "defs": Array [ + Object { + "name": Object { + "name": "intersection", + "range": Array [ + 42, + 71, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 42, + 71, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 38, + 72, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "intersection", + "range": Array [ + 42, + 71, + ], + "type": "Identifier", + }, + ], + "name": "intersection", + "references": Array [], + "scope": Object { + "$ref": 4, + }, + }, + Object { + "$id": 2, + "defs": Array [ + Object { + "name": Object { + "name": "precedence1", + "range": Array [ + 77, + 115, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 77, + 115, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 73, + 116, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "precedence1", + "range": Array [ + 77, + 115, + ], + "type": "Identifier", + }, + ], + "name": "precedence1", + "references": Array [], + "scope": Object { + "$ref": 4, + }, + }, + Object { + "$id": 3, + "defs": Array [ + Object { + "name": Object { + "name": "precedence2", + "range": Array [ + 121, + 159, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 121, + 159, + ], + "type": "VariableDeclarator", + }, + "parent": Object { + "range": Array [ + 117, + 160, + ], + "type": "VariableDeclaration", + }, + "type": "Variable", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "precedence2", + "range": Array [ + 121, + 159, + ], + "type": "Identifier", + }, + ], + "name": "precedence2", + "references": Array [], + "scope": Object { + "$ref": 4, + }, + }, + ], +} +`; + +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-union-type.src.ts 1`] = ` +Object { + "$id": 0, + "block": Object { + "range": Array [ + 0, + 27, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 0, + }, + "variables": Array [], +} +`; diff --git a/tests/lib/__snapshots__/typescript.js.snap b/tests/lib/__snapshots__/typescript.js.snap index 5703c0c..b9b3e3b 100644 --- a/tests/lib/__snapshots__/typescript.js.snap +++ b/tests/lib/__snapshots__/typescript.js.snap @@ -10448,29 +10448,12 @@ Object { "line": 1, }, }, + "members": Array [], "range": Array [ 33, 35, ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 35, - "line": 1, - }, - "start": Object { - "column": 33, - "line": 1, - }, - }, - "members": Array [], - "range": Array [ - 33, - 35, - ], - "type": "TSTypeLiteral", - }, + "type": "TSTypeLiteral", }, ], "range": Array [ @@ -21070,7 +21053,7 @@ Object { 9, 11, ], - "type": "ArrayPattern", + "type": "ArrayExpression", }, "type": "AssignmentPattern", }, diff --git a/visitor-keys.js b/visitor-keys.js index 1803e8a..5e3bad7 100644 --- a/visitor-keys.js +++ b/visitor-keys.js @@ -35,6 +35,7 @@ module.exports = Evk.unionWith({ TSAsyncKeyword: [], TSBooleanKeyword: [], TSCallSignature: ["typeParameters", "parameters", "typeAnnotation"], + TSConditionalType: ["checkType", "extendsType", "trueType", "falseType"], TSConstructSignature: ["typeParameters", "params", "typeAnnotation"], TSConstructorType: ["typeAnnotation", "parameters"], TSDeclareKeyword: [], @@ -48,12 +49,15 @@ module.exports = Evk.unionWith({ TSExternalModuleReference: ["expression"], TSImportType: ["parameter", "qualifier", "typeParameters"], TSLiteralType: ["literal"], + TSIntersectionType: ["types"], + TSIndexedAccessType: ["indexType", "objectType"], TSIndexSignature: ["typeAnnotation", "index"], TSInterfaceBody: ["body"], TSInterfaceDeclaration: ["id", "typeParameters", "heritage", "body"], TSInterfaceHeritage: ["id", "typeParameters"], TSImportEqualsDeclaration: ["name", "moduleReference"], TSFunctionType: ["parameters", "typeAnnotation"], + TSMappedType: ["typeParameter"], TSMethodSignature: ["typeAnnotation", "typeParameters", "key", "params"], TSModuleBlock: ["body"], TSModuleDeclaration: ["id", "body"], @@ -63,7 +67,9 @@ module.exports = Evk.unionWith({ TSNullKeyword: [], TSNumberKeyword: [], TSObjectKeyword: [], + TSOptionalType: ["typeAnnotation"], TSParameterProperty: ["parameter"], + TSParenthesizedType: ["typeAnnotation"], TSPrivateKeyword: [], TSPropertySignature: ["typeAnnotation", "key", "initializer"], TSProtectedKeyword: [], @@ -71,9 +77,11 @@ module.exports = Evk.unionWith({ TSQualifiedName: ["left", "right"], TSQuestionToken: [], TSReadonlyKeyword: [], + TSRestType: ["typeAnnotation"], TSStaticKeyword: [], TSStringKeyword: [], TSSymbolKeyword: [], + TSTupleType: ["elementTypes"], TSTypeAnnotation: ["typeAnnotation"], TSTypeAliasDeclaration: ["id", "typeParameters", "typeAnnotation"], TSTypeLiteral: ["members"], From 3b40d25b025126be4b9cd0c6a694e141ff7f2e60 Mon Sep 17 00:00:00 2001 From: Armano Date: Wed, 2 Jan 2019 00:56:21 +0100 Subject: [PATCH 10/18] Upgrade: typescript-estree to 9.0.0 and add new tests --- analyze-scope.js | 33 +++++++-- package.json | 2 +- .../fixtures/scope-analysis/expression-as.ts | 1 + tests/fixtures/scope-analysis/types-infer.ts | 5 ++ .../lib/__snapshots__/scope-analysis.js.snap | 72 +++++++++++++++++++ visitor-keys.js | 7 +- 6 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 tests/fixtures/scope-analysis/expression-as.ts create mode 100644 tests/fixtures/scope-analysis/types-infer.ts diff --git a/analyze-scope.js b/analyze-scope.js index 0248ba1..d66365c 100644 --- a/analyze-scope.js +++ b/analyze-scope.js @@ -355,6 +355,23 @@ class Referencer extends OriginalReferencer { } } + /** + * Visit as expression. + * @param {TSAsExpression} node The TSAsExpression node to visit. + * @returns {void} + */ + TSAsExpression(node) { + this.visit(node.expression); + + if (this.typeMode) { + this.visit(node.typeAnnotation); + } else { + this.typeMode = true; + this.visit(node.typeAnnotation); + this.typeMode = false; + } + } + /** * Switch to the type mode and visit child nodes to find `typeof x` expression in type declarations. * @param {TSTypeAnnotation} node The TSTypeAnnotation node to visit. @@ -400,6 +417,14 @@ class Referencer extends OriginalReferencer { } } + /** + * @param {TSInferType} node The TSInferType node to visit. + * @returns {void} + */ + TSInferType(node) { + this.visitTypeNodes(node); + } + /** * @param {TSTypeReference} node The TSTypeReference node to visit. * @returns {void} @@ -659,11 +684,11 @@ class Referencer extends OriginalReferencer { * @returns {void} */ TSImportEqualsDeclaration(node) { - const { name, moduleReference } = node; - if (name && name.type === "Identifier") { + const { id, moduleReference } = node; + if (id && id.type === "Identifier") { this.currentScope().__define( - name, - new Definition("ImportBinding", name, node, null, null, null) + id, + new Definition("ImportBinding", id, node, null, null, null) ); } this.visit(moduleReference); diff --git a/package.json b/package.json index c1f67f7..f8a95a0 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "dependencies": { "eslint-scope": "^4.0.0", "eslint-visitor-keys": "^1.0.0", - "typescript-estree": "8.1.0" + "typescript-estree": "9.0.0" }, "devDependencies": { "eslint": "^4.19.1", diff --git a/tests/fixtures/scope-analysis/expression-as.ts b/tests/fixtures/scope-analysis/expression-as.ts new file mode 100644 index 0000000..952b959 --- /dev/null +++ b/tests/fixtures/scope-analysis/expression-as.ts @@ -0,0 +1 @@ +(a as number as any) = 42; diff --git a/tests/fixtures/scope-analysis/types-infer.ts b/tests/fixtures/scope-analysis/types-infer.ts new file mode 100644 index 0000000..45ab5c0 --- /dev/null +++ b/tests/fixtures/scope-analysis/types-infer.ts @@ -0,0 +1,5 @@ +type Unpacked = + T extends (infer U)[] ? U : + T extends infer U ? U : + T extends Promise ? U : + T; diff --git a/tests/lib/__snapshots__/scope-analysis.js.snap b/tests/lib/__snapshots__/scope-analysis.js.snap index 8954a6f..825eb45 100644 --- a/tests/lib/__snapshots__/scope-analysis.js.snap +++ b/tests/lib/__snapshots__/scope-analysis.js.snap @@ -3396,6 +3396,53 @@ Object { } `; +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/expression-as.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 27, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [ + Object { + "$id": 0, + "from": Object { + "$ref": 1, + }, + "identifier": Object { + "name": "a", + "range": Array [ + 1, + 2, + ], + "type": "Identifier", + }, + "kind": "r", + "resolved": null, + "writeExpr": undefined, + }, + ], + "throughReferences": Array [ + Object { + "$ref": 0, + }, + ], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [], +} +`; + exports[`TypeScript scope analysis tests/fixtures/scope-analysis/expression-type-parameters.ts 1`] = ` Object { "$id": 14, @@ -7339,6 +7386,31 @@ Object { } `; +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-infer.ts 1`] = ` +Object { + "$id": 0, + "block": Object { + "range": Array [ + 0, + 147, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 0, + }, + "variables": Array [], +} +`; + exports[`TypeScript scope analysis tests/fixtures/scope-analysis/types-intersection-type.src.ts 1`] = ` Object { "$id": 0, diff --git a/visitor-keys.js b/visitor-keys.js index 5e3bad7..9243a80 100644 --- a/visitor-keys.js +++ b/visitor-keys.js @@ -32,7 +32,9 @@ module.exports = Evk.unionWith({ TSAbstractMethodDefinition: ["key", "value"], TSAnyKeyword: [], TSArrayType: ["elementType"], + TSAsExpression: ["expression", "typeAnnotation"], TSAsyncKeyword: [], + TSBigIntKeyword: [], TSBooleanKeyword: [], TSCallSignature: ["typeParameters", "parameters", "typeAnnotation"], TSConditionalType: ["checkType", "extendsType", "trueType", "falseType"], @@ -48,6 +50,7 @@ module.exports = Evk.unionWith({ TSExportKeyword: [], TSExternalModuleReference: ["expression"], TSImportType: ["parameter", "qualifier", "typeParameters"], + TSInferType: ["typeParameter"], TSLiteralType: ["literal"], TSIntersectionType: ["types"], TSIndexedAccessType: ["indexType", "objectType"], @@ -55,7 +58,7 @@ module.exports = Evk.unionWith({ TSInterfaceBody: ["body"], TSInterfaceDeclaration: ["id", "typeParameters", "heritage", "body"], TSInterfaceHeritage: ["id", "typeParameters"], - TSImportEqualsDeclaration: ["name", "moduleReference"], + TSImportEqualsDeclaration: ["id", "moduleReference"], TSFunctionType: ["parameters", "typeAnnotation"], TSMappedType: ["typeParameter"], TSMethodSignature: ["typeAnnotation", "typeParameters", "key", "params"], @@ -81,6 +84,7 @@ module.exports = Evk.unionWith({ TSStaticKeyword: [], TSStringKeyword: [], TSSymbolKeyword: [], + TSThisType: [], TSTupleType: ["elementTypes"], TSTypeAnnotation: ["typeAnnotation"], TSTypeAliasDeclaration: ["id", "typeParameters", "typeAnnotation"], @@ -94,5 +98,6 @@ module.exports = Evk.unionWith({ TSTypeQuery: ["exprName"], TSUnionType: ["types"], TSUndefinedKeyword: [], + TSUnknownKeyword: [], TSVoidKeyword: [] }); From 1b9195ac695c01903ef2ed85e71fdd449c0c0b40 Mon Sep 17 00:00:00 2001 From: Armano Date: Sat, 5 Jan 2019 04:41:42 +0100 Subject: [PATCH 11/18] Upgrade: typescript-estree to 12.0.0 and add new tests --- analyze-scope.js | 31 ++++++----- package.json | 2 +- .../scope-analysis/export-as-namespace.ts | 1 + .../lib/__snapshots__/scope-analysis.js.snap | 51 ++++++++++++++++++- tests/lib/__snapshots__/typescript.js.snap | 11 ++-- visitor-keys.js | 8 +-- 6 files changed, 76 insertions(+), 28 deletions(-) create mode 100644 tests/fixtures/scope-analysis/export-as-namespace.ts diff --git a/analyze-scope.js b/analyze-scope.js index d66365c..fb82921 100644 --- a/analyze-scope.js +++ b/analyze-scope.js @@ -346,13 +346,24 @@ class Referencer extends OriginalReferencer { * @returns {void} */ TSInterfaceDeclaration(node) { + this.visitTypeNodes(node); + } + + /** + * Visit type assertion. + * @param {TSTypeAssertion} node The TSTypeAssertion node to visit. + * @returns {void} + */ + TSTypeAssertion(node) { if (this.typeMode) { - this.visitChildren(node); + this.visit(node.typeAnnotation); } else { this.typeMode = true; - this.visitChildren(node); + this.visit(node.typeAnnotation); this.typeMode = false; } + + this.visit(node.expression); } /** @@ -378,13 +389,7 @@ class Referencer extends OriginalReferencer { * @returns {void} */ TSTypeAnnotation(node) { - if (this.typeMode) { - this.visitChildren(node); - } else { - this.typeMode = true; - this.visitChildren(node); - this.typeMode = false; - } + this.visitTypeNodes(node); } /** @@ -393,13 +398,7 @@ class Referencer extends OriginalReferencer { * @returns {void} */ TSTypeParameterDeclaration(node) { - if (this.typeMode) { - this.visitChildren(node); - } else { - this.typeMode = true; - this.visitChildren(node); - this.typeMode = false; - } + this.visitTypeNodes(node); } /** diff --git a/package.json b/package.json index f8a95a0..fb1e890 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "dependencies": { "eslint-scope": "^4.0.0", "eslint-visitor-keys": "^1.0.0", - "typescript-estree": "9.0.0" + "typescript-estree": "12.0.0" }, "devDependencies": { "eslint": "^4.19.1", diff --git a/tests/fixtures/scope-analysis/export-as-namespace.ts b/tests/fixtures/scope-analysis/export-as-namespace.ts new file mode 100644 index 0000000..ff8bbad --- /dev/null +++ b/tests/fixtures/scope-analysis/export-as-namespace.ts @@ -0,0 +1 @@ +export as namespace a; diff --git a/tests/lib/__snapshots__/scope-analysis.js.snap b/tests/lib/__snapshots__/scope-analysis.js.snap index 825eb45..0db4dd7 100644 --- a/tests/lib/__snapshots__/scope-analysis.js.snap +++ b/tests/lib/__snapshots__/scope-analysis.js.snap @@ -3396,6 +3396,53 @@ Object { } `; +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/export-as-namespace.ts 1`] = ` +Object { + "$id": 1, + "block": Object { + "range": Array [ + 0, + 23, + ], + "type": "Program", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [ + Object { + "$id": 0, + "from": Object { + "$ref": 1, + }, + "identifier": Object { + "name": "a", + "range": Array [ + 20, + 21, + ], + "type": "Identifier", + }, + "kind": "r", + "resolved": null, + "writeExpr": undefined, + }, + ], + "throughReferences": Array [ + Object { + "$ref": 0, + }, + ], + "type": "global", + "upperScope": null, + "variableMap": Object {}, + "variableScope": Object { + "$ref": 1, + }, + "variables": Array [], +} +`; + exports[`TypeScript scope analysis tests/fixtures/scope-analysis/expression-as.ts 1`] = ` Object { "$id": 1, @@ -5677,7 +5724,7 @@ Object { 21, 26, ], - "type": "TSTypeAssertionExpression", + "type": "TSTypeAssertion", }, }, Object { @@ -5949,7 +5996,7 @@ Object { 27, 40, ], - "type": "TSTypeAssertionExpression", + "type": "TSTypeAssertion", }, }, Object { diff --git a/tests/lib/__snapshots__/typescript.js.snap b/tests/lib/__snapshots__/typescript.js.snap index b9b3e3b..3f20999 100644 --- a/tests/lib/__snapshots__/typescript.js.snap +++ b/tests/lib/__snapshots__/typescript.js.snap @@ -31746,8 +31746,7 @@ Object { 245, 265, ], - "type": "TSConstructSignature", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { "column": 23, @@ -31781,6 +31780,7 @@ Object { "type": "TSStringKeyword", }, }, + "type": "TSConstructSignatureDeclaration", }, Object { "loc": Object { @@ -31836,8 +31836,7 @@ Object { 270, 293, ], - "type": "TSConstructSignature", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { "column": 26, @@ -31871,6 +31870,7 @@ Object { "type": "TSStringKeyword", }, }, + "type": "TSConstructSignatureDeclaration", "typeParameters": Object { "loc": Object { "end": Object { @@ -34095,8 +34095,7 @@ Object { 21, 47, ], - "type": "TSConstructSignature", - "typeAnnotation": null, + "type": "TSConstructSignatureDeclaration", }, ], "loc": Object { diff --git a/visitor-keys.js b/visitor-keys.js index 9243a80..b26eea3 100644 --- a/visitor-keys.js +++ b/visitor-keys.js @@ -36,9 +36,9 @@ module.exports = Evk.unionWith({ TSAsyncKeyword: [], TSBigIntKeyword: [], TSBooleanKeyword: [], - TSCallSignature: ["typeParameters", "parameters", "typeAnnotation"], + TSCallSignatureDeclaration: ["typeParameters", "params", "returnType"], TSConditionalType: ["checkType", "extendsType", "trueType", "falseType"], - TSConstructSignature: ["typeParameters", "params", "typeAnnotation"], + TSConstructSignatureDeclaration: ["typeParameters", "params", "returnType"], TSConstructorType: ["typeAnnotation", "parameters"], TSDeclareKeyword: [], TSEmptyBodyDeclareFunction: ["id", "typeParameters", "params", "returnType"], @@ -64,6 +64,7 @@ module.exports = Evk.unionWith({ TSMethodSignature: ["typeAnnotation", "typeParameters", "key", "params"], TSModuleBlock: ["body"], TSModuleDeclaration: ["id", "body"], + TSNamespaceExportDeclaration: ["id"], TSNamespaceFunctionDeclaration: [], TSNonNullExpression: ["expression"], TSNeverKeyword: [], @@ -86,8 +87,9 @@ module.exports = Evk.unionWith({ TSSymbolKeyword: [], TSThisType: [], TSTupleType: ["elementTypes"], - TSTypeAnnotation: ["typeAnnotation"], TSTypeAliasDeclaration: ["id", "typeParameters", "typeAnnotation"], + TSTypeAnnotation: ["typeAnnotation"], + TSTypeAssertion: ["typeAnnotation", "expression"], TSTypeLiteral: ["members"], TSTypeOperator: ["typeAnnotation"], TSTypeParameter: ["constraint", "default"], From 219135bae177bc6894764bfdb91abd7a7787400f Mon Sep 17 00:00:00 2001 From: Armano Date: Sun, 6 Jan 2019 19:41:22 +0100 Subject: [PATCH 12/18] Upgrade: typescript-estree to 13.5.1 --- analyze-scope.js | 10 ++--- package.json | 2 +- parser.js | 8 ---- tests/lib/__snapshots__/ecma-features.js.snap | 4 +- .../lib/__snapshots__/scope-analysis.js.snap | 4 +- tests/lib/__snapshots__/typescript.js.snap | 37 +++++++++---------- visitor-keys.js | 8 ++-- 7 files changed, 28 insertions(+), 45 deletions(-) diff --git a/analyze-scope.js b/analyze-scope.js index fb82921..aa2ccc5 100644 --- a/analyze-scope.js +++ b/analyze-scope.js @@ -120,7 +120,7 @@ class Referencer extends OriginalReferencer { const { defs, identifiers } = upperScope.set.get(id.name); for (let i = 0; i < defs.length; ++i) { const def = defs[i]; - if (def.type === "FunctionName" && def.node.type === "TSEmptyBodyFunctionDeclaration") { + if (def.type === "FunctionName" && def.node.type === "TSDeclareFunction") { defs.splice(i, 1); identifiers.splice(i, 1); break; @@ -292,10 +292,10 @@ class Referencer extends OriginalReferencer { /** * Define the variable of this function declaration only once. * Because to avoid confusion of `no-redeclare` rule by overloading. - * @param {TSEmptyBodyFunctionDeclaration} node The TSEmptyBodyFunctionDeclaration node to visit. + * @param {TSDeclareFunction} node The TSDeclareFunction node to visit. * @returns {void} */ - TSEmptyBodyFunctionDeclaration(node) { + TSDeclareFunction(node) { const upperTypeMode = this.typeMode; const scope = this.currentScope(); const { id, typeParameters, params, returnType } = node; @@ -319,10 +319,6 @@ class Referencer extends OriginalReferencer { this.typeMode = upperTypeMode; } - TSEmptyBodyDeclareFunction(node) { - this.TSEmptyBodyFunctionDeclaration(node); - } - /** * Create reference objects for the references in parameters and return type. * @param {TSEmptyBodyFunctionExpression} node The TSEmptyBodyFunctionExpression node to visit. diff --git a/package.json b/package.json index fb1e890..7315d3b 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "dependencies": { "eslint-scope": "^4.0.0", "eslint-visitor-keys": "^1.0.0", - "typescript-estree": "12.0.0" + "typescript-estree": "13.5.1" }, "devDependencies": { "eslint": "^4.19.1", diff --git a/parser.js b/parser.js index e59361c..9774d4c 100644 --- a/parser.js +++ b/parser.js @@ -41,16 +41,8 @@ exports.parseForESLint = function parseForESLint(code, options) { traverser.traverse(ast, { enter: node => { switch (node.type) { - // Just for backward compatibility. - case "TSDeclareFunction": - if (!node.body) { - node.type = "TSEmptyBodyDeclareFunction"; - } - break; - // Function#body cannot be null in ESTree spec. case "FunctionExpression": - case "FunctionDeclaration": if (!node.body) { node.type = `TSEmptyBody${node.type}`; } diff --git a/tests/lib/__snapshots__/ecma-features.js.snap b/tests/lib/__snapshots__/ecma-features.js.snap index 7ff6256..2f2fee9 100644 --- a/tests/lib/__snapshots__/ecma-features.js.snap +++ b/tests/lib/__snapshots__/ecma-features.js.snap @@ -102133,7 +102133,7 @@ Object { 0, 24, ], - "type": "TSEmptyBodyFunctionDeclaration", + "type": "TSDeclareFunction", }, ], "comments": Array [], @@ -102468,7 +102468,7 @@ Object { 0, 23, ], - "type": "TSEmptyBodyFunctionDeclaration", + "type": "TSDeclareFunction", }, ], "comments": Array [], diff --git a/tests/lib/__snapshots__/scope-analysis.js.snap b/tests/lib/__snapshots__/scope-analysis.js.snap index 0db4dd7..576f432 100644 --- a/tests/lib/__snapshots__/scope-analysis.js.snap +++ b/tests/lib/__snapshots__/scope-analysis.js.snap @@ -1689,7 +1689,7 @@ Object { 0, 37, ], - "type": "TSEmptyBodyDeclareFunction", + "type": "TSDeclareFunction", }, "parent": null, "type": "FunctionName", @@ -4188,7 +4188,7 @@ Object { 0, 18, ], - "type": "TSEmptyBodyFunctionDeclaration", + "type": "TSDeclareFunction", }, "parent": null, "type": "FunctionName", diff --git a/tests/lib/__snapshots__/typescript.js.snap b/tests/lib/__snapshots__/typescript.js.snap index 3f20999..682c025 100644 --- a/tests/lib/__snapshots__/typescript.js.snap +++ b/tests/lib/__snapshots__/typescript.js.snap @@ -10822,7 +10822,7 @@ Object { "line": 9, }, }, - "parameters": Array [ + "params": Array [ Object { "argument": Object { "loc": Object { @@ -10914,20 +10914,19 @@ Object { 180, 205, ], - "type": "TSConstructorType", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { "column": 47, "line": 9, }, "start": Object { - "column": 44, + "column": 43, "line": 9, }, }, "range": Array [ - 202, + 201, 205, ], "type": "TSTypeAnnotation", @@ -10967,7 +10966,7 @@ Object { }, }, }, - "typeParameters": null, + "type": "TSConstructorType", }, "typeParameters": Object { "loc": Object { @@ -20726,7 +20725,7 @@ Object { "type": "TSStringKeyword", }, }, - "type": "TSEmptyBodyDeclareFunction", + "type": "TSDeclareFunction", }, ], "comments": Array [], @@ -23686,7 +23685,7 @@ Object { "line": 1, }, }, - "parameters": Array [ + "params": Array [ Object { "loc": Object { "end": Object { @@ -23744,20 +23743,19 @@ Object { 27, 46, ], - "type": "TSFunctionType", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { "column": 46, "line": 1, }, "start": Object { - "column": 40, + "column": 39, "line": 1, }, }, "range": Array [ - 40, + 39, 46, ], "type": "TSTypeAnnotation", @@ -23779,7 +23777,7 @@ Object { "type": "TSVoidKeyword", }, }, - "typeParameters": null, + "type": "TSFunctionType", }, }, "loc": Object { @@ -43967,7 +43965,7 @@ Object { "line": 2, }, }, - "parameters": Array [ + "params": Array [ Object { "loc": Object { "end": Object { @@ -44095,20 +44093,19 @@ Object { 49, 79, ], - "type": "TSFunctionType", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { "column": 57, "line": 2, }, "start": Object { - "column": 51, + "column": 50, "line": 2, }, }, "range": Array [ - 73, + 72, 79, ], "type": "TSTypeAnnotation", @@ -44130,7 +44127,7 @@ Object { "type": "TSVoidKeyword", }, }, - "typeParameters": null, + "type": "TSFunctionType", }, }, }, @@ -66021,7 +66018,7 @@ Object { }, }, }, - "type": "TSEmptyBodyFunctionDeclaration", + "type": "TSDeclareFunction", }, "loc": Object { "end": Object { diff --git a/visitor-keys.js b/visitor-keys.js index b26eea3..3051858 100644 --- a/visitor-keys.js +++ b/visitor-keys.js @@ -39,10 +39,9 @@ module.exports = Evk.unionWith({ TSCallSignatureDeclaration: ["typeParameters", "params", "returnType"], TSConditionalType: ["checkType", "extendsType", "trueType", "falseType"], TSConstructSignatureDeclaration: ["typeParameters", "params", "returnType"], - TSConstructorType: ["typeAnnotation", "parameters"], + TSConstructorType: ["typeParameters", "params", "returnType"], + TSDeclareFunction: ["id", "typeParameters", "params", "returnType"], TSDeclareKeyword: [], - TSEmptyBodyDeclareFunction: ["id", "typeParameters", "params", "returnType"], - TSEmptyBodyFunctionDeclaration: ["id", "typeParameters", "params", "returnType"], TSEmptyBodyFunctionExpression: ["id", "typeParameters", "params", "returnType"], TSEnumDeclaration: ["members"], TSEnumMember: ["id", "initializer"], @@ -59,13 +58,12 @@ module.exports = Evk.unionWith({ TSInterfaceDeclaration: ["id", "typeParameters", "heritage", "body"], TSInterfaceHeritage: ["id", "typeParameters"], TSImportEqualsDeclaration: ["id", "moduleReference"], - TSFunctionType: ["parameters", "typeAnnotation"], + TSFunctionType: ["typeParameters", "params", "returnType"], TSMappedType: ["typeParameter"], TSMethodSignature: ["typeAnnotation", "typeParameters", "key", "params"], TSModuleBlock: ["body"], TSModuleDeclaration: ["id", "body"], TSNamespaceExportDeclaration: ["id"], - TSNamespaceFunctionDeclaration: [], TSNonNullExpression: ["expression"], TSNeverKeyword: [], TSNullKeyword: [], From 08f5a74d85c4314ed9039e2afcce54963187bfca Mon Sep 17 00:00:00 2001 From: Armano Date: Tue, 8 Jan 2019 02:46:17 +0100 Subject: [PATCH 13/18] Fix: fix issue with exporting anonymous without name --- analyze-scope.js | 20 +- .../export-default-anonymous-function.src.ts | 3 + tests/lib/__snapshots__/typescript.js.snap | 389 ++++++++++++++++++ 3 files changed, 403 insertions(+), 9 deletions(-) create mode 100644 tests/fixtures/typescript/basics/export-default-anonymous-function.src.ts diff --git a/analyze-scope.js b/analyze-scope.js index aa2ccc5..3dd78ae 100644 --- a/analyze-scope.js +++ b/analyze-scope.js @@ -241,7 +241,7 @@ class Referencer extends OriginalReferencer { /** * Don't create the reference object for the key if not computed. - * @param {TSEmptyBodyFunctionDeclaration} node The TSEmptyBodyFunctionDeclaration node to visit. + * @param {ClassProperty} node The ClassProperty node to visit. * @returns {void} */ ClassProperty(node) { @@ -301,14 +301,16 @@ class Referencer extends OriginalReferencer { const { id, typeParameters, params, returnType } = node; // Ignore this if other overloadings have already existed. - const variable = scope.set.get(id.name); - const defs = variable && variable.defs; - const existed = defs && defs.some(d => d.type === "FunctionName"); - if (!existed) { - scope.__define( - id, - new Definition("FunctionName", id, node, null, null, null) - ); + if (id) { + const variable = scope.set.get(id.name); + const defs = variable && variable.defs; + const existed = defs && defs.some(d => d.type === "FunctionName"); + if (!existed) { + scope.__define( + id, + new Definition("FunctionName", id, node, null, null, null) + ); + } } // Find `typeof` expressions. diff --git a/tests/fixtures/typescript/basics/export-default-anonymous-function.src.ts b/tests/fixtures/typescript/basics/export-default-anonymous-function.src.ts new file mode 100644 index 0000000..70b8a55 --- /dev/null +++ b/tests/fixtures/typescript/basics/export-default-anonymous-function.src.ts @@ -0,0 +1,3 @@ +declare module "foo" { + export default function (): string; +} diff --git a/tests/lib/__snapshots__/typescript.js.snap b/tests/lib/__snapshots__/typescript.js.snap index 682c025..1c950e3 100644 --- a/tests/lib/__snapshots__/typescript.js.snap +++ b/tests/lib/__snapshots__/typescript.js.snap @@ -21469,6 +21469,395 @@ Object { } `; +exports[`typescript fixtures/basics/export-default-anonymous-function.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "declaration": Object { + "async": false, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 39, + "line": 2, + }, + "start": Object { + "column": 19, + "line": 2, + }, + }, + "params": Array [], + "range": Array [ + 42, + 62, + ], + "returnType": Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 30, + "line": 2, + }, + }, + "range": Array [ + 53, + 61, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 32, + "line": 2, + }, + }, + "range": Array [ + 55, + 61, + ], + "type": "TSStringKeyword", + }, + }, + "type": "TSDeclareFunction", + }, + "loc": Object { + "end": Object { + "column": 39, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 27, + 62, + ], + "type": "ExportDefaultDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 64, + ], + "type": "TSModuleBlock", + }, + "declare": true, + "id": Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 20, + ], + "raw": "\\"foo\\"", + "type": "Literal", + "value": "foo", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 64, + ], + "type": "TSModuleDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 65, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 7, + ], + "type": "Identifier", + "value": "declare", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "range": Array [ + 8, + 14, + ], + "type": "Identifier", + "value": "module", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 20, + ], + "type": "String", + "value": "\\"foo\\"", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 22, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 27, + 33, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "range": Array [ + 34, + 41, + ], + "type": "Keyword", + "value": "default", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 19, + "line": 2, + }, + }, + "range": Array [ + 42, + 50, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 2, + }, + "start": Object { + "column": 28, + "line": 2, + }, + }, + "range": Array [ + 51, + 52, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 30, + "line": 2, + }, + "start": Object { + "column": 29, + "line": 2, + }, + }, + "range": Array [ + 52, + 53, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 31, + "line": 2, + }, + "start": Object { + "column": 30, + "line": 2, + }, + }, + "range": Array [ + 53, + 54, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 32, + "line": 2, + }, + }, + "range": Array [ + 55, + 61, + ], + "type": "Identifier", + "value": "string", + }, + Object { + "loc": Object { + "end": Object { + "column": 39, + "line": 2, + }, + "start": Object { + "column": 38, + "line": 2, + }, + }, + "range": Array [ + 61, + 62, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 63, + 64, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + exports[`typescript fixtures/basics/export-default-class-with-generic.src 1`] = ` Object { "body": Array [ From c689e487f86eb3a6fd6c886b9add68c5e24a2dd5 Mon Sep 17 00:00:00 2001 From: Armano Date: Tue, 8 Jan 2019 02:59:17 +0100 Subject: [PATCH 14/18] Upgrade: typescript-estree to 13.5.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7315d3b..ca2ef07 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "dependencies": { "eslint-scope": "^4.0.0", "eslint-visitor-keys": "^1.0.0", - "typescript-estree": "13.5.1" + "typescript-estree": "13.5.2" }, "devDependencies": { "eslint": "^4.19.1", From bcf54f798894945493dab38f2ca7a1e30cc89f96 Mon Sep 17 00:00:00 2001 From: Armano Date: Fri, 11 Jan 2019 00:55:52 +0100 Subject: [PATCH 15/18] Upgrade: typescript-estree to 14.0.0 --- analyze-scope.js | 15 + package.json | 2 +- tests/fixtures/scope-analysis/rest-element.ts | 1 + .../fixtures/scope-analysis/type-parameter.ts | 1 + .../lib/__snapshots__/scope-analysis.js.snap | 265 ++++++ tests/lib/__snapshots__/typescript.js.snap | 824 ++++++++++++++---- visitor-keys.js | 3 +- 7 files changed, 952 insertions(+), 159 deletions(-) create mode 100644 tests/fixtures/scope-analysis/rest-element.ts create mode 100644 tests/fixtures/scope-analysis/type-parameter.ts diff --git a/analyze-scope.js b/analyze-scope.js index 3dd78ae..774b38d 100644 --- a/analyze-scope.js +++ b/analyze-scope.js @@ -65,6 +65,13 @@ class PatternVisitor extends OriginalPatternVisitor { this.rightHandNodes.push(node.typeAnnotation); } } + + RestElement(node) { + super.RestElement(node); + if (node.typeAnnotation) { + this.rightHandNodes.push(node.typeAnnotation); + } + } } class Referencer extends OriginalReferencer { @@ -414,6 +421,14 @@ class Referencer extends OriginalReferencer { } } + /** + * @param {TSTypeParameter} node The TSTypeParameter node to visit. + * @returns {void} + */ + TSTypeParameter(node) { + this.visitTypeNodes(node); + } + /** * @param {TSInferType} node The TSInferType node to visit. * @returns {void} diff --git a/package.json b/package.json index ca2ef07..e9d1072 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "dependencies": { "eslint-scope": "^4.0.0", "eslint-visitor-keys": "^1.0.0", - "typescript-estree": "13.5.2" + "typescript-estree": "14.0.0" }, "devDependencies": { "eslint": "^4.19.1", diff --git a/tests/fixtures/scope-analysis/rest-element.ts b/tests/fixtures/scope-analysis/rest-element.ts new file mode 100644 index 0000000..6f14540 --- /dev/null +++ b/tests/fixtures/scope-analysis/rest-element.ts @@ -0,0 +1 @@ +function foo(...args: string[]) {} diff --git a/tests/fixtures/scope-analysis/type-parameter.ts b/tests/fixtures/scope-analysis/type-parameter.ts new file mode 100644 index 0000000..f5f233e --- /dev/null +++ b/tests/fixtures/scope-analysis/type-parameter.ts @@ -0,0 +1 @@ +function f() {} diff --git a/tests/lib/__snapshots__/scope-analysis.js.snap b/tests/lib/__snapshots__/scope-analysis.js.snap index 576f432..bf51b47 100644 --- a/tests/lib/__snapshots__/scope-analysis.js.snap +++ b/tests/lib/__snapshots__/scope-analysis.js.snap @@ -5392,6 +5392,160 @@ Object { } `; +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/rest-element.ts 1`] = ` +Object { + "$id": 4, + "block": Object { + "range": Array [ + 0, + 36, + ], + "type": "Program", + }, + "childScopes": Array [ + Object { + "$id": 3, + "block": Object { + "range": Array [ + 0, + 34, + ], + "type": "FunctionDeclaration", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "function", + "upperScope": Object { + "$ref": 4, + }, + "variableMap": Object { + "args": Object { + "$ref": 2, + }, + "arguments": Object { + "$ref": 1, + }, + }, + "variableScope": Object { + "$ref": 3, + }, + "variables": Array [ + Object { + "$id": 1, + "defs": Array [], + "eslintUsed": undefined, + "identifiers": Array [], + "name": "arguments", + "references": Array [], + "scope": Object { + "$ref": 3, + }, + }, + Object { + "$id": 2, + "defs": Array [ + Object { + "name": Object { + "name": "args", + "range": Array [ + 16, + 20, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 0, + 34, + ], + "type": "FunctionDeclaration", + }, + "parent": null, + "type": "Parameter", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "args", + "range": Array [ + 16, + 20, + ], + "type": "Identifier", + }, + ], + "name": "args", + "references": Array [], + "scope": Object { + "$ref": 3, + }, + }, + ], + }, + ], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "foo": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 4, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "foo", + "range": Array [ + 9, + 12, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 0, + 34, + ], + "type": "FunctionDeclaration", + }, + "parent": null, + "type": "FunctionName", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "foo", + "range": Array [ + 9, + 12, + ], + "type": "Identifier", + }, + ], + "name": "foo", + "references": Array [], + "scope": Object { + "$ref": 4, + }, + }, + ], +} +`; + exports[`TypeScript scope analysis tests/fixtures/scope-analysis/type-alias.ts 1`] = ` Object { "$id": 0, @@ -5809,6 +5963,117 @@ Object { } `; +exports[`TypeScript scope analysis tests/fixtures/scope-analysis/type-parameter.ts 1`] = ` +Object { + "$id": 3, + "block": Object { + "range": Array [ + 0, + 20, + ], + "type": "Program", + }, + "childScopes": Array [ + Object { + "$id": 2, + "block": Object { + "range": Array [ + 0, + 18, + ], + "type": "FunctionDeclaration", + }, + "childScopes": Array [], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "function", + "upperScope": Object { + "$ref": 3, + }, + "variableMap": Object { + "arguments": Object { + "$ref": 1, + }, + }, + "variableScope": Object { + "$ref": 2, + }, + "variables": Array [ + Object { + "$id": 1, + "defs": Array [], + "eslintUsed": undefined, + "identifiers": Array [], + "name": "arguments", + "references": Array [], + "scope": Object { + "$ref": 2, + }, + }, + ], + }, + ], + "functionExpressionScope": false, + "isStrict": false, + "references": Array [], + "throughReferences": Array [], + "type": "global", + "upperScope": null, + "variableMap": Object { + "f": Object { + "$ref": 0, + }, + }, + "variableScope": Object { + "$ref": 3, + }, + "variables": Array [ + Object { + "$id": 0, + "defs": Array [ + Object { + "name": Object { + "name": "f", + "range": Array [ + 9, + 10, + ], + "type": "Identifier", + }, + "node": Object { + "range": Array [ + 0, + 18, + ], + "type": "FunctionDeclaration", + }, + "parent": null, + "type": "FunctionName", + }, + ], + "eslintUsed": undefined, + "identifiers": Array [ + Object { + "name": "f", + "range": Array [ + 9, + 10, + ], + "type": "Identifier", + }, + ], + "name": "f", + "references": Array [], + "scope": Object { + "$ref": 3, + }, + }, + ], +} +`; + exports[`TypeScript scope analysis tests/fixtures/scope-analysis/typeof.ts 1`] = ` Object { "$id": 3, diff --git a/tests/lib/__snapshots__/typescript.js.snap b/tests/lib/__snapshots__/typescript.js.snap index 1c950e3..e8833dc 100644 --- a/tests/lib/__snapshots__/typescript.js.snap +++ b/tests/lib/__snapshots__/typescript.js.snap @@ -82,7 +82,24 @@ Object { "line": 1, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 13, + 14, + ], + "type": "Identifier", + }, "range": Array [ 13, 14, @@ -398,7 +415,24 @@ Object { "line": 1, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 11, + 12, + ], + "type": "Identifier", + }, "range": Array [ 11, 36, @@ -3301,7 +3335,24 @@ Object { "line": 1, }, }, - "name": "X", + "name": Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "name": "X", + "range": Array [ + 1, + 2, + ], + "type": "Identifier", + }, "range": Array [ 1, 2, @@ -7241,7 +7292,24 @@ Object { "line": 1, }, }, - "name": "A", + "name": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "name": "A", + "range": Array [ + 10, + 11, + ], + "type": "Identifier", + }, "range": Array [ 10, 11, @@ -7715,7 +7783,24 @@ Object { "line": 1, }, }, - "name": "A", + "name": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "name": "A", + "range": Array [ + 10, + 11, + ], + "type": "Identifier", + }, "range": Array [ 10, 21, @@ -8146,7 +8231,24 @@ Object { "line": 2, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "name": "T", + "range": Array [ + 21, + 22, + ], + "type": "Identifier", + }, "range": Array [ 21, 22, @@ -8593,7 +8695,24 @@ Object { "line": 2, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "name": "T", + "range": Array [ + 21, + 22, + ], + "type": "Identifier", + }, "range": Array [ 21, 28, @@ -10473,7 +10592,24 @@ Object { "line": 1, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 11, + 12, + ], + "type": "Identifier", + }, "range": Array [ 11, 36, @@ -10827,7 +10963,7 @@ Object { "argument": Object { "loc": Object { "end": Object { - "column": 41, + "column": 34, "line": 9, }, "start": Object { @@ -10838,60 +10974,9 @@ Object { "name": "args", "range": Array [ 188, - 199, + 192, ], "type": "Identifier", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 41, - "line": 9, - }, - "start": Object { - "column": 34, - "line": 9, - }, - }, - "range": Array [ - 192, - 199, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "elementType": Object { - "loc": Object { - "end": Object { - "column": 39, - "line": 9, - }, - "start": Object { - "column": 36, - "line": 9, - }, - }, - "range": Array [ - 194, - 197, - ], - "type": "TSAnyKeyword", - }, - "loc": Object { - "end": Object { - "column": 41, - "line": 9, - }, - "start": Object { - "column": 36, - "line": 9, - }, - }, - "range": Array [ - 194, - 199, - ], - "type": "TSArrayType", - }, - }, }, "loc": Object { "end": Object { @@ -10908,6 +10993,57 @@ Object { 199, ], "type": "RestElement", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 41, + "line": 9, + }, + "start": Object { + "column": 34, + "line": 9, + }, + }, + "range": Array [ + 192, + 199, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "elementType": Object { + "loc": Object { + "end": Object { + "column": 39, + "line": 9, + }, + "start": Object { + "column": 36, + "line": 9, + }, + }, + "range": Array [ + 194, + 197, + ], + "type": "TSAnyKeyword", + }, + "loc": Object { + "end": Object { + "column": 41, + "line": 9, + }, + "start": Object { + "column": 36, + "line": 9, + }, + }, + "range": Array [ + 194, + 199, + ], + "type": "TSArrayType", + }, + }, }, ], "range": Array [ @@ -10991,7 +11127,24 @@ Object { "line": 9, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 9, + }, + "start": Object { + "column": 17, + "line": 9, + }, + }, + "name": "T", + "range": Array [ + 175, + 176, + ], + "type": "Identifier", + }, "range": Array [ 175, 176, @@ -19149,7 +19302,24 @@ Object { "line": 1, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 10, + 11, + ], + "type": "Identifier", + }, "range": Array [ 10, 11, @@ -19427,7 +19597,24 @@ Object { "line": 1, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 10, + 11, + ], + "type": "Identifier", + }, "range": Array [ 10, 17, @@ -19706,7 +19893,24 @@ Object { "line": 1, }, }, - "name": "__P", + "name": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "name": "__P", + "range": Array [ + 8, + 11, + ], + "type": "Identifier", + }, "range": Array [ 8, 11, @@ -21921,7 +22125,24 @@ Object { "line": 1, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 21, + 22, + ], + "type": "Identifier", + }, "range": Array [ 21, 22, @@ -22182,7 +22403,24 @@ Object { "line": 1, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 21, + 22, + ], + "type": "Identifier", + }, "range": Array [ 21, 22, @@ -22200,7 +22438,24 @@ Object { "line": 1, }, }, - "name": "U", + "name": Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 1, + }, + "start": Object { + "column": 24, + "line": 1, + }, + }, + "name": "U", + "range": Array [ + 24, + 25, + ], + "type": "Identifier", + }, "range": Array [ 24, 25, @@ -22514,7 +22769,24 @@ Object { "line": 1, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 17, + 18, + ], + "type": "Identifier", + }, "range": Array [ 17, 18, @@ -22794,7 +23066,24 @@ Object { "line": 1, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 17, + 18, + ], + "type": "Identifier", + }, "range": Array [ 17, 18, @@ -22812,7 +23101,24 @@ Object { "line": 1, }, }, - "name": "U", + "name": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "name": "U", + "range": Array [ + 20, + 21, + ], + "type": "Identifier", + }, "range": Array [ 20, 21, @@ -26460,7 +26766,24 @@ Object { "line": 1, }, }, - "name": "X", + "name": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "name": "X", + "range": Array [ + 11, + 12, + ], + "type": "Identifier", + }, "range": Array [ 11, 12, @@ -26886,7 +27209,24 @@ Object { "line": 1, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 1, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 28, + 29, + ], + "type": "Identifier", + }, "range": Array [ 28, 29, @@ -27364,7 +27704,24 @@ Object { "line": 1, }, }, - "name": "X", + "name": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "name": "X", + "range": Array [ + 11, + 12, + ], + "type": "Identifier", + }, "range": Array [ 11, 23, @@ -28454,7 +28811,7 @@ Object { "argument": Object { "loc": Object { "end": Object { - "column": 69, + "column": 55, "line": 1, }, "start": Object { @@ -28465,9 +28822,41 @@ Object { "name": "args", "range": Array [ 51, - 69, + 55, ], "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 69, + "line": 1, + }, + "start": Object { + "column": 48, + "line": 1, + }, + }, + "range": Array [ + 48, + 69, + ], + "type": "RestElement", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 69, + "line": 1, + }, + "start": Object { + "column": 55, + "line": 1, + }, + }, + "range": Array [ + 55, + 69, + ], + "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { @@ -28475,19 +28864,19 @@ Object { "line": 1, }, "start": Object { - "column": 55, + "column": 56, "line": 1, }, }, "range": Array [ - 55, + 56, 69, ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { + "type": "TSTypeReference", + "typeName": Object { "loc": Object { "end": Object { - "column": 69, + "column": 61, "line": 1, }, "start": Object { @@ -28495,83 +28884,51 @@ Object { "line": 1, }, }, + "name": "Array", "range": Array [ 56, - 69, + 61, ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 61, - "line": 1, - }, - "start": Object { - "column": 56, - "line": 1, - }, + "type": "Identifier", + }, + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 69, + "line": 1, }, - "name": "Array", - "range": Array [ - 56, - 61, - ], - "type": "Identifier", - }, - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 69, - "line": 1, - }, - "start": Object { - "column": 61, - "line": 1, - }, + "start": Object { + "column": 61, + "line": 1, }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 68, - "line": 1, - }, - "start": Object { - "column": 62, - "line": 1, - }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 68, + "line": 1, + }, + "start": Object { + "column": 62, + "line": 1, }, - "range": Array [ - 62, - 68, - ], - "type": "TSStringKeyword", }, - ], - "range": Array [ - 61, - 69, - ], - "type": "TSTypeParameterInstantiation", - }, + "range": Array [ + 62, + 68, + ], + "type": "TSStringKeyword", + }, + ], + "range": Array [ + 61, + 69, + ], + "type": "TSTypeParameterInstantiation", }, }, }, - "loc": Object { - "end": Object { - "column": 69, - "line": 1, - }, - "start": Object { - "column": 48, - "line": 1, - }, - }, - "range": Array [ - 48, - 69, - ], - "type": "RestElement", }, ], "range": Array [ @@ -30924,7 +31281,24 @@ Object { "line": 1, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + }, "range": Array [ 14, 15, @@ -32064,7 +32438,24 @@ Object { "line": 11, }, }, - "name": "J", + "name": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 11, + }, + "start": Object { + "column": 8, + "line": 11, + }, + }, + "name": "J", + "range": Array [ + 222, + 223, + ], + "type": "Identifier", + }, "range": Array [ 222, 223, @@ -32281,7 +32672,24 @@ Object { "line": 13, }, }, - "name": "F", + "name": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 13, + }, + "start": Object { + "column": 9, + "line": 13, + }, + }, + "name": "F", + "range": Array [ + 275, + 276, + ], + "type": "Identifier", + }, "range": Array [ 275, 276, @@ -34962,7 +35370,24 @@ Object { "line": 1, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + }, "range": Array [ 14, 15, @@ -35295,7 +35720,24 @@ Object { "line": 1, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 15, + 16, + ], + "type": "Identifier", + }, "range": Array [ 15, 16, @@ -41021,7 +41463,24 @@ Object { "line": 1, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 12, + 13, + ], + "type": "Identifier", + }, "range": Array [ 12, 13, @@ -41496,7 +41955,24 @@ Object { "line": 1, }, }, - "name": "T", + "name": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 12, + 13, + ], + "type": "Identifier", + }, "range": Array [ 12, 24, @@ -43015,7 +43491,24 @@ Object { "line": 2, }, }, - "name": "A", + "name": Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 2, + }, + "start": Object { + "column": 24, + "line": 2, + }, + }, + "name": "A", + "range": Array [ + 68, + 69, + ], + "type": "Identifier", + }, "range": Array [ 68, 69, @@ -43144,7 +43637,24 @@ Object { "line": 3, }, }, - "name": "A", + "name": Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 3, + }, + "start": Object { + "column": 24, + "line": 3, + }, + }, + "name": "A", + "range": Array [ + 112, + 113, + ], + "type": "Identifier", + }, "range": Array [ 112, 129, diff --git a/visitor-keys.js b/visitor-keys.js index 3051858..38f03a2 100644 --- a/visitor-keys.js +++ b/visitor-keys.js @@ -19,6 +19,7 @@ module.exports = Evk.unionWith({ Identifier: ["decorators", "typeAnnotation"], MethodDefinition: ["decorators", "key", "value"], ObjectPattern: ["properties", "typeAnnotation"], + RestElement: ["argument", "typeAnnotation"], NewExpression: ["callee", "typeParameters", "arguments"], CallExpression: ["callee", "typeParameters", "arguments"], @@ -90,7 +91,7 @@ module.exports = Evk.unionWith({ TSTypeAssertion: ["typeAnnotation", "expression"], TSTypeLiteral: ["members"], TSTypeOperator: ["typeAnnotation"], - TSTypeParameter: ["constraint", "default"], + TSTypeParameter: ["name", "constraint", "default"], TSTypeParameterDeclaration: ["params"], TSTypeParameterInstantiation: ["params"], TSTypePredicate: ["typeAnnotation", "parameterName"], From 71b3de6dbac51bb81ffc83bd09fb2c71b3b8c11e Mon Sep 17 00:00:00 2001 From: Armano Date: Fri, 11 Jan 2019 01:00:58 +0100 Subject: [PATCH 16/18] Upgrade: typescript-estree to 15.0.0 --- analyze-scope.js | 4 +- package.json | 2 +- tests/lib/__snapshots__/typescript.js.snap | 70 +++++++--------------- visitor-keys.js | 2 +- 4 files changed, 27 insertions(+), 51 deletions(-) diff --git a/analyze-scope.js b/analyze-scope.js index 774b38d..b75a746 100644 --- a/analyze-scope.js +++ b/analyze-scope.js @@ -564,7 +564,7 @@ class Referencer extends OriginalReferencer { */ TSMethodSignature(node) { const upperTypeMode = this.typeMode; - const { computed, key, typeParameters, params, typeAnnotation } = node; + const { computed, key, typeParameters, params, returnType } = node; if (computed) { this.typeMode = false; @@ -576,7 +576,7 @@ class Referencer extends OriginalReferencer { } this.visit(typeParameters); params.forEach(this.visit, this); - this.visit(typeAnnotation); // Maybe returnType? + this.visit(returnType); this.typeMode = upperTypeMode; } diff --git a/package.json b/package.json index e9d1072..12db75e 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "dependencies": { "eslint-scope": "^4.0.0", "eslint-visitor-keys": "^1.0.0", - "typescript-estree": "14.0.0" + "typescript-estree": "15.0.0" }, "devDependencies": { "eslint": "^4.19.1", diff --git a/tests/lib/__snapshots__/typescript.js.snap b/tests/lib/__snapshots__/typescript.js.snap index e8833dc..25acd61 100644 --- a/tests/lib/__snapshots__/typescript.js.snap +++ b/tests/lib/__snapshots__/typescript.js.snap @@ -31989,15 +31989,12 @@ Object { "line": 8, }, }, - "optional": false, "params": Array [], "range": Array [ 149, 161, ], - "static": false, - "type": "TSMethodSignature", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { "column": 15, @@ -32031,6 +32028,7 @@ Object { "type": "TSVoidKeyword", }, }, + "type": "TSMethodSignature", }, Object { "computed": false, @@ -32123,9 +32121,7 @@ Object { 166, 186, ], - "static": false, - "type": "TSMethodSignature", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { "column": 23, @@ -32159,6 +32155,7 @@ Object { "type": "TSVoidKeyword", }, }, + "type": "TSMethodSignature", }, Object { "computed": true, @@ -32251,9 +32248,7 @@ Object { 191, 213, ], - "static": false, - "type": "TSMethodSignature", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { "column": 25, @@ -32287,6 +32282,7 @@ Object { "type": "TSVoidKeyword", }, }, + "type": "TSMethodSignature", }, Object { "computed": false, @@ -32318,7 +32314,6 @@ Object { "line": 11, }, }, - "optional": false, "params": Array [ Object { "loc": Object { @@ -32379,9 +32374,7 @@ Object { 218, 240, ], - "static": false, - "type": "TSMethodSignature", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { "column": 25, @@ -32415,6 +32408,7 @@ Object { "type": "TSVoidKeyword", }, }, + "type": "TSMethodSignature", "typeParameters": Object { "loc": Object { "end": Object { @@ -35937,7 +35931,6 @@ Object { "line": 6, }, }, - "optional": false, "params": Array [ Object { "loc": Object { @@ -35962,9 +35955,7 @@ Object { 76, 85, ], - "static": false, "type": "TSMethodSignature", - "typeAnnotation": null, }, ], "loc": Object { @@ -36466,9 +36457,7 @@ Object { 49, 79, ], - "static": false, "type": "TSMethodSignature", - "typeAnnotation": null, }, ], "loc": Object { @@ -44818,7 +44807,6 @@ Object { "line": 2, }, }, - "optional": false, "params": Array [ Object { "loc": Object { @@ -45035,9 +45023,7 @@ Object { 23, 87, ], - "static": false, - "type": "TSMethodSignature", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { "column": 64, @@ -45071,6 +45057,7 @@ Object { "type": "TSVoidKeyword", }, }, + "type": "TSMethodSignature", }, ], "loc": Object { @@ -61695,7 +61682,6 @@ Object { "line": 17, }, }, - "optional": false, "params": Array [ Object { "loc": Object { @@ -61754,9 +61740,7 @@ Object { 393, 421, ], - "static": false, - "type": "TSMethodSignature", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { "column": 31, @@ -61790,6 +61774,7 @@ Object { "type": "TSVoidKeyword", }, }, + "type": "TSMethodSignature", }, Object { "accessibility": "private", @@ -61822,7 +61807,6 @@ Object { "line": 18, }, }, - "optional": false, "params": Array [ Object { "loc": Object { @@ -61881,9 +61865,7 @@ Object { 426, 455, ], - "static": false, - "type": "TSMethodSignature", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { "column": 32, @@ -61917,6 +61899,7 @@ Object { "type": "TSVoidKeyword", }, }, + "type": "TSMethodSignature", }, Object { "accessibility": "protected", @@ -61949,7 +61932,6 @@ Object { "line": 19, }, }, - "optional": false, "params": Array [ Object { "loc": Object { @@ -62008,9 +61990,7 @@ Object { 460, 491, ], - "static": false, - "type": "TSMethodSignature", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { "column": 34, @@ -62044,6 +62024,7 @@ Object { "type": "TSVoidKeyword", }, }, + "type": "TSMethodSignature", }, Object { "computed": false, @@ -62075,7 +62056,6 @@ Object { "line": 20, }, }, - "optional": false, "params": Array [ Object { "loc": Object { @@ -62134,9 +62114,7 @@ Object { 496, 524, ], - "static": true, - "type": "TSMethodSignature", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { "column": 31, @@ -62170,6 +62148,8 @@ Object { "type": "TSVoidKeyword", }, }, + "static": true, + "type": "TSMethodSignature", }, Object { "computed": false, @@ -62202,7 +62182,6 @@ Object { "line": 21, }, }, - "optional": false, "params": Array [ Object { "loc": Object { @@ -62261,9 +62240,7 @@ Object { 529, 557, ], - "static": false, - "type": "TSMethodSignature", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { "column": 31, @@ -62297,6 +62274,7 @@ Object { "type": "TSVoidKeyword", }, }, + "type": "TSMethodSignature", }, Object { "computed": false, @@ -62328,7 +62306,6 @@ Object { "line": 22, }, }, - "optional": false, "params": Array [ Object { "loc": Object { @@ -62388,9 +62365,7 @@ Object { 592, ], "readonly": true, - "static": false, - "type": "TSMethodSignature", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { "column": 33, @@ -62424,6 +62399,7 @@ Object { "type": "TSVoidKeyword", }, }, + "type": "TSMethodSignature", }, ], "loc": Object { diff --git a/visitor-keys.js b/visitor-keys.js index 38f03a2..3ba3af7 100644 --- a/visitor-keys.js +++ b/visitor-keys.js @@ -61,7 +61,7 @@ module.exports = Evk.unionWith({ TSImportEqualsDeclaration: ["id", "moduleReference"], TSFunctionType: ["typeParameters", "params", "returnType"], TSMappedType: ["typeParameter"], - TSMethodSignature: ["typeAnnotation", "typeParameters", "key", "params"], + TSMethodSignature: ["typeParameters", "key", "params", "returnType"], TSModuleBlock: ["body"], TSModuleDeclaration: ["id", "body"], TSNamespaceExportDeclaration: ["id"], From 10ec394c605a61e3980285453cdd9c6dc49ce9c8 Mon Sep 17 00:00:00 2001 From: Armano Date: Fri, 11 Jan 2019 01:14:44 +0100 Subject: [PATCH 17/18] test: fix eol issue --- tests/lib/__snapshots__/scope-analysis.js.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/lib/__snapshots__/scope-analysis.js.snap b/tests/lib/__snapshots__/scope-analysis.js.snap index bf51b47..561adcd 100644 --- a/tests/lib/__snapshots__/scope-analysis.js.snap +++ b/tests/lib/__snapshots__/scope-analysis.js.snap @@ -5398,7 +5398,7 @@ Object { "block": Object { "range": Array [ 0, - 36, + 35, ], "type": "Program", }, @@ -5969,7 +5969,7 @@ Object { "block": Object { "range": Array [ 0, - 20, + 19, ], "type": "Program", }, From 7b60a14405730f827eb5209e4b4a112b0b6ea9ec Mon Sep 17 00:00:00 2001 From: Armano Date: Sat, 12 Jan 2019 21:21:10 +0100 Subject: [PATCH 18/18] Upgrade: typescript-estree to 18.0.0 --- analyze-scope.js | 20 + package.json | 2 +- tests/lib/__snapshots__/ecma-features.js.snap | 2 +- tests/lib/__snapshots__/typescript.js.snap | 625 +++++++++--------- visitor-keys.js | 7 +- 5 files changed, 336 insertions(+), 320 deletions(-) diff --git a/analyze-scope.js b/analyze-scope.js index b75a746..5505973 100644 --- a/analyze-scope.js +++ b/analyze-scope.js @@ -354,6 +354,26 @@ class Referencer extends OriginalReferencer { this.visitTypeNodes(node); } + /** + * Don't make variable because it declares only types. + * Switch to the type mode and visit child nodes to find `typeof x` expression in type declarations. + * @param {TSClassImplements} node The TSClassImplements node to visit. + * @returns {void} + */ + TSClassImplements(node) { + this.visitTypeNodes(node); + } + + /** + * Don't make variable because it declares only types. + * Switch to the type mode and visit child nodes to find `typeof x` expression in type declarations. + * @param {TSIndexSignature} node The TSIndexSignature node to visit. + * @returns {void} + */ + TSIndexSignature(node) { + this.visitTypeNodes(node); + } + /** * Visit type assertion. * @param {TSTypeAssertion} node The TSTypeAssertion node to visit. diff --git a/package.json b/package.json index 12db75e..54316fc 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "dependencies": { "eslint-scope": "^4.0.0", "eslint-visitor-keys": "^1.0.0", - "typescript-estree": "15.0.0" + "typescript-estree": "18.0.0" }, "devDependencies": { "eslint": "^4.19.1", diff --git a/tests/lib/__snapshots__/ecma-features.js.snap b/tests/lib/__snapshots__/ecma-features.js.snap index 2f2fee9..591436e 100644 --- a/tests/lib/__snapshots__/ecma-features.js.snap +++ b/tests/lib/__snapshots__/ecma-features.js.snap @@ -41588,7 +41588,7 @@ Object { 1, 23, ], - "type": "ObjectPattern", + "type": "ObjectExpression", }, "loc": Object { "end": Object { diff --git a/tests/lib/__snapshots__/typescript.js.snap b/tests/lib/__snapshots__/typescript.js.snap index 25acd61..dcb703d 100644 --- a/tests/lib/__snapshots__/typescript.js.snap +++ b/tests/lib/__snapshots__/typescript.js.snap @@ -2926,7 +2926,6 @@ Object { ], "type": "TSInterfaceBody", }, - "heritage": Array [], "id": Object { "loc": Object { "end": Object { @@ -6906,7 +6905,7 @@ Object { }, "implements": Array [ Object { - "id": Object { + "expression": Object { "loc": Object { "end": Object { "column": 77, @@ -6938,7 +6937,7 @@ Object { 66, 77, ], - "type": "ClassImplements", + "type": "TSClassImplements", }, ], "loc": Object { @@ -9097,7 +9096,7 @@ Object { }, "implements": Array [ Object { - "id": Object { + "expression": Object { "loc": Object { "end": Object { "column": 24, @@ -9129,7 +9128,7 @@ Object { 21, 24, ], - "type": "ClassImplements", + "type": "TSClassImplements", }, ], "loc": Object { @@ -9322,7 +9321,7 @@ Object { }, "implements": Array [ Object { - "id": Object { + "expression": Object { "loc": Object { "end": Object { "column": 56, @@ -9354,7 +9353,7 @@ Object { 45, 56, ], - "type": "ClassImplements", + "type": "TSClassImplements", }, ], "loc": Object { @@ -9600,7 +9599,7 @@ Object { }, "implements": Array [ Object { - "id": Object { + "expression": Object { "loc": Object { "end": Object { "column": 24, @@ -9632,7 +9631,7 @@ Object { 21, 24, ], - "type": "ClassImplements", + "type": "TSClassImplements", "typeParameters": Object { "loc": Object { "end": Object { @@ -9933,7 +9932,7 @@ Object { }, "implements": Array [ Object { - "id": Object { + "expression": Object { "loc": Object { "end": Object { "column": 24, @@ -9965,7 +9964,7 @@ Object { 21, 24, ], - "type": "ClassImplements", + "type": "TSClassImplements", "typeParameters": Object { "loc": Object { "end": Object { @@ -10663,7 +10662,7 @@ Object { }, "implements": Array [ Object { - "id": Object { + "expression": Object { "loc": Object { "end": Object { "column": 38, @@ -10695,7 +10694,7 @@ Object { 123, 124, ], - "type": "ClassImplements", + "type": "TSClassImplements", }, ], "loc": Object { @@ -10878,7 +10877,6 @@ Object { ], "type": "TSInterfaceBody", }, - "heritage": Array [], "id": Object { "loc": Object { "end": Object { @@ -30705,9 +30703,9 @@ Object { ], "type": "TSInterfaceBody", }, - "heritage": Array [ + "extends": Array [ Object { - "id": Object { + "expression": Object { "loc": Object { "end": Object { "column": 25, @@ -30929,9 +30927,9 @@ Object { ], "type": "TSInterfaceBody", }, - "heritage": Array [ + "extends": Array [ Object { - "id": Object { + "expression": Object { "loc": Object { "end": Object { "column": 25, @@ -30966,7 +30964,7 @@ Object { "type": "TSInterfaceHeritage", }, Object { - "id": Object { + "expression": Object { "loc": Object { "end": Object { "column": 29, @@ -31224,7 +31222,6 @@ Object { ], "type": "TSInterfaceBody", }, - "heritage": Array [], "id": Object { "loc": Object { "end": Object { @@ -31751,39 +31748,34 @@ Object { }, }, Object { - "index": Object { - "loc": Object { - "end": Object { - "column": 16, - "line": 6, - }, - "start": Object { - "column": 5, - "line": 6, - }, + "loc": Object { + "end": Object { + "column": 26, + "line": 6, }, - "name": "eee", - "range": Array [ - 95, - 106, - ], - "type": "Identifier", - "typeAnnotation": Object { + "start": Object { + "column": 4, + "line": 6, + }, + }, + "parameters": Array [ + Object { "loc": Object { "end": Object { "column": 16, "line": 6, }, "start": Object { - "column": 8, + "column": 5, "line": 6, }, }, + "name": "eee", "range": Array [ - 98, + 95, 106, ], - "type": "TSTypeAnnotation", + "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { @@ -31791,33 +31783,39 @@ Object { "line": 6, }, "start": Object { - "column": 10, + "column": 8, "line": 6, }, }, "range": Array [ - 100, + 98, 106, ], - "type": "TSNumberKeyword", + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 6, + }, + "start": Object { + "column": 10, + "line": 6, + }, + }, + "range": Array [ + 100, + 106, + ], + "type": "TSNumberKeyword", + }, }, }, - }, - "loc": Object { - "end": Object { - "column": 26, - "line": 6, - }, - "start": Object { - "column": 4, - "line": 6, - }, - }, + ], "range": Array [ 94, 116, ], - "static": false, "type": "TSIndexSignature", "typeAnnotation": Object { "loc": Object { @@ -31855,40 +31853,35 @@ Object { }, }, Object { - "index": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 7, - }, - "start": Object { - "column": 5, - "line": 7, - }, + "loc": Object { + "end": Object { + "column": 27, + "line": 7, }, - "name": "fff", - "optional": true, - "range": Array [ - 122, - 134, - ], - "type": "Identifier", - "typeAnnotation": Object { + "start": Object { + "column": 4, + "line": 7, + }, + }, + "parameters": Array [ + Object { "loc": Object { "end": Object { "column": 17, "line": 7, }, "start": Object { - "column": 9, + "column": 5, "line": 7, }, }, + "name": "fff", + "optional": true, "range": Array [ - 126, + 122, 134, ], - "type": "TSTypeAnnotation", + "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { @@ -31896,33 +31889,39 @@ Object { "line": 7, }, "start": Object { - "column": 11, + "column": 9, "line": 7, }, }, "range": Array [ - 128, + 126, 134, ], - "type": "TSNumberKeyword", + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 7, + }, + "start": Object { + "column": 11, + "line": 7, + }, + }, + "range": Array [ + 128, + 134, + ], + "type": "TSNumberKeyword", + }, }, }, - }, - "loc": Object { - "end": Object { - "column": 27, - "line": 7, - }, - "start": Object { - "column": 4, - "line": 7, - }, - }, + ], "range": Array [ 121, 144, ], - "static": false, "type": "TSIndexSignature", "typeAnnotation": Object { "loc": Object { @@ -32715,7 +32714,6 @@ Object { ], "type": "TSInterfaceBody", }, - "heritage": Array [], "id": Object { "loc": Object { "end": Object { @@ -34903,7 +34901,6 @@ Object { ], "type": "TSInterfaceBody", }, - "heritage": Array [], "id": Object { "loc": Object { "end": Object { @@ -35217,9 +35214,9 @@ Object { ], "type": "TSInterfaceBody", }, - "heritage": Array [ + "extends": Array [ Object { - "id": Object { + "expression": Object { "loc": Object { "end": Object { "column": 28, @@ -35657,7 +35654,6 @@ Object { ], "type": "TSInterfaceBody", }, - "heritage": Array [], "id": Object { "loc": Object { "end": Object { @@ -35974,7 +35970,6 @@ Object { ], "type": "TSInterfaceBody", }, - "heritage": Array [], "id": Object { "loc": Object { "end": Object { @@ -36476,7 +36471,6 @@ Object { ], "type": "TSInterfaceBody", }, - "heritage": Array [], "id": Object { "loc": Object { "end": Object { @@ -37061,7 +37055,6 @@ Object { ], "type": "TSInterfaceBody", }, - "heritage": Array [], "id": Object { "loc": Object { "end": Object { @@ -45076,7 +45069,6 @@ Object { ], "type": "TSInterfaceBody", }, - "heritage": Array [], "id": Object { "loc": Object { "end": Object { @@ -58742,7 +58734,7 @@ Object { }, "implements": Array [ Object { - "id": Object { + "expression": Object { "loc": Object { "end": Object { "column": 32, @@ -58774,7 +58766,7 @@ Object { 29, 32, ], - "type": "ClassImplements", + "type": "TSClassImplements", }, ], "loc": Object { @@ -59451,7 +59443,6 @@ Object { "type": "Decorator", }, ], - "heritage": Array [], "id": Object { "loc": Object { "end": Object { @@ -60353,7 +60344,6 @@ Object { ], "type": "TSInterfaceBody", }, - "heritage": Array [], "id": Object { "loc": Object { "end": Object { @@ -61024,39 +61014,34 @@ Object { }, Object { "accessibility": "public", - "index": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 10, - }, - "start": Object { - "column": 12, - "line": 10, - }, + "loc": Object { + "end": Object { + "column": 33, + "line": 10, }, - "name": "baz", - "range": Array [ - 190, - 201, - ], - "type": "Identifier", - "typeAnnotation": Object { + "start": Object { + "column": 4, + "line": 10, + }, + }, + "parameters": Array [ + Object { "loc": Object { "end": Object { "column": 23, "line": 10, }, "start": Object { - "column": 15, + "column": 12, "line": 10, }, }, + "name": "baz", "range": Array [ - 193, + 190, 201, ], - "type": "TSTypeAnnotation", + "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { @@ -61064,33 +61049,39 @@ Object { "line": 10, }, "start": Object { - "column": 17, + "column": 15, "line": 10, }, }, "range": Array [ - 195, + 193, 201, ], - "type": "TSStringKeyword", + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 10, + }, + "start": Object { + "column": 17, + "line": 10, + }, + }, + "range": Array [ + 195, + 201, + ], + "type": "TSStringKeyword", + }, }, }, - }, - "loc": Object { - "end": Object { - "column": 33, - "line": 10, - }, - "start": Object { - "column": 4, - "line": 10, - }, - }, + ], "range": Array [ 182, 211, ], - "static": false, "type": "TSIndexSignature", "typeAnnotation": Object { "loc": Object { @@ -61129,39 +61120,34 @@ Object { }, Object { "accessibility": "private", - "index": Object { - "loc": Object { - "end": Object { - "column": 24, - "line": 11, - }, - "start": Object { - "column": 13, - "line": 11, - }, + "loc": Object { + "end": Object { + "column": 34, + "line": 11, }, - "name": "baz", - "range": Array [ - 225, - 236, - ], - "type": "Identifier", - "typeAnnotation": Object { + "start": Object { + "column": 4, + "line": 11, + }, + }, + "parameters": Array [ + Object { "loc": Object { "end": Object { "column": 24, "line": 11, }, "start": Object { - "column": 16, + "column": 13, "line": 11, }, }, + "name": "baz", "range": Array [ - 228, + 225, 236, ], - "type": "TSTypeAnnotation", + "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { @@ -61169,33 +61155,39 @@ Object { "line": 11, }, "start": Object { - "column": 18, + "column": 16, "line": 11, }, }, "range": Array [ - 230, + 228, 236, ], - "type": "TSStringKeyword", + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 11, + }, + "start": Object { + "column": 18, + "line": 11, + }, + }, + "range": Array [ + 230, + 236, + ], + "type": "TSStringKeyword", + }, }, }, - }, - "loc": Object { - "end": Object { - "column": 34, - "line": 11, - }, - "start": Object { - "column": 4, - "line": 11, - }, - }, + ], "range": Array [ 216, 246, ], - "static": false, "type": "TSIndexSignature", "typeAnnotation": Object { "loc": Object { @@ -61234,39 +61226,34 @@ Object { }, Object { "accessibility": "protected", - "index": Object { - "loc": Object { - "end": Object { - "column": 26, - "line": 12, - }, - "start": Object { - "column": 15, - "line": 12, - }, + "loc": Object { + "end": Object { + "column": 36, + "line": 12, }, - "name": "baz", - "range": Array [ - 262, - 273, - ], - "type": "Identifier", - "typeAnnotation": Object { + "start": Object { + "column": 4, + "line": 12, + }, + }, + "parameters": Array [ + Object { "loc": Object { "end": Object { "column": 26, "line": 12, }, "start": Object { - "column": 18, + "column": 15, "line": 12, }, }, + "name": "baz", "range": Array [ - 265, + 262, 273, ], - "type": "TSTypeAnnotation", + "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { @@ -61274,33 +61261,39 @@ Object { "line": 12, }, "start": Object { - "column": 20, + "column": 18, "line": 12, }, }, "range": Array [ - 267, + 265, 273, ], - "type": "TSStringKeyword", + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 12, + }, + "start": Object { + "column": 20, + "line": 12, + }, + }, + "range": Array [ + 267, + 273, + ], + "type": "TSStringKeyword", + }, }, }, - }, - "loc": Object { - "end": Object { - "column": 36, - "line": 12, - }, - "start": Object { - "column": 4, - "line": 12, - }, - }, + ], "range": Array [ 251, 283, ], - "static": false, "type": "TSIndexSignature", "typeAnnotation": Object { "loc": Object { @@ -61338,39 +61331,34 @@ Object { }, }, Object { - "index": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 13, - }, - "start": Object { - "column": 12, - "line": 13, - }, + "loc": Object { + "end": Object { + "column": 33, + "line": 13, }, - "name": "baz", - "range": Array [ - 296, - 307, - ], - "type": "Identifier", - "typeAnnotation": Object { + "start": Object { + "column": 4, + "line": 13, + }, + }, + "parameters": Array [ + Object { "loc": Object { "end": Object { "column": 23, "line": 13, }, "start": Object { - "column": 15, + "column": 12, "line": 13, }, }, + "name": "baz", "range": Array [ - 299, + 296, 307, ], - "type": "TSTypeAnnotation", + "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { @@ -61378,28 +61366,35 @@ Object { "line": 13, }, "start": Object { - "column": 17, + "column": 15, "line": 13, }, }, "range": Array [ - 301, + 299, 307, ], - "type": "TSStringKeyword", + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 13, + }, + "start": Object { + "column": 17, + "line": 13, + }, + }, + "range": Array [ + 301, + 307, + ], + "type": "TSStringKeyword", + }, }, }, - }, - "loc": Object { - "end": Object { - "column": 33, - "line": 13, - }, - "start": Object { - "column": 4, - "line": 13, - }, - }, + ], "range": Array [ 288, 317, @@ -61443,39 +61438,34 @@ Object { }, Object { "export": true, - "index": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 14, - }, - "start": Object { - "column": 12, - "line": 14, - }, + "loc": Object { + "end": Object { + "column": 33, + "line": 14, }, - "name": "baz", - "range": Array [ - 330, - 341, - ], - "type": "Identifier", - "typeAnnotation": Object { + "start": Object { + "column": 4, + "line": 14, + }, + }, + "parameters": Array [ + Object { "loc": Object { "end": Object { "column": 23, "line": 14, }, "start": Object { - "column": 15, + "column": 12, "line": 14, }, }, + "name": "baz", "range": Array [ - 333, + 330, 341, ], - "type": "TSTypeAnnotation", + "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { @@ -61483,33 +61473,39 @@ Object { "line": 14, }, "start": Object { - "column": 17, + "column": 15, "line": 14, }, }, "range": Array [ - 335, + 333, 341, ], - "type": "TSStringKeyword", + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 14, + }, + "start": Object { + "column": 17, + "line": 14, + }, + }, + "range": Array [ + 335, + 341, + ], + "type": "TSStringKeyword", + }, }, }, - }, - "loc": Object { - "end": Object { - "column": 33, - "line": 14, - }, - "start": Object { - "column": 4, - "line": 14, - }, - }, + ], "range": Array [ 322, 351, ], - "static": false, "type": "TSIndexSignature", "typeAnnotation": Object { "loc": Object { @@ -61547,39 +61543,34 @@ Object { }, }, Object { - "index": Object { - "loc": Object { - "end": Object { - "column": 25, - "line": 15, - }, - "start": Object { - "column": 14, - "line": 15, - }, + "loc": Object { + "end": Object { + "column": 35, + "line": 15, }, - "name": "baz", - "range": Array [ - 366, - 377, - ], - "type": "Identifier", - "typeAnnotation": Object { + "start": Object { + "column": 4, + "line": 15, + }, + }, + "parameters": Array [ + Object { "loc": Object { "end": Object { "column": 25, "line": 15, }, "start": Object { - "column": 17, + "column": 14, "line": 15, }, }, + "name": "baz", "range": Array [ - 369, + 366, 377, ], - "type": "TSTypeAnnotation", + "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { @@ -61587,34 +61578,40 @@ Object { "line": 15, }, "start": Object { - "column": 19, + "column": 17, "line": 15, }, }, "range": Array [ - 371, + 369, 377, ], - "type": "TSStringKeyword", + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 15, + }, + "start": Object { + "column": 19, + "line": 15, + }, + }, + "range": Array [ + 371, + 377, + ], + "type": "TSStringKeyword", + }, }, }, - }, - "loc": Object { - "end": Object { - "column": 35, - "line": 15, - }, - "start": Object { - "column": 4, - "line": 15, - }, - }, + ], "range": Array [ 356, 387, ], "readonly": true, - "static": false, "type": "TSIndexSignature", "typeAnnotation": Object { "loc": Object { @@ -62418,7 +62415,6 @@ Object { ], "type": "TSInterfaceBody", }, - "heritage": Array [], "id": Object { "loc": Object { "end": Object { @@ -68642,7 +68638,6 @@ Object { ], "type": "TSInterfaceBody", }, - "heritage": Array [], "id": Object { "loc": Object { "end": Object { diff --git a/visitor-keys.js b/visitor-keys.js index 3ba3af7..210a5ac 100644 --- a/visitor-keys.js +++ b/visitor-keys.js @@ -38,6 +38,7 @@ module.exports = Evk.unionWith({ TSBigIntKeyword: [], TSBooleanKeyword: [], TSCallSignatureDeclaration: ["typeParameters", "params", "returnType"], + TSClassImplements: ["expression", "typeParameters"], TSConditionalType: ["checkType", "extendsType", "trueType", "falseType"], TSConstructSignatureDeclaration: ["typeParameters", "params", "returnType"], TSConstructorType: ["typeParameters", "params", "returnType"], @@ -54,10 +55,10 @@ module.exports = Evk.unionWith({ TSLiteralType: ["literal"], TSIntersectionType: ["types"], TSIndexedAccessType: ["indexType", "objectType"], - TSIndexSignature: ["typeAnnotation", "index"], + TSIndexSignature: ["typeAnnotation", "parameters"], TSInterfaceBody: ["body"], - TSInterfaceDeclaration: ["id", "typeParameters", "heritage", "body"], - TSInterfaceHeritage: ["id", "typeParameters"], + TSInterfaceDeclaration: ["id", "typeParameters", "extends", "body"], + TSInterfaceHeritage: ["expression", "typeParameters"], TSImportEqualsDeclaration: ["id", "moduleReference"], TSFunctionType: ["typeParameters", "params", "returnType"], TSMappedType: ["typeParameter"],