From 3efb265ea85406f8700cca1c40a87f5c30b1452b Mon Sep 17 00:00:00 2001 From: Armano Date: Sat, 2 Feb 2019 15:35:59 +0100 Subject: [PATCH 01/26] test(ts-estree): add regression test for decorators on variables (#186) --- .../lib/__snapshots__/typescript.ts.snap | 244 ++++++++++++++++++ .../decorator-on-variable.src.ts | 2 + .../semantic-diagnostics-enabled.ts.snap | 9 + .../lib/__snapshots__/typescript.ts.snap | 243 +++++++++++++++++ 4 files changed, 498 insertions(+) create mode 100644 packages/shared-fixtures/fixtures/typescript/errorRecovery/decorator-on-variable.src.ts diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index f540948a5558..f57d7523a358 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -89541,6 +89541,250 @@ Object { } `; +exports[`typescript fixtures/errorRecovery/decorator-on-variable.src 1`] = ` +Object { + "body": Array [ + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "name": "a", + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + }, + "init": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 18, + 19, + ], + "raw": "1", + "type": "Literal", + "value": 1, + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 14, + 19, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "const", + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 19, + ], + "type": "VariableDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 20, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 1, + ], + "type": "Punctuator", + "value": "@", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "range": Array [ + 1, + 5, + ], + "type": "Identifier", + "value": "deco", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 6, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 7, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 8, + 13, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + "value": "a", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Numeric", + "value": "1", + }, + ], + "type": "Program", +} +`; + exports[`typescript fixtures/errorRecovery/empty-type-arguments.src 1`] = ` Object { "body": Array [ diff --git a/packages/shared-fixtures/fixtures/typescript/errorRecovery/decorator-on-variable.src.ts b/packages/shared-fixtures/fixtures/typescript/errorRecovery/decorator-on-variable.src.ts new file mode 100644 index 000000000000..700dea545cce --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/errorRecovery/decorator-on-variable.src.ts @@ -0,0 +1,2 @@ +@deco() +const a = 1 diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap index 1db62d5b9140..a0cc4cb96444 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap @@ -2299,6 +2299,15 @@ Object { } `; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/decorator-on-variable.src 1`] = ` +Object { + "column": 0, + "index": 0, + "lineNumber": 1, + "message": "Decorators are not valid here.", +} +`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-arguments.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/enum-with-keywords.src 1`] = ` diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index b807e63a8220..0c1e0c5afe60 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -88851,6 +88851,249 @@ Object { } `; +exports[`typescript fixtures/errorRecovery/decorator-on-variable.src 1`] = ` +Object { + "body": Array [ + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "name": "a", + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + }, + "init": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 18, + 19, + ], + "raw": "1", + "type": "Literal", + "value": 1, + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 14, + 19, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "const", + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 19, + ], + "type": "VariableDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 20, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 1, + ], + "type": "Punctuator", + "value": "@", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "range": Array [ + 1, + 5, + ], + "type": "Identifier", + "value": "deco", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 6, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 7, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 8, + 13, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + "value": "a", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Numeric", + "value": "1", + }, + ], + "type": "Program", +} +`; + exports[`typescript fixtures/errorRecovery/empty-type-arguments.src 1`] = ` Object { "body": Array [ From 3b0fed6674e84523ef84005229e9e271a65d6e23 Mon Sep 17 00:00:00 2001 From: Kanitkorn Sujautra Date: Sun, 3 Feb 2019 21:57:23 +0900 Subject: [PATCH 02/26] docs(eslint-plugin): fix rule URLs still point to the old repository (#189) * docs(eslint-plugin): update rule url to the new repo Fix https://github.com/typescript-eslint/typescript-eslint/issues/188 * docs(eslint-plugin): add a link for no-unnecessary-type-assertion rule --- packages/eslint-plugin/ROADMAP.md | 57 ++++++++++++++++--------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/packages/eslint-plugin/ROADMAP.md b/packages/eslint-plugin/ROADMAP.md index 378a3140ffb8..48e0696eea9c 100644 --- a/packages/eslint-plugin/ROADMAP.md +++ b/packages/eslint-plugin/ROADMAP.md @@ -557,34 +557,35 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint- -[`@typescript-eslint/adjacent-overload-signatures`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/adjacent-overload-signatures.md -[`@typescript-eslint/ban-types`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/ban-types.md -[`@typescript-eslint/explicit-member-accessibility`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/explicit-member-accessibility.md -[`@typescript-eslint/member-ordering`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/member-ordering.md -[`@typescript-eslint/no-explicit-any`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-explicit-any.md -[`@typescript-eslint/no-empty-interface`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-empty-interface.md -[`@typescript-eslint/no-inferrable-types`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-inferrable-types.md -[`@typescript-eslint/prefer-namespace-keyword`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/prefer-namespace-keyword.md -[`@typescript-eslint/no-namespace`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-namespace.md -[`@typescript-eslint/no-non-null-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-non-null-assertion.md -[`@typescript-eslint/no-triple-slash-reference`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-triple-slash-reference.md -[`@typescript-eslint/no-var-requires`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-var-requires.md -[`@typescript-eslint/type-annotation-spacing`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/type-annotation-spacing.md -[`@typescript-eslint/no-misused-new`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-misused-new.md -[`@typescript-eslint/no-object-literal-type-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-object-literal-type-assertion.md -[`@typescript-eslint/no-this-alias`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-this-alias.md -[`@typescript-eslint/no-extraneous-class`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-extraneous-class.md -[`@typescript-eslint/no-unused-vars`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-unused-vars.md -[`@typescript-eslint/no-use-before-define`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-use-before-define.md -[`@typescript-eslint/indent`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/indent.md -[`@typescript-eslint/array-type`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/array-type.md -[`@typescript-eslint/class-name-casing`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/class-name-casing.md -[`@typescript-eslint/interface-name-prefix`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/interface-name-prefix.md -[`@typescript-eslint/no-angle-bracket-type-assertion`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-angle-bracket-type-assertion.md -[`@typescript-eslint/no-parameter-properties`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-parameter-properties.md -[`@typescript-eslint/member-delimiter-style`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/member-delimiter-style.md -[`@typescript-eslint/prefer-interface`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/prefer-interface.md -[`@typescript-eslint/no-array-constructor`]: https://github.com/bradzacher/@typescript-eslint/eslint-plugin/blob/master/docs/rules/no-array-constructor.md +[`@typescript-eslint/adjacent-overload-signatures`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md +[`@typescript-eslint/ban-types`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md +[`@typescript-eslint/explicit-member-accessibility`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md +[`@typescript-eslint/member-ordering`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-ordering.md +[`@typescript-eslint/no-explicit-any`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-explicit-any.md +[`@typescript-eslint/no-empty-interface`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-empty-interface.md +[`@typescript-eslint/no-inferrable-types`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-inferrable-types.md +[`@typescript-eslint/prefer-namespace-keyword`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-namespace-keyword.md +[`@typescript-eslint/no-namespace`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-namespace.md +[`@typescript-eslint/no-non-null-assertion`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-non-null-assertion.md +[`@typescript-eslint/no-triple-slash-reference`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-triple-slash-reference.md +[`@typescript-eslint/no-unnecessary-type-assertion`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md +[`@typescript-eslint/no-var-requires`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-var-requires.md +[`@typescript-eslint/type-annotation-spacing`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/type-annotation-spacing.md +[`@typescript-eslint/no-misused-new`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-misused-new.md +[`@typescript-eslint/no-object-literal-type-assertion`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-object-literal-type-assertion.md +[`@typescript-eslint/no-this-alias`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-this-alias.md +[`@typescript-eslint/no-extraneous-class`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extraneous-class.md +[`@typescript-eslint/no-unused-vars`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md +[`@typescript-eslint/no-use-before-define`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-use-before-define.md +[`@typescript-eslint/indent`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/indent.md +[`@typescript-eslint/array-type`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md +[`@typescript-eslint/class-name-casing`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/class-name-casing.md +[`@typescript-eslint/interface-name-prefix`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/interface-name-prefix.md +[`@typescript-eslint/no-angle-bracket-type-assertion`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-angle-bracket-type-assertion.md +[`@typescript-eslint/no-parameter-properties`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-parameter-properties.md +[`@typescript-eslint/member-delimiter-style`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-delimiter-style.md +[`@typescript-eslint/prefer-interface`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-interface.md +[`@typescript-eslint/no-array-constructor`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-array-constructor.md From f03ed0765fd93539a5aef71ddd66fde8d92f1ce3 Mon Sep 17 00:00:00 2001 From: Armano Date: Sun, 3 Feb 2019 17:09:48 +0100 Subject: [PATCH 03/26] docs(eslint-plugin): replace whitespaces with
tag (#198) --- packages/eslint-plugin/ROADMAP.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/eslint-plugin/ROADMAP.md b/packages/eslint-plugin/ROADMAP.md index 48e0696eea9c..f26d0e80175c 100644 --- a/packages/eslint-plugin/ROADMAP.md +++ b/packages/eslint-plugin/ROADMAP.md @@ -1,9 +1,9 @@ # Roadmap -✅ (28) = done -🌟 (79) = in ESLint core -🔌 (33) = in another plugin -🌓 (16) = implementations differ or ESLint version is missing functionality +✅ (28) = done
+🌟 (79) = in ESLint core
+🔌 (33) = in another plugin
+🌓 (16) = implementations differ or ESLint version is missing functionality
🛑 (70) = unimplemented ## TSLint rules @@ -96,7 +96,7 @@ | [`use-default-type-parameter`] | 🛑 | N/A | | [`use-isnan`] | 🌟 | [`use-isnan`][use-isnan] | -[1] The ESLint rule also supports silencing with an extra set of parens (`if ((foo = bar)) {}`) +[1] The ESLint rule also supports silencing with an extra set of parens (`if ((foo = bar)) {}`)
[2] Missing private class member support. [`@typescript-eslint/no-unused-vars`] adds support for some TS-specific features. ### Maintainability @@ -120,7 +120,7 @@ | [`prefer-readonly`] | 🛑 | N/A | | [`trailing-comma`] | 🌓 | [`comma-dangle`][comma-dangle] or [Prettier] | -[1] Only warns when importing deprecated symbols +[1] Only warns when importing deprecated symbols
[2] Missing support for blank-line-delimited sections ### Style @@ -179,7 +179,7 @@ | [`variable-name`] | 🌟 | [2] | | [`whitespace`] | 🔌 | Use [Prettier] | -[1] Recommended config: `["error", { blankLine: "always", prev: "*", next: "return" }]` +[1] Recommended config: `["error", { blankLine: "always", prev: "*", next: "return" }]`
[2] [`camelcase`][camelcase], [`no-underscore-dangle`][no-underscore-dangle], [`id-blacklist`][id-blacklist], and/or [`id-match`][id-match] ## tslint-microsoft-contrib rules @@ -245,10 +245,10 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint- | `use-named-parameter` | 🛑 | N/A | | `use-simple-attributes` | 🛑 | N/A | -[1] Enforces blank lines both at the beginning and end of a block -[2] Recommended config: `["error", "ForInStatement"]` -[3] Recommended config: `["error", "declaration", { "allowArrowFunctions": true }]` -[4] Recommended config: `["error", { "terms": ["BUG", "HACK", "FIXME", "LATER", "LATER2", "TODO"], "location": "anywhere" }]` +[1] Enforces blank lines both at the beginning and end of a block
+[2] Recommended config: `["error", "ForInStatement"]`
+[3] Recommended config: `["error", "declaration", { "allowArrowFunctions": true }]`
+[4] Recommended config: `["error", { "terms": ["BUG", "HACK", "FIXME", "LATER", "LATER2", "TODO"], "location": "anywhere" }]`
[5] Does not check class fields. [insecure-random]: https://github.com/desktop/desktop/blob/master/eslint-rules/insecure-random.js @@ -310,7 +310,7 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint- | `react-a11y-titles` | 🛑 | N/A | | `react-anchor-blank-noopener` | 🛑 | N/A | -[1] TSLint rule is more strict +[1] TSLint rule is more strict
[2] ESLint rule only reports for click handlers [prettier]: https://prettier.io From f35c20b100dfa516d695000f6cdc38b6fd5248a2 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sun, 3 Feb 2019 11:10:41 -0500 Subject: [PATCH 04/26] chore: removed unnecessary path prefix from .vscode/launch.json (#196) --- .vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 18bf27ada556..4ac7bc13cdd0 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,7 +12,7 @@ "program": "${workspaceFolder}/node_modules/jest/bin/jest.js", "args": [ "--colors", - "${workspaceFolder}/packages/eslint-plugin/tests/lib/rules/${fileBasename}" + "tests/lib/rules/${fileBasename}" ], "console": "integratedTerminal", "internalConsoleOptions": "neverOpen" From f856e76629e4f737a727c53cfd58f7561e490579 Mon Sep 17 00:00:00 2001 From: Armano Date: Sun, 3 Feb 2019 19:23:40 +0100 Subject: [PATCH 05/26] test(*): update eslint-plugin-jest and enable recommended rules (#190) --- .eslintrc.json | 15 +++++++++++---- package.json | 2 +- packages/parser/tests/lib/parser.ts | 2 +- packages/typescript-estree/tests/lib/parse.ts | 6 +++--- .../typescript-estree/tests/lib/semanticInfo.ts | 4 ++-- .../tests/lib/warn-on-unsupported-ts.ts | 2 +- yarn.lock | 8 ++++---- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index f44790c843c8..40a5182652ad 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -29,10 +29,10 @@ "overrides": [ { "files": [ - "packages/eslint-plugin-tslint/**/*.ts", - "packages/eslint-plugin/**/*.js", - "packages/parser/**/*.ts", - "packages/typescript-estree/**/*.ts" + "packages/eslint-plugin-tslint/tests/**/*.ts", + "packages/eslint-plugin/tests/**/*.js", + "packages/parser/tests/**/*.ts", + "packages/typescript-estree/tests/**/*.ts" ], "env": { "jest/globals": true @@ -40,8 +40,15 @@ "rules": { "jest/no-disabled-tests": "warn", "jest/no-focused-tests": "error", + "jest/no-alias-methods": "error", "jest/no-identical-title": "error", + "jest/no-jasmine-globals": "error", + "jest/no-jest-import": "error", + "jest/no-test-prefixes": "error", + "jest/no-test-callback": "error", + "jest/no-test-return-statement": "error", "jest/prefer-to-have-length": "warn", + "jest/prefer-spy-on": "error", "jest/valid-expect": "error" } }, diff --git a/package.json b/package.json index 18059f7381ed..a95c4a1a5710 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "cz-conventional-changelog": "2.1.0", "eslint": "^5.12.1", "eslint-plugin-eslint-plugin": "^2.0.1", - "eslint-plugin-jest": "^22.1.3", + "eslint-plugin-jest": "^22.2.2", "glob": "7.1.2", "husky": "^1.3.1", "jest": "23.6.0", diff --git a/packages/parser/tests/lib/parser.ts b/packages/parser/tests/lib/parser.ts index bfc23bac5abb..332be8b6e43c 100644 --- a/packages/parser/tests/lib/parser.ts +++ b/packages/parser/tests/lib/parser.ts @@ -24,7 +24,7 @@ describe('parser', () => { sourceType: 'script', useJSXTextNode: true }); - expect(spyScope).toHaveBeenCalledWith(jasmine.any(Object), { + expect(spyScope).toHaveBeenCalledWith(expect.any(Object), { ecmaFeatures: {}, sourceType: 'script' }); diff --git a/packages/typescript-estree/tests/lib/parse.ts b/packages/typescript-estree/tests/lib/parse.ts index fc7e8af99a10..6bed7ce8bcef 100644 --- a/packages/typescript-estree/tests/lib/parse.ts +++ b/packages/typescript-estree/tests/lib/parse.ts @@ -82,7 +82,7 @@ describe('parse()', () => { }); expect(spy).toHaveBeenCalledWith( - jasmine.any(Object), + expect.any(Object), { code: 'let foo = bar;', comment: true, @@ -96,8 +96,8 @@ describe('parse()', () => { projects: [], range: true, strict: false, - tokens: jasmine.any(Array), - tsconfigRootDir: jasmine.any(String), + tokens: expect.any(Array), + tsconfigRootDir: expect.any(String), useJSXTextNode: false }, false diff --git a/packages/typescript-estree/tests/lib/semanticInfo.ts b/packages/typescript-estree/tests/lib/semanticInfo.ts index e45cae843ed5..f5612f191cc5 100644 --- a/packages/typescript-estree/tests/lib/semanticInfo.ts +++ b/packages/typescript-estree/tests/lib/semanticInfo.ts @@ -179,7 +179,7 @@ describe('semanticInfo', () => { badConfig.project = './tsconfigs.json'; expect(() => parseCodeAndGenerateServices(readFileSync(fileName, 'utf8'), badConfig) - ).toThrowError(/File .+tsconfigs\.json' not found/); + ).toThrow(/File .+tsconfigs\.json' not found/); }); it('fail to read project file', () => { @@ -188,7 +188,7 @@ describe('semanticInfo', () => { badConfig.project = '.'; expect(() => parseCodeAndGenerateServices(readFileSync(fileName, 'utf8'), badConfig) - ).toThrowError(/File .+semanticInfo' not found/); + ).toThrow(/File .+semanticInfo' not found/); }); it('malformed project file', () => { diff --git a/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts b/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts index d984007bf757..565b997c35fc 100644 --- a/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts +++ b/packages/typescript-estree/tests/lib/warn-on-unsupported-ts.ts @@ -11,7 +11,7 @@ describe('Warn on unsupported TypeScript version', () => { it('should warn the user if they are using an unsupported TypeScript version', () => { (semver.satisfies as jest.Mock).mockReturnValue(false); - console.log = jest.fn(); + jest.spyOn(console, 'log').mockImplementation(); parser.parse(''); expect(console.log).toHaveBeenCalledWith( expect.stringContaining( diff --git a/yarn.lock b/yarn.lock index 6980f52cafb8..1969160e6c41 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2378,10 +2378,10 @@ eslint-plugin-eslint-plugin@^2.0.1: resolved "https://registry.yarnpkg.com/eslint-plugin-eslint-plugin/-/eslint-plugin-eslint-plugin-2.0.1.tgz#d275434969dbde3da1d4cb7a121dc8d88457c786" integrity sha512-kJ5TZsRJH/xYstG07v3YeOy/W5SDAEzV+bvvoL0aiG1HtqDmg4mJvNPnn/JngANMmsx8oXlJrIcBTCpJzm+9kg== -eslint-plugin-jest@^22.1.3: - version "22.1.3" - resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-22.1.3.tgz#4444108dfcddc5d2117ed6dc551f529d7e73a99e" - integrity sha512-JTZTI6WQoNruAugNyCO8fXfTONVcDd5i6dMRFA5g3rUFn1UDDLILY1bTL6alvNXbW2U7Sc2OSpi8m08pInnq0A== +eslint-plugin-jest@^22.2.2: + version "22.2.2" + resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-22.2.2.tgz#2a80d70a20c27dfb1503a6f32cdcb647fe5476df" + integrity sha512-hnWgh9o39VJfz6lJEyQJdTW7dN2yynlGkmPOlU/oMHh+d7WVMsJP1GeDTB520VCDljEdKExCwD5IBpQIUl4mJg== eslint-scope@^4.0.0: version "4.0.0" From a36e727277d9815cfdd6f0b67e0981d84035698f Mon Sep 17 00:00:00 2001 From: Armano Date: Sun, 3 Feb 2019 19:40:26 +0100 Subject: [PATCH 06/26] test(ts-estree): add test for parsing nested jsx tag names (#191) --- .../tests/lib/__snapshots__/jsx.ts.snap | 1716 +++++++++++++++++ .../tag-names-with-multi-dots-multi.src.js | 3 + .../tests/ast-alignment/fixtures-to-test.ts | 7 +- .../tests/lib/__snapshots__/jsx.ts.snap | 1715 ++++++++++++++++ .../semantic-diagnostics-enabled.ts.snap | 9 + 5 files changed, 3449 insertions(+), 1 deletion(-) create mode 100644 packages/shared-fixtures/fixtures/jsx/tag-names-with-multi-dots-multi.src.js diff --git a/packages/parser/tests/lib/__snapshots__/jsx.ts.snap b/packages/parser/tests/lib/__snapshots__/jsx.ts.snap index 8a6365ac56b6..02d917e3fb56 100644 --- a/packages/parser/tests/lib/__snapshots__/jsx.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/jsx.ts.snap @@ -9463,6 +9463,1722 @@ Object { } `; +exports[`JSX useJSXTextNode: false fixtures/tag-names-with-multi-dots-multi.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "children": Array [ + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 16, + ], + "raw": " + ", + "type": "Literal", + "value": " + ", + }, + Object { + "children": Array [], + "closingElement": Object { + "loc": Object { + "end": Object { + "column": 57, + "line": 2, + }, + "start": Object { + "column": 29, + "line": 2, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 56, + "line": 2, + }, + "start": Object { + "column": 31, + "line": 2, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 49, + "line": 2, + }, + "start": Object { + "column": 31, + "line": 2, + }, + }, + "object": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 41, + "line": 2, + }, + "start": Object { + "column": 31, + "line": 2, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 2, + }, + "start": Object { + "column": 31, + "line": 2, + }, + }, + "range": Array [ + 45, + 49, + ], + "type": "ThisExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 41, + "line": 2, + }, + "start": Object { + "column": 36, + "line": 2, + }, + }, + "name": "const", + "range": Array [ + 50, + 55, + ], + "type": "Identifier", + }, + "range": Array [ + 45, + 55, + ], + "type": "MemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 49, + "line": 2, + }, + "start": Object { + "column": 42, + "line": 2, + }, + }, + "name": "declare", + "range": Array [ + 56, + 63, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 45, + 63, + ], + "type": "JSXMemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 56, + "line": 2, + }, + "start": Object { + "column": 50, + "line": 2, + }, + }, + "name": "static", + "range": Array [ + 64, + 70, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 45, + 70, + ], + "type": "JSXMemberExpression", + }, + "range": Array [ + 43, + 71, + ], + "type": "JSXClosingElement", + }, + "loc": Object { + "end": Object { + "column": 57, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "openingElement": Object { + "attributes": Array [], + "loc": Object { + "end": Object { + "column": 29, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, + }, + "object": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, + }, + "range": Array [ + 17, + 21, + ], + "type": "ThisExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "name": "const", + "range": Array [ + 22, + 27, + ], + "type": "Identifier", + }, + "range": Array [ + 17, + 27, + ], + "type": "MemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 2, + }, + "start": Object { + "column": 14, + "line": 2, + }, + }, + "name": "declare", + "range": Array [ + 28, + 35, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 17, + 35, + ], + "type": "JSXMemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 2, + }, + "start": Object { + "column": 22, + "line": 2, + }, + }, + "name": "static", + "range": Array [ + 36, + 42, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 17, + 42, + ], + "type": "JSXMemberExpression", + }, + "range": Array [ + 16, + 43, + ], + "selfClosing": false, + "type": "JSXOpeningElement", + }, + "range": Array [ + 16, + 71, + ], + "type": "JSXElement", + }, + Object { + "loc": Object { + "end": Object { + "column": 0, + "line": 3, + }, + "start": Object { + "column": 57, + "line": 2, + }, + }, + "range": Array [ + 71, + 72, + ], + "raw": " +", + "type": "Literal", + "value": " +", + }, + ], + "closingElement": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "object": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 9, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "object": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 7, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "object": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "name": "a", + "range": Array [ + 74, + 75, + ], + "type": "Identifier", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "name": "b", + "range": Array [ + 76, + 77, + ], + "type": "Identifier", + }, + "range": Array [ + 74, + 77, + ], + "type": "MemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 3, + }, + "start": Object { + "column": 6, + "line": 3, + }, + }, + "name": "c", + "range": Array [ + 78, + 79, + ], + "type": "Identifier", + }, + "range": Array [ + 74, + 79, + ], + "type": "MemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "name": "d", + "range": Array [ + 80, + 81, + ], + "type": "Identifier", + }, + "range": Array [ + 74, + 81, + ], + "type": "MemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 3, + }, + }, + "name": "e", + "range": Array [ + 82, + 83, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 74, + 83, + ], + "type": "JSXMemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 12, + "line": 3, + }, + }, + "name": "f", + "range": Array [ + 84, + 85, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 74, + 85, + ], + "type": "JSXMemberExpression", + }, + "range": Array [ + 72, + 86, + ], + "type": "JSXClosingElement", + }, + "loc": Object { + "end": Object { + "column": 14, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "openingElement": Object { + "attributes": Array [], + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "object": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "object": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "object": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "name": "a", + "range": Array [ + 1, + 2, + ], + "type": "Identifier", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 3, + "line": 1, + }, + }, + "name": "b", + "range": Array [ + 3, + 4, + ], + "type": "Identifier", + }, + "range": Array [ + 1, + 4, + ], + "type": "MemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "name": "c", + "range": Array [ + 5, + 6, + ], + "type": "Identifier", + }, + "range": Array [ + 1, + 6, + ], + "type": "MemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "name": "d", + "range": Array [ + 7, + 8, + ], + "type": "Identifier", + }, + "range": Array [ + 1, + 8, + ], + "type": "MemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "name": "e", + "range": Array [ + 9, + 10, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 1, + 10, + ], + "type": "JSXMemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "name": "f", + "range": Array [ + 11, + 12, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 1, + 12, + ], + "type": "JSXMemberExpression", + }, + "range": Array [ + 0, + 13, + ], + "selfClosing": false, + "type": "JSXOpeningElement", + }, + "range": Array [ + 0, + 86, + ], + "type": "JSXElement", + }, + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 87, + ], + "type": "ExpressionStatement", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 88, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 1, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "range": Array [ + 1, + 2, + ], + "type": "JSXIdentifier", + "value": "a", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 1, + }, + "start": Object { + "column": 2, + "line": 1, + }, + }, + "range": Array [ + 2, + 3, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 3, + "line": 1, + }, + }, + "range": Array [ + 3, + 4, + ], + "type": "JSXIdentifier", + "value": "b", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 5, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 6, + ], + "type": "JSXIdentifier", + "value": "c", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 7, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 8, + ], + "type": "JSXIdentifier", + "value": "d", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "range": Array [ + 8, + 9, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 10, + ], + "type": "JSXIdentifier", + "value": "e", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 12, + ], + "type": "JSXIdentifier", + "value": "f", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, + 13, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 16, + ], + "type": "JSXText", + "value": " + ", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, + }, + "range": Array [ + 17, + 21, + ], + "type": "Keyword", + "value": "this", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "range": Array [ + 21, + 22, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 22, + 27, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "range": Array [ + 27, + 28, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 2, + }, + "start": Object { + "column": 14, + "line": 2, + }, + }, + "range": Array [ + 28, + 35, + ], + "type": "Keyword", + "value": "declare", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 2, + }, + "start": Object { + "column": 21, + "line": 2, + }, + }, + "range": Array [ + 35, + 36, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 2, + }, + "start": Object { + "column": 22, + "line": 2, + }, + }, + "range": Array [ + 36, + 42, + ], + "type": "Keyword", + "value": "static", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 2, + }, + "start": Object { + "column": 28, + "line": 2, + }, + }, + "range": Array [ + 42, + 43, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 30, + "line": 2, + }, + "start": Object { + "column": 29, + "line": 2, + }, + }, + "range": Array [ + 43, + 44, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 31, + "line": 2, + }, + "start": Object { + "column": 30, + "line": 2, + }, + }, + "range": Array [ + 44, + 45, + ], + "type": "Punctuator", + "value": "/", + }, + Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 2, + }, + "start": Object { + "column": 31, + "line": 2, + }, + }, + "range": Array [ + 45, + 49, + ], + "type": "Keyword", + "value": "this", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 2, + }, + "start": Object { + "column": 35, + "line": 2, + }, + }, + "range": Array [ + 49, + 50, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 41, + "line": 2, + }, + "start": Object { + "column": 36, + "line": 2, + }, + }, + "range": Array [ + 50, + 55, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 2, + }, + "start": Object { + "column": 41, + "line": 2, + }, + }, + "range": Array [ + 55, + 56, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 49, + "line": 2, + }, + "start": Object { + "column": 42, + "line": 2, + }, + }, + "range": Array [ + 56, + 63, + ], + "type": "Keyword", + "value": "declare", + }, + Object { + "loc": Object { + "end": Object { + "column": 50, + "line": 2, + }, + "start": Object { + "column": 49, + "line": 2, + }, + }, + "range": Array [ + 63, + 64, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 56, + "line": 2, + }, + "start": Object { + "column": 50, + "line": 2, + }, + }, + "range": Array [ + 64, + 70, + ], + "type": "Keyword", + "value": "static", + }, + Object { + "loc": Object { + "end": Object { + "column": 57, + "line": 2, + }, + "start": Object { + "column": 56, + "line": 2, + }, + }, + "range": Array [ + 70, + 71, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 0, + "line": 3, + }, + "start": Object { + "column": 57, + "line": 2, + }, + }, + "range": Array [ + 71, + 72, + ], + "type": "JSXText", + "value": " +", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 72, + 73, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 3, + }, + "start": Object { + "column": 1, + "line": 3, + }, + }, + "range": Array [ + 73, + 74, + ], + "type": "Punctuator", + "value": "/", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "range": Array [ + 74, + 75, + ], + "type": "JSXIdentifier", + "value": "a", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, + }, + "range": Array [ + 75, + 76, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "range": Array [ + 76, + 77, + ], + "type": "JSXIdentifier", + "value": "b", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 3, + }, + "start": Object { + "column": 5, + "line": 3, + }, + }, + "range": Array [ + 77, + 78, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 3, + }, + "start": Object { + "column": 6, + "line": 3, + }, + }, + "range": Array [ + 78, + 79, + ], + "type": "JSXIdentifier", + "value": "c", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 3, + }, + "start": Object { + "column": 7, + "line": 3, + }, + }, + "range": Array [ + 79, + 80, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 80, + 81, + ], + "type": "JSXIdentifier", + "value": "d", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 3, + }, + "start": Object { + "column": 9, + "line": 3, + }, + }, + "range": Array [ + 81, + 82, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 3, + }, + }, + "range": Array [ + 82, + 83, + ], + "type": "JSXIdentifier", + "value": "e", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 3, + }, + "start": Object { + "column": 11, + "line": 3, + }, + }, + "range": Array [ + 83, + 84, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 12, + "line": 3, + }, + }, + "range": Array [ + 84, + 85, + ], + "type": "JSXIdentifier", + "value": "f", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 3, + }, + "start": Object { + "column": 13, + "line": 3, + }, + }, + "range": Array [ + 85, + 86, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 14, + "line": 3, + }, + }, + "range": Array [ + 86, + 87, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`JSX useJSXTextNode: false fixtures/test-content.src 1`] = ` Object { "body": Array [ diff --git a/packages/shared-fixtures/fixtures/jsx/tag-names-with-multi-dots-multi.src.js b/packages/shared-fixtures/fixtures/jsx/tag-names-with-multi-dots-multi.src.js new file mode 100644 index 000000000000..1599e0620cd9 --- /dev/null +++ b/packages/shared-fixtures/fixtures/jsx/tag-names-with-multi-dots-multi.src.js @@ -0,0 +1,3 @@ + + +; diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts index e92f68f968f4..ede45e93fcda 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -284,7 +284,12 @@ tester.addFixturePatternConfig('javascript/unicodeCodePointEscapes'); /* ================================================== */ tester.addFixturePatternConfig('jsx', { - ignore: jsxFilesWithKnownIssues + ignore: jsxFilesWithKnownIssues.concat([ + /** + * ts-estree: nested jsx tag names are not correctly converted + */ + 'tag-names-with-multi-dots-multi' + ]) }); tester.addFixturePatternConfig('jsx-useJSXTextNode'); diff --git a/packages/typescript-estree/tests/lib/__snapshots__/jsx.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/jsx.ts.snap index 1da61ddcac7e..cb1f698c267c 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/jsx.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/jsx.ts.snap @@ -9423,6 +9423,1721 @@ Object { } `; +exports[`JSX useJSXTextNode: false fixtures/tag-names-with-multi-dots-multi.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "children": Array [ + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 16, + ], + "raw": " + ", + "type": "Literal", + "value": " + ", + }, + Object { + "children": Array [], + "closingElement": Object { + "loc": Object { + "end": Object { + "column": 57, + "line": 2, + }, + "start": Object { + "column": 29, + "line": 2, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 56, + "line": 2, + }, + "start": Object { + "column": 31, + "line": 2, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 49, + "line": 2, + }, + "start": Object { + "column": 31, + "line": 2, + }, + }, + "object": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 41, + "line": 2, + }, + "start": Object { + "column": 31, + "line": 2, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 2, + }, + "start": Object { + "column": 31, + "line": 2, + }, + }, + "range": Array [ + 45, + 49, + ], + "type": "ThisExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 41, + "line": 2, + }, + "start": Object { + "column": 36, + "line": 2, + }, + }, + "name": "const", + "range": Array [ + 50, + 55, + ], + "type": "Identifier", + }, + "range": Array [ + 45, + 55, + ], + "type": "MemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 49, + "line": 2, + }, + "start": Object { + "column": 42, + "line": 2, + }, + }, + "name": "declare", + "range": Array [ + 56, + 63, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 45, + 63, + ], + "type": "JSXMemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 56, + "line": 2, + }, + "start": Object { + "column": 50, + "line": 2, + }, + }, + "name": "static", + "range": Array [ + 64, + 70, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 45, + 70, + ], + "type": "JSXMemberExpression", + }, + "range": Array [ + 43, + 71, + ], + "type": "JSXClosingElement", + }, + "loc": Object { + "end": Object { + "column": 57, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "openingElement": Object { + "attributes": Array [], + "loc": Object { + "end": Object { + "column": 29, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, + }, + "object": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, + }, + "range": Array [ + 17, + 21, + ], + "type": "ThisExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "name": "const", + "range": Array [ + 22, + 27, + ], + "type": "Identifier", + }, + "range": Array [ + 17, + 27, + ], + "type": "MemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 2, + }, + "start": Object { + "column": 14, + "line": 2, + }, + }, + "name": "declare", + "range": Array [ + 28, + 35, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 17, + 35, + ], + "type": "JSXMemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 2, + }, + "start": Object { + "column": 22, + "line": 2, + }, + }, + "name": "static", + "range": Array [ + 36, + 42, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 17, + 42, + ], + "type": "JSXMemberExpression", + }, + "range": Array [ + 16, + 43, + ], + "selfClosing": false, + "type": "JSXOpeningElement", + }, + "range": Array [ + 16, + 71, + ], + "type": "JSXElement", + }, + Object { + "loc": Object { + "end": Object { + "column": 0, + "line": 3, + }, + "start": Object { + "column": 57, + "line": 2, + }, + }, + "range": Array [ + 71, + 72, + ], + "raw": " +", + "type": "Literal", + "value": " +", + }, + ], + "closingElement": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "object": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 9, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "object": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 7, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "object": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "name": "a", + "range": Array [ + 74, + 75, + ], + "type": "Identifier", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "name": "b", + "range": Array [ + 76, + 77, + ], + "type": "Identifier", + }, + "range": Array [ + 74, + 77, + ], + "type": "MemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 3, + }, + "start": Object { + "column": 6, + "line": 3, + }, + }, + "name": "c", + "range": Array [ + 78, + 79, + ], + "type": "Identifier", + }, + "range": Array [ + 74, + 79, + ], + "type": "MemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "name": "d", + "range": Array [ + 80, + 81, + ], + "type": "Identifier", + }, + "range": Array [ + 74, + 81, + ], + "type": "MemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 3, + }, + }, + "name": "e", + "range": Array [ + 82, + 83, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 74, + 83, + ], + "type": "JSXMemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 12, + "line": 3, + }, + }, + "name": "f", + "range": Array [ + 84, + 85, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 74, + 85, + ], + "type": "JSXMemberExpression", + }, + "range": Array [ + 72, + 86, + ], + "type": "JSXClosingElement", + }, + "loc": Object { + "end": Object { + "column": 14, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "openingElement": Object { + "attributes": Array [], + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "object": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "object": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "object": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "name": "a", + "range": Array [ + 1, + 2, + ], + "type": "Identifier", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 3, + "line": 1, + }, + }, + "name": "b", + "range": Array [ + 3, + 4, + ], + "type": "Identifier", + }, + "range": Array [ + 1, + 4, + ], + "type": "MemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "name": "c", + "range": Array [ + 5, + 6, + ], + "type": "Identifier", + }, + "range": Array [ + 1, + 6, + ], + "type": "MemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "name": "d", + "range": Array [ + 7, + 8, + ], + "type": "Identifier", + }, + "range": Array [ + 1, + 8, + ], + "type": "MemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "name": "e", + "range": Array [ + 9, + 10, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 1, + 10, + ], + "type": "JSXMemberExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "name": "f", + "range": Array [ + 11, + 12, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 1, + 12, + ], + "type": "JSXMemberExpression", + }, + "range": Array [ + 0, + 13, + ], + "selfClosing": false, + "type": "JSXOpeningElement", + }, + "range": Array [ + 0, + 86, + ], + "type": "JSXElement", + }, + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 87, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 88, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 1, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "range": Array [ + 1, + 2, + ], + "type": "JSXIdentifier", + "value": "a", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 1, + }, + "start": Object { + "column": 2, + "line": 1, + }, + }, + "range": Array [ + 2, + 3, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 3, + "line": 1, + }, + }, + "range": Array [ + 3, + 4, + ], + "type": "JSXIdentifier", + "value": "b", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 5, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 6, + ], + "type": "JSXIdentifier", + "value": "c", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 7, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 8, + ], + "type": "JSXIdentifier", + "value": "d", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "range": Array [ + 8, + 9, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 10, + ], + "type": "JSXIdentifier", + "value": "e", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 12, + ], + "type": "JSXIdentifier", + "value": "f", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, + 13, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 16, + ], + "type": "JSXText", + "value": " + ", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, + }, + "range": Array [ + 17, + 21, + ], + "type": "Keyword", + "value": "this", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "range": Array [ + 21, + 22, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 22, + 27, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "range": Array [ + 27, + 28, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 2, + }, + "start": Object { + "column": 14, + "line": 2, + }, + }, + "range": Array [ + 28, + 35, + ], + "type": "Keyword", + "value": "declare", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 2, + }, + "start": Object { + "column": 21, + "line": 2, + }, + }, + "range": Array [ + 35, + 36, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 2, + }, + "start": Object { + "column": 22, + "line": 2, + }, + }, + "range": Array [ + 36, + 42, + ], + "type": "Keyword", + "value": "static", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 2, + }, + "start": Object { + "column": 28, + "line": 2, + }, + }, + "range": Array [ + 42, + 43, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 30, + "line": 2, + }, + "start": Object { + "column": 29, + "line": 2, + }, + }, + "range": Array [ + 43, + 44, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 31, + "line": 2, + }, + "start": Object { + "column": 30, + "line": 2, + }, + }, + "range": Array [ + 44, + 45, + ], + "type": "Punctuator", + "value": "/", + }, + Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 2, + }, + "start": Object { + "column": 31, + "line": 2, + }, + }, + "range": Array [ + 45, + 49, + ], + "type": "Keyword", + "value": "this", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 2, + }, + "start": Object { + "column": 35, + "line": 2, + }, + }, + "range": Array [ + 49, + 50, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 41, + "line": 2, + }, + "start": Object { + "column": 36, + "line": 2, + }, + }, + "range": Array [ + 50, + 55, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 2, + }, + "start": Object { + "column": 41, + "line": 2, + }, + }, + "range": Array [ + 55, + 56, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 49, + "line": 2, + }, + "start": Object { + "column": 42, + "line": 2, + }, + }, + "range": Array [ + 56, + 63, + ], + "type": "Keyword", + "value": "declare", + }, + Object { + "loc": Object { + "end": Object { + "column": 50, + "line": 2, + }, + "start": Object { + "column": 49, + "line": 2, + }, + }, + "range": Array [ + 63, + 64, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 56, + "line": 2, + }, + "start": Object { + "column": 50, + "line": 2, + }, + }, + "range": Array [ + 64, + 70, + ], + "type": "Keyword", + "value": "static", + }, + Object { + "loc": Object { + "end": Object { + "column": 57, + "line": 2, + }, + "start": Object { + "column": 56, + "line": 2, + }, + }, + "range": Array [ + 70, + 71, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 0, + "line": 3, + }, + "start": Object { + "column": 57, + "line": 2, + }, + }, + "range": Array [ + 71, + 72, + ], + "type": "JSXText", + "value": " +", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 72, + 73, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 3, + }, + "start": Object { + "column": 1, + "line": 3, + }, + }, + "range": Array [ + 73, + 74, + ], + "type": "Punctuator", + "value": "/", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "range": Array [ + 74, + 75, + ], + "type": "JSXIdentifier", + "value": "a", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, + }, + "range": Array [ + 75, + 76, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "range": Array [ + 76, + 77, + ], + "type": "JSXIdentifier", + "value": "b", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 3, + }, + "start": Object { + "column": 5, + "line": 3, + }, + }, + "range": Array [ + 77, + 78, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 3, + }, + "start": Object { + "column": 6, + "line": 3, + }, + }, + "range": Array [ + 78, + 79, + ], + "type": "JSXIdentifier", + "value": "c", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 3, + }, + "start": Object { + "column": 7, + "line": 3, + }, + }, + "range": Array [ + 79, + 80, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 80, + 81, + ], + "type": "JSXIdentifier", + "value": "d", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 3, + }, + "start": Object { + "column": 9, + "line": 3, + }, + }, + "range": Array [ + 81, + 82, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 3, + }, + }, + "range": Array [ + 82, + 83, + ], + "type": "JSXIdentifier", + "value": "e", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 3, + }, + "start": Object { + "column": 11, + "line": 3, + }, + }, + "range": Array [ + 83, + 84, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 12, + "line": 3, + }, + }, + "range": Array [ + 84, + 85, + ], + "type": "JSXIdentifier", + "value": "f", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 3, + }, + "start": Object { + "column": 13, + "line": 3, + }, + }, + "range": Array [ + 85, + 86, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 14, + "line": 3, + }, + }, + "range": Array [ + 86, + 87, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`JSX useJSXTextNode: false fixtures/test-content.src 1`] = ` Object { "body": Array [ diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap index a0cc4cb96444..842757edb3df 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap @@ -1798,6 +1798,15 @@ Object { } `; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/tag-names-with-multi-dots-multi.src 1`] = ` +Object { + "column": 7, + "index": 21, + "lineNumber": 2, + "message": "'>' expected.", +} +`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/test-content.src 1`] = ` Object { "column": 5, From bf13399ce05275a21d95bfea327eb9b0356c8e2c Mon Sep 17 00:00:00 2001 From: Kanitkorn Sujautra Date: Mon, 4 Feb 2019 04:15:23 +0900 Subject: [PATCH 07/26] docs(eslint-plugin): add missing rule and remove duplicate rule (#200) * add missing restrict-plus-operands * remove duplicate rule function-name --- packages/eslint-plugin/ROADMAP.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin/ROADMAP.md b/packages/eslint-plugin/ROADMAP.md index f26d0e80175c..bd0480101cf1 100644 --- a/packages/eslint-plugin/ROADMAP.md +++ b/packages/eslint-plugin/ROADMAP.md @@ -1,10 +1,10 @@ # Roadmap -✅ (28) = done
+✅ (29) = done
🌟 (79) = in ESLint core
🔌 (33) = in another plugin
🌓 (16) = implementations differ or ESLint version is missing functionality
-🛑 (70) = unimplemented +🛑 (68) = unimplemented ## TSLint rules @@ -87,7 +87,7 @@ | [`prefer-conditional-expression`] | 🛑 | N/A | | [`prefer-object-spread`] | 🌟 | [`prefer-object-spread`][prefer-object-spread] | | [`radix`] | 🌟 | [`radix`][radix] | -| [`restrict-plus-operands`] | 🛑 | N/A | +| [`restrict-plus-operands`] | ✅ | [`@typescript-eslint/restrict-plus-operands`] | | [`strict-boolean-expressions`] | 🛑 | N/A | | [`strict-type-predicates`] | 🛑 | N/A | | [`switch-default`] | 🌟 | [`default-case`][default-case] | @@ -214,7 +214,6 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint- | `export-name` | 🛑 | N/A ([relevant plugin][plugin:import]) | | `function-name` | 🛑 | N/A | | `import-name` | 🛑 | N/A ([relevant plugin][plugin:import]) | -| `function-name` | 🛑 | N/A | | `informative-docs` | 🛑 | N/A | | `insecure-random` | 🔌 | [custom implementation][insecure-random] | | `max-func-body-length` | 🌟 | [`max-statements`][max-statements] | @@ -577,6 +576,7 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint- [`@typescript-eslint/no-extraneous-class`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extraneous-class.md [`@typescript-eslint/no-unused-vars`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md [`@typescript-eslint/no-use-before-define`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-use-before-define.md +[`@typescript-eslint/restrict-plus-operands`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/restrict-plus-operands.md [`@typescript-eslint/indent`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/indent.md [`@typescript-eslint/array-type`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md [`@typescript-eslint/class-name-casing`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/class-name-casing.md From 773723b4e38e7b33f43fff0c9e4a109742ebb332 Mon Sep 17 00:00:00 2001 From: Armano Date: Sun, 3 Feb 2019 21:32:51 +0100 Subject: [PATCH 08/26] refactor(ts-estree): add types to converter (#156) --- .../typescript-estree/src/ast-converter.ts | 27 +- .../typescript-estree/src/convert-comments.ts | 55 +- packages/typescript-estree/src/convert.ts | 3903 ++++++++--------- .../src/estree/experimental.ts | 30 - .../src/estree/extensions.ts | 63 - packages/typescript-estree/src/estree/spec.ts | 985 ----- packages/typescript-estree/src/node-utils.ts | 228 +- .../typescript-estree/src/parser-options.ts | 35 + packages/typescript-estree/src/parser.ts | 44 +- .../src/temp-types-based-on-js-source.ts | 106 - .../typescript-estree/src/tsconfig-parser.ts | 25 +- packages/typescript-estree/src/typedefs.ts | 1409 ++++++ .../typescript-estree/tests/lib/comments.ts | 2 +- .../typescript-estree/tests/lib/javascript.ts | 2 +- packages/typescript-estree/tests/lib/jsx.ts | 2 +- packages/typescript-estree/tests/lib/parse.ts | 2 +- .../tests/lib/semanticInfo.ts | 2 +- packages/typescript-estree/tests/lib/tsx.ts | 2 +- .../typescript-estree/tests/lib/typescript.ts | 2 +- .../typescript-estree/tools/test-utils.ts | 2 +- 20 files changed, 3568 insertions(+), 3358 deletions(-) delete mode 100644 packages/typescript-estree/src/estree/experimental.ts delete mode 100644 packages/typescript-estree/src/estree/extensions.ts delete mode 100644 packages/typescript-estree/src/estree/spec.ts create mode 100644 packages/typescript-estree/src/parser-options.ts delete mode 100644 packages/typescript-estree/src/temp-types-based-on-js-source.ts create mode 100644 packages/typescript-estree/src/typedefs.ts diff --git a/packages/typescript-estree/src/ast-converter.ts b/packages/typescript-estree/src/ast-converter.ts index 13d2212c5c4f..131539a981b8 100644 --- a/packages/typescript-estree/src/ast-converter.ts +++ b/packages/typescript-estree/src/ast-converter.ts @@ -5,11 +5,11 @@ * @copyright jQuery Foundation and other contributors, https://jquery.org/ * MIT License */ -import convert, { getASTMaps, resetASTMaps, convertError } from './convert'; +import { convertError, Converter } from './convert'; import { convertComments } from './convert-comments'; import { convertTokens } from './node-utils'; import ts from 'typescript'; -import { Extra } from './temp-types-based-on-js-source'; +import { Extra } from './parser-options'; export default function astConverter( ast: ts.SourceFile, @@ -27,17 +27,14 @@ export default function astConverter( /** * Recursively convert the TypeScript AST into an ESTree-compatible AST */ - const estree: any = convert({ - node: ast, - parent: null, - ast, - additionalOptions: { - errorOnUnknownASTType: extra.errorOnUnknownASTType || false, - useJSXTextNode: extra.useJSXTextNode || false, - shouldProvideParserServices - } + const instance = new Converter(ast, { + errorOnUnknownASTType: extra.errorOnUnknownASTType || false, + useJSXTextNode: extra.useJSXTextNode || false, + shouldProvideParserServices }); + const estree = instance.convertProgram(); + /** * Optionally convert and include all tokens in the AST */ @@ -52,11 +49,9 @@ export default function astConverter( estree.comments = convertComments(ast, extra.code); } - let astMaps = undefined; - if (shouldProvideParserServices) { - astMaps = getASTMaps(); - resetASTMaps(); - } + const astMaps = shouldProvideParserServices + ? instance.getASTMaps() + : undefined; return { estree, astMaps }; } diff --git a/packages/typescript-estree/src/convert-comments.ts b/packages/typescript-estree/src/convert-comments.ts index ac7f8504d8aa..59a2326122c8 100644 --- a/packages/typescript-estree/src/convert-comments.ts +++ b/packages/typescript-estree/src/convert-comments.ts @@ -7,31 +7,28 @@ import ts from 'typescript'; import { getLocFor, getNodeContainer } from './node-utils'; -import { - ESTreeComment, - LineAndColumnData -} from './temp-types-based-on-js-source'; +import * as es from './typedefs'; /** * Converts a TypeScript comment to an Esprima comment. - * @param {boolean} block True if it's a block comment, false if not. - * @param {string} text The text of the comment. - * @param {number} start The index at which the comment starts. - * @param {number} end The index at which the comment ends. - * @param {LineAndColumnData} startLoc The location at which the comment starts. - * @param {LineAndColumnData} endLoc The location at which the comment ends. - * @returns {Object} The comment object. - * @private + * @param block True if it's a block comment, false if not. + * @param text The text of the comment. + * @param start The index at which the comment starts. + * @param end The index at which the comment ends. + * @param startLoc The location at which the comment starts. + * @param endLoc The location at which the comment ends. + * @returns The comment object. + * @internal */ function convertTypeScriptCommentToEsprimaComment( block: boolean, text: string, start: number, end: number, - startLoc: LineAndColumnData, - endLoc: LineAndColumnData -): ESTreeComment { - const comment: ESTreeComment = { + startLoc: es.LineAndColumnData, + endLoc: es.LineAndColumnData +): es.Comment { + const comment: es.OptionalRangeAndLoc = { type: block ? 'Block' : 'Line', value: text }; @@ -47,22 +44,22 @@ function convertTypeScriptCommentToEsprimaComment( }; } - return comment; + return comment as es.Comment; } /** * Convert comment from TypeScript Triva Scanner. - * @param {ts.Scanner} triviaScanner TS Scanner - * @param {ts.SourceFile} ast the AST object - * @param {string} code TypeScript code - * @returns {ESTreeComment} the converted ESTreeComment + * @param triviaScanner TS Scanner + * @param ast the AST object + * @param code TypeScript code + * @returns the converted Comment * @private */ function getCommentFromTriviaScanner( triviaScanner: ts.Scanner, ast: ts.SourceFile, code: string -): ESTreeComment { +): es.Comment { const kind = triviaScanner.getToken(); const isBlock = kind === ts.SyntaxKind.MultiLineCommentTrivia; const range = { @@ -77,7 +74,7 @@ function getCommentFromTriviaScanner( : comment.replace(/^\/\//, ''); const loc = getLocFor(range.pos, range.end, ast); - const esprimaComment = convertTypeScriptCommentToEsprimaComment( + return convertTypeScriptCommentToEsprimaComment( isBlock, text, range.pos, @@ -85,22 +82,20 @@ function getCommentFromTriviaScanner( loc.start, loc.end ); - - return esprimaComment; } /** * Convert all comments for the given AST. - * @param {ts.SourceFile} ast the AST object - * @param {string} code the TypeScript code - * @returns {ESTreeComment[]} the converted ESTreeComment + * @param ast the AST object + * @param code the TypeScript code + * @returns the converted ESTreeComment * @private */ export function convertComments( ast: ts.SourceFile, code: string -): ESTreeComment[] { - const comments: ESTreeComment[] = []; +): es.Comment[] { + const comments: es.Comment[] = []; /** * Create a TypeScript Scanner, with skipTrivia set to false so that diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 9a7adebc8e2e..8e2d6a876a15 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -6,65 +6,44 @@ * MIT License */ import ts from 'typescript'; +import * as es from './typedefs'; import { canContainDirective, + convertToken, createError, - getLoc, - getLocFor, findNextToken, - convertToken, - hasModifier, fixExports, - getTSNodeAccessibility, + getBinaryExpressionType, + getDeclarationKind, + getLastModifier, + getLineAndCharacterFor, + getLocFor, + getRange, getTextForTokenKind, - isJSXToken, + getTSNodeAccessibility, + hasModifier, + isComma, isComputedProperty, isESTreeClassMember, - isComma, - getBinaryExpressionType, + isJSXToken, isOptional, - unescapeStringLiteralText, - getDeclarationKind, - getLastModifier, - getLineAndCharacterFor + unescapeStringLiteralText } from './node-utils'; import { AST_NODE_TYPES } from './ast-node-types'; -import { ESTreeNode } from './temp-types-based-on-js-source'; import { TSNode } from './ts-nodes'; const SyntaxKind = ts.SyntaxKind; -let esTreeNodeToTSNodeMap = new WeakMap(); -let tsNodeToESTreeNodeMap = new WeakMap(); - -export function resetASTMaps() { - esTreeNodeToTSNodeMap = new WeakMap(); - tsNodeToESTreeNodeMap = new WeakMap(); -} - -export function getASTMaps() { - return { esTreeNodeToTSNodeMap, tsNodeToESTreeNodeMap }; -} - -interface ConvertAdditionalOptions { +interface ConverterOptions { errorOnUnknownASTType: boolean; useJSXTextNode: boolean; shouldProvideParserServices: boolean; } -interface ConvertConfig { - node: ts.Node; - parent?: ts.Node | null; - inTypeMode?: boolean; - allowPattern?: boolean; - ast: ts.SourceFile; - additionalOptions: ConvertAdditionalOptions; -} - /** * Extends and formats a given error object - * @param {Object} error the error object - * @returns {Object} converted error object + * @param error the error object + * @returns converted error object */ export function convertError(error: any) { return createError( @@ -74,121 +53,171 @@ export function convertError(error: any) { ); } -/** - * Converts a TypeScript node into an ESTree node - * @param {Object} config configuration options for the conversion - * @param {TSNode} config.node the ts.Node - * @param {ts.Node} config.parent the parent ts.Node - * @param {ts.SourceFile} config.ast the full TypeScript AST - * @param {Object} config.additionalOptions additional options for the conversion - * @returns {ESTreeNode|null} the converted ESTreeNode - */ -export default function convert(config: ConvertConfig): ESTreeNode | null { - const node: TSNode = config.node as TSNode; - const parent = config.parent; - const ast = config.ast; - const additionalOptions = config.additionalOptions || {}; +export class Converter { + private readonly ast: ts.SourceFile; + private options: ConverterOptions; + private esTreeNodeToTSNodeMap = new WeakMap(); + private tsNodeToESTreeNodeMap = new WeakMap(); + + private allowPattern: boolean = false; + private inTypeMode: boolean = false; /** - * Exit early for null and undefined + * Converts a TypeScript node into an ESTree node + * @param ast the full TypeScript AST + * @param options additional options for the conversion + * @returns the converted ESTreeNode */ - if (!node) { - return null; + constructor(ast: ts.SourceFile, options: ConverterOptions) { + this.ast = ast; + this.options = options; + } + + getASTMaps() { + return { + esTreeNodeToTSNodeMap: this.esTreeNodeToTSNodeMap, + tsNodeToESTreeNodeMap: this.tsNodeToESTreeNodeMap + }; + } + + convertProgram(): es.Program { + return this.converter(this.ast) as es.Program; } /** - * Create a new ESTree node + * Converts a TypeScript node into an ESTree node. + * @param node the child ts.Node + * @param parent parentNode + * @param inTypeMode flag to determine if we are in typeMode + * @param allowPattern flag to determine if patterns are allowed + * @returns the converted ESTree node */ - let result: ESTreeNode = { - type: '' as AST_NODE_TYPES, - range: [node.getStart(ast), node.end], - loc: getLoc(node, ast) - }; - - function converter( - child?: ts.Node, + private converter( + node?: ts.Node, + parent?: ts.Node, inTypeMode?: boolean, allowPattern?: boolean - ): ESTreeNode | null { - if (!child) { + ): any { + /** + * Exit early for null and undefined + */ + if (!node) { return null; } - return convert({ - node: child, - parent: node, - inTypeMode, - allowPattern, - ast, - additionalOptions - }); + + const typeMode = this.inTypeMode; + const pattern = this.allowPattern; + if (inTypeMode !== undefined) { + this.inTypeMode = inTypeMode; + } + if (allowPattern !== undefined) { + this.allowPattern = allowPattern; + } + + let result: es.BaseNode | null = this.convertNode( + node as TSNode, + parent || node.parent + ); + + if (result && this.options.shouldProvideParserServices) { + this.tsNodeToESTreeNodeMap.set(node, result); + this.esTreeNodeToTSNodeMap.set(result, node); + } + + this.inTypeMode = typeMode; + this.allowPattern = pattern; + return result; } /** * Converts a TypeScript node into an ESTree node. - * @param {ts.Node} child the child ts.Node - * @returns {ESTreeNode|null} the converted ESTree node + * @param child the child ts.Node + * @param parent parentNode + * @returns the converted ESTree node */ - function convertPattern(child?: ts.Node): ESTreeNode | null { - return converter(child, config.inTypeMode, true); + private convertPattern(child?: ts.Node, parent?: ts.Node): any | null { + return this.converter(child, parent, this.inTypeMode, true); } /** * Converts a TypeScript node into an ESTree node. - * @param {ts.Node} child the child ts.Node - * @returns {ESTreeNode|null} the converted ESTree node + * @param child the child ts.Node + * @param parent parentNode + * @returns the converted ESTree node */ - function convertChild(child?: ts.Node): ESTreeNode | null { - return converter(child, config.inTypeMode, false); + private convertChild(child?: ts.Node, parent?: ts.Node): any | null { + return this.converter(child, parent, this.inTypeMode, false); } /** * Converts a TypeScript node into an ESTree node. - * @param {ts.Node} child the child ts.Node - * @returns {ESTreeNode|null} the converted ESTree node + * @param child the child ts.Node + * @param parent parentNode + * @returns the converted ESTree node */ - function convertChildType(child?: ts.Node): ESTreeNode | null { - return converter(child, true, false); + private convertType(child?: ts.Node, parent?: ts.Node): any | null { + return this.converter(child, parent, true, false); + } + + private createNode( + node: ts.Node, + data: es.OptionalRangeAndLoc + ): T { + const result = data; + if (!result.range) { + result.range = getRange(node, this.ast); + } + if (!result.loc) { + result.loc = getLocFor(result.range[0], result.range[1], this.ast); + } + + return result as T; } /** * Converts a child into a type annotation. This creates an intermediary * TypeAnnotation node to match what Flow does. - * @param {ts.TypeNode} child The TypeScript AST node to convert. - * @returns {ESTreeNode} The type annotation node. + * @param child The TypeScript AST node to convert. + * @param parent parentNode + * @returns The type annotation node. */ - function convertTypeAnnotation(child: ts.TypeNode): ESTreeNode { - const annotation = convertChildType(child); + private convertTypeAnnotation( + child: ts.TypeNode, + parent: ts.Node + ): es.TSTypeAnnotation { // in FunctionType and ConstructorType typeAnnotation has 2 characters `=>` and in other places is just colon const offset = - node.kind === SyntaxKind.FunctionType || - node.kind === SyntaxKind.ConstructorType + parent.kind === SyntaxKind.FunctionType || + parent.kind === SyntaxKind.ConstructorType ? 2 : 1; const annotationStartCol = child.getFullStart() - offset; - const loc = getLocFor(annotationStartCol, child.end, ast); + const loc = getLocFor(annotationStartCol, child.end, this.ast); return { type: AST_NODE_TYPES.TSTypeAnnotation, loc, range: [annotationStartCol, child.end], - typeAnnotation: annotation + typeAnnotation: this.convertType(child) }; } /** * Coverts body Nodes and add directive field to StringLiterals - * @param {ts.NodeArray} nodes of ts.Node - * @returns {ESTreeNode[]} Array of body statements + * @param nodes of ts.Node + * @param parent parentNode + * @returns Array of body statements */ - function convertBodyExpressions( - nodes: ts.NodeArray - ): ESTreeNode[] { - let allowDirectives = canContainDirective(node); + private convertBodyExpressions( + nodes: ts.NodeArray, + parent: ts.Node + ): any[] { + let allowDirectives = canContainDirective(parent); return ( nodes .map(statement => { - const child = convertChild(statement); + const child = this.convertChild(statement); if (allowDirectives) { if ( child && @@ -196,14 +225,14 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { ts.isExpressionStatement(statement) && ts.isStringLiteral(statement.expression) ) { - const raw = child.expression.raw!; + const raw = child.expression.raw; child.directive = raw.slice(1, -1); - return child!; // child can be null but it's filtered below + return child; // child can be null but it's filtered below } else { allowDirectives = false; } } - return child!; // child can be null but it's filtered below + return child; // child can be null but it's filtered below }) // filter out unknown nodes for now .filter(statement => statement) @@ -212,58 +241,60 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { /** * Converts a ts.Node's typeArguments to TSTypeParameterInstantiation node - * @param {ts.NodeArray} typeArguments ts.Node typeArguments - * @returns {ESTreeNode} TypeParameterInstantiation node + * @param typeArguments ts.Node typeArguments + * @returns TypeParameterInstantiation node */ - function convertTypeArgumentsToTypeParameters( - typeArguments: ts.NodeArray - ): ESTreeNode { - const greaterThanToken = findNextToken(typeArguments, ast, ast)!; + private convertTypeArgumentsToTypeParameters( + typeArguments: ts.NodeArray + ): es.TSTypeParameterInstantiation { + const greaterThanToken = findNextToken(typeArguments, this.ast, this.ast)!; return { type: AST_NODE_TYPES.TSTypeParameterInstantiation, range: [typeArguments.pos - 1, greaterThanToken.end], - loc: getLocFor(typeArguments.pos - 1, greaterThanToken.end, ast), - params: typeArguments.map(typeArgument => convertChildType(typeArgument)) + loc: getLocFor(typeArguments.pos - 1, greaterThanToken.end, this.ast), + params: typeArguments.map(typeArgument => this.convertType(typeArgument)) }; } /** * Converts a ts.Node's typeParameters to TSTypeParameterDeclaration node - * @param {ts.NodeArray} typeParameters ts.Node typeParameters - * @returns {ESTreeNode} TypeParameterDeclaration node + * @param typeParameters ts.Node typeParameters + * @returns TypeParameterDeclaration node */ - function convertTSTypeParametersToTypeParametersDeclaration( - typeParameters: ts.NodeArray - ): ESTreeNode { - const greaterThanToken = findNextToken(typeParameters, ast, ast)!; + private convertTSTypeParametersToTypeParametersDeclaration( + typeParameters: ts.NodeArray + ): es.TSTypeParameterDeclaration { + const greaterThanToken = findNextToken(typeParameters, this.ast, this.ast)!; return { type: AST_NODE_TYPES.TSTypeParameterDeclaration, range: [typeParameters.pos - 1, greaterThanToken.end], - loc: getLocFor(typeParameters.pos - 1, greaterThanToken.end, ast), + loc: getLocFor(typeParameters.pos - 1, greaterThanToken.end, this.ast), params: typeParameters.map(typeParameter => - convertChildType(typeParameter) + this.convertType(typeParameter) ) }; } /** * Converts an array of ts.Node parameters into an array of ESTreeNode params - * @param {ts.Node[]} parameters An array of ts.Node params to be converted - * @returns {ESTreeNode[]} an array of converted ESTreeNode params + * @param parameters An array of ts.Node params to be converted + * @returns an array of converted ESTreeNode params */ - function convertParameters(parameters: ts.NodeArray): ESTreeNode[] { + private convertParameters( + parameters: ts.NodeArray + ): (es.TSParameterProperty | es.RestElement | es.AssignmentPattern)[] { if (!parameters || !parameters.length) { return []; } return parameters.map(param => { - const convertedParam = convertChild(param)!; + const convertedParam = this.convertChild(param); if (!param.decorators || !param.decorators.length) { return convertedParam; } return Object.assign(convertedParam, { - decorators: param.decorators.map(convertChild) + decorators: param.decorators.map(el => this.convertChild(el)) }); }); } @@ -272,21 +303,20 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { * For nodes that are copied directly from the TypeScript AST into * ESTree mostly as-is. The only difference is the addition of a type * property instead of a kind property. Recursively copies all children. - * @returns {void} */ - function deeplyCopy(): void { + private deeplyCopy(node: ts.Node): any { const customType = `TS${SyntaxKind[node.kind]}` as AST_NODE_TYPES; /** * If the "errorOnUnknownASTType" option is set to true, throw an error, * otherwise fallback to just including the unknown type as-is. */ - if ( - additionalOptions.errorOnUnknownASTType && - !AST_NODE_TYPES[customType] - ) { + if (this.options.errorOnUnknownASTType && !AST_NODE_TYPES[customType]) { throw new Error(`Unknown AST_NODE_TYPE: "${customType}"`); } - result.type = customType; + const result = this.createNode(node, { + type: customType + }); + Object.keys(node) .filter( key => @@ -297,83 +327,105 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { .forEach(key => { if (key === 'type') { result.typeAnnotation = (node as any).type - ? convertTypeAnnotation((node as any).type) + ? this.convertTypeAnnotation((node as any).type, node) : null; } else if (key === 'typeArguments') { result.typeParameters = (node as any).typeArguments - ? convertTypeArgumentsToTypeParameters((node as any).typeArguments) + ? this.convertTypeArgumentsToTypeParameters( + (node as any).typeArguments + ) : null; } else if (key === 'typeParameters') { result.typeParameters = (node as any).typeParameters - ? convertTSTypeParametersToTypeParametersDeclaration( + ? this.convertTSTypeParametersToTypeParametersDeclaration( (node as any).typeParameters ) : null; } else if (key === 'decorators') { if (node.decorators && node.decorators.length) { - result.decorators = node.decorators.map(convertChild); + result.decorators = node.decorators.map((el: any) => + this.convertChild(el) + ); } } else { if (Array.isArray((node as any)[key])) { - (result as any)[key] = (node as any)[key].map(convertChild); + result[key] = (node as any)[key].map((el: any) => + this.convertChild(el) + ); } else if ( (node as any)[key] && typeof (node as any)[key] === 'object' && (node as any)[key].kind ) { // need to check node[key].kind to ensure we don't try to convert a symbol - (result as any)[key] = convertChild((node as any)[key]); + result[key] = this.convertChild((node as any)[key]); } else { - (result as any)[key] = (node as any)[key]; + result[key] = (node as any)[key]; } } }); + return result; } /** * Converts a TypeScript JSX node.tagName into an ESTree node.name - * @param {ts.JsxTagNameExpression} tagName the tagName object from a JSX ts.Node - * @returns {Object} the converted ESTree name object + * @param tagName the tagName object from a JSX ts.Node + * @param parent + * @returns the converted ESTree name object */ - function convertTypeScriptJSXTagNameToESTreeName( - tagName: ts.JsxTagNameExpression - ): ESTreeNode { - const tagNameToken = convertToken(tagName, ast); - - if (tagNameToken.type === AST_NODE_TYPES.JSXMemberExpression) { + private convertTypeScriptJSXTagNameToESTreeName( + tagName: ts.JsxTagNameExpression, + parent: ts.Node + ): es.JSXMemberExpression | es.JSXIdentifier { + // TODO: remove convertToken call + const tagNameToken = convertToken(tagName, this.ast); + + if (tagName.kind === SyntaxKind.PropertyAccessExpression) { const isNestedMemberExpression = - (node as any).tagName.expression.kind === - SyntaxKind.PropertyAccessExpression; + tagName.expression.kind === SyntaxKind.PropertyAccessExpression; // Convert TSNode left and right objects into ESTreeNode object // and property objects - tagNameToken.object = convertChild((node as any).tagName.expression); - tagNameToken.property = convertChild((node as any).tagName.name); + const object = this.convertChild(tagName.expression, parent); + const property = this.convertChild(tagName.name, parent); // Assign the appropriate types - tagNameToken.object.type = isNestedMemberExpression + object.type = isNestedMemberExpression ? AST_NODE_TYPES.JSXMemberExpression : AST_NODE_TYPES.JSXIdentifier; - tagNameToken.property.type = AST_NODE_TYPES.JSXIdentifier; + property.type = AST_NODE_TYPES.JSXIdentifier; if ((tagName as any).expression.kind === SyntaxKind.ThisKeyword) { - tagNameToken.object.name = 'this'; + object.name = 'this'; } + + return this.createNode(tagName, { + type: AST_NODE_TYPES.JSXMemberExpression, + range: tagNameToken.range, + loc: tagNameToken.loc, + object: object, + property: property + }); } else { - tagNameToken.type = AST_NODE_TYPES.JSXIdentifier; - tagNameToken.name = tagNameToken.value; + return this.createNode(tagName, { + type: AST_NODE_TYPES.JSXIdentifier, + range: tagNameToken.range, + loc: tagNameToken.loc, + name: tagNameToken.value + }); } - - delete tagNameToken.value; - - return tagNameToken; } /** * Applies the given TS modifiers to the given result object. - * @param {ts.ModifiersArray} modifiers original ts.Nodes from the node.modifiers array - * @returns {void} (the current result object will be mutated) + * @param result + * @param modifiers original ts.Nodes from the node.modifiers array + * @returns the current result object will be mutated + * @deprecated This method adds not standardized `modifiers` property in nodes */ - function applyModifiersToResult(modifiers?: ts.ModifiersArray): void { + private applyModifiersToResult( + result: es.TSEnumDeclaration | es.TSModuleDeclaration, + modifiers?: ts.ModifiersArray + ): void { if (!modifiers || !modifiers.length) { return; } @@ -396,7 +448,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { handledModifierIndices[i] = true; break; case SyntaxKind.ConstKeyword: - result.const = true; + (result as any).const = true; handledModifierIndices[i] = true; break; case SyntaxKind.DeclareKeyword: @@ -417,2091 +469,2022 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { if (!remainingModifiers || !remainingModifiers.length) { return; } - result.modifiers = remainingModifiers.map(convertChild); + result.modifiers = remainingModifiers.map(el => this.convertChild(el)); } /** * Uses the current TSNode's end location for its `type` to adjust the location data of the given * ESTreeNode, which should be the parent of the final typeAnnotation node - * @param {ESTreeNode} typeAnnotationParent The node that will have its location data mutated - * @returns {void} + * @param typeAnnotationParent The node that will have its location data mutated + * @param node */ - function fixTypeAnnotationParentLocation( - typeAnnotationParent: ESTreeNode + private fixTypeAnnotationParentLocation( + typeAnnotationParent: es.BaseNode, + node: ts.TypeNode ): void { - typeAnnotationParent.range[1] = (node as any).type.getEnd(); - typeAnnotationParent.loc = getLocFor( - typeAnnotationParent.range[0], + typeAnnotationParent.range[1] = node.getEnd(); + typeAnnotationParent.loc.end = getLineAndCharacterFor( typeAnnotationParent.range[1], - ast + this.ast ); } /** + * Converts a TypeScript node into an ESTree node. * The core of the conversion logic: * Identify and convert each relevant TypeScript SyntaxKind + * @param node the child ts.Node + * @param parent parentNode + * @returns the converted ESTree node */ - switch (node.kind) { - case SyntaxKind.SourceFile: - Object.assign(result, { - type: AST_NODE_TYPES.Program, - body: convertBodyExpressions(node.statements), - // externalModuleIndicator is internal field in TSC - sourceType: (node as any).externalModuleIndicator ? 'module' : 'script' - }); + private convertNode(node: TSNode, parent: ts.Node): es.Node | null { + switch (node.kind) { + case SyntaxKind.SourceFile: { + return this.createNode(node, { + type: AST_NODE_TYPES.Program, + body: this.convertBodyExpressions(node.statements, node), + // externalModuleIndicator is internal field in TSC + sourceType: (node as any).externalModuleIndicator + ? 'module' + : 'script', + range: [node.getStart(this.ast), node.endOfFileToken.end] + }); + } - result.range[1] = node.endOfFileToken.end; - result.loc = getLocFor(node.getStart(ast), result.range[1], ast); - break; + case SyntaxKind.Block: { + return this.createNode(node, { + type: AST_NODE_TYPES.BlockStatement, + body: this.convertBodyExpressions(node.statements, node) + }); + } - case SyntaxKind.Block: - Object.assign(result, { - type: AST_NODE_TYPES.BlockStatement, - body: convertBodyExpressions(node.statements) - }); - break; + case SyntaxKind.Identifier: { + return this.createNode(node, { + type: AST_NODE_TYPES.Identifier, + name: node.text + }); + } - case SyntaxKind.Identifier: - Object.assign(result, { - type: AST_NODE_TYPES.Identifier, - name: node.text - }); - break; + case SyntaxKind.WithStatement: + return this.createNode(node, { + type: AST_NODE_TYPES.WithStatement, + object: this.convertChild(node.expression), + body: this.convertChild(node.statement) + }); - case SyntaxKind.WithStatement: - Object.assign(result, { - type: AST_NODE_TYPES.WithStatement, - object: convertChild(node.expression), - body: convertChild(node.statement) - }); - break; + // Control Flow - // Control Flow + case SyntaxKind.ReturnStatement: + return this.createNode(node, { + type: AST_NODE_TYPES.ReturnStatement, + argument: this.convertChild(node.expression) + }); - case SyntaxKind.ReturnStatement: - Object.assign(result, { - type: AST_NODE_TYPES.ReturnStatement, - argument: convertChild(node.expression) - }); - break; + case SyntaxKind.LabeledStatement: + return this.createNode(node, { + type: AST_NODE_TYPES.LabeledStatement, + label: this.convertChild(node.label), + body: this.convertChild(node.statement) + }); - case SyntaxKind.LabeledStatement: - Object.assign(result, { - type: AST_NODE_TYPES.LabeledStatement, - label: convertChild(node.label), - body: convertChild(node.statement) - }); - break; + case SyntaxKind.ContinueStatement: + return this.createNode(node, { + type: AST_NODE_TYPES.ContinueStatement, + label: this.convertChild(node.label) + }); - case SyntaxKind.BreakStatement: - case SyntaxKind.ContinueStatement: - Object.assign(result, { - type: SyntaxKind[node.kind], - label: convertChild(node.label) - }); - break; + case SyntaxKind.BreakStatement: + return this.createNode(node, { + type: AST_NODE_TYPES.BreakStatement, + label: this.convertChild(node.label) + }); - // Choice + // Choice - case SyntaxKind.IfStatement: - Object.assign(result, { - type: AST_NODE_TYPES.IfStatement, - test: convertChild(node.expression), - consequent: convertChild(node.thenStatement), - alternate: convertChild(node.elseStatement) - }); - break; + case SyntaxKind.IfStatement: + return this.createNode(node, { + type: AST_NODE_TYPES.IfStatement, + test: this.convertChild(node.expression), + consequent: this.convertChild(node.thenStatement), + alternate: this.convertChild(node.elseStatement) + }); - case SyntaxKind.SwitchStatement: - Object.assign(result, { - type: AST_NODE_TYPES.SwitchStatement, - discriminant: convertChild(node.expression), - cases: node.caseBlock.clauses.map(convertChild) - }); - break; - - case SyntaxKind.CaseClause: - case SyntaxKind.DefaultClause: - Object.assign(result, { - type: AST_NODE_TYPES.SwitchCase, - // expression is present in case only - test: - node.kind === SyntaxKind.CaseClause - ? convertChild(node.expression) - : null, - consequent: node.statements.map(convertChild) - }); - break; + case SyntaxKind.SwitchStatement: + return this.createNode(node, { + type: AST_NODE_TYPES.SwitchStatement, + discriminant: this.convertChild(node.expression), + cases: node.caseBlock.clauses.map(el => this.convertChild(el)) + }); - // Exceptions + case SyntaxKind.CaseClause: + case SyntaxKind.DefaultClause: + return this.createNode(node, { + type: AST_NODE_TYPES.SwitchCase, + // expression is present in case only + test: + node.kind === SyntaxKind.CaseClause + ? this.convertChild(node.expression) + : null, + consequent: node.statements.map(el => this.convertChild(el)) + }); - case SyntaxKind.ThrowStatement: - Object.assign(result, { - type: AST_NODE_TYPES.ThrowStatement, - argument: convertChild(node.expression) - }); - break; - - case SyntaxKind.TryStatement: - Object.assign(result, { - type: AST_NODE_TYPES.TryStatement, - block: convert({ - node: node.tryBlock, - parent: null, - ast, - additionalOptions - }), - handler: convertChild(node.catchClause), - finalizer: convertChild(node.finallyBlock) - }); - break; - - case SyntaxKind.CatchClause: - Object.assign(result, { - type: AST_NODE_TYPES.CatchClause, - param: node.variableDeclaration - ? convertChild(node.variableDeclaration.name) - : null, - body: convertChild(node.block) - }); - break; + // Exceptions - // Loops + case SyntaxKind.ThrowStatement: + return this.createNode(node, { + type: AST_NODE_TYPES.ThrowStatement, + argument: this.convertChild(node.expression) + }); - case SyntaxKind.WhileStatement: - Object.assign(result, { - type: AST_NODE_TYPES.WhileStatement, - test: convertChild(node.expression), - body: convertChild(node.statement) - }); - break; + case SyntaxKind.TryStatement: + return this.createNode(node, { + type: AST_NODE_TYPES.TryStatement, + block: this.convertChild(node.tryBlock), + handler: this.convertChild(node.catchClause), + finalizer: this.convertChild(node.finallyBlock) + }); - /** - * Unlike other parsers, TypeScript calls a "DoWhileStatement" - * a "DoStatement" - */ - case SyntaxKind.DoStatement: - Object.assign(result, { - type: AST_NODE_TYPES.DoWhileStatement, - test: convertChild(node.expression), - body: convertChild(node.statement) - }); - break; - - case SyntaxKind.ForStatement: - Object.assign(result, { - type: AST_NODE_TYPES.ForStatement, - init: convertChild(node.initializer), - test: convertChild(node.condition), - update: convertChild(node.incrementor), - body: convertChild(node.statement) - }); - break; - - case SyntaxKind.ForInStatement: - case SyntaxKind.ForOfStatement: { - Object.assign(result, { - type: SyntaxKind[node.kind], - left: convertPattern(node.initializer), - right: convertChild(node.expression), - body: convertChild(node.statement) - }); + case SyntaxKind.CatchClause: + return this.createNode(node, { + type: AST_NODE_TYPES.CatchClause, + param: node.variableDeclaration + ? this.convertChild(node.variableDeclaration.name) + : null, + body: this.convertChild(node.block) + }); - // await is only available in for of statement - if (node.kind === SyntaxKind.ForOfStatement) { - (result as any).await = Boolean( - node.awaitModifier && - node.awaitModifier.kind === SyntaxKind.AwaitKeyword - ); - } - break; - } + // Loops - // Declarations + case SyntaxKind.WhileStatement: + return this.createNode(node, { + type: AST_NODE_TYPES.WhileStatement, + test: this.convertChild(node.expression), + body: this.convertChild(node.statement) + }); - case SyntaxKind.FunctionDeclaration: { - const isDeclare = hasModifier(SyntaxKind.DeclareKeyword, node); - let functionDeclarationType = AST_NODE_TYPES.FunctionDeclaration; - if (isDeclare || !node.body) { - functionDeclarationType = AST_NODE_TYPES.TSDeclareFunction; - } + /** + * Unlike other parsers, TypeScript calls a "DoWhileStatement" + * a "DoStatement" + */ + case SyntaxKind.DoStatement: + return this.createNode(node, { + type: AST_NODE_TYPES.DoWhileStatement, + test: this.convertChild(node.expression), + body: this.convertChild(node.statement) + }); - Object.assign(result, { - type: functionDeclarationType, - id: convertChild(node.name), - generator: !!node.asteriskToken, - expression: false, - async: hasModifier(SyntaxKind.AsyncKeyword, node), - params: convertParameters(node.parameters), - body: convertChild(node.body) || undefined - }); + case SyntaxKind.ForStatement: + return this.createNode(node, { + type: AST_NODE_TYPES.ForStatement, + init: this.convertChild(node.initializer), + test: this.convertChild(node.condition), + update: this.convertChild(node.incrementor), + body: this.convertChild(node.statement) + }); - // Process returnType - if (node.type) { - result.returnType = convertTypeAnnotation(node.type); - } + case SyntaxKind.ForInStatement: + return this.createNode(node, { + type: AST_NODE_TYPES.ForInStatement, + left: this.convertPattern(node.initializer), + right: this.convertChild(node.expression), + body: this.convertChild(node.statement) + }); - if (isDeclare) { - result.declare = true; - } + case SyntaxKind.ForOfStatement: + return this.createNode(node, { + type: AST_NODE_TYPES.ForOfStatement, + left: this.convertPattern(node.initializer), + right: this.convertChild(node.expression), + body: this.convertChild(node.statement), + await: Boolean( + node.awaitModifier && + node.awaitModifier.kind === SyntaxKind.AwaitKeyword + ) + }); - // Process typeParameters - if (node.typeParameters && node.typeParameters.length) { - result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration( - node.typeParameters - ); - } + // Declarations + + case SyntaxKind.FunctionDeclaration: { + const isDeclare = hasModifier(SyntaxKind.DeclareKeyword, node); + + const result = this.createNode< + es.TSDeclareFunction | es.FunctionDeclaration + >(node, { + type: + isDeclare || !node.body + ? AST_NODE_TYPES.TSDeclareFunction + : AST_NODE_TYPES.FunctionDeclaration, + id: this.convertChild(node.name), + generator: !!node.asteriskToken, + expression: false, + async: hasModifier(SyntaxKind.AsyncKeyword, node), + params: this.convertParameters(node.parameters), + body: this.convertChild(node.body) || undefined + }); - // check for exports - result = fixExports(node, result, ast); + // Process returnType + if (node.type) { + result.returnType = this.convertTypeAnnotation(node.type, node); + } - break; - } + if (isDeclare) { + result.declare = true; + } - case SyntaxKind.VariableDeclaration: { - Object.assign(result, { - type: AST_NODE_TYPES.VariableDeclarator, - id: convertPattern(node.name), - init: convertChild(node.initializer) - }); + // Process typeParameters + if (node.typeParameters && node.typeParameters.length) { + result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( + node.typeParameters + ); + } - if (node.exclamationToken) { - (result as any).definite = true; + // check for exports + return fixExports(node, result, this.ast); } - if (node.type) { - result.id!.typeAnnotation = convertTypeAnnotation(node.type); - fixTypeAnnotationParentLocation(result.id!); - } - break; - } + case SyntaxKind.VariableDeclaration: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.VariableDeclarator, + id: this.convertPattern(node.name), + init: this.convertChild(node.initializer) + }); - case SyntaxKind.VariableStatement: - Object.assign(result, { - type: AST_NODE_TYPES.VariableDeclaration, - declarations: node.declarationList.declarations.map(convertChild), - kind: getDeclarationKind(node.declarationList) - }); + if (node.exclamationToken) { + result.definite = true; + } - if (hasModifier(SyntaxKind.DeclareKeyword, node)) { - result.declare = true; + if (node.type) { + result.id.typeAnnotation = this.convertTypeAnnotation( + node.type, + node + ); + this.fixTypeAnnotationParentLocation(result.id, node.type); + } + return result; } - // check for exports - result = fixExports(node, result, ast); - break; - - // mostly for for-of, for-in - case SyntaxKind.VariableDeclarationList: - Object.assign(result, { - type: AST_NODE_TYPES.VariableDeclaration, - declarations: node.declarations.map(convertChild), - kind: getDeclarationKind(node) - }); - break; - - // Expressions - - case SyntaxKind.ExpressionStatement: - Object.assign(result, { - type: AST_NODE_TYPES.ExpressionStatement, - expression: convertChild(node.expression) - }); - break; + case SyntaxKind.VariableStatement: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.VariableDeclaration, + declarations: node.declarationList.declarations.map(el => + this.convertChild(el) + ), + kind: getDeclarationKind(node.declarationList) + }); - case SyntaxKind.ThisKeyword: - Object.assign(result, { - type: AST_NODE_TYPES.ThisExpression - }); - break; + if (hasModifier(SyntaxKind.DeclareKeyword, node)) { + result.declare = true; + } - case SyntaxKind.ArrayLiteralExpression: { - // TypeScript uses ArrayLiteralExpression in destructuring assignment, too - if (config.allowPattern) { - Object.assign(result, { - type: AST_NODE_TYPES.ArrayPattern, - elements: node.elements.map(convertPattern) - }); - } else { - Object.assign(result, { - type: AST_NODE_TYPES.ArrayExpression, - elements: node.elements.map(convertChild) - }); + // check for exports + return fixExports(node, result, this.ast); } - break; - } - case SyntaxKind.ObjectLiteralExpression: { - // TypeScript uses ObjectLiteralExpression in destructuring assignment, too - if (config.allowPattern) { - Object.assign(result, { - type: AST_NODE_TYPES.ObjectPattern, - properties: node.properties.map(convertPattern) - }); - } else { - Object.assign(result, { - type: AST_NODE_TYPES.ObjectExpression, - properties: node.properties.map(convertChild) + // mostly for for-of, for-in + case SyntaxKind.VariableDeclarationList: + return this.createNode(node, { + type: AST_NODE_TYPES.VariableDeclaration, + declarations: node.declarations.map(el => this.convertChild(el)), + kind: getDeclarationKind(node) }); - } - break; - } - case SyntaxKind.PropertyAssignment: - Object.assign(result, { - type: AST_NODE_TYPES.Property, - key: convertChild(node.name), - value: converter( - node.initializer, - config.inTypeMode, - config.allowPattern - ), - computed: isComputedProperty(node.name), - method: false, - shorthand: false, - kind: 'init' - }); - break; + // Expressions - case SyntaxKind.ShorthandPropertyAssignment: { - if (node.objectAssignmentInitializer) { - Object.assign(result, { - type: AST_NODE_TYPES.Property, - key: convertChild(node.name), - value: { - type: AST_NODE_TYPES.AssignmentPattern, - left: convertPattern(node.name), - right: convertChild(node.objectAssignmentInitializer), - loc: result.loc, - range: result.range - }, - computed: false, - method: false, - shorthand: true, - kind: 'init' + case SyntaxKind.ExpressionStatement: + return this.createNode(node, { + type: AST_NODE_TYPES.ExpressionStatement, + expression: this.convertChild(node.expression) }); - } else { - // TODO: this node has no initializer field - Object.assign(result, { - type: AST_NODE_TYPES.Property, - key: convertChild(node.name), - value: convertChild((node as any).initializer || node.name), - computed: false, - method: false, - shorthand: true, - kind: 'init' - }); - } - break; - } - - case SyntaxKind.ComputedPropertyName: - return convertChild(node.expression); - - case SyntaxKind.PropertyDeclaration: { - const isAbstract = hasModifier(SyntaxKind.AbstractKeyword, node); - Object.assign(result, { - type: isAbstract - ? AST_NODE_TYPES.TSAbstractClassProperty - : AST_NODE_TYPES.ClassProperty, - key: convertChild(node.name), - value: convertChild(node.initializer), - computed: isComputedProperty(node.name), - static: hasModifier(SyntaxKind.StaticKeyword, node), - readonly: hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined - }); - - if (node.type) { - result.typeAnnotation = convertTypeAnnotation(node.type); - } - - if (node.decorators) { - result.decorators = node.decorators.map(convertChild); - } - - const accessibility = getTSNodeAccessibility(node); - if (accessibility) { - result.accessibility = accessibility; - } - - if (node.name.kind === SyntaxKind.Identifier && node.questionToken) { - result.optional = true; - } - if (node.exclamationToken) { - (result as any).definite = true; - } + case SyntaxKind.ThisKeyword: + return this.createNode(node, { + type: AST_NODE_TYPES.ThisExpression + }); - if ( - (result as any).key.type === AST_NODE_TYPES.Literal && - node.questionToken - ) { - result.optional = true; + case SyntaxKind.ArrayLiteralExpression: { + // TypeScript uses ArrayLiteralExpression in destructuring assignment, too + if (this.allowPattern) { + return this.createNode(node, { + type: AST_NODE_TYPES.ArrayPattern, + elements: node.elements.map(el => this.convertPattern(el)) + }); + } else { + return this.createNode(node, { + type: AST_NODE_TYPES.ArrayExpression, + elements: node.elements.map(el => this.convertChild(el)) + }); + } } - break; - } - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.MethodDeclaration: { - const method: ESTreeNode = { - type: AST_NODE_TYPES.FunctionExpression, - id: null, - generator: !!node.asteriskToken, - expression: false, // ESTreeNode as ESTreeNode here - async: hasModifier(SyntaxKind.AsyncKeyword, node), - body: convertChild(node.body), - range: [node.parameters.pos - 1, result.range[1]], - loc: { - start: getLineAndCharacterFor(node.parameters.pos - 1, ast), - end: result.loc.end + case SyntaxKind.ObjectLiteralExpression: { + // TypeScript uses ObjectLiteralExpression in destructuring assignment, too + if (this.allowPattern) { + return this.createNode(node, { + type: AST_NODE_TYPES.ObjectPattern, + properties: node.properties.map(el => this.convertPattern(el)) + }); + } else { + return this.createNode(node, { + type: AST_NODE_TYPES.ObjectExpression, + properties: node.properties.map(el => this.convertChild(el)) + }); } - } as any; - - if (node.type) { - (method as any).returnType = convertTypeAnnotation(node.type); } - if (parent!.kind === SyntaxKind.ObjectLiteralExpression) { - (method as any).params = node.parameters.map(convertChild); - - Object.assign(result, { + case SyntaxKind.PropertyAssignment: + return this.createNode(node, { type: AST_NODE_TYPES.Property, - key: convertChild(node.name), - value: method, + key: this.convertChild(node.name), + value: this.converter( + node.initializer, + node, + this.inTypeMode, + this.allowPattern + ), computed: isComputedProperty(node.name), - method: node.kind === SyntaxKind.MethodDeclaration, + method: false, shorthand: false, kind: 'init' }); - } else { - // class - /** - * Unlike in object literal methods, class method params can have decorators - */ - (method as any).params = convertParameters(node.parameters); + case SyntaxKind.ShorthandPropertyAssignment: { + if (node.objectAssignmentInitializer) { + return this.createNode(node, { + type: AST_NODE_TYPES.Property, + key: this.convertChild(node.name), + value: this.createNode(node, { + type: AST_NODE_TYPES.AssignmentPattern, + left: this.convertPattern(node.name), + right: this.convertChild(node.objectAssignmentInitializer) + }), + computed: false, + method: false, + shorthand: true, + kind: 'init' + }); + } else { + return this.createNode(node, { + type: AST_NODE_TYPES.Property, + key: this.convertChild(node.name), + value: this.convertChild(node.name), + computed: false, + method: false, + shorthand: true, + kind: 'init' + }); + } + } - /** - * TypeScript class methods can be defined as "abstract" - */ - const methodDefinitionType = hasModifier( - SyntaxKind.AbstractKeyword, - node - ) - ? AST_NODE_TYPES.TSAbstractMethodDefinition - : AST_NODE_TYPES.MethodDefinition; - - Object.assign(result, { - type: methodDefinitionType, - key: convertChild(node.name), - value: method, + case SyntaxKind.ComputedPropertyName: + return this.convertChild(node.expression); + + case SyntaxKind.PropertyDeclaration: { + const isAbstract = hasModifier(SyntaxKind.AbstractKeyword, node); + const result = this.createNode< + es.TSAbstractClassProperty | es.ClassProperty + >(node, { + type: isAbstract + ? AST_NODE_TYPES.TSAbstractClassProperty + : AST_NODE_TYPES.ClassProperty, + key: this.convertChild(node.name), + value: this.convertChild(node.initializer), computed: isComputedProperty(node.name), static: hasModifier(SyntaxKind.StaticKeyword, node), - kind: 'method' + readonly: hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined }); + if (node.type) { + result.typeAnnotation = this.convertTypeAnnotation(node.type, node); + } + if (node.decorators) { - result.decorators = node.decorators.map(convertChild); + result.decorators = node.decorators.map(el => this.convertChild(el)); } const accessibility = getTSNodeAccessibility(node); if (accessibility) { result.accessibility = accessibility; } - } - - if ( - (result as any).key.type === AST_NODE_TYPES.Identifier && - node.questionToken - ) { - (result as any).key.optional = true; - } - if (node.kind === SyntaxKind.GetAccessor) { - (result as any).kind = 'get'; - } else if (node.kind === SyntaxKind.SetAccessor) { - (result as any).kind = 'set'; - } else if ( - !(result as any).static && - node.name.kind === SyntaxKind.StringLiteral && - node.name.text === 'constructor' && - result.type !== AST_NODE_TYPES.Property - ) { - (result as any).kind = 'constructor'; - } + if (node.name.kind === SyntaxKind.Identifier && node.questionToken) { + result.optional = true; + } - // Process typeParameters - if (node.typeParameters && node.typeParameters.length) { - if (result.type !== AST_NODE_TYPES.Property) { - method.typeParameters = convertTSTypeParametersToTypeParametersDeclaration( - node.typeParameters - ); - } else { - result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration( - node.typeParameters - ); + if (node.exclamationToken) { + result.definite = true; } - } - break; - } + if (result.key.type === AST_NODE_TYPES.Literal && node.questionToken) { + result.optional = true; + } + return result; + } + + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.MethodDeclaration: { + const method = this.createNode(node, { + type: AST_NODE_TYPES.FunctionExpression, + id: null, + generator: !!node.asteriskToken, + expression: false, // ESTreeNode as ESTreeNode here + async: hasModifier(SyntaxKind.AsyncKeyword, node), + body: this.convertChild(node.body), + range: [node.parameters.pos - 1, node.end], + params: [] + }); - // TypeScript uses this even for static methods named "constructor" - case SyntaxKind.Constructor: { - const lastModifier = getLastModifier(node); - const constructorToken = - (lastModifier && findNextToken(lastModifier, node, ast)) || - node.getFirstToken()!; - - const constructorTokenRange = [ - constructorToken.getStart(ast), - constructorToken.end - ]; - - const constructor: ESTreeNode = { - type: AST_NODE_TYPES.FunctionExpression, - id: null, - params: convertParameters(node.parameters), - generator: false, - expression: false, // is not present in ESTreeNode - async: false, - body: convertChild(node.body), - range: [node.parameters.pos - 1, result.range[1]], - loc: { - start: getLineAndCharacterFor(node.parameters.pos - 1, ast), - end: result.loc.end - } - } as any; - - // Process typeParameters - if (node.typeParameters && node.typeParameters.length) { - constructor.typeParameters = convertTSTypeParametersToTypeParametersDeclaration( - node.typeParameters - ); - } + if (node.type) { + method.returnType = this.convertTypeAnnotation(node.type, node); + } - // Process returnType - if (node.type) { - constructor.returnType = convertTypeAnnotation(node.type); - } + let result: + | es.Property + | es.TSAbstractMethodDefinition + | es.MethodDefinition; - const constructorKey = { - type: AST_NODE_TYPES.Identifier, - name: 'constructor', - range: constructorTokenRange, - loc: getLocFor(constructorTokenRange[0], constructorTokenRange[1], ast) - }; + if (parent.kind === SyntaxKind.ObjectLiteralExpression) { + method.params = node.parameters.map(el => this.convertChild(el)); - const isStatic = hasModifier(SyntaxKind.StaticKeyword, node); + result = this.createNode(node, { + type: AST_NODE_TYPES.Property, + key: this.convertChild(node.name), + value: method, + computed: isComputedProperty(node.name), + method: node.kind === SyntaxKind.MethodDeclaration, + shorthand: false, + kind: 'init' + }); + } else { + // class + + /** + * Unlike in object literal methods, class method params can have decorators + */ + method.params = this.convertParameters(node.parameters); + + /** + * TypeScript class methods can be defined as "abstract" + */ + const methodDefinitionType = hasModifier( + SyntaxKind.AbstractKeyword, + node + ) + ? AST_NODE_TYPES.TSAbstractMethodDefinition + : AST_NODE_TYPES.MethodDefinition; + + result = this.createNode< + es.TSAbstractMethodDefinition | es.MethodDefinition + >(node, { + type: methodDefinitionType, + key: this.convertChild(node.name), + value: method, + computed: isComputedProperty(node.name), + static: hasModifier(SyntaxKind.StaticKeyword, node), + kind: 'method' + }); - Object.assign(result, { - type: hasModifier(SyntaxKind.AbstractKeyword, node) - ? AST_NODE_TYPES.TSAbstractMethodDefinition - : AST_NODE_TYPES.MethodDefinition, - key: constructorKey, - value: constructor, - computed: false, - static: isStatic, - kind: isStatic ? 'method' : 'constructor' - }); + if (node.decorators) { + result.decorators = node.decorators.map(el => + this.convertChild(el) + ); + } - const accessibility = getTSNodeAccessibility(node); - if (accessibility) { - result.accessibility = accessibility; - } + const accessibility = getTSNodeAccessibility(node); + if (accessibility) { + result.accessibility = accessibility; + } + } - break; - } + if ( + result.key.type === AST_NODE_TYPES.Identifier && + node.questionToken + ) { + result.key.optional = true; + } - case SyntaxKind.FunctionExpression: - Object.assign(result, { - type: AST_NODE_TYPES.FunctionExpression, - id: convertChild(node.name), - generator: !!node.asteriskToken, - params: convertParameters(node.parameters), - body: convertChild(node.body), - async: hasModifier(SyntaxKind.AsyncKeyword, node), - expression: false - }); + if (node.kind === SyntaxKind.GetAccessor) { + result.kind = 'get'; + } else if (node.kind === SyntaxKind.SetAccessor) { + result.kind = 'set'; + } else if ( + !(result as es.MethodDefinition).static && + node.name.kind === SyntaxKind.StringLiteral && + node.name.text === 'constructor' && + result.type !== AST_NODE_TYPES.Property + ) { + result.kind = 'constructor'; + } - // Process returnType - if (node.type) { - result.returnType = convertTypeAnnotation(node.type); - } + // Process typeParameters + if (node.typeParameters && node.typeParameters.length) { + if (result.type !== AST_NODE_TYPES.Property) { + method.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( + node.typeParameters + ); + } else { + result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( + node.typeParameters + ); + } + } + return result; + } + + // TypeScript uses this even for static methods named "constructor" + case SyntaxKind.Constructor: { + const lastModifier = getLastModifier(node); + const constructorToken = + (lastModifier && findNextToken(lastModifier, node, this.ast)) || + node.getFirstToken()!; + + const constructor = this.createNode(node, { + type: AST_NODE_TYPES.FunctionExpression, + id: null, + params: this.convertParameters(node.parameters), + generator: false, + expression: false, // is not present in ESTreeNode + async: false, + body: this.convertChild(node.body), + range: [node.parameters.pos - 1, node.end] + }); - // Process typeParameters - if (node.typeParameters && node.typeParameters.length) { - result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration( - node.typeParameters - ); - } - break; + // Process typeParameters + if (node.typeParameters && node.typeParameters.length) { + constructor.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( + node.typeParameters + ); + } - case SyntaxKind.SuperKeyword: - Object.assign(result, { - type: AST_NODE_TYPES.Super - }); - break; + // Process returnType + if (node.type) { + constructor.returnType = this.convertTypeAnnotation(node.type, node); + } - case SyntaxKind.ArrayBindingPattern: - Object.assign(result, { - type: AST_NODE_TYPES.ArrayPattern, - elements: node.elements.map(convertPattern) - }); - break; + const constructorKey = this.createNode(node, { + type: AST_NODE_TYPES.Identifier, + name: 'constructor', + range: [constructorToken.getStart(this.ast), constructorToken.end] + }); - // occurs with missing array elements like [,] - case SyntaxKind.OmittedExpression: - return null; + const isStatic = hasModifier(SyntaxKind.StaticKeyword, node); + const result = this.createNode< + es.TSAbstractMethodDefinition | es.MethodDefinition + >(node, { + type: hasModifier(SyntaxKind.AbstractKeyword, node) + ? AST_NODE_TYPES.TSAbstractMethodDefinition + : AST_NODE_TYPES.MethodDefinition, + key: constructorKey, + value: constructor, + computed: false, + static: isStatic, + kind: isStatic ? 'method' : 'constructor' + }); - case SyntaxKind.ObjectBindingPattern: - Object.assign(result, { - type: AST_NODE_TYPES.ObjectPattern, - properties: node.elements.map(convertPattern) - }); - break; + const accessibility = getTSNodeAccessibility(node); + if (accessibility) { + result.accessibility = accessibility; + } + + return result; + } - case SyntaxKind.BindingElement: - if (parent!.kind === SyntaxKind.ArrayBindingPattern) { - const arrayItem = convert({ - node: node.name, - parent, - ast, - additionalOptions + case SyntaxKind.FunctionExpression: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.FunctionExpression, + id: this.convertChild(node.name), + generator: !!node.asteriskToken, + params: this.convertParameters(node.parameters), + body: this.convertChild(node.body), + async: hasModifier(SyntaxKind.AsyncKeyword, node), + expression: false }); - if (node.initializer) { - Object.assign(result, { - type: AST_NODE_TYPES.AssignmentPattern, - left: arrayItem, - right: convertChild(node.initializer) - }); - } else if (node.dotDotDotToken) { - Object.assign(result, { - type: AST_NODE_TYPES.RestElement, - argument: arrayItem - }); - } else { - return arrayItem; + // Process returnType + if (node.type) { + result.returnType = this.convertTypeAnnotation(node.type, node); } - } else if (parent!.kind === SyntaxKind.ObjectBindingPattern) { - if (node.dotDotDotToken) { - Object.assign(result, { - type: AST_NODE_TYPES.RestElement, - argument: convertChild(node.propertyName || node.name) - }); - } else { - Object.assign(result, { - type: AST_NODE_TYPES.Property, - key: convertChild(node.propertyName || node.name), - value: convertChild(node.name), - computed: Boolean( - node.propertyName && - node.propertyName.kind === SyntaxKind.ComputedPropertyName - ), - method: false, - shorthand: !node.propertyName, - kind: 'init' - }); + + // Process typeParameters + if (node.typeParameters && node.typeParameters.length) { + result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( + node.typeParameters + ); } + return result; + } - if (node.initializer) { - (result as any).value = { - type: AST_NODE_TYPES.AssignmentPattern, - left: convertChild(node.name), - right: convertChild(node.initializer), - range: [node.name.getStart(ast), node.initializer.end], - loc: getLocFor(node.name.getStart(ast), node.initializer.end, ast) - }; - } - } - break; - - case SyntaxKind.ArrowFunction: - Object.assign(result, { - type: AST_NODE_TYPES.ArrowFunctionExpression, - generator: false, - id: null, - params: convertParameters(node.parameters), - body: convertChild(node.body), - async: hasModifier(SyntaxKind.AsyncKeyword, node), - expression: node.body.kind !== SyntaxKind.Block - }); + case SyntaxKind.SuperKeyword: + return this.createNode(node, { + type: AST_NODE_TYPES.Super + }); - // Process returnType - if (node.type) { - result.returnType = convertTypeAnnotation(node.type); - } + case SyntaxKind.ArrayBindingPattern: + return this.createNode(node, { + type: AST_NODE_TYPES.ArrayPattern, + elements: node.elements.map(el => this.convertPattern(el)) + }); - // Process typeParameters - if (node.typeParameters && node.typeParameters.length) { - result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration( - node.typeParameters - ); - } - break; + // occurs with missing array elements like [,] + case SyntaxKind.OmittedExpression: + return null; - case SyntaxKind.YieldExpression: - Object.assign(result, { - type: AST_NODE_TYPES.YieldExpression, - delegate: !!node.asteriskToken, - argument: convertChild(node.expression) - }); - break; + case SyntaxKind.ObjectBindingPattern: + return this.createNode(node, { + type: AST_NODE_TYPES.ObjectPattern, + properties: node.elements.map(el => this.convertPattern(el)) + }); - case SyntaxKind.AwaitExpression: - Object.assign(result, { - type: AST_NODE_TYPES.AwaitExpression, - argument: convertChild(node.expression) - }); - break; - - // Template Literals - - case SyntaxKind.NoSubstitutionTemplateLiteral: - Object.assign(result, { - type: AST_NODE_TYPES.TemplateLiteral, - quasis: [ - { - type: AST_NODE_TYPES.TemplateElement, - value: { - raw: ast.text.slice(node.getStart(ast) + 1, node.end - 1), - cooked: node.text - }, - tail: true, - range: result.range, - loc: result.loc + case SyntaxKind.BindingElement: { + if (parent.kind === SyntaxKind.ArrayBindingPattern) { + const arrayItem = this.convertChild(node.name, parent); + + if (node.initializer) { + return this.createNode(node, { + type: AST_NODE_TYPES.AssignmentPattern, + left: arrayItem, + right: this.convertChild(node.initializer) + }); + } else if (node.dotDotDotToken) { + return this.createNode(node, { + type: AST_NODE_TYPES.RestElement, + argument: arrayItem + }); + } else { + return arrayItem; + } + } else if (parent.kind === SyntaxKind.ObjectBindingPattern) { + let result: es.RestElement | es.Property; + if (node.dotDotDotToken) { + result = this.createNode(node, { + type: AST_NODE_TYPES.RestElement, + argument: this.convertChild(node.propertyName || node.name) + }); + } else { + result = this.createNode(node, { + type: AST_NODE_TYPES.Property, + key: this.convertChild(node.propertyName || node.name), + value: this.convertChild(node.name), + computed: Boolean( + node.propertyName && + node.propertyName.kind === SyntaxKind.ComputedPropertyName + ), + method: false, + shorthand: !node.propertyName, + kind: 'init' + }); } - ], - expressions: [] - }); - break; - case SyntaxKind.TemplateExpression: - Object.assign(result, { - type: AST_NODE_TYPES.TemplateLiteral, - quasis: [convertChild(node.head)], - expressions: [] - }); + if (node.initializer) { + result.value = this.createNode(node, { + type: AST_NODE_TYPES.AssignmentPattern, + left: this.convertChild(node.name), + right: this.convertChild(node.initializer), + range: [node.name.getStart(this.ast), node.initializer.end] + }); + } + return result; + } + return null; + } + + case SyntaxKind.ArrowFunction: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.ArrowFunctionExpression, + generator: false, + id: null, + params: this.convertParameters(node.parameters), + body: this.convertChild(node.body), + async: hasModifier(SyntaxKind.AsyncKeyword, node), + expression: node.body.kind !== SyntaxKind.Block + }); - node.templateSpans.forEach(templateSpan => { - (result as any).expressions.push(convertChild(templateSpan.expression)); - (result as any).quasis.push(convertChild(templateSpan.literal)); - }); - break; - - case SyntaxKind.TaggedTemplateExpression: - Object.assign(result, { - type: AST_NODE_TYPES.TaggedTemplateExpression, - typeParameters: node.typeArguments - ? convertTypeArgumentsToTypeParameters(node.typeArguments) - : undefined, - tag: convertChild(node.tag), - quasi: convertChild(node.template) - }); - break; - - case SyntaxKind.TemplateHead: - case SyntaxKind.TemplateMiddle: - case SyntaxKind.TemplateTail: { - const tail = node.kind === SyntaxKind.TemplateTail; - Object.assign(result, { - type: AST_NODE_TYPES.TemplateElement, - value: { - raw: ast.text.slice( - node.getStart(ast) + 1, - node.end - (tail ? 1 : 2) - ), - cooked: node.text - }, - tail - }); - break; - } + // Process returnType + if (node.type) { + result.returnType = this.convertTypeAnnotation(node.type, node); + } - // Patterns + // Process typeParameters + if (node.typeParameters && node.typeParameters.length) { + result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( + node.typeParameters + ); + } + return result; + } - case SyntaxKind.SpreadAssignment: - case SyntaxKind.SpreadElement: { - if (config.allowPattern) { - Object.assign(result, { - type: AST_NODE_TYPES.RestElement, - argument: convertPattern(node.expression) - }); - } else { - Object.assign(result, { - type: AST_NODE_TYPES.SpreadElement, - argument: convertChild(node.expression) + case SyntaxKind.YieldExpression: + return this.createNode(node, { + type: AST_NODE_TYPES.YieldExpression, + delegate: !!node.asteriskToken, + argument: this.convertChild(node.expression) }); - } - break; - } - case SyntaxKind.Parameter: { - let parameter: ESTreeNode; + case SyntaxKind.AwaitExpression: + return this.createNode(node, { + type: AST_NODE_TYPES.AwaitExpression, + argument: this.convertChild(node.expression) + }); - if (node.dotDotDotToken) { - Object.assign(result, { - type: AST_NODE_TYPES.RestElement, - argument: convertChild(node.name) + // Template Literals + + case SyntaxKind.NoSubstitutionTemplateLiteral: + return this.createNode(node, { + type: AST_NODE_TYPES.TemplateLiteral, + quasis: [ + this.createNode(node, { + type: AST_NODE_TYPES.TemplateElement, + value: { + raw: this.ast.text.slice( + node.getStart(this.ast) + 1, + node.end - 1 + ), + cooked: node.text + }, + tail: true + }) + ], + expressions: [] }); - parameter = result; - } else if (node.initializer) { - parameter = convertChild(node.name)!; - Object.assign(result, { - type: AST_NODE_TYPES.AssignmentPattern, - left: parameter, - right: convertChild(node.initializer) + + case SyntaxKind.TemplateExpression: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.TemplateLiteral, + quasis: [this.convertChild(node.head)], + expressions: [] }); - if (node.modifiers) { - // AssignmentPattern should not contain modifiers in range - result.range[0] = parameter.range[0]; - result.loc = getLocFor(result.range[0], result.range[1], ast); - } - } else { - parameter = result = convert({ - node: node.name, - parent, - ast, - additionalOptions - })!; - } - - if (node.type) { - parameter.typeAnnotation = convertTypeAnnotation(node.type); - fixTypeAnnotationParentLocation(parameter); - } - - if (node.questionToken) { - if (node.questionToken.end > parameter.range[1]) { - parameter.range[1] = node.questionToken.end; - parameter.loc = getLocFor( - parameter.range[0], - parameter.range[1], - ast - ); - } - parameter.optional = true; + node.templateSpans.forEach(templateSpan => { + result.expressions.push(this.convertChild(templateSpan.expression)); + result.quasis.push(this.convertChild(templateSpan.literal)); + }); + return result; } - if (node.modifiers) { - return { - type: AST_NODE_TYPES.TSParameterProperty, - range: [node.getStart(ast), node.end], - loc: getLoc(node, ast), - accessibility: getTSNodeAccessibility(node) || undefined, - readonly: hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined, - static: hasModifier(SyntaxKind.StaticKeyword, node) || undefined, - export: hasModifier(SyntaxKind.ExportKeyword, node) || undefined, - parameter: result - }; + case SyntaxKind.TaggedTemplateExpression: + return this.createNode(node, { + type: AST_NODE_TYPES.TaggedTemplateExpression, + typeParameters: node.typeArguments + ? this.convertTypeArgumentsToTypeParameters(node.typeArguments) + : undefined, + tag: this.convertChild(node.tag), + quasi: this.convertChild(node.template) + }); + + case SyntaxKind.TemplateHead: + case SyntaxKind.TemplateMiddle: + case SyntaxKind.TemplateTail: { + const tail = node.kind === SyntaxKind.TemplateTail; + return this.createNode(node, { + type: AST_NODE_TYPES.TemplateElement, + value: { + raw: this.ast.text.slice( + node.getStart(this.ast) + 1, + node.end - (tail ? 1 : 2) + ), + cooked: node.text + }, + tail + }); } - break; - } + // Patterns - // Classes + case SyntaxKind.SpreadAssignment: + case SyntaxKind.SpreadElement: { + if (this.allowPattern) { + return this.createNode(node, { + type: AST_NODE_TYPES.RestElement, + argument: this.convertPattern(node.expression) + }); + } else { + return this.createNode(node, { + type: AST_NODE_TYPES.SpreadElement, + argument: this.convertChild(node.expression) + }); + } + } - case SyntaxKind.ClassDeclaration: - case SyntaxKind.ClassExpression: { - const heritageClauses = node.heritageClauses || []; - let classNodeType = SyntaxKind[node.kind]; + case SyntaxKind.Parameter: { + let parameter: any; + let result: es.RestElement | es.AssignmentPattern; - if (node.typeParameters && node.typeParameters.length) { - result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration( - node.typeParameters - ); - } + if (node.dotDotDotToken) { + parameter = result = this.createNode(node, { + type: AST_NODE_TYPES.RestElement, + argument: this.convertChild(node.name) + }); + } else if (node.initializer) { + parameter = this.convertChild(node.name); + result = this.createNode(node, { + type: AST_NODE_TYPES.AssignmentPattern, + left: parameter, + right: this.convertChild(node.initializer) + }); - const superClass = heritageClauses.find( - clause => clause.token === SyntaxKind.ExtendsKeyword - ); + if (node.modifiers) { + // AssignmentPattern should not contain modifiers in range + result.range[0] = parameter.range[0]; + result.loc = getLocFor(result.range[0], result.range[1], this.ast); + } + } else { + parameter = result = this.convertChild(node.name, parent); + } - if (superClass) { - if (superClass.types.length > 1) { - throw createError( - ast, - superClass.types[1].pos, - 'Classes can only extend a single class.' + if (node.type) { + parameter.typeAnnotation = this.convertTypeAnnotation( + node.type, + node ); + this.fixTypeAnnotationParentLocation(parameter, node.type); } - if (superClass.types[0] && superClass.types[0].typeArguments) { - (result as any).superTypeParameters = convertTypeArgumentsToTypeParameters( - superClass.types[0].typeArguments - ); + if (node.questionToken) { + if (node.questionToken.end > parameter.range[1]) { + parameter.range[1] = node.questionToken.end; + parameter.loc.end = getLineAndCharacterFor( + parameter.range[1], + this.ast + ); + } + parameter.optional = true; + } + + if (node.modifiers) { + return this.createNode(node, { + type: AST_NODE_TYPES.TSParameterProperty, + accessibility: getTSNodeAccessibility(node) || undefined, + readonly: + hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined, + static: hasModifier(SyntaxKind.StaticKeyword, node) || undefined, + export: hasModifier(SyntaxKind.ExportKeyword, node) || undefined, + parameter: result + }); } + return result; } - const implementsClause = heritageClauses.find( - clause => clause.token === SyntaxKind.ImplementsKeyword - ); + // Classes - const classBodyRange = [node.members.pos - 1, node.end]; + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: { + const heritageClauses = node.heritageClauses || []; + let classNodeType = + node.kind === SyntaxKind.ClassDeclaration + ? AST_NODE_TYPES.ClassDeclaration + : AST_NODE_TYPES.ClassExpression; - Object.assign(result, { - type: classNodeType, - id: convertChild(node.name), - body: { - type: AST_NODE_TYPES.ClassBody, - body: [], - range: classBodyRange, - loc: getLocFor(classBodyRange[0], classBodyRange[1], ast) - }, - superClass: - superClass && superClass.types[0] - ? convertChild(superClass.types[0].expression) - : null - }); + const superClass = heritageClauses.find( + clause => clause.token === SyntaxKind.ExtendsKeyword + ); - if (implementsClause) { - result.implements = implementsClause.types.map(convertChild); - } + const implementsClause = heritageClauses.find( + clause => clause.token === SyntaxKind.ImplementsKeyword + ); - /** - * TypeScript class declarations can be defined as "abstract" - */ - if (hasModifier(SyntaxKind.AbstractKeyword, node)) { - result.abstract = true; - } + const result = this.createNode< + es.ClassDeclaration | es.ClassExpression + >(node, { + type: classNodeType, + id: this.convertChild(node.name), + body: this.createNode(node, { + type: AST_NODE_TYPES.ClassBody, + body: [], + range: [node.members.pos - 1, node.end] + }), + superClass: + superClass && superClass.types[0] + ? this.convertChild(superClass.types[0].expression) + : null + }); - if (hasModifier(SyntaxKind.DeclareKeyword, node)) { - result.declare = true; - } + if (superClass) { + if (superClass.types.length > 1) { + throw createError( + this.ast, + superClass.types[1].pos, + 'Classes can only extend a single class.' + ); + } - if (node.decorators) { - result.decorators = node.decorators.map(convertChild); - } + if (superClass.types[0] && superClass.types[0].typeArguments) { + result.superTypeParameters = this.convertTypeArgumentsToTypeParameters( + superClass.types[0].typeArguments + ); + } + } - const filteredMembers = node.members.filter(isESTreeClassMember); + if (node.typeParameters && node.typeParameters.length) { + result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( + node.typeParameters + ); + } - if (filteredMembers.length) { - result.body.body = filteredMembers.map(convertChild); - } + if (implementsClause) { + result.implements = implementsClause.types.map(el => + this.convertChild(el) + ); + } - // check for exports - result = fixExports(node, result, ast); + /** + * TypeScript class declarations can be defined as "abstract" + */ + if (hasModifier(SyntaxKind.AbstractKeyword, node)) { + result.abstract = true; + } - break; - } + if (hasModifier(SyntaxKind.DeclareKeyword, node)) { + result.declare = true; + } - // Modules - case SyntaxKind.ModuleBlock: - Object.assign(result, { - type: AST_NODE_TYPES.TSModuleBlock, - body: convertBodyExpressions(node.statements) - }); - break; + if (node.decorators) { + result.decorators = node.decorators.map(el => this.convertChild(el)); + } - case SyntaxKind.ImportDeclaration: - Object.assign(result, { - type: AST_NODE_TYPES.ImportDeclaration, - source: convertChild(node.moduleSpecifier), - specifiers: [] - }); + const filteredMembers = node.members.filter(isESTreeClassMember); - if (node.importClause) { - if (node.importClause.name) { - result.specifiers!.push(convertChild(node.importClause)); - } - - if (node.importClause.namedBindings) { - switch (node.importClause.namedBindings.kind) { - case SyntaxKind.NamespaceImport: - result.specifiers!.push( - convertChild(node.importClause.namedBindings) - ); - break; - case SyntaxKind.NamedImports: - result.specifiers = result.specifiers!.concat( - node.importClause.namedBindings.elements.map(convertChild) - ); - break; - } + if (filteredMembers.length) { + result.body.body = filteredMembers.map(el => this.convertChild(el)); } + + // check for exports + return fixExports(node, result, this.ast); } - break; - case SyntaxKind.NamespaceImport: - Object.assign(result, { - type: AST_NODE_TYPES.ImportNamespaceSpecifier, - local: convertChild(node.name) - }); - break; + // Modules + case SyntaxKind.ModuleBlock: + return this.createNode(node, { + type: AST_NODE_TYPES.TSModuleBlock, + body: this.convertBodyExpressions(node.statements, node) + }); - case SyntaxKind.ImportSpecifier: - Object.assign(result, { - type: AST_NODE_TYPES.ImportSpecifier, - local: convertChild(node.name), - imported: convertChild(node.propertyName || node.name) - }); - break; + case SyntaxKind.ImportDeclaration: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.ImportDeclaration, + source: this.convertChild(node.moduleSpecifier), + specifiers: [] + }); - case SyntaxKind.ImportClause: - Object.assign(result, { - type: AST_NODE_TYPES.ImportDefaultSpecifier, - local: convertChild(node.name) - }); + if (node.importClause) { + if (node.importClause.name) { + result.specifiers.push(this.convertChild(node.importClause)); + } - // have to adjust location information due to tree differences - result.range[1] = node.name!.end; - result.loc = getLocFor(result.range[0], result.range[1], ast); - break; + if (node.importClause.namedBindings) { + switch (node.importClause.namedBindings.kind) { + case SyntaxKind.NamespaceImport: + result.specifiers.push( + this.convertChild(node.importClause.namedBindings) + ); + break; + case SyntaxKind.NamedImports: + result.specifiers = result.specifiers.concat( + node.importClause.namedBindings.elements.map(el => + this.convertChild(el) + ) + ); + break; + } + } + } + return result; + } - case SyntaxKind.ExportDeclaration: - if (node.exportClause) { - Object.assign(result, { - type: AST_NODE_TYPES.ExportNamedDeclaration, - source: convertChild(node.moduleSpecifier), - specifiers: node.exportClause.elements.map(convertChild), - declaration: null - }); - } else { - Object.assign(result, { - type: AST_NODE_TYPES.ExportAllDeclaration, - source: convertChild(node.moduleSpecifier) + case SyntaxKind.NamespaceImport: + return this.createNode(node, { + type: AST_NODE_TYPES.ImportNamespaceSpecifier, + local: this.convertChild(node.name) }); - } - break; - case SyntaxKind.ExportSpecifier: - Object.assign(result, { - type: AST_NODE_TYPES.ExportSpecifier, - local: convertChild(node.propertyName || node.name), - exported: convertChild(node.name) - }); - break; + case SyntaxKind.ImportSpecifier: + return this.createNode(node, { + type: AST_NODE_TYPES.ImportSpecifier, + local: this.convertChild(node.name), + imported: this.convertChild(node.propertyName || node.name) + }); - case SyntaxKind.ExportAssignment: - if (node.isExportEquals) { - Object.assign(result, { - type: AST_NODE_TYPES.TSExportAssignment, - expression: convertChild(node.expression) + case SyntaxKind.ImportClause: + return this.createNode(node, { + type: AST_NODE_TYPES.ImportDefaultSpecifier, + local: this.convertChild(node.name), + range: [node.getStart(this.ast), node.name!.end] }); - } else { - Object.assign(result, { - type: AST_NODE_TYPES.ExportDefaultDeclaration, - declaration: convertChild(node.expression) + + case SyntaxKind.ExportDeclaration: + if (node.exportClause) { + return this.createNode(node, { + type: AST_NODE_TYPES.ExportNamedDeclaration, + source: this.convertChild(node.moduleSpecifier), + specifiers: node.exportClause.elements.map(el => + this.convertChild(el) + ), + declaration: null + }); + } else { + return this.createNode(node, { + type: AST_NODE_TYPES.ExportAllDeclaration, + source: this.convertChild(node.moduleSpecifier) + }); + } + + case SyntaxKind.ExportSpecifier: + return this.createNode(node, { + type: AST_NODE_TYPES.ExportSpecifier, + local: this.convertChild(node.propertyName || node.name), + exported: this.convertChild(node.name) }); - } - break; - // Unary Operations + case SyntaxKind.ExportAssignment: + if (node.isExportEquals) { + return this.createNode(node, { + type: AST_NODE_TYPES.TSExportAssignment, + expression: this.convertChild(node.expression) + }); + } else { + return this.createNode(node, { + type: AST_NODE_TYPES.ExportDefaultDeclaration, + declaration: this.convertChild(node.expression) + }); + } + + // Unary Operations - case SyntaxKind.PrefixUnaryExpression: - case SyntaxKind.PostfixUnaryExpression: { - const operator = getTextForTokenKind(node.operator) || ''; - Object.assign(result, { + case SyntaxKind.PrefixUnaryExpression: + case SyntaxKind.PostfixUnaryExpression: { + const operator = (getTextForTokenKind(node.operator) || '') as any; /** * ESTree uses UpdateExpression for ++/-- */ - type: /^(?:\+\+|--)$/.test(operator) - ? AST_NODE_TYPES.UpdateExpression - : AST_NODE_TYPES.UnaryExpression, - operator, - prefix: node.kind === SyntaxKind.PrefixUnaryExpression, - argument: convertChild(node.operand) - }); - break; - } + if (/^(?:\+\+|--)$/.test(operator)) { + return this.createNode(node, { + type: AST_NODE_TYPES.UpdateExpression, + operator, + prefix: node.kind === SyntaxKind.PrefixUnaryExpression, + argument: this.convertChild(node.operand) + }); + } else { + return this.createNode(node, { + type: AST_NODE_TYPES.UnaryExpression, + operator, + prefix: node.kind === SyntaxKind.PrefixUnaryExpression, + argument: this.convertChild(node.operand) + }); + } + } - case SyntaxKind.DeleteExpression: - Object.assign(result, { - type: AST_NODE_TYPES.UnaryExpression, - operator: 'delete', - prefix: true, - argument: convertChild(node.expression) - }); - break; - - case SyntaxKind.VoidExpression: - Object.assign(result, { - type: AST_NODE_TYPES.UnaryExpression, - operator: 'void', - prefix: true, - argument: convertChild(node.expression) - }); - break; - - case SyntaxKind.TypeOfExpression: - Object.assign(result, { - type: AST_NODE_TYPES.UnaryExpression, - operator: 'typeof', - prefix: true, - argument: convertChild(node.expression) - }); - break; + case SyntaxKind.DeleteExpression: + return this.createNode(node, { + type: AST_NODE_TYPES.UnaryExpression, + operator: 'delete', + prefix: true, + argument: this.convertChild(node.expression) + }); - case SyntaxKind.TypeOperator: - Object.assign(result, { - type: AST_NODE_TYPES.TSTypeOperator, - operator: getTextForTokenKind(node.operator), - typeAnnotation: convertChild(node.type) - }); - break; + case SyntaxKind.VoidExpression: + return this.createNode(node, { + type: AST_NODE_TYPES.UnaryExpression, + operator: 'void', + prefix: true, + argument: this.convertChild(node.expression) + }); - // Binary Operations + case SyntaxKind.TypeOfExpression: + return this.createNode(node, { + type: AST_NODE_TYPES.UnaryExpression, + operator: 'typeof', + prefix: true, + argument: this.convertChild(node.expression) + }); - case SyntaxKind.BinaryExpression: - // TypeScript uses BinaryExpression for sequences as well - if (isComma(node.operatorToken)) { - Object.assign(result, { - type: AST_NODE_TYPES.SequenceExpression, - expressions: [] + case SyntaxKind.TypeOperator: + return this.createNode(node, { + type: AST_NODE_TYPES.TSTypeOperator, + operator: getTextForTokenKind(node.operator) as any, + typeAnnotation: this.convertChild(node.type) }); - const left = convertChild(node.left)!, - right = convertChild(node.right)!; + // Binary Operations - if (left.type === AST_NODE_TYPES.SequenceExpression) { - (result as any).expressions = (result as any).expressions.concat( - (left as any).expressions - ); - } else { - (result as any).expressions.push(left); - } + case SyntaxKind.BinaryExpression: { + // TypeScript uses BinaryExpression for sequences as well + if (isComma(node.operatorToken)) { + const result = this.createNode(node, { + type: AST_NODE_TYPES.SequenceExpression, + expressions: [] + }); - if (right.type === AST_NODE_TYPES.SequenceExpression) { - (result as any).expressions = (result as any).expressions.concat( - (right as any).expressions - ); + const left = this.convertChild(node.left), + right = this.convertChild(node.right); + + if (left.type === AST_NODE_TYPES.SequenceExpression) { + result.expressions = result.expressions.concat(left.expressions); + } else { + result.expressions.push(left); + } + + if (right.type === AST_NODE_TYPES.SequenceExpression) { + result.expressions = result.expressions.concat(right.expressions); + } else { + result.expressions.push(right); + } + return result; } else { - (result as any).expressions.push(right); - } - } else { - const type = getBinaryExpressionType(node.operatorToken); - Object.assign(result, { - type, - operator: getTextForTokenKind(node.operatorToken.kind), - left: converter( - node.left, - config.inTypeMode, + const type = getBinaryExpressionType(node.operatorToken); + if ( + this.allowPattern && type === AST_NODE_TYPES.AssignmentExpression - ), - right: convertChild(node.right) - }); - - // if the binary expression is in a destructured array, switch it - if (result.type === AST_NODE_TYPES.AssignmentExpression) { - if (config.allowPattern) { - delete (result as any).operator; - result.type = AST_NODE_TYPES.AssignmentPattern; + ) { + return this.createNode(node, { + type: AST_NODE_TYPES.AssignmentPattern, + left: this.convertPattern(node.left, node), + right: this.convertChild(node.right) + }); } + return this.createNode< + es.AssignmentExpression | es.LogicalExpression | es.BinaryExpression + >(node, { + type: type, + operator: getTextForTokenKind(node.operatorToken.kind)!, + left: this.converter( + node.left, + node, + this.inTypeMode, + type === AST_NODE_TYPES.AssignmentExpression + ), + right: this.convertChild(node.right) + }); } } - break; - case SyntaxKind.PropertyAccessExpression: - if (isJSXToken(parent!)) { - const jsxMemberExpression = { - type: AST_NODE_TYPES.MemberExpression, - object: convertChild(node.expression), - property: convertChild(node.name) - }; - const isNestedMemberExpression = - node.expression.kind === SyntaxKind.PropertyAccessExpression; - if (node.expression.kind === SyntaxKind.ThisKeyword) { - (jsxMemberExpression as any).object.name = 'this'; - } - - (jsxMemberExpression as any).object.type = isNestedMemberExpression - ? AST_NODE_TYPES.MemberExpression - : AST_NODE_TYPES.JSXIdentifier; - (jsxMemberExpression as any).property.type = - AST_NODE_TYPES.JSXIdentifier; - Object.assign(result, jsxMemberExpression); - } else { - Object.assign(result, { + case SyntaxKind.PropertyAccessExpression: + if (isJSXToken(parent)) { + const jsxMemberExpression = this.createNode( + node, + { + type: AST_NODE_TYPES.MemberExpression, + object: this.convertChild(node.expression), + property: this.convertChild(node.name) + } + ); + // TODO: refactor this + const isNestedMemberExpression = + node.expression.kind === SyntaxKind.PropertyAccessExpression; + if (node.expression.kind === SyntaxKind.ThisKeyword) { + (jsxMemberExpression.object as any).name = 'this'; + } + + (jsxMemberExpression.object as any).type = isNestedMemberExpression + ? AST_NODE_TYPES.MemberExpression + : AST_NODE_TYPES.JSXIdentifier; + (jsxMemberExpression as any).property.type = + AST_NODE_TYPES.JSXIdentifier; + return jsxMemberExpression; + } else { + return this.createNode(node, { + type: AST_NODE_TYPES.MemberExpression, + object: this.convertChild(node.expression), + property: this.convertChild(node.name), + computed: false + }); + } + + case SyntaxKind.ElementAccessExpression: + return this.createNode(node, { type: AST_NODE_TYPES.MemberExpression, - object: convertChild(node.expression), - property: convertChild(node.name), - computed: false + object: this.convertChild(node.expression), + property: this.convertChild(node.argumentExpression), + computed: true }); - } - break; - case SyntaxKind.ElementAccessExpression: - Object.assign(result, { - type: AST_NODE_TYPES.MemberExpression, - object: convertChild(node.expression), - property: convertChild(node.argumentExpression), - computed: true - }); - break; - - case SyntaxKind.ConditionalExpression: - Object.assign(result, { - type: AST_NODE_TYPES.ConditionalExpression, - test: convertChild(node.condition), - consequent: convertChild(node.whenTrue), - alternate: convertChild(node.whenFalse) - }); - break; + case SyntaxKind.ConditionalExpression: + return this.createNode(node, { + type: AST_NODE_TYPES.ConditionalExpression, + test: this.convertChild(node.condition), + consequent: this.convertChild(node.whenTrue), + alternate: this.convertChild(node.whenFalse) + }); - case SyntaxKind.CallExpression: - Object.assign(result, { - type: AST_NODE_TYPES.CallExpression, - callee: convertChild(node.expression), - arguments: node.arguments.map(convertChild) - }); - if (node.typeArguments && node.typeArguments.length) { - result.typeParameters = convertTypeArgumentsToTypeParameters( - node.typeArguments - ); + case SyntaxKind.CallExpression: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.CallExpression, + callee: this.convertChild(node.expression), + arguments: node.arguments.map(el => this.convertChild(el)) + }); + if (node.typeArguments && node.typeArguments.length) { + result.typeParameters = this.convertTypeArgumentsToTypeParameters( + node.typeArguments + ); + } + return result; } - break; - case SyntaxKind.NewExpression: - Object.assign(result, { - type: AST_NODE_TYPES.NewExpression, - callee: convertChild(node.expression), - arguments: node.arguments ? node.arguments.map(convertChild) : [] - }); - if (node.typeArguments && node.typeArguments.length) { - result.typeParameters = convertTypeArgumentsToTypeParameters( - node.typeArguments - ); + case SyntaxKind.NewExpression: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.NewExpression, + callee: this.convertChild(node.expression), + arguments: node.arguments + ? node.arguments.map(el => this.convertChild(el)) + : [] + }); + if (node.typeArguments && node.typeArguments.length) { + result.typeParameters = this.convertTypeArgumentsToTypeParameters( + node.typeArguments + ); + } + return result; } - break; - - case SyntaxKind.MetaProperty: { - const newToken = convertToken(node.getFirstToken()!, ast); - Object.assign(result, { - type: AST_NODE_TYPES.MetaProperty, - meta: { - type: AST_NODE_TYPES.Identifier, - range: newToken.range, - loc: newToken.loc, - name: getTextForTokenKind(node.keywordToken) - }, - property: convertChild(node.name) - }); - break; - } - - case SyntaxKind.Decorator: { - Object.assign(result, { - type: AST_NODE_TYPES.Decorator, - expression: convertChild(node.expression) - }); - break; - } - // Literals + case SyntaxKind.MetaProperty: { + return this.createNode(node, { + type: AST_NODE_TYPES.MetaProperty, + meta: this.createNode(node.getFirstToken()!, { + type: AST_NODE_TYPES.Identifier, + name: getTextForTokenKind(node.keywordToken)! + }), + property: this.convertChild(node.name) + }); + } - case SyntaxKind.StringLiteral: - Object.assign(result, { - type: AST_NODE_TYPES.Literal, - raw: ast.text.slice(result.range[0], result.range[1]) - }); - if ((parent as any).name && (parent as any).name === node) { - (result as any).value = node.text; - } else { - (result as any).value = unescapeStringLiteralText(node.text); - } - break; - - case SyntaxKind.NumericLiteral: { - Object.assign(result, { - type: AST_NODE_TYPES.Literal, - value: Number(node.text), - raw: node.getText() - }); - break; - } + case SyntaxKind.Decorator: { + return this.createNode(node, { + type: AST_NODE_TYPES.Decorator, + expression: this.convertChild(node.expression) + }); + } - case SyntaxKind.BigIntLiteral: { - const raw = ast.text.slice(result.range[0], result.range[1]); - const value = raw.slice(0, -1); // remove suffix `n` - Object.assign(result, { - type: AST_NODE_TYPES.BigIntLiteral, - raw, - value - }); - break; - } + // Literals - case SyntaxKind.RegularExpressionLiteral: { - const pattern = node.text.slice(1, node.text.lastIndexOf('/')); - const flags = node.text.slice(node.text.lastIndexOf('/') + 1); + case SyntaxKind.StringLiteral: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.Literal, + raw: '', + value: '' + }); + result.raw = this.ast.text.slice(result.range[0], result.range[1]); + if ((parent as any).name && (parent as any).name === node) { + result.value = node.text; + } else { + result.value = unescapeStringLiteralText(node.text); + } + return result; + } - let regex = null; - try { - regex = new RegExp(pattern, flags); - } catch (exception) { - regex = null; + case SyntaxKind.NumericLiteral: { + return this.createNode(node, { + type: AST_NODE_TYPES.Literal, + value: Number(node.text), + raw: node.getText() + }); } - Object.assign(result, { - type: AST_NODE_TYPES.Literal, - value: regex, - raw: node.text, - regex: { - pattern, - flags - } - }); - break; - } + case SyntaxKind.BigIntLiteral: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.BigIntLiteral, + raw: '', + value: '' + }); + result.raw = this.ast.text.slice(result.range[0], result.range[1]); + result.value = result.raw.slice(0, -1); // remove suffix `n` + return result; + } - case SyntaxKind.TrueKeyword: - Object.assign(result, { - type: AST_NODE_TYPES.Literal, - value: true, - raw: 'true' - }); - break; + case SyntaxKind.RegularExpressionLiteral: { + const pattern = node.text.slice(1, node.text.lastIndexOf('/')); + const flags = node.text.slice(node.text.lastIndexOf('/') + 1); - case SyntaxKind.FalseKeyword: - Object.assign(result, { - type: AST_NODE_TYPES.Literal, - value: false, - raw: 'false' - }); - break; + let regex = null; + try { + regex = new RegExp(pattern, flags); + } catch (exception) { + regex = null; + } - case SyntaxKind.NullKeyword: { - if (config.inTypeMode) { - Object.assign(result, { - type: AST_NODE_TYPES.TSNullKeyword - }); - } else { - Object.assign(result, { + return this.createNode(node, { type: AST_NODE_TYPES.Literal, - value: null, - raw: 'null' + value: regex, + raw: node.text, + regex: { + pattern, + flags + } }); } - break; - } - case SyntaxKind.ImportKeyword: - Object.assign(result, { - type: AST_NODE_TYPES.Import - }); - break; + case SyntaxKind.TrueKeyword: + return this.createNode(node, { + type: AST_NODE_TYPES.Literal, + value: true, + raw: 'true' + }); - case SyntaxKind.EmptyStatement: - case SyntaxKind.DebuggerStatement: - Object.assign(result, { - type: SyntaxKind[node.kind] - }); - break; + case SyntaxKind.FalseKeyword: + return this.createNode(node, { + type: AST_NODE_TYPES.Literal, + value: false, + raw: 'false' + }); - // JSX + case SyntaxKind.NullKeyword: { + if (this.inTypeMode) { + return this.createNode(node, { + type: AST_NODE_TYPES.TSNullKeyword + }); + } else { + return this.createNode(node, { + type: AST_NODE_TYPES.Literal, + value: null, + raw: 'null' + }); + } + } - case SyntaxKind.JsxElement: - Object.assign(result, { - type: AST_NODE_TYPES.JSXElement, - openingElement: convertChild(node.openingElement), - closingElement: convertChild(node.closingElement), - children: node.children.map(convertChild) - }); + case SyntaxKind.ImportKeyword: + return this.createNode(node, { + type: AST_NODE_TYPES.Import + }); - break; + case SyntaxKind.EmptyStatement: + return this.createNode(node, { + type: AST_NODE_TYPES.EmptyStatement + }); - case SyntaxKind.JsxFragment: - Object.assign(result, { - type: AST_NODE_TYPES.JSXFragment, - openingFragment: convertChild(node.openingFragment), - closingFragment: convertChild(node.closingFragment), - children: node.children.map(convertChild) - }); - break; + case SyntaxKind.DebuggerStatement: + return this.createNode(node, { + type: AST_NODE_TYPES.DebuggerStatement + }); - case SyntaxKind.JsxSelfClosingElement: { - Object.assign(result, { - type: AST_NODE_TYPES.JSXElement, - /** - * Convert SyntaxKind.JsxSelfClosingElement to SyntaxKind.JsxOpeningElement, - * TypeScript does not seem to have the idea of openingElement when tag is self-closing - */ - openingElement: { + // JSX + + case SyntaxKind.JsxElement: + return this.createNode(node, { + type: AST_NODE_TYPES.JSXElement, + openingElement: this.convertChild(node.openingElement), + closingElement: this.convertChild(node.closingElement), + children: node.children.map(el => this.convertChild(el)) + }); + + case SyntaxKind.JsxFragment: + return this.createNode(node, { + type: AST_NODE_TYPES.JSXFragment, + openingFragment: this.convertChild(node.openingFragment), + closingFragment: this.convertChild(node.closingFragment), + children: node.children.map(el => this.convertChild(el)) + }); + + case SyntaxKind.JsxSelfClosingElement: { + return this.createNode(node, { + type: AST_NODE_TYPES.JSXElement, + /** + * Convert SyntaxKind.JsxSelfClosingElement to SyntaxKind.JsxOpeningElement, + * TypeScript does not seem to have the idea of openingElement when tag is self-closing + */ + openingElement: this.createNode(node, { + type: AST_NODE_TYPES.JSXOpeningElement, + typeParameters: node.typeArguments + ? this.convertTypeArgumentsToTypeParameters(node.typeArguments) + : undefined, + selfClosing: true, + name: this.convertTypeScriptJSXTagNameToESTreeName( + node.tagName, + node + ), + attributes: node.attributes.properties.map(el => + this.convertChild(el) + ), + range: getRange(node, this.ast) + }), + closingElement: null, + children: [] + }); + } + + case SyntaxKind.JsxOpeningElement: + return this.createNode(node, { type: AST_NODE_TYPES.JSXOpeningElement, typeParameters: node.typeArguments - ? convertTypeArgumentsToTypeParameters(node.typeArguments) + ? this.convertTypeArgumentsToTypeParameters(node.typeArguments) : undefined, - selfClosing: true, - name: convertTypeScriptJSXTagNameToESTreeName(node.tagName), - attributes: node.attributes.properties.map(convertChild), - range: result.range, - loc: result.loc - }, - closingElement: null, - children: [] - }); - break; - } - - case SyntaxKind.JsxOpeningElement: - Object.assign(result, { - type: AST_NODE_TYPES.JSXOpeningElement, - typeParameters: node.typeArguments - ? convertTypeArgumentsToTypeParameters(node.typeArguments) - : undefined, - selfClosing: false, - name: convertTypeScriptJSXTagNameToESTreeName(node.tagName), - attributes: node.attributes.properties.map(convertChild) - }); - break; + selfClosing: false, + name: this.convertTypeScriptJSXTagNameToESTreeName( + node.tagName, + node + ), + attributes: node.attributes.properties.map(el => + this.convertChild(el) + ) + }); - case SyntaxKind.JsxClosingElement: - Object.assign(result, { - type: AST_NODE_TYPES.JSXClosingElement, - name: convertTypeScriptJSXTagNameToESTreeName(node.tagName) - }); - break; + case SyntaxKind.JsxClosingElement: + return this.createNode(node, { + type: AST_NODE_TYPES.JSXClosingElement, + name: this.convertTypeScriptJSXTagNameToESTreeName(node.tagName, node) + }); - case SyntaxKind.JsxOpeningFragment: - Object.assign(result, { - type: AST_NODE_TYPES.JSXOpeningFragment - }); - break; - case SyntaxKind.JsxClosingFragment: - Object.assign(result, { - type: AST_NODE_TYPES.JSXClosingFragment - }); - break; - - case SyntaxKind.JsxExpression: { - const expression = node.expression - ? convertChild(node.expression) - : { - type: AST_NODE_TYPES.JSXEmptyExpression, - loc: { - start: getLineAndCharacterFor(result.range[0] + 1, ast), - end: { - line: result.loc.end.line, - column: result.loc.end.column - 1 - } - }, - range: [result.range[0] + 1, result.range[1] - 1] - }; - - Object.assign(result, { - type: node.dotDotDotToken - ? AST_NODE_TYPES.JSXSpreadChild - : AST_NODE_TYPES.JSXExpressionContainer, - expression - }); + case SyntaxKind.JsxOpeningFragment: + return this.createNode(node, { + type: AST_NODE_TYPES.JSXOpeningFragment + }); - break; - } + case SyntaxKind.JsxClosingFragment: + return this.createNode(node, { + type: AST_NODE_TYPES.JSXClosingFragment + }); - case SyntaxKind.JsxAttribute: { - const attributeName = convertToken(node.name, ast); - attributeName.type = AST_NODE_TYPES.JSXIdentifier; - attributeName.name = attributeName.value; - delete attributeName.value; + case SyntaxKind.JsxExpression: { + const expression = node.expression + ? this.convertChild(node.expression) + : this.createNode(node, { + type: AST_NODE_TYPES.JSXEmptyExpression, + range: [node.getStart(this.ast) + 1, node.getEnd() - 1] + }); - Object.assign(result, { - type: AST_NODE_TYPES.JSXAttribute, - name: attributeName, - value: convertChild(node.initializer) - }); + if (node.dotDotDotToken) { + return this.createNode(node, { + type: AST_NODE_TYPES.JSXSpreadChild, + expression + }); + } else { + return this.createNode(node, { + type: AST_NODE_TYPES.JSXExpressionContainer, + expression + }); + } + } - break; - } + case SyntaxKind.JsxAttribute: { + const attributeName = this.convertChild(node.name); + attributeName.type = AST_NODE_TYPES.JSXIdentifier; - /** - * The JSX AST changed the node type for string literals - * inside a JSX Element from `Literal` to `JSXText`. We - * provide a flag to support both types until `Literal` - * node type is deprecated in ESLint v5. - */ - case SyntaxKind.JsxText: { - const start = node.getFullStart(); - const end = node.getEnd(); - - const type = additionalOptions.useJSXTextNode - ? AST_NODE_TYPES.JSXText - : AST_NODE_TYPES.Literal; - - Object.assign(result, { - type, - value: ast.text.slice(start, end), - raw: ast.text.slice(start, end) - }); + return this.createNode(node, { + type: AST_NODE_TYPES.JSXAttribute, + name: attributeName, + value: this.convertChild(node.initializer) + }); + } - result.loc = getLocFor(start, end, ast); - result.range = [start, end]; + /** + * The JSX AST changed the node type for string literals + * inside a JSX Element from `Literal` to `JSXText`. We + * provide a flag to support both types until `Literal` + * node type is deprecated in ESLint v5. + */ + case SyntaxKind.JsxText: { + const start = node.getFullStart(); + const end = node.getEnd(); + + if (this.options.useJSXTextNode) { + return this.createNode(node, { + type: AST_NODE_TYPES.JSXText, + value: this.ast.text.slice(start, end), + raw: this.ast.text.slice(start, end), + range: [start, end] + }); + } else { + return this.createNode(node, { + type: AST_NODE_TYPES.Literal, + value: this.ast.text.slice(start, end), + raw: this.ast.text.slice(start, end), + range: [start, end] + }); + } + } - break; - } + case SyntaxKind.JsxSpreadAttribute: + return this.createNode(node, { + type: AST_NODE_TYPES.JSXSpreadAttribute, + argument: this.convertChild(node.expression) + }); - case SyntaxKind.JsxSpreadAttribute: - Object.assign(result, { - type: AST_NODE_TYPES.JSXSpreadAttribute, - argument: convertChild(node.expression) - }); - break; + case SyntaxKind.QualifiedName: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSQualifiedName, + left: this.convertChild(node.left), + right: this.convertChild(node.right) + }); + } - case SyntaxKind.QualifiedName: { - Object.assign(result, { - type: AST_NODE_TYPES.TSQualifiedName, - left: convertChild(node.left), - right: convertChild(node.right) - }); - break; - } + // TypeScript specific - // TypeScript specific + case SyntaxKind.TypeReference: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSTypeReference, + typeName: this.convertType(node.typeName), + typeParameters: node.typeArguments + ? this.convertTypeArgumentsToTypeParameters(node.typeArguments) + : undefined + }); + } - case SyntaxKind.TypeReference: { - Object.assign(result, { - type: AST_NODE_TYPES.TSTypeReference, - typeName: convertChildType(node.typeName), - typeParameters: node.typeArguments - ? convertTypeArgumentsToTypeParameters(node.typeArguments) - : undefined - }); - break; - } + case SyntaxKind.TypeParameter: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSTypeParameter, + name: this.convertType(node.name), + constraint: node.constraint + ? this.convertType(node.constraint) + : undefined, + default: node.default ? this.convertType(node.default) : undefined + }); + } - case SyntaxKind.TypeParameter: { - Object.assign(result, { - type: AST_NODE_TYPES.TSTypeParameter, - name: convertChildType(node.name), - constraint: node.constraint - ? convertChildType(node.constraint) - : undefined, - default: node.default ? convertChildType(node.default) : undefined - }); - break; - } + case SyntaxKind.ThisType: + case SyntaxKind.AnyKeyword: + case SyntaxKind.BigIntKeyword: + case SyntaxKind.BooleanKeyword: + case SyntaxKind.NeverKeyword: + case SyntaxKind.NumberKeyword: + case SyntaxKind.ObjectKeyword: + case SyntaxKind.StringKeyword: + case SyntaxKind.SymbolKeyword: + case SyntaxKind.UnknownKeyword: + case SyntaxKind.VoidKeyword: + case SyntaxKind.UndefinedKeyword: { + return this.createNode(node, { + type: AST_NODE_TYPES[`TS${SyntaxKind[node.kind]}` as AST_NODE_TYPES] + }); + } - case SyntaxKind.ThisType: - case SyntaxKind.AnyKeyword: - case SyntaxKind.BigIntKeyword: - case SyntaxKind.BooleanKeyword: - case SyntaxKind.NeverKeyword: - case SyntaxKind.NumberKeyword: - case SyntaxKind.ObjectKeyword: - case SyntaxKind.StringKeyword: - case SyntaxKind.SymbolKeyword: - case SyntaxKind.UnknownKeyword: - case SyntaxKind.VoidKeyword: - case SyntaxKind.UndefinedKeyword: { - Object.assign(result, { - type: AST_NODE_TYPES[`TS${SyntaxKind[node.kind]}` as AST_NODE_TYPES] - }); - break; - } + case SyntaxKind.NonNullExpression: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSNonNullExpression, + expression: this.convertChild(node.expression) + }); + } - case SyntaxKind.NonNullExpression: { - Object.assign(result, { - type: AST_NODE_TYPES.TSNonNullExpression, - expression: convertChild(node.expression) - }); - break; - } + case SyntaxKind.TypeLiteral: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSTypeLiteral, + members: node.members.map(el => this.convertChild(el)) + }); + } - case SyntaxKind.TypeLiteral: { - Object.assign(result, { - type: AST_NODE_TYPES.TSTypeLiteral, - members: node.members.map(convertChild) - }); - break; - } + case SyntaxKind.ArrayType: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSArrayType, + elementType: this.convertType(node.elementType) + }); + } - case SyntaxKind.ArrayType: { - Object.assign(result, { - type: AST_NODE_TYPES.TSArrayType, - elementType: convertChildType(node.elementType) - }); - break; - } + case SyntaxKind.IndexedAccessType: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSIndexedAccessType, + objectType: this.convertType(node.objectType), + indexType: this.convertType(node.indexType) + }); + } - case SyntaxKind.IndexedAccessType: { - Object.assign(result, { - type: AST_NODE_TYPES.TSIndexedAccessType, - objectType: convertChildType(node.objectType), - indexType: convertChildType(node.indexType) - }); - break; - } + case SyntaxKind.ConditionalType: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSConditionalType, + checkType: this.convertType(node.checkType), + extendsType: this.convertType(node.extendsType), + trueType: this.convertType(node.trueType), + falseType: this.convertType(node.falseType) + }); + } - case SyntaxKind.ConditionalType: { - Object.assign(result, { - type: AST_NODE_TYPES.TSConditionalType, - checkType: convertChildType(node.checkType), - extendsType: convertChildType(node.extendsType), - trueType: convertChildType(node.trueType), - falseType: convertChildType(node.falseType) - }); - break; - } + case SyntaxKind.TypeQuery: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSTypeQuery, + exprName: this.convertType(node.exprName) + }); + } - case SyntaxKind.TypeQuery: { - Object.assign(result, { - type: AST_NODE_TYPES.TSTypeQuery, - exprName: convertChildType(node.exprName) - }); - break; - } + case SyntaxKind.MappedType: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.TSMappedType, + typeParameter: this.convertType(node.typeParameter) + }); - case SyntaxKind.MappedType: { - Object.assign(result, { - type: AST_NODE_TYPES.TSMappedType, - typeParameter: convertChildType(node.typeParameter) - }); + if (node.readonlyToken) { + if (node.readonlyToken.kind === SyntaxKind.ReadonlyKeyword) { + result.readonly = true; + } else { + result.readonly = getTextForTokenKind(node.readonlyToken.kind) as + | '+' + | '-'; + } + } - if (node.readonlyToken) { - if (node.readonlyToken.kind === SyntaxKind.ReadonlyKeyword) { - result.readonly = true; - } else { - result.readonly = getTextForTokenKind(node.readonlyToken.kind); + if (node.questionToken) { + if (node.questionToken.kind === SyntaxKind.QuestionToken) { + result.optional = true; + } else { + result.optional = getTextForTokenKind(node.questionToken.kind) as + | '+' + | '-'; + } } - } - if (node.questionToken) { - if (node.questionToken.kind === SyntaxKind.QuestionToken) { - result.optional = true; - } else { - result.optional = getTextForTokenKind(node.questionToken.kind); + if (node.type) { + result.typeAnnotation = this.convertType(node.type); } + return result; } - if (node.type) { - result.typeAnnotation = convertChildType(node.type); - } - break; - } + case SyntaxKind.ParenthesizedExpression: + return this.convertChild(node.expression, parent); - case SyntaxKind.ParenthesizedExpression: - return convert({ - node: node.expression, - parent, - ast, - additionalOptions - }); + case SyntaxKind.TypeAliasDeclaration: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.TSTypeAliasDeclaration, + id: this.convertChild(node.name), + typeAnnotation: this.convertType(node.type) + }); - case SyntaxKind.TypeAliasDeclaration: { - Object.assign(result, { - type: AST_NODE_TYPES.TSTypeAliasDeclaration, - id: convertChild(node.name), - typeAnnotation: convertChildType(node.type) - }); + if (hasModifier(SyntaxKind.DeclareKeyword, node)) { + result.declare = true; + } - if (hasModifier(SyntaxKind.DeclareKeyword, node)) { - result.declare = true; - } + // Process typeParameters + if (node.typeParameters && node.typeParameters.length) { + result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( + node.typeParameters + ); + } - // Process typeParameters - if (node.typeParameters && node.typeParameters.length) { - result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration( - node.typeParameters - ); + // check for exports + return fixExports(node, result, this.ast); } - // check for exports - result = fixExports(node, result, ast); - break; - } + case SyntaxKind.MethodSignature: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.TSMethodSignature, + computed: isComputedProperty(node.name), + key: this.convertChild(node.name), + params: this.convertParameters(node.parameters) + }); - case SyntaxKind.MethodSignature: { - Object.assign(result, { - type: AST_NODE_TYPES.TSMethodSignature, - computed: isComputedProperty(node.name), - key: convertChild(node.name), - params: convertParameters(node.parameters) - }); + if (isOptional(node)) { + result.optional = true; + } - if (isOptional(node)) { - result.optional = true; - } + if (node.type) { + result.returnType = this.convertTypeAnnotation(node.type, node); + } - if (node.type) { - result.returnType = convertTypeAnnotation(node.type); - } + if (hasModifier(SyntaxKind.ReadonlyKeyword, node)) { + result.readonly = true; + } - if (hasModifier(SyntaxKind.ReadonlyKeyword, node)) { - result.readonly = true; - } + if (node.typeParameters) { + result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( + node.typeParameters + ); + } - if (node.typeParameters) { - result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration( - node.typeParameters - ); - } + const accessibility = getTSNodeAccessibility(node); + if (accessibility) { + result.accessibility = accessibility; + } - const accessibility = getTSNodeAccessibility(node); - if (accessibility) { - result.accessibility = accessibility; - } + if (hasModifier(SyntaxKind.ExportKeyword, node)) { + result.export = true; + } - if (hasModifier(SyntaxKind.ExportKeyword, node)) { - result.export = true; + if (hasModifier(SyntaxKind.StaticKeyword, node)) { + result.static = true; + } + return result; } - if (hasModifier(SyntaxKind.StaticKeyword, node)) { - result.static = true; - } - break; - } + case SyntaxKind.PropertySignature: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.TSPropertySignature, + optional: isOptional(node) || undefined, + computed: isComputedProperty(node.name), + key: this.convertChild(node.name), + typeAnnotation: node.type + ? this.convertTypeAnnotation(node.type, node) + : undefined, + initializer: this.convertChild(node.initializer) || undefined, + readonly: hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined, + static: hasModifier(SyntaxKind.StaticKeyword, node) || undefined, + export: hasModifier(SyntaxKind.ExportKeyword, node) || undefined + }); - case SyntaxKind.PropertySignature: { - Object.assign(result, { - type: AST_NODE_TYPES.TSPropertySignature, - optional: isOptional(node) || undefined, - computed: isComputedProperty(node.name), - key: convertChild(node.name), - typeAnnotation: node.type - ? convertTypeAnnotation(node.type) - : undefined, - initializer: convertChild(node.initializer) || undefined, - readonly: hasModifier(SyntaxKind.ReadonlyKeyword, node) || undefined, - static: hasModifier(SyntaxKind.StaticKeyword, node) || undefined, - export: hasModifier(SyntaxKind.ExportKeyword, node) || undefined - }); + const accessibility = getTSNodeAccessibility(node); + if (accessibility) { + result.accessibility = accessibility; + } - const accessibility = getTSNodeAccessibility(node); - if (accessibility) { - result.accessibility = accessibility; + return result; } - break; - } + case SyntaxKind.IndexSignature: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.TSIndexSignature, + parameters: node.parameters.map(el => this.convertChild(el)) + }); - case SyntaxKind.IndexSignature: { - Object.assign(result, { - type: AST_NODE_TYPES.TSIndexSignature, - parameters: node.parameters.map(convertChild) - }); + if (node.type) { + result.typeAnnotation = this.convertTypeAnnotation(node.type, node); + } - if (node.type) { - result.typeAnnotation = convertTypeAnnotation(node.type); - } + if (hasModifier(SyntaxKind.ReadonlyKeyword, node)) { + result.readonly = true; + } - if (hasModifier(SyntaxKind.ReadonlyKeyword, node)) { - result.readonly = true; - } + const accessibility = getTSNodeAccessibility(node); + if (accessibility) { + result.accessibility = accessibility; + } - const accessibility = getTSNodeAccessibility(node); - if (accessibility) { - result.accessibility = accessibility; - } + if (hasModifier(SyntaxKind.ExportKeyword, node)) { + result.export = true; + } - if (hasModifier(SyntaxKind.ExportKeyword, node)) { - result.export = true; - } + if (hasModifier(SyntaxKind.StaticKeyword, node)) { + result.static = true; + } + return result; + } + case SyntaxKind.ConstructorType: + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructSignature: + case SyntaxKind.CallSignature: { + let type: AST_NODE_TYPES; + switch (node.kind) { + case SyntaxKind.ConstructSignature: + type = AST_NODE_TYPES.TSConstructSignatureDeclaration; + break; + case SyntaxKind.CallSignature: + type = AST_NODE_TYPES.TSCallSignatureDeclaration; + break; + case SyntaxKind.FunctionType: + type = AST_NODE_TYPES.TSFunctionType; + break; + case SyntaxKind.ConstructorType: + default: + type = AST_NODE_TYPES.TSConstructorType; + break; + } + const result = this.createNode< + | es.TSConstructSignatureDeclaration + | es.TSCallSignatureDeclaration + | es.TSFunctionType + | es.TSConstructorType + >(node, { + type: type, + params: this.convertParameters(node.parameters) + }); - if (hasModifier(SyntaxKind.StaticKeyword, node)) { - result.static = true; - } - break; - } - case SyntaxKind.ConstructorType: - case SyntaxKind.FunctionType: - case SyntaxKind.ConstructSignature: - case SyntaxKind.CallSignature: { - let type: AST_NODE_TYPES; - switch (node.kind) { - case SyntaxKind.ConstructSignature: - type = AST_NODE_TYPES.TSConstructSignatureDeclaration; - break; - case SyntaxKind.CallSignature: - type = AST_NODE_TYPES.TSCallSignatureDeclaration; - break; - case SyntaxKind.FunctionType: - type = AST_NODE_TYPES.TSFunctionType; - break; - case SyntaxKind.ConstructorType: - default: - type = AST_NODE_TYPES.TSConstructorType; - break; - } - Object.assign(result, { - type: type, - params: convertParameters(node.parameters) - }); + if (node.type) { + result.returnType = this.convertTypeAnnotation(node.type, node); + } - if (node.type) { - result.returnType = convertTypeAnnotation(node.type); - } + if (node.typeParameters) { + result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( + node.typeParameters + ); + } - if (node.typeParameters) { - result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration( - node.typeParameters - ); + return result; } - break; - } + case SyntaxKind.ExpressionWithTypeArguments: { + const result = this.createNode< + es.TSInterfaceHeritage | es.TSClassImplements + >(node, { + type: + parent && parent.kind === SyntaxKind.InterfaceDeclaration + ? AST_NODE_TYPES.TSInterfaceHeritage + : AST_NODE_TYPES.TSClassImplements, + expression: this.convertChild(node.expression) + }); - case SyntaxKind.ExpressionWithTypeArguments: { - Object.assign(result, { - type: - parent && parent.kind === SyntaxKind.InterfaceDeclaration - ? AST_NODE_TYPES.TSInterfaceHeritage - : AST_NODE_TYPES.TSClassImplements, - expression: convertChild(node.expression) - }); + if (node.typeArguments && node.typeArguments.length) { + result.typeParameters = this.convertTypeArgumentsToTypeParameters( + node.typeArguments + ); + } + return result; + } + + case SyntaxKind.InterfaceDeclaration: { + const interfaceHeritageClauses = node.heritageClauses || []; + const result = this.createNode(node, { + type: AST_NODE_TYPES.TSInterfaceDeclaration, + body: this.createNode(node, { + type: AST_NODE_TYPES.TSInterfaceBody, + body: node.members.map(member => this.convertChild(member)), + range: [node.members.pos - 1, node.end] + }), + id: this.convertChild(node.name) + }); - if (node.typeArguments && node.typeArguments.length) { - result.typeParameters = convertTypeArgumentsToTypeParameters( - node.typeArguments - ); - } - break; - } + if (node.typeParameters && node.typeParameters.length) { + result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( + node.typeParameters + ); + } - case SyntaxKind.InterfaceDeclaration: { - const interfaceHeritageClauses = node.heritageClauses || []; + if (interfaceHeritageClauses.length > 0) { + const interfaceExtends = []; + const interfaceImplements = []; - if (node.typeParameters && node.typeParameters.length) { - result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration( - node.typeParameters - ); - } + for (const heritageClause of interfaceHeritageClauses) { + if (heritageClause.token === SyntaxKind.ExtendsKeyword) { + for (const n of heritageClause.types) { + interfaceExtends.push(this.convertChild(n, node)); + } + } else if (heritageClause.token === SyntaxKind.ImplementsKeyword) { + for (const n of heritageClause.types) { + interfaceImplements.push(this.convertChild(n, node)); + } + } + } - const interfaceBodyRange = [node.members.pos - 1, node.end]; + if (interfaceExtends.length) { + result.extends = interfaceExtends; + } - Object.assign(result, { - type: AST_NODE_TYPES.TSInterfaceDeclaration, - body: { - type: AST_NODE_TYPES.TSInterfaceBody, - body: node.members.map(member => convertChild(member)), - range: interfaceBodyRange, - loc: getLocFor(interfaceBodyRange[0], interfaceBodyRange[1], ast) - }, - id: convertChild(node.name) - }); + if (interfaceImplements.length) { + result.implements = interfaceImplements; + } + } + + /** + * Semantically, decorators are not allowed on interface declarations, + * but the TypeScript compiler will parse them and produce a valid AST, + * so we handle them here too. + */ + if (node.decorators) { + result.decorators = node.decorators.map(el => this.convertChild(el)); + } + if (hasModifier(SyntaxKind.AbstractKeyword, node)) { + result.abstract = true; + } + if (hasModifier(SyntaxKind.DeclareKeyword, node)) { + result.declare = true; + } + // check for exports + return fixExports(node, result, this.ast); + } - if (interfaceHeritageClauses.length > 0) { - const interfaceExtends = []; - const interfaceImplements = []; + case SyntaxKind.FirstTypeNode: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.TSTypePredicate, + parameterName: this.convertChild(node.parameterName), + typeAnnotation: this.convertTypeAnnotation(node.type, node) + }); + /** + * Specific fix for type-guard location data + */ + result.typeAnnotation.loc = result.typeAnnotation.typeAnnotation.loc; + result.typeAnnotation.range = + result.typeAnnotation.typeAnnotation.range; + return result; + } + + case SyntaxKind.ImportType: + return this.createNode(node, { + type: AST_NODE_TYPES.TSImportType, + isTypeOf: !!node.isTypeOf, + parameter: this.convertChild(node.argument), + qualifier: this.convertChild(node.qualifier), + typeParameters: node.typeArguments + ? this.convertTypeArgumentsToTypeParameters(node.typeArguments) + : null + }); - for (const heritageClause of interfaceHeritageClauses) { - if (heritageClause.token === SyntaxKind.ExtendsKeyword) { - for (const n of heritageClause.types) { - interfaceExtends.push(convertChild(n)); - } - } else if (heritageClause.token === SyntaxKind.ImplementsKeyword) { - for (const n of heritageClause.types) { - interfaceImplements.push(convertChild(n)); - } - } + case SyntaxKind.EnumDeclaration: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.TSEnumDeclaration, + id: this.convertChild(node.name), + members: node.members.map(el => this.convertChild(el)) + }); + // apply modifiers first... + this.applyModifiersToResult(result, node.modifiers); + /** + * Semantically, decorators are not allowed on enum declarations, + * but the TypeScript compiler will parse them and produce a valid AST, + * so we handle them here too. + */ + if (node.decorators) { + result.decorators = node.decorators.map(el => this.convertChild(el)); } + // ...then check for exports + return fixExports(node, result, this.ast); + } - if (interfaceExtends.length) { - result.extends = interfaceExtends; + case SyntaxKind.EnumMember: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.TSEnumMember, + id: this.convertChild(node.name) + }); + if (node.initializer) { + result.initializer = this.convertChild(node.initializer); } + return result; + } - if (interfaceImplements.length) { - result.implements = interfaceImplements; + case SyntaxKind.ModuleDeclaration: { + const result = this.createNode(node, { + type: AST_NODE_TYPES.TSModuleDeclaration, + id: this.convertChild(node.name) + }); + if (node.body) { + result.body = this.convertChild(node.body); } + // apply modifiers first... + this.applyModifiersToResult(result, node.modifiers); + if (node.flags & ts.NodeFlags.GlobalAugmentation) { + result.global = true; + } + // ...then check for exports + return fixExports(node, result, this.ast); } - /** - * Semantically, decorators are not allowed on interface declarations, - * but the TypeScript compiler will parse them and produce a valid AST, - * so we handle them here too. - */ - if (node.decorators) { - result.decorators = node.decorators.map(convertChild); + // TypeScript specific types + case SyntaxKind.OptionalType: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSOptionalType, + typeAnnotation: this.convertType(node.type) + }); } - if (hasModifier(SyntaxKind.AbstractKeyword, node)) { - result.abstract = true; + case SyntaxKind.ParenthesizedType: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSParenthesizedType, + typeAnnotation: this.convertType(node.type) + }); } - if (hasModifier(SyntaxKind.DeclareKeyword, node)) { - result.declare = true; + case SyntaxKind.TupleType: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSTupleType, + elementTypes: node.elementTypes.map(el => this.convertType(el)) + }); } - // check for exports - result = fixExports(node, result, ast); - - break; - } - - case SyntaxKind.FirstTypeNode: - Object.assign(result, { - type: AST_NODE_TYPES.TSTypePredicate, - parameterName: convertChild(node.parameterName), - typeAnnotation: convertTypeAnnotation(node.type) - }); - /** - * Specific fix for type-guard location data - */ - result.typeAnnotation!.loc = result.typeAnnotation!.typeAnnotation!.loc; - result.typeAnnotation!.range = result.typeAnnotation!.typeAnnotation!.range; - break; - - case SyntaxKind.ImportType: - Object.assign(result, { - type: AST_NODE_TYPES.TSImportType, - isTypeOf: !!node.isTypeOf, - parameter: convertChild(node.argument), - qualifier: convertChild(node.qualifier), - typeParameters: node.typeArguments - ? convertTypeArgumentsToTypeParameters(node.typeArguments) - : null - }); - break; - - case SyntaxKind.EnumDeclaration: { - Object.assign(result, { - type: AST_NODE_TYPES.TSEnumDeclaration, - id: convertChild(node.name), - members: node.members.map(convertChild) - }); - // apply modifiers first... - applyModifiersToResult(node.modifiers); - // ...then check for exports - result = fixExports(node, result, ast); - /** - * Semantically, decorators are not allowed on enum declarations, - * but the TypeScript compiler will parse them and produce a valid AST, - * so we handle them here too. - */ - if (node.decorators) { - result.decorators = node.decorators.map(convertChild); + case SyntaxKind.UnionType: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSUnionType, + types: node.types.map(el => this.convertType(el)) + }); } - break; - } - - case SyntaxKind.EnumMember: { - Object.assign(result, { - type: AST_NODE_TYPES.TSEnumMember, - id: convertChild(node.name) - }); - if (node.initializer) { - (result as any).initializer = convertChild(node.initializer); + case SyntaxKind.IntersectionType: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSIntersectionType, + types: node.types.map(el => this.convertType(el)) + }); } - break; - } - - case SyntaxKind.AbstractKeyword: { - Object.assign(result, { - type: AST_NODE_TYPES.TSAbstractKeyword - }); - break; - } - - case SyntaxKind.ModuleDeclaration: { - Object.assign(result, { - type: AST_NODE_TYPES.TSModuleDeclaration, - id: convertChild(node.name) - }); - if (node.body) { - result.body = convertChild(node.body); + case SyntaxKind.RestType: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSRestType, + typeAnnotation: this.convertType(node.type) + }); } - // apply modifiers first... - applyModifiersToResult(node.modifiers); - if (node.flags & ts.NodeFlags.GlobalAugmentation) { - result.global = true; + case SyntaxKind.AsExpression: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSAsExpression, + expression: this.convertChild(node.expression), + typeAnnotation: this.convertType(node.type) + }); } - // ...then check for exports - result = fixExports(node, result, ast); - break; - } - - // TypeScript specific types - case SyntaxKind.OptionalType: { - Object.assign(result, { - type: AST_NODE_TYPES.TSOptionalType, - typeAnnotation: convertChildType(node.type) - }); - break; - } - case SyntaxKind.ParenthesizedType: { - Object.assign(result, { - type: AST_NODE_TYPES.TSParenthesizedType, - typeAnnotation: convertChildType(node.type) - }); - break; - } - case SyntaxKind.TupleType: { - Object.assign(result, { - type: AST_NODE_TYPES.TSTupleType, - elementTypes: node.elementTypes.map(convertChildType) - }); - break; - } - case SyntaxKind.UnionType: { - Object.assign(result, { - type: AST_NODE_TYPES.TSUnionType, - types: node.types.map(convertChildType) - }); - break; - } - case SyntaxKind.IntersectionType: { - Object.assign(result, { - type: AST_NODE_TYPES.TSIntersectionType, - types: node.types.map(convertChildType) - }); - break; - } - case SyntaxKind.RestType: { - Object.assign(result, { - type: AST_NODE_TYPES.TSRestType, - typeAnnotation: convertChildType(node.type) - }); - break; - } - case SyntaxKind.AsExpression: { - Object.assign(result, { - type: AST_NODE_TYPES.TSAsExpression, - expression: convertChild(node.expression), - typeAnnotation: convertChildType(node.type) - }); - break; - } - case SyntaxKind.InferType: { - Object.assign(result, { - type: AST_NODE_TYPES.TSInferType, - typeParameter: convertChildType(node.typeParameter) - }); - break; - } - case SyntaxKind.LiteralType: { - Object.assign(result, { - type: AST_NODE_TYPES.TSLiteralType, - literal: convertChildType(node.literal) - }); - break; - } - case SyntaxKind.TypeAssertionExpression: { - Object.assign(result, { - type: AST_NODE_TYPES.TSTypeAssertion, - typeAnnotation: convertChildType(node.type), - expression: convertChild(node.expression) - }); - break; - } - case SyntaxKind.ImportEqualsDeclaration: { - Object.assign(result, { - type: AST_NODE_TYPES.TSImportEqualsDeclaration, - id: convertChild(node.name), - moduleReference: convertChild(node.moduleReference), - isExport: hasModifier(SyntaxKind.ExportKeyword, node) - }); - break; - } - case SyntaxKind.ExternalModuleReference: { - Object.assign(result, { - type: AST_NODE_TYPES.TSExternalModuleReference, - expression: convertChild(node.expression) - }); - break; - } - case SyntaxKind.NamespaceExportDeclaration: { - Object.assign(result, { - type: AST_NODE_TYPES.TSNamespaceExportDeclaration, - id: convertChild(node.name) - }); - break; + case SyntaxKind.InferType: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSInferType, + typeParameter: this.convertType(node.typeParameter) + }); + } + case SyntaxKind.LiteralType: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSLiteralType, + literal: this.convertType(node.literal) + }); + } + case SyntaxKind.TypeAssertionExpression: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSTypeAssertion, + typeAnnotation: this.convertType(node.type), + expression: this.convertChild(node.expression) + }); + } + case SyntaxKind.ImportEqualsDeclaration: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSImportEqualsDeclaration, + id: this.convertChild(node.name), + moduleReference: this.convertChild(node.moduleReference), + isExport: hasModifier(SyntaxKind.ExportKeyword, node) + }); + } + case SyntaxKind.ExternalModuleReference: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSExternalModuleReference, + expression: this.convertChild(node.expression) + }); + } + case SyntaxKind.NamespaceExportDeclaration: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSNamespaceExportDeclaration, + id: this.convertChild(node.name) + }); + } + case SyntaxKind.AbstractKeyword: { + return this.createNode(node, { + type: AST_NODE_TYPES.TSAbstractKeyword + }); + } + default: + return this.deeplyCopy(node); } - - default: - deeplyCopy(); } - - if (additionalOptions.shouldProvideParserServices) { - tsNodeToESTreeNodeMap.set(node, result); - esTreeNodeToTSNodeMap.set(result, node); - } - - return result; } diff --git a/packages/typescript-estree/src/estree/experimental.ts b/packages/typescript-estree/src/estree/experimental.ts deleted file mode 100644 index 103d9ffd53a5..000000000000 --- a/packages/typescript-estree/src/estree/experimental.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Node, Expression, MethodDefinition, Property, Class } from './spec'; - -/** - * Decorator - */ -export interface Decorator extends Node { - type: 'Decorator'; - expression: Expression; -} - -/** - * MethodDefinition - */ -export interface ExtendedMethodDefinition extends MethodDefinition { - decorators: Decorator[]; -} - -/** - * Property - */ -export interface ExtendedProperty extends Property { - decorators: Decorator[]; -} - -/** - * Class - */ -export interface ExtendedClass extends Class { - decorators: Decorator[]; -} diff --git a/packages/typescript-estree/src/estree/extensions.ts b/packages/typescript-estree/src/estree/extensions.ts deleted file mode 100644 index 5e036917a3b3..000000000000 --- a/packages/typescript-estree/src/estree/extensions.ts +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Based on https://github.com/estree/estree/blob/master/extensions/type-annotations.md - */ - -import { - Identifier, - Function, - ObjectPattern, - ArrayPattern, - RestElement -} from './spec'; - -/** - * Type Annotations - */ - -/** - * Any type annotation. - */ -export interface TypeAnnotation extends Node {} - -/** - * Identifier - * - * The `typeAnnotation` property is used only in the case of variable declarations with type annotations or function arguments with type annotations. - */ -export interface ExtendedIdentifier extends Identifier { - typeAnnotation: TypeAnnotation | null; -} - -/** - * Functions - * - * The `returnType` property is used to specify the type annotation for the return value of the function. - */ -export interface ExtendedFunction extends Function { - returnType: TypeAnnotation | null; -} - -/** - * Patterns - */ - -/** - * ObjectPattern - */ -export interface ExtendedObjectPattern extends ObjectPattern { - typeAnnotation: TypeAnnotation | null; -} - -/** - * ArrayPattern - */ -export interface ExtendedArrayPattern extends ArrayPattern { - typeAnnotation: TypeAnnotation | null; -} - -/** - * RestElement - */ -export interface ExtendedRestElement extends RestElement { - typeAnnotation: TypeAnnotation | null; -} diff --git a/packages/typescript-estree/src/estree/spec.ts b/packages/typescript-estree/src/estree/spec.ts deleted file mode 100644 index 1d2a0a765ee6..000000000000 --- a/packages/typescript-estree/src/estree/spec.ts +++ /dev/null @@ -1,985 +0,0 @@ -/** - * This document specifies the core ESTree AST node types based on: - * - ES5: https://github.com/estree/estree/blob/master/es5.md - * - ES2015: https://github.com/estree/estree/blob/master/es2015.md - * - ES2016: https://github.com/estree/estree/blob/master/es2016.md - * - ES2017: https://github.com/estree/estree/blob/master/es2017.md - * - ES2018: https://github.com/estree/estree/blob/master/es2018.md - */ - -/** - * Node objects - * - * ESTree AST nodes are represented as `Node` objects, which may have any prototype inheritance but which implement the following interface: - */ - -export interface Node { - type: string; - loc: SourceLocation | null; -} - -/** - * The `type` field is a string representing the AST variant type. Each subtype of `Node` is documented below with the specific string of its `type` field. You can use this field to determine which interface a node implements. - * - * The `loc` field represents the source location information of the node. If the node contains no information about the source location, the field is `null`; otherwise it is an object consisting of a start position (the position of the first character of the parsed source region) and an end position (the position of the first character after the parsed source region): - */ -export interface SourceLocation { - source: string | null; - start: Position; - end: Position; -} - -/** - * Each `Position` object consists of a `line` number (1-indexed) and a `column` number (0-indexed): - */ -export interface Position { - line: number; // >= 1 - column: number; // >= 0 -} - -/** - * Identifier - * - * An identifier. Note that an identifier may be an expression or a destructuring pattern. - */ -export interface Identifier extends Expression, Pattern { - type: 'Identifier'; - name: string; -} - -/** - * Literal - * - * A literal token. Note that a literal can be an expression. - */ -export interface Literal extends Expression { - type: 'Literal'; - value: string | boolean | null | number | RegExp; -} - -/** - * RegExpLiteral - * - * The `regex` property allows regexes to be represented in environments that don’t - * support certain flags such as `y` or `u`. In environments that don't support - * these flags `value` will be `null` as the regex can't be represented natively. - */ -export interface RegExpLiteral extends Literal { - regex: { - pattern: string; - flags: string; - }; -} - -/** - * Programs - * - * A complete program source tree. - * - * ES2015+ Parsers must specify sourceType as "module" if the source has been parsed as an ES6 module. Otherwise, sourceType must be "script". - */ -export interface Program extends Node { - type: 'Program'; - body: Array; - sourceType: 'script' | 'module'; -} - -/** - * Functions - * - * A function declaration or expression. - */ -export interface Function extends Node { - id: Identifier | null; - params: Pattern[]; - body: FunctionBody; - generator: boolean; - async: boolean; -} - -/** - * Statements - * - * Any statement. - */ -export interface Statement extends Node {} - -/** - * ExpressionStatement - * - * An expression statement, i.e., a statement consisting of a single expression. - */ -export interface ExpressionStatement extends Statement { - type: 'ExpressionStatement'; - expression: Expression; -} - -/** - * Directive - * - * A directive from the directive prologue of a script or function. - * The `directive` property is the raw string source of the directive without quotes. - */ -export interface Directive extends Node { - type: 'ExpressionStatement'; - expression: Literal; - directive: string; -} - -/** - * BlockStatement - * - * A block statement, i.e., a sequence of statements surrounded by braces. - */ -export interface BlockStatement extends Statement { - type: 'BlockStatement'; - body: Statement[]; -} - -/** - * FunctionBody - * - * The body of a function, which is a block statement that may begin with directives. - */ -export interface FunctionBody extends BlockStatement { - body: Array; -} - -/** - * EmptyStatement - * - * An empty statement, i.e., a solitary semicolon. - */ -export interface EmptyStatement extends Statement { - type: 'EmptyStatement'; -} - -/** - * DebuggerStatement - * - * A `debugger` statement. - */ -export interface DebuggerStatement extends Statement { - type: 'DebuggerStatement'; -} - -/** - * WithStatement - * - * A `with` statement. - */ -export interface WithStatement extends Statement { - type: 'WithStatement'; - object: Expression; - body: Statement; -} - -/** - * Control flow - */ - -/** - * ReturnStatement - * - * A `return` statement. - */ -export interface ReturnStatement extends Statement { - type: 'ReturnStatement'; - argument: Expression | null; -} - -/** - * LabeledStatement - * - * A labeled statement, i.e., a statement prefixed by a `break`/`continue` label. - */ -export interface LabeledStatement extends Statement { - type: 'LabeledStatement'; - label: Identifier; - body: Statement; -} - -/** - * BreakStatement - * - * A `break` statement. - */ -export interface BreakStatement extends Statement { - type: 'BreakStatement'; - label: Identifier | null; -} - -/** - * ContinueStatement - * - * A `continue` statement. - */ -export interface ContinueStatement extends Statement { - type: 'ContinueStatement'; - label: Identifier | null; -} - -/** - * Choice - */ - -/** - * IfStatement - * - * An `if` statement. - */ -export interface IfStatement extends Statement { - type: 'IfStatement'; - test: Expression; - consequent: Statement; - alternate: Statement | null; -} - -/** - * SwitchStatement - * - * A `switch` statement. - */ -export interface SwitchStatement extends Statement { - type: 'SwitchStatement'; - discriminant: Expression; - cases: SwitchCase[]; -} - -/** - * SwitchCase - * - * A `case` (if `test` is an `Expression`) or `default` (if `test === null`) clause in the body of a `switch` statement. - */ -export interface SwitchCase extends Node { - type: 'SwitchCase'; - test: Expression | null; - consequent: Statement[]; -} - -/** - * Exceptions - */ - -/** - * ThrowStatement - * - * A `throw` statement. - */ -export interface ThrowStatement extends Statement { - type: 'ThrowStatement'; - argument: Expression; -} - -/** - * TryStatement - * - * A `try` statement. If `handler` is `null` then `finalizer` must be a `BlockStatement`. - */ -export interface TryStatement extends Statement { - type: 'TryStatement'; - block: BlockStatement; - handler: CatchClause | null; - finalizer: BlockStatement | null; -} - -/** - * CatchClause - * - * A `catch` clause following a `try` block. - * - * The param is null if the catch binding is omitted. E.g., try { foo() } catch { bar() } - */ -export interface CatchClause extends Node { - type: 'CatchClause'; - param: Pattern | null; - body: BlockStatement; -} - -/** - * Loops - */ - -/** - * WhileStatement - * - * A `while` statement. - */ -export interface WhileStatement extends Statement { - type: 'WhileStatement'; - test: Expression; - body: Statement; -} - -/** - * DoWhileStatement - * - * A `do`/`while` statement. - */ -export interface DoWhileStatement extends Statement { - type: 'DoWhileStatement'; - body: Statement; - test: Expression; -} - -/** - * ForStatement - * - * A `for` statement. - */ -export interface ForStatement extends Statement { - type: 'ForStatement'; - init: VariableDeclaration | Expression | null; - test: Expression | null; - update: Expression | null; - body: Statement; -} - -/** - * ForInStatement - * - * A `for`/`in` statement. - */ -export interface ForInStatement extends Statement { - type: 'ForInStatement'; - left: VariableDeclaration | Pattern; - right: Expression; - body: Statement; -} - -/** - * ForOfStatement - * - * A `for`/`of` statement and for-await-of statements, e.g., for await (const x of xs) { - */ -export interface ForOfStatement { - type: 'ForOfStatement'; - left: VariableDeclaration | Pattern; - right: Expression; - body: Statement; - await: boolean; -} - -/** - * Declarations - * - * Any declaration node. Note that declarations are considered statements; this is because declarations can appear in any statement context. - */ -export interface Declaration extends Statement {} - -/** - * FunctionDeclaration - * - * A function declaration. Note that unlike in the parent interface `Function`, the `id` cannot be `null`. - */ -export interface FunctionDeclaration extends Function, Declaration { - type: 'FunctionDeclaration'; - id: Identifier; -} - -/** - * VariableDeclaration - * - * A variable declaration. - */ -export interface VariableDeclaration extends Declaration { - type: 'VariableDeclaration'; - declarations: VariableDeclarator[]; - kind: 'var' | 'let' | 'const'; -} - -/** - * VariableDeclarator - * - * A variable declarator. - */ -export interface VariableDeclarator extends Node { - type: 'VariableDeclarator'; - id: Pattern; - init: Expression | null; -} - -/** - * Expressions - * - * Any expression node. Since the left-hand side of an assignment may be any expression in general, an expression can also be a pattern. - */ -export interface Expression extends Node {} - -/** - * Super - * - * A super pseudo-expression. - */ -export interface Super extends Node { - type: 'Super'; -} - -/** - * ThisExpression - * - * A `this` expression. - */ -export interface ThisExpression extends Expression { - type: 'ThisExpression'; -} - -/** - * SpreadElement - * - * Spread expression, e.g., [head, ...iter, tail], f(head, ...iter, ...tail). - */ -export interface SpreadElement extends Node { - type: 'SpreadElement'; - argument: Expression; -} - -/** - * ArrayExpression - * - * An array expression. - */ -export interface ArrayExpression extends Expression { - type: 'ArrayExpression'; - elements: Array; -} - -/** - * ObjectExpression - * - * An object expression. - * - * Spread properties, e.g., {a: 1, ...obj, b: 2}. - */ -export interface ObjectExpression extends Expression { - type: 'ObjectExpression'; - properties: Array; -} - -/** - * Property - * - * A literal property in an object expression can have either a string or number as its `value`. Ordinary property initializers have a `kind` value `"init"`; getters and setters have the kind values `"get"` and `"set"`, respectively. - */ -export interface Property extends Node { - type: 'Property'; - key: Literal | Identifier | Expression; - value: Expression; - kind: 'init' | 'get' | 'set'; - method: boolean; - shorthand: boolean; - computed: boolean; -} - -/** - * FunctionExpression - * - * A `function` expression. - */ -export interface FunctionExpression extends Function, Expression { - type: 'FunctionExpression'; -} - -/** - * ArrowFunctionExpression - * - * A fat arrow function expression, e.g., let foo = (bar) => { / body / }. - */ -export interface ArrowFunctionExpression extends Expression { - id: Identifier | null; - params: Pattern[]; - type: 'ArrowFunctionExpression'; - body: FunctionBody | Expression; - generator: boolean; - expression: boolean; -} - -/** - * Unary operations - */ - -/** - * UnaryExpression - * - * A unary operator expression. - */ -export interface UnaryExpression extends Expression { - type: 'UnaryExpression'; - operator: UnaryOperator; - prefix: boolean; - argument: Expression; -} - -/** - * UnaryOperator - * - * A unary operator token. - */ -export type UnaryOperator = - | '-' - | '+' - | '!' - | '~' - | 'typeof' - | 'void' - | 'delete'; - -/** - * UpdateExpression - * - * An update (increment or decrement) operator expression. - */ -export interface UpdateExpression extends Expression { - type: 'UpdateExpression'; - operator: UpdateOperator; - argument: Expression; - prefix: boolean; -} - -/** - * UpdateOperator - * - * An update (increment or decrement) operator token. - */ -export type UpdateOperator = '++' | '--'; - -/** - * Binary operations - */ - -/** - * BinaryExpression - * - * A binary operator expression. - */ -export interface BinaryExpression extends Expression { - type: 'BinaryExpression'; - operator: BinaryOperator; - left: Expression; - right: Expression; -} - -/** - * BinaryOperator - * - * A binary operator token. - */ -export type BinaryOperator = - | '==' - | '!=' - | '===' - | '!==' - | '<' - | '<=' - | '>' - | '>=' - | '<<' - | '>>' - | '>>>' - | '+' - | '-' - | '*' - | '/' - | '%' - | '|' - | '^' - | '&' - | 'in' - | 'instanceof' - | '**'; - -/** - * AssignmentExpression - * - * An assignment operator expression. - * - * FROM ESTREE DOCS: - * - * ``` - * FIXME: This describes the Esprima and Acorn behaviors, which is not currently aligned with the SpiderMonkey behavior. - * - * extend interface AssignmentExpression { - * left: Pattern; - * } - * - * Note that pre-ES6 code was allowed to pass references around and so left was much more liberal; an implementation might choose to continue using old definition if it needs to support such legacy code. - * ``` - */ -export interface AssignmentExpression extends Expression { - type: 'AssignmentExpression'; - operator: AssignmentOperator; - left: Pattern | Expression; - right: Expression; -} - -/** - * AssignmentOperator - * - * An assignment operator token. - */ -export type AssignmentOperator = - | '=' - | '+=' - | '-=' - | '*=' - | '/=' - | '%=' - | '<<=' - | '>>=' - | '>>>=' - | '|=' - | '^=' - | '&=' - | '**='; - -/** - * LogicalExpression - * - * A logical operator expression. - */ -export interface LogicalExpression extends Expression { - type: 'LogicalExpression'; - operator: LogicalOperator; - left: Expression; - right: Expression; -} - -/** - * LogicalOperator - * - * A logical operator token. - */ -export type LogicalOperator = '||' | '&&'; - -/** - * MemberExpression - * - * A member expression. If `computed` is `true`, the node corresponds to a computed (`a[b]`) member expression and `property` is an `Expression`. If `computed` is `false`, the node corresponds to a static (`a.b`) member expression and `property` is an `Identifier`. - */ -export interface MemberExpression extends Expression, Pattern { - type: 'MemberExpression'; - object: Expression | Super; - property: Expression; - computed: boolean; -} - -/** - * ConditionalExpression - * - * A conditional expression, i.e., a ternary `?`/`:` expression. - */ -export interface ConditionalExpression extends Expression { - type: 'ConditionalExpression'; - test: Expression; - alternate: Expression; - consequent: Expression; -} - -/** - * CallExpression - * - * A function or method call expression. - */ -export interface CallExpression extends Expression { - type: 'CallExpression'; - callee: Expression | Super; - arguments: Array; -} - -/** - * NewExpression - * - * A `new` expression. - */ -export interface NewExpression extends Expression { - type: 'NewExpression'; - callee: Expression; - arguments: Array; -} - -/** - * SequenceExpression - * - * A sequence expression, i.e., a comma-separated sequence of expressions. - */ -export interface SequenceExpression extends Expression { - type: 'SequenceExpression'; - expressions: Expression[]; -} - -/** - * YieldExpression - * - * A yield expression. - */ -export interface YieldExpression extends Expression { - type: 'YieldExpression'; - argument: Expression | null; - delegate: boolean; -} - -/** - * AwaitExpression - */ -export interface AwaitExpression extends Expression { - type: 'AwaitExpression'; - argument: Expression; -} - -/** - * Template Literals - */ - -/** - * TemplateLiteral - */ -export interface TemplateLiteral extends Expression { - type: 'TemplateLiteral'; - quasis: TemplateElement[]; - expressions: Expression[]; -} - -/** - * TaggedTemplateExpression - */ -export interface TaggedTemplateExpression extends Expression { - type: 'TaggedTemplateExpression'; - tag: Expression; - quasi: TemplateLiteral; -} - -/** - * TemplateElement - * - * If the template literal is tagged and the text has an invalid escape, cooked will be null, e.g., tag`\unicode and \u{55}` - */ -export interface TemplateElement extends Node { - type: 'TemplateElement'; - tail: boolean; - value: { - cooked: string | null; - raw: string; - }; -} - -/** - * Patterns - * - * Destructuring binding and assignment are not part of ES5, but all binding positions accept Pattern to allow for destructuring in ES6. Nevertheless, for ES5, the only Pattern subtype is Identifier. - */ -export interface Pattern extends Node {} - -/** - * AssignmentProperty - */ -export interface AssignmentProperty extends Property { - type: 'Property'; // inherited - value: Pattern; - kind: 'init'; - method: false; -} - -/** - * ObjectPattern - * - * Rest properties, e.g., {a, ...rest} = obj. - */ -export interface ObjectPattern extends Pattern { - type: 'ObjectPattern'; - properties: Array; -} - -/** - * ArrayPattern - */ -export interface ArrayPattern extends Pattern { - type: 'ArrayPattern'; - elements: Array; -} - -/** - * RestElement - */ -export interface RestElement extends Pattern { - type: 'RestElement'; - argument: Pattern; -} - -/** - * AssignmentPattern - */ -export interface AssignmentPattern extends Pattern { - type: 'AssignmentPattern'; - left: Pattern; - right: Expression; -} - -/** - * Classes - */ - -/** - * Class - */ -export interface Class extends Node { - id: Identifier | null; - superClass: Expression | null; - body: ClassBody; -} - -/** - * ClassBody - */ -export interface ClassBody extends Node { - type: 'ClassBody'; - body: MethodDefinition[]; -} - -/** - * MethodDefinition - */ -export interface MethodDefinition extends Node { - type: 'MethodDefinition'; - key: Expression; - value: FunctionExpression; - kind: 'constructor' | 'method' | 'get' | 'set'; - computed: boolean; - static: boolean; -} - -/** - * ClassDeclaration - */ -export interface ClassDeclaration extends Class, Declaration { - type: 'ClassDeclaration'; - id: Identifier; -} - -/** - * ClassExpression - */ -export interface ClassExpression extends Class, Expression { - type: 'ClassExpression'; -} - -/** - * MetaProperty - */ -export interface MetaProperty extends Expression { - type: 'MetaProperty'; - meta: Identifier; - property: Identifier; -} - -/** - * Modules - */ - -/** - * ModuleDeclaration - * - * A module `import` or `export` declaration. - */ -export interface ModuleDeclaration extends Node {} - -/** - * ModuleSpecifier - * - * A specifier in an import or export declaration. - */ -export interface ModuleSpecifier extends Node { - local: Identifier; -} - -/** - * Imports - */ - -/** - * ImportDeclaration - * - * An import declaration, e.g., `import foo from "mod";`. - */ -export interface ImportDeclaration extends ModuleDeclaration { - type: 'ImportDeclaration'; - specifiers: Array< - ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier - >; - source: Literal; -} - -/** - * ImportSpecifier - * - * An imported variable binding, e.g., `{foo}` in `import {foo} from "mod"` or `{foo as bar}` in `import {foo as bar} from "mod"`. The `imported` field refers to the name of the export imported from the module. The `local` field refers to the binding imported into the local module scope. If it is a basic named import, such as in `import {foo} from "mod"`, both `imported` and `local` are equivalent `Identifier` nodes; in this case an `Identifier` node representing `foo`. If it is an aliased import, such as in `import {foo as bar} from "mod"`, the `imported` field is an `Identifier` node representing `foo`, and the `local` field is an `Identifier` node representing `bar`. - */ -export interface ImportSpecifier extends ModuleSpecifier { - type: 'ImportSpecifier'; - imported: Identifier; -} - -/** - * ImportDefaultSpecifier - * - * A default import specifier, e.g., `foo` in `import foo from "mod.js"`. - */ -export interface ImportDefaultSpecifier extends ModuleSpecifier { - type: 'ImportDefaultSpecifier'; -} - -/** - * ImportNamespaceSpecifier - * - * A namespace import specifier, e.g., `* as foo` in `import * as foo from "mod.js"`. - */ -export interface ImportNamespaceSpecifier extends ModuleSpecifier { - type: 'ImportNamespaceSpecifier'; -} - -/** - * Exports - */ - -/** - * ExportNamedDeclaration - * - * An export named declaration, e.g., `export {foo, bar};`, `export {foo} from "mod";` or `export var foo = 1;`. - * - * _Note: Having `declaration` populated with non-empty `specifiers` or non-null `source` results in an invalid state._ - */ -export interface ExportNamedDeclaration extends ModuleDeclaration { - type: 'ExportNamedDeclaration'; - declaration: Declaration | null; - specifiers: [ExportSpecifier]; - source: Literal | null; -} - -/** - * ExportSpecifier - * - * An exported variable binding, e.g., `{foo}` in `export {foo}` or `{bar as foo}` in `export {bar as foo}`. The `exported` field refers to the name exported in the module. The `local` field refers to the binding into the local module scope. If it is a basic named export, such as in `export {foo}`, both `exported` and `local` are equivalent `Identifier` nodes; in this case an `Identifier` node representing `foo`. If it is an aliased export, such as in `export {bar as foo}`, the `exported` field is an `Identifier` node representing `foo`, and the `local` field is an `Identifier` node representing `bar`. - */ -export interface ExportSpecifier extends ModuleSpecifier { - type: 'ExportSpecifier'; - exported: Identifier; -} - -/** - * ExportDefaultDeclaration - * - * An export default declaration, e.g., `export default function () {};` or `export default 1;`. - */ -export interface ExportDefaultDeclaration extends ModuleDeclaration { - type: 'ExportDefaultDeclaration'; - declaration: Declaration | Expression; -} - -/** - * ExportAllDeclaration - * - * An export batch declaration, e.g., `export * from "mod";`. - */ -export interface ExportAllDeclaration extends ModuleDeclaration { - type: 'ExportAllDeclaration'; - source: Literal; -} diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index d79353f755e6..aa5a10418c76 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -6,12 +6,7 @@ */ import ts from 'typescript'; import unescape from 'lodash.unescape'; -import { - ESTreeNodeLoc, - ESTreeNode, - ESTreeToken, - LineAndColumnData -} from './temp-types-based-on-js-source'; +import * as es from './typedefs'; import { AST_NODE_TYPES } from './ast-node-types'; const SyntaxKind = ts.SyntaxKind; @@ -102,8 +97,8 @@ const TOKEN_TO_TEXT: { readonly [P in ts.SyntaxKind]?: string } = { /** * Returns true if the given ts.Token is the assignment operator - * @param {ts.Token} operator the operator token - * @returns {boolean} is assignment + * @param operator the operator token + * @returns is assignment */ export function isAssignmentOperator( operator: ts.Token @@ -113,8 +108,8 @@ export function isAssignmentOperator( /** * Returns true if the given ts.Token is a logical operator - * @param {ts.Token} operator the operator token - * @returns {boolean} is a logical operator + * @param operator the operator token + * @returns is a logical operator */ export function isLogicalOperator( operator: ts.Token @@ -124,8 +119,8 @@ export function isLogicalOperator( /** * Returns the string form of the given TSToken SyntaxKind - * @param {number} kind the token's SyntaxKind - * @returns {string} the token applicable token as a string + * @param kind the token's SyntaxKind + * @returns the token applicable token as a string */ export function getTextForTokenKind(kind: ts.SyntaxKind): string | undefined { return TOKEN_TO_TEXT[kind]; @@ -133,8 +128,8 @@ export function getTextForTokenKind(kind: ts.SyntaxKind): string | undefined { /** * Returns true if the given ts.Node is a valid ESTree class member - * @param {ts.Node} node TypeScript AST node - * @returns {boolean} is valid ESTree class member + * @param node TypeScript AST node + * @returns is valid ESTree class member */ export function isESTreeClassMember(node: ts.Node): boolean { return node.kind !== SyntaxKind.SemicolonClassElement; @@ -142,9 +137,9 @@ export function isESTreeClassMember(node: ts.Node): boolean { /** * Checks if a ts.Node has a modifier - * @param {ts.KeywordSyntaxKind} modifierKind TypeScript SyntaxKind modifier - * @param {ts.Node} node TypeScript AST node - * @returns {boolean} has the modifier specified + * @param modifierKind TypeScript SyntaxKind modifier + * @param node TypeScript AST node + * @returns has the modifier specified */ export function hasModifier( modifierKind: ts.KeywordSyntaxKind, @@ -173,8 +168,8 @@ export function getLastModifier(node: ts.Node): ts.Modifier | null { /** * Returns true if the given ts.Token is a comma - * @param {ts.Node} token the TypeScript token - * @returns {boolean} is comma + * @param token the TypeScript token + * @returns is comma */ export function isComma(token: ts.Node): boolean { return token.kind === SyntaxKind.CommaToken; @@ -182,8 +177,8 @@ export function isComma(token: ts.Node): boolean { /** * Returns true if the given ts.Node is a comment - * @param {ts.Node} node the TypeScript node - * @returns {boolean} is comment + * @param node the TypeScript node + * @returns is comment */ export function isComment(node: ts.Node): boolean { return ( @@ -194,8 +189,8 @@ export function isComment(node: ts.Node): boolean { /** * Returns true if the given ts.Node is a JSDoc comment - * @param {ts.Node} node the TypeScript node - * @returns {boolean} is JSDoc comment + * @param node the TypeScript node + * @returns is JSDoc comment */ export function isJSDocComment(node: ts.Node): boolean { return node.kind === SyntaxKind.JSDocComment; @@ -203,8 +198,8 @@ export function isJSDocComment(node: ts.Node): boolean { /** * Returns the binary expression type of the given ts.Token - * @param {ts.Token} operator the operator token - * @returns {string} the binary expression type + * @param operator the operator token + * @returns the binary expression type */ export function getBinaryExpressionType( operator: ts.Token @@ -229,7 +224,7 @@ export function getBinaryExpressionType( export function getLineAndCharacterFor( pos: number, ast: ts.SourceFile -): LineAndColumnData { +): es.LineAndColumnData { const loc = ast.getLineAndCharacterOfPosition(pos); return { line: loc.line + 1, @@ -240,16 +235,16 @@ export function getLineAndCharacterFor( /** * Returns line and column data for the given start and end positions, * for the given AST - * @param {number} start start data - * @param {number} end end data - * @param {ts.SourceFile} ast the AST object - * @returns {ESTreeNodeLoc} the loc data + * @param start start data + * @param end end data + * @param ast the AST object + * @returns the loc data */ export function getLocFor( start: number, end: number, ast: ts.SourceFile -): ESTreeNodeLoc { +): es.SourceLocation { return { start: getLineAndCharacterFor(start, ast), end: getLineAndCharacterFor(end, ast) @@ -258,8 +253,8 @@ export function getLocFor( /** * Check whatever node can contain directive - * @param {ts.Node} node - * @returns {boolean} returns true if node can contain directive + * @param node + * @returns returns true if node can contain directive */ export function canContainDirective(node: ts.Node): boolean { switch (node.kind) { @@ -285,23 +280,19 @@ export function canContainDirective(node: ts.Node): boolean { } /** - * Returns line and column data for the given ts.Node or ts.Token, - * for the given AST - * @param {ts.Node} nodeOrToken the ts.Node or ts.Token - * @param {ts.SourceFile} ast the AST object - * @returns {ESTreeLoc} the loc data + * Returns range for the given ts.Node + * @param node the ts.Node or ts.Token + * @param ast the AST object + * @returns the range data */ -export function getLoc( - nodeOrToken: ts.Node, - ast: ts.SourceFile -): ESTreeNodeLoc { - return getLocFor(nodeOrToken.getStart(ast), nodeOrToken.end, ast); +export function getRange(node: ts.Node, ast: ts.SourceFile): [number, number] { + return [node.getStart(ast), node.getEnd()]; } /** * Returns true if a given ts.Node is a token - * @param {ts.Node} node the ts.Node - * @returns {boolean} is a token + * @param node the ts.Node + * @returns is a token */ export function isToken(node: ts.Node): boolean { return ( @@ -311,8 +302,8 @@ export function isToken(node: ts.Node): boolean { /** * Returns true if a given ts.Node is a JSX token - * @param {ts.Node} node ts.Node to be checked - * @returns {boolean} is a JSX token + * @param node ts.Node to be checked + * @returns is a JSX token */ export function isJSXToken(node: ts.Node): boolean { return ( @@ -322,8 +313,8 @@ export function isJSXToken(node: ts.Node): boolean { /** * Returns the declaration kind of the given ts.Node - * @param {ts.VariableDeclarationList} node TypeScript AST node - * @returns {string} declaration kind + * @param node TypeScript AST node + * @returns declaration kind */ export function getDeclarationKind( node: ts.VariableDeclarationList @@ -339,8 +330,8 @@ export function getDeclarationKind( /** * Gets a ts.Node's accessibility level - * @param {ts.Node} node The ts.Node - * @returns {string | null} accessibility "public", "protected", "private", or null + * @param node The ts.Node + * @returns accessibility "public", "protected", "private", or null */ export function getTSNodeAccessibility( node: ts.Node @@ -368,10 +359,10 @@ export function getTSNodeAccessibility( /** * Finds the next token based on the previous one and its parent * Had to copy this from TS instead of using TS's version because theirs doesn't pass the ast to getChildren - * @param {ts.TextRange} previousToken The previous TSToken - * @param {ts.Node} parent The parent TSNode - * @param {ts.SourceFile} ast The TS AST - * @returns {ts.Node|undefined} the next TSToken + * @param previousToken The previous TSToken + * @param parent The parent TSNode + * @param ast The TS AST + * @returns the next TSToken */ export function findNextToken( previousToken: ts.TextRange, @@ -400,9 +391,9 @@ export function findNextToken( /** * Find the first matching ancestor based on the given predicate function. - * @param {ts.Node} node The current ts.Node - * @param {Function} predicate The predicate function to apply to each checked ancestor - * @returns {ts.Node|undefined} a matching parent ts.Node + * @param node The current ts.Node + * @param predicate The predicate function to apply to each checked ancestor + * @returns a matching parent ts.Node */ export function findFirstMatchingAncestor( node: ts.Node, @@ -419,8 +410,8 @@ export function findFirstMatchingAncestor( /** * Returns true if a given ts.Node has a JSX token within its hierarchy - * @param {ts.Node} node ts.Node to be checked - * @returns {boolean} has JSX ancestor + * @param node ts.Node to be checked + * @returns has JSX ancestor */ export function hasJSXAncestor(node: ts.Node): boolean { return !!findFirstMatchingAncestor(node, isJSXToken); @@ -428,8 +419,8 @@ export function hasJSXAncestor(node: ts.Node): boolean { /** * Unescape the text content of string literals, e.g. & -> & - * @param {string} text The escaped string literal text. - * @returns {string} The unescaped string literal text. + * @param text The escaped string literal text. + * @returns The unescaped string literal text. */ export function unescapeStringLiteralText(text: string): string { return unescape(text); @@ -437,8 +428,8 @@ export function unescapeStringLiteralText(text: string): string { /** * Returns true if a given ts.Node is a computed property - * @param {ts.Node} node ts.Node to be checked - * @returns {boolean} is Computed Property + * @param node ts.Node to be checked + * @returns is Computed Property */ export function isComputedProperty(node: ts.Node): boolean { return node.kind === SyntaxKind.ComputedPropertyName; @@ -446,8 +437,8 @@ export function isComputedProperty(node: ts.Node): boolean { /** * Returns true if a given ts.Node is optional (has QuestionToken) - * @param {ts.Node} node ts.Node to be checked - * @returns {boolean} is Optional + * @param node ts.Node to be checked + * @returns is Optional */ export function isOptional(node: { questionToken?: ts.QuestionToken; @@ -459,16 +450,16 @@ export function isOptional(node: { /** * Fixes the exports of the given ts.Node - * @param {ts.Node} node the ts.Node - * @param {ESTreeNode} result result - * @param {ts.SourceFile} ast the AST - * @returns {ESTreeNode} the ESTreeNode with fixed exports + * @param node the ts.Node + * @param result result + * @param ast the AST + * @returns the ESTreeNode with fixed exports */ -export function fixExports( +export function fixExports( node: ts.Node, - result: ESTreeNode, + result: T, ast: ts.SourceFile -): ESTreeNode { +): es.ExportDefaultDeclaration | es.ExportNamedDeclaration | T { // check for exports if (node.modifiers && node.modifiers[0].kind === SyntaxKind.ExportKeyword) { const exportKeyword = node.modifiers[0]; @@ -480,26 +471,26 @@ export function fixExports( ? findNextToken(nextModifier, ast, ast) : findNextToken(exportKeyword, ast, ast); - result.range[0] = varToken!.getStart(ast); - result.loc = getLocFor(result.range[0], result.range[1], ast); - - const declarationType = declarationIsDefault - ? AST_NODE_TYPES.ExportDefaultDeclaration - : AST_NODE_TYPES.ExportNamedDeclaration; + result.range![0] = varToken!.getStart(ast); + result.loc = getLocFor(result.range![0], result.range![1], ast); - const newResult: any = { - type: declarationType, - declaration: result, - range: [exportKeyword.getStart(ast), result.range[1]], - loc: getLocFor(exportKeyword.getStart(ast), result.range[1], ast) - }; - - if (!declarationIsDefault) { - newResult.specifiers = []; - newResult.source = null; + if (declarationIsDefault) { + return { + type: AST_NODE_TYPES.ExportDefaultDeclaration, + declaration: result as any, + range: [exportKeyword.getStart(ast), result.range![1]], + loc: getLocFor(exportKeyword.getStart(ast), result.range![1], ast) + }; + } else { + return { + type: AST_NODE_TYPES.ExportNamedDeclaration, + declaration: result as any, + range: [exportKeyword.getStart(ast), result.range![1]], + loc: getLocFor(exportKeyword.getStart(ast), result.range![1], ast), + specifiers: [], + source: null + }; } - - return newResult; } return result; @@ -507,10 +498,10 @@ export function fixExports( /** * Returns the type of a given ts.Token - * @param {ts.Token} token the ts.Token - * @returns {string} the token type + * @param token the ts.Token + * @returns the token type */ -export function getTokenType(token: any): string { +export function getTokenType(token: any): es.TokenType { // Need two checks for keywords since some are also identifiers if (token.originalKeywordKind) { switch (token.originalKeywordKind) { @@ -614,18 +605,18 @@ export function getTokenType(token: any): string { /** * Extends and formats a given ts.Token, for a given AST - * @param {ts.Node} token the ts.Token - * @param {ts.SourceFile} ast the AST object - * @returns {ESTreeToken} the converted ESTreeToken + * @param token the ts.Token + * @param ast the AST object + * @returns the converted es.Token */ -export function convertToken(token: ts.Node, ast: ts.SourceFile): ESTreeToken { +export function convertToken(token: ts.Node, ast: ts.SourceFile): es.Token { const start = token.kind === SyntaxKind.JsxText ? token.getFullStart() : token.getStart(ast), end = token.getEnd(), value = ast.text.slice(start, end), - newToken: any = { + newToken: es.Token = { type: getTokenType(token), value, range: [start, end], @@ -644,14 +635,13 @@ export function convertToken(token: ts.Node, ast: ts.SourceFile): ESTreeToken { /** * Converts all tokens for the given AST - * @param {ts.SourceFile} ast the AST object - * @returns {ESTreeToken[]} the converted ESTreeTokens + * @param ast the AST object + * @returns the converted Tokens */ -export function convertTokens(ast: ts.SourceFile): ESTreeToken[] { - const result: ESTreeToken[] = []; +export function convertTokens(ast: ts.SourceFile): es.Token[] { + const result: es.Token[] = []; /** - * @param {ts.Node} node the ts.Node - * @returns {void} + * @param node the ts.Node */ function walk(node: ts.Node): void { // TypeScript generates tokens for types in JSDoc blocks. Comment tokens @@ -676,10 +666,10 @@ export function convertTokens(ast: ts.SourceFile): ESTreeToken[] { /** * Get container token node between range - * @param {ts.SourceFile} ast the AST object - * @param {number} start The index at which the comment starts. - * @param {number} end The index at which the comment ends. - * @returns {ts.Node} typescript container token + * @param ast the AST object + * @param start The index at which the comment starts. + * @param end The index at which the comment ends. + * @returns typescript container token * @private */ export function getNodeContainer( @@ -690,8 +680,7 @@ export function getNodeContainer( let container: ts.Node | null = null; /** - * @param {ts.Node} node the ts.Node - * @returns {void} + * @param node the ts.Node */ function walk(node: ts.Node): void { const nodeStart = node.pos; @@ -711,10 +700,10 @@ export function getNodeContainer( } /** - * @param {ts.SourceFile} ast the AST object - * @param {number} start the index at which the error starts - * @param {string} message the error message - * @returns {Object} converted error object + * @param ast the AST object + * @param start the index at which the error starts + * @param message the error message + * @returns converted error object */ export function createError( ast: ts.SourceFile, @@ -731,8 +720,8 @@ export function createError( } /** - * @param {ts.Node} n the TSNode - * @param {ts.SourceFile} ast the TS AST + * @param n the TSNode + * @param ast the TS AST */ export function nodeHasTokens(n: ts.Node, ast: ts.SourceFile) { // If we have a token or node that has a non-zero width, it must have tokens. @@ -746,9 +735,8 @@ export function nodeHasTokens(n: ts.Node, ast: ts.SourceFile) { * Like `forEach`, but suitable for use with numbers and strings (which may be falsy). * @template T * @template U - * @param {ReadonlyArray|undefined} array - * @param {(element: T, index: number) => (U|undefined)} callback - * @returns {U|undefined} + * @param array + * @param callback */ export function firstDefined( array: ReadonlyArray | undefined, diff --git a/packages/typescript-estree/src/parser-options.ts b/packages/typescript-estree/src/parser-options.ts new file mode 100644 index 000000000000..a838db4af139 --- /dev/null +++ b/packages/typescript-estree/src/parser-options.ts @@ -0,0 +1,35 @@ +import { Token, Comment } from './typedefs'; + +export interface Extra { + errorOnUnknownASTType: boolean; + errorOnTypeScriptSyntacticAndSemanticIssues: boolean; + useJSXTextNode: boolean; + tokens: null | Token[]; + comment: boolean; + code: string; + range: boolean; + loc: boolean; + comments: Comment[]; + strict: boolean; + jsx: boolean; + log: Function; + projects: string[]; + tsconfigRootDir: string; + extraFileExtensions: string[]; +} + +export interface ParserOptions { + range?: boolean; + loc?: boolean; + tokens?: boolean; + comment?: boolean; + jsx?: boolean; + errorOnUnknownASTType?: boolean; + errorOnTypeScriptSyntacticAndSemanticIssues?: boolean; + useJSXTextNode?: boolean; + loggerFn?: Function | false; + project?: string | string[]; + filePath?: string; + tsconfigRootDir?: string; + extraFileExtensions?: string[]; +} diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index 225899a106f9..3c9680df06d4 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -13,14 +13,9 @@ import semver from 'semver'; import ts from 'typescript'; import convert from './ast-converter'; import { convertError } from './convert'; -import { Program } from './estree/spec'; import { firstDefined } from './node-utils'; -import { - ESTreeComment, - ESTreeToken, - Extra, - ParserOptions -} from './temp-types-based-on-js-source'; +import * as es from './typedefs'; +import { Extra, ParserOptions } from './parser-options'; import { getFirstSemanticOrSyntacticError } from './semantic-errors'; const packageJSON = require('../package.json'); @@ -49,7 +44,6 @@ function getFileName({ jsx }: { jsx?: boolean }) { /** * Resets the extra config object - * @returns {void} */ function resetExtra(): void { extra = { @@ -72,9 +66,9 @@ function resetExtra(): void { } /** - * @param {string} code The code of the file being linted - * @param {Object} options The config object - * @returns {{ast: ts.SourceFile, program: ts.Program} | undefined} If found, returns the source file corresponding to the code and the containing program + * @param code The code of the file being linted + * @param options The config object + * @returns If found, returns the source file corresponding to the code and the containing program */ function getASTFromProject(code: string, options: ParserOptions) { return firstDefined( @@ -93,9 +87,9 @@ function getASTFromProject(code: string, options: ParserOptions) { } /** - * @param {string} code The code of the file being linted - * @param {Object} options The config object - * @returns {{ast: ts.SourceFile, program: ts.Program} | undefined} If found, returns the source file corresponding to the code and the containing program + * @param code The code of the file being linted + * @param options The config object + * @returns If found, returns the source file corresponding to the code and the containing program */ function getASTAndDefaultProject(code: string, options: ParserOptions) { const fileName = options.filePath || getFileName(options); @@ -105,8 +99,8 @@ function getASTAndDefaultProject(code: string, options: ParserOptions) { } /** - * @param {string} code The code of the file being linted - * @returns {{ast: ts.SourceFile, program: ts.Program}} Returns a new source file and program corresponding to the linted code + * @param code The code of the file being linted + * @returns Returns a new source file and program corresponding to the linted code */ function createNewProgram(code: string) { const FILENAME = getFileName(extra); @@ -162,10 +156,10 @@ function createNewProgram(code: string) { } /** - * @param {string} code The code of the file being linted - * @param {Object} options The config object - * @param {boolean} shouldProvideParserServices True iff the program should be attempted to be calculated from provided tsconfig files - * @returns {{ast: ts.SourceFile, program: ts.Program}} Returns a source file and program corresponding to the linted code + * @param code The code of the file being linted + * @param options The config object + * @param shouldProvideParserServices True iff the program should be attempted to be calculated from provided tsconfig files + * @returns Returns a source file and program corresponding to the linted code */ function getProgramAndAST( code: string, @@ -275,10 +269,10 @@ function warnAboutTSVersion(): void { // Parser //------------------------------------------------------------------------------ -type AST = Program & +type AST = es.Program & (T['range'] extends true ? { range: [number, number] } : {}) & - (T['tokens'] extends true ? { tokens: ESTreeToken[] } : {}) & - (T['comment'] extends true ? { comments: ESTreeComment[] } : {}); + (T['tokens'] extends true ? { tokens: es.Token[] } : {}) & + (T['comment'] extends true ? { comments: es.Comment[] } : {}); interface ParseAndGenerateServicesResult { ast: AST; @@ -342,7 +336,7 @@ export function parse( * Convert the TypeScript AST to an ESTree-compatible one */ const { estree } = convert(ast, extra, false); - return estree; + return estree as AST; } export function parseAndGenerateServices< @@ -406,7 +400,7 @@ export function parseAndGenerateServices< * Return the converted AST and additional parser services */ return { - ast: estree, + ast: estree as AST, services: { program: shouldProvideParserServices ? program : undefined, esTreeNodeToTSNodeMap: diff --git a/packages/typescript-estree/src/temp-types-based-on-js-source.ts b/packages/typescript-estree/src/temp-types-based-on-js-source.ts deleted file mode 100644 index a2234fc1308a..000000000000 --- a/packages/typescript-estree/src/temp-types-based-on-js-source.ts +++ /dev/null @@ -1,106 +0,0 @@ -/** - * NOTE: The following types are inferred from usage within the original JavaScript source. - * - * They will be gradually replaced with the more accurate types derived from the ESTree spec, and its - * applicable extensions - */ -import { AST_NODE_TYPES } from './ast-node-types'; - -export interface ESTreeToken { - type: AST_NODE_TYPES; - range: [number, number]; - loc: ESTreeNodeLoc; - value: string; - regex?: { - pattern: string; - flags: string; - }; - object?: any; - property?: any; - name?: any; -} - -export interface ESTreeNode { - type: AST_NODE_TYPES; - range: [number, number]; - loc: ESTreeNodeLoc; - declaration?: ESTreeNode; - specifiers?: (ESTreeNode | null)[]; - source?: any; - typeAnnotation?: ESTreeNode | null; - typeParameters?: ESTreeNode | null; - id?: ESTreeNode | null; - raw?: string; - value?: string; - expression?: ESTreeNode | null; - decorators?: (ESTreeNode | null)[]; - implements?: (ESTreeNode | null)[]; - extends?: (ESTreeNode | null)[]; - const?: boolean; - declare?: boolean; - global?: boolean; - modifiers?: any; - body?: any; - params?: any; - accessibility?: 'public' | 'protected' | 'private'; - readonly?: boolean | string; - static?: boolean; - export?: boolean; - parameter?: any; - abstract?: boolean; - typeName?: ESTreeNode | null; - directive?: string; - returnType?: ESTreeNode; - optional?: boolean | string; -} - -export interface ESTreeComment { - type: 'Block' | 'Line'; - range?: [number, number]; - loc?: ESTreeNodeLoc; - value: string; -} - -export interface LineAndColumnData { - line: number; - column: number; -} - -export interface ESTreeNodeLoc { - start: LineAndColumnData; - end: LineAndColumnData; -} - -export interface Extra { - errorOnUnknownASTType: boolean; - errorOnTypeScriptSyntacticAndSemanticIssues: boolean; - useJSXTextNode: boolean; - tokens: null | ESTreeToken[]; - comment: boolean; - code: string; - range: boolean; - loc: boolean; - comments: ESTreeComment[]; - strict: boolean; - jsx: boolean; - log: Function; - projects: string[]; - tsconfigRootDir: string; - extraFileExtensions: string[]; -} - -export interface ParserOptions { - range?: boolean; - loc?: boolean; - tokens?: boolean; - comment?: boolean; - jsx?: boolean; - errorOnUnknownASTType?: boolean; - errorOnTypeScriptSyntacticAndSemanticIssues?: boolean; - useJSXTextNode?: boolean; - loggerFn?: Function | false; - project?: string | string[]; - filePath?: string; - tsconfigRootDir?: string; - extraFileExtensions?: string[]; -} diff --git a/packages/typescript-estree/src/tsconfig-parser.ts b/packages/typescript-estree/src/tsconfig-parser.ts index 2212c4d0b1d0..3d68a034c16e 100644 --- a/packages/typescript-estree/src/tsconfig-parser.ts +++ b/packages/typescript-estree/src/tsconfig-parser.ts @@ -2,7 +2,7 @@ import path from 'path'; import ts from 'typescript'; -import { Extra } from './temp-types-based-on-js-source'; +import { Extra } from './parser-options'; //------------------------------------------------------------------------------ // Environment calculation @@ -10,7 +10,6 @@ import { Extra } from './temp-types-based-on-js-source'; /** * Default compiler options for program generation from single root file - * @type {ts.CompilerOptions} */ const defaultCompilerOptions: ts.CompilerOptions = { allowNonTsExtensions: true, @@ -19,7 +18,6 @@ const defaultCompilerOptions: ts.CompilerOptions = { /** * Maps tsconfig paths to their corresponding file contents and resulting watches - * @type {Map>} */ const knownWatchProgramMap = new Map< string, @@ -29,13 +27,11 @@ const knownWatchProgramMap = new Map< /** * Maps file paths to their set of corresponding watch callbacks * There may be more than one per file if a file is shared between projects - * @type {Map} */ const watchCallbackTrackingMap = new Map(); /** * Holds information about the file currently being linted - * @type {{code: string, filePath: string}} */ const currentLintOperationState = { code: '', @@ -44,8 +40,7 @@ const currentLintOperationState = { /** * Appropriately report issues found when reading a config file - * @param {ts.Diagnostic} diagnostic The diagnostic raised when creating a program - * @returns {void} + * @param diagnostic The diagnostic raised when creating a program */ function diagnosticReporter(diagnostic: ts.Diagnostic): void { throw new Error( @@ -57,11 +52,11 @@ const noopFileWatcher = { close: () => {} }; /** * Calculate project environments using options provided by consumer and paths from config - * @param {string} code The code being linted - * @param {string} filePath The path of the file being parsed - * @param {string} extra.tsconfigRootDir The root directory for relative tsconfig paths - * @param {string[]} extra.project Provided tsconfig paths - * @returns {ts.Program[]} The programs corresponding to the supplied tsconfig paths + * @param code The code being linted + * @param filePath The path of the file being parsed + * @param extra.tsconfigRootDir The root directory for relative tsconfig paths + * @param extra.project Provided tsconfig paths + * @returns The programs corresponding to the supplied tsconfig paths */ export function calculateProjectParserOptions( code: string, @@ -187,9 +182,9 @@ export function calculateProjectParserOptions( * Create program from single root file. Requires a single tsconfig to be specified. * @param code The code being linted * @param filePath The file being linted - * @param {string} extra.tsconfigRootDir The root directory for relative tsconfig paths - * @param {string[]} extra.project Provided tsconfig paths - * @returns {ts.Program} The program containing just the file being linted and associated library files + * @param extra.tsconfigRootDir The root directory for relative tsconfig paths + * @param extra.project Provided tsconfig paths + * @returns The program containing just the file being linted and associated library files */ export function createProgram(code: string, filePath: string, extra: Extra) { if (!extra.projects || extra.projects.length !== 1) { diff --git a/packages/typescript-estree/src/typedefs.ts b/packages/typescript-estree/src/typedefs.ts new file mode 100644 index 000000000000..140ed6e09a49 --- /dev/null +++ b/packages/typescript-estree/src/typedefs.ts @@ -0,0 +1,1409 @@ +import { AST_NODE_TYPES } from './ast-node-types'; + +export interface LineAndColumnData { + /** + * Line number (1-indexed) + */ + line: number; + /** + * Column number on the line (0-indexed) + */ + column: number; +} +export interface SourceLocation { + /** + * The position of the first character of the parsed source region + */ + start: LineAndColumnData; + /** + * The position of the first character after the parsed source region + */ + end: LineAndColumnData; +} + +export interface BaseNode { + /** + * The source location information of the node. + */ + loc: SourceLocation; + /** + * An array of two numbers. + * Both numbers are a 0-based index which is the position in the array of source code characters. + * The first is the start position of the node, the second is the end position of the node. + */ + range: [number, number]; + /** + * The parent node of the current node + */ + parent?: Node; + + // every node *will* have a type, but let the nodes define their own exact string + // type: string; + + // we don't ever set this from within ts-estree + // source?: string | null; +} + +/* + * Token and Comment are pseudo-nodes to represent pieces of source code + * + * NOTE: + * They are not included in the `Node` union below on purpose because they + * are not ever included as part of the standard AST tree. + */ + +export type TokenType = + | 'Boolean' + | 'Identifier' + | 'JSXIdentifier' + | 'JSXMemberExpression' + | 'JSXText' + | 'Keyword' + | 'Null' + | 'Numeric' + | 'Punctuator' + | 'RegularExpression' + | 'String' + | 'Template'; + +export interface Token extends BaseNode { + type: TokenType; + value: string; + regex?: { + pattern: string; + flags: string; + }; +} +export interface Comment extends BaseNode { + type: 'Line' | 'Block'; + value: string; +} + +export type OptionalRangeAndLoc = Pick< + T, + Exclude +> & { + range?: [number, number]; + loc?: SourceLocation; +}; + +// Every single valid AST Node +// Please keep it sorted alphabetically. +export type Node = + | ArrayExpression + | ArrayPattern + | ArrowFunctionExpression + | AssignmentExpression + | AssignmentPattern + | AwaitExpression + | BigIntLiteral + | BinaryExpression + | BlockStatement + | BreakStatement + | CallExpression + | CatchClause + | ClassBody + | ClassDeclaration + | ClassExpression + | ClassProperty + | ConditionalExpression + | ContinueStatement + | DebuggerStatement + | Decorator + | DoWhileStatement + | EmptyStatement + | ExportAllDeclaration + | ExportDefaultDeclaration + | ExportNamedDeclaration + | ExportSpecifier + | ExpressionStatement + | ForInStatement + | ForOfStatement + | ForStatement + | FunctionDeclaration + | FunctionExpression + | Identifier + | IfStatement + | Import + | ImportDeclaration + | ImportDefaultSpecifier + | ImportNamespaceSpecifier + | ImportSpecifier + | JSXAttribute + | JSXClosingElement + | JSXClosingFragment + | JSXElement + | JSXEmptyExpression + | JSXExpressionContainer + | JSXFragment + | JSXIdentifier + | JSXOpeningElement + | JSXOpeningFragment + | JSXSpreadAttribute + | JSXSpreadChild + | JSXText + | LabeledStatement + | Literal + | LogicalExpression + | MemberExpression + | MetaProperty + | MethodDefinition + | NewExpression + | ObjectExpression + | ObjectPattern + | Program + | Property + | RestElement + | ReturnStatement + | SequenceExpression + | SpreadElement + | Super + | SwitchCase + | SwitchStatement + | TaggedTemplateExpression + | TemplateElement + | TemplateLiteral + | ThisExpression + | ThrowStatement + | TryStatement + | TSAbstractClassProperty + | TSAbstractKeyword + | TSAbstractMethodDefinition + | TSAnyKeyword + | TSArrayType + | TSAsExpression + | TSAsyncKeyword + | TSBigIntKeyword + | TSBooleanKeyword + | TSCallSignatureDeclaration + | TSClassImplements + | TSConditionalType + | TSConstructorType + | TSConstructSignatureDeclaration + | TSDeclareFunction + | TSDeclareKeyword + | TSEnumDeclaration + | TSEnumMember + | TSExportAssignment + | TSExportKeyword + | TSExternalModuleReference + | TSFunctionType + | TSImportEqualsDeclaration + | TSImportType + | TSIndexedAccessType + | TSIndexSignature + | TSInferType + | TSInterfaceDeclaration + | TSInterfaceBody + | TSInterfaceHeritage + | TSIntersectionType + | TSLiteralType + | TSMappedType + | TSMethodSignature + | TSModuleBlock + | TSModuleDeclaration + | TSNamespaceExportDeclaration + | TSNeverKeyword + | TSNonNullExpression + | TSNullKeyword + | TSNumberKeyword + | TSObjectKeyword + | TSOptionalType + | TSParameterProperty + | TSParenthesizedType + | TSPropertySignature + | TSPublicKeyword + | TSPrivateKeyword + | TSProtectedKeyword + | TSQualifiedName + | TSReadonlyKeyword + | TSRestType + | TSStaticKeyword + | TSStringKeyword + | TSSymbolKeyword + | TSThisType + | TSTupleType + | TSTypeAliasDeclaration + | TSTypeAnnotation + | TSTypeAssertion + | TSTypeLiteral + | TSTypeOperator + | TSTypeParameter + | TSTypeParameterDeclaration + | TSTypeParameterInstantiation + | TSTypePredicate + | TSTypeQuery + | TSTypeReference + | TSUndefinedKeyword + | TSUnionType + | TSUnknownKeyword + | TSVoidKeyword + | UpdateExpression + | UnaryExpression + | VariableDeclaration + | VariableDeclarator + | WhileStatement + | WithStatement + | YieldExpression; + +////////// +// Reusable Unions +// These are based off of types used in the Typescript AST definitions +// **Ensure you sort the union members alphabetically** +////////// + +export type Accessibility = 'public' | 'protected' | 'private'; +export type BindingPattern = ArrayPattern | ObjectPattern; +export type BindingName = BindingPattern | Identifier; +export type ClassElement = + | ClassProperty + | FunctionExpression + | MethodDefinition + | TSAbstractClassProperty + | TSAbstractMethodDefinition + | TSIndexSignature; +export type DeclarationStatement = + | ClassDeclaration + | ClassExpression + | ExportAllDeclaration + | ExportNamedDeclaration + | FunctionDeclaration + | TSDeclareFunction + | TSImportEqualsDeclaration + | TSInterfaceDeclaration + | TSModuleDeclaration + | TSNamespaceExportDeclaration + | TSTypeAliasDeclaration + | TSEnumDeclaration; +export type EntityName = Identifier | TSQualifiedName; +export type ExportDeclaration = + | ClassDeclaration + | ClassExpression + | FunctionDeclaration + | TSDeclareFunction + | TSEnumDeclaration + | TSInterfaceDeclaration + | TSModuleDeclaration + | TSTypeAliasDeclaration + | VariableDeclarator; +export type Expression = + | ArrowFunctionExpression + | AssignmentExpression + | BinaryExpression + | ConditionalExpression + | JSXClosingElement + | JSXClosingFragment + | JSXExpressionContainer + | JSXOpeningElement + | JSXOpeningFragment + | JSXSpreadChild + | LogicalExpression + | RestElement + | SequenceExpression + | SpreadElement + | TSAsExpression + | TSUnaryExpression + | YieldExpression; +export type ExpressionWithTypeArguments = + | TSClassImplements + | TSInterfaceHeritage; +export type ForInitialiser = Expression | VariableDeclaration; +export type ImportClause = + | ImportDefaultSpecifier + | ImportNamespaceSpecifier + | ImportSpecifier; +export type IterationStatement = + | DoWhileStatement + | ForInStatement + | ForOfStatement + | ForStatement + | WhileStatement; +export type JSXChild = JSXElement | JSXExpression | JSXFragment | JSXText; +export type JSXExpression = + | JSXEmptyExpression + | JSXSpreadChild + | JSXExpressionContainer; +export type JSXTagNameExpression = JSXIdentifier | JSXMemberExpression; +export type LeftHandSideExpression = + | CallExpression + | ClassExpression + | ClassDeclaration + | FunctionExpression + | LiteralExpression + | MemberExpression + | PrimaryExpression + | TaggedTemplateExpression + | TSNonNullExpression; +export type LiteralExpression = BigIntLiteral | Literal | TemplateLiteral; +export type Modifier = + | TSAbstractKeyword + | TSAsyncKeyword + | TSDeclareKeyword + | TSExportKeyword + | TSPublicKeyword + | TSPrivateKeyword + | TSProtectedKeyword + | TSReadonlyKeyword + | TSStaticKeyword; +export type ObjectLiteralElementLike = + | MethodDefinition + | Property + | RestElement + | SpreadElement + | TSAbstractMethodDefinition; +export type Parameter = AssignmentPattern | RestElement | TSParameterProperty; +export type PrimaryExpression = + | ArrayExpression + | ArrayPattern + | ClassExpression + | FunctionExpression + | Identifier + | Import + | JSXElement + | JSXFragment + | JSXOpeningElement + | Literal + | LiteralExpression + | MetaProperty + | ObjectExpression + | ObjectPattern + | Super + | TemplateLiteral + | ThisExpression + | TSNullKeyword; +export type PropertyName = Identifier | Literal; +export type Statement = + | BlockStatement + | BreakStatement + | ContinueStatement + | DebuggerStatement + | DeclarationStatement + | EmptyStatement + | ExpressionStatement + | IfStatement + | IterationStatement + | ImportDeclaration + | LabeledStatement + | TSModuleBlock + | ReturnStatement + | SwitchStatement + | ThrowStatement + | TryStatement + | VariableDeclaration + | WithStatement; +export type TypeElement = + | TSCallSignatureDeclaration + | TSConstructSignatureDeclaration + | TSIndexSignature + | TSMethodSignature + | TSPropertySignature; +export type TypeNode = + | ThisExpression + | TSAnyKeyword + | TSArrayType + | TSBigIntKeyword + | TSBooleanKeyword + | TSClassImplements + | TSConditionalType + | TSConstructorType + | TSFunctionType + | TSImportType + | TSIndexedAccessType + | TSInferType + | TSInterfaceHeritage + | TSIntersectionType + | TSLiteralType + | TSMappedType + | TSNeverKeyword + | TSNullKeyword + | TSNumberKeyword + | TSObjectKeyword + | TSOptionalType + | TSParenthesizedType + | TSRestType + | TSStringKeyword + | TSSymbolKeyword + | TSThisType + | TSTupleType + | TSTypeLiteral + | TSTypeOperator + | TSTypeReference + | TSTypePredicate + | TSTypeQuery + | TSUndefinedKeyword + | TSUnionType + | TSUnknownKeyword + | TSVoidKeyword; +export type TSUnaryExpression = + | AwaitExpression + | LeftHandSideExpression + | TSTypeAssertion + | UnaryExpression + | UpdateExpression; + +/////////////// +// Base, common types +// **Ensure you sort the interfaces alphabetically** +/////////////// + +interface BinaryExpressionBase extends BaseNode { + operator: string; + left: Expression; + right: Expression; +} + +interface ClassDeclarationBase extends BaseNode { + typeParameters?: TSTypeParameterDeclaration; + superTypeParameters?: TSTypeParameterInstantiation; + id?: Identifier; + body: ClassBody; + superClass?: LeftHandSideExpression; + implements?: ExpressionWithTypeArguments[]; + abstract?: boolean; + declare?: boolean; + decorators?: Decorator[]; +} + +interface ClassPropertyBase extends BaseNode { + key: PropertyName; + value: Expression; + computed: boolean; + static: boolean; + readonly?: boolean; + decorators?: Decorator[]; + accessibility?: Accessibility; + optional?: boolean; + definite?: boolean; + typeAnnotation?: TSTypeAnnotation; +} + +interface FunctionDeclarationBase extends BaseNode { + id: Identifier | null; + generator: boolean; + expression: boolean; + async: boolean; + params: Parameter[]; + body?: BlockStatement | null; + returnType?: TSTypeAnnotation; + typeParameters?: TSTypeParameterDeclaration; + declare?: boolean; +} + +interface FunctionSignatureBase extends BaseNode { + params: Parameter[]; + returnType?: TSTypeAnnotation; + typeParameters?: TSTypeParameterDeclaration; +} + +interface LiteralBase extends BaseNode { + raw: string; + value: boolean | number | RegExp | string | null; + regex?: { + pattern: string; + flags: string; + }; +} + +interface MethodDefinitionBase extends BaseNode { + key: PropertyName; + value: FunctionExpression; + computed: boolean; + static: boolean; + kind: 'method' | 'get' | 'set' | 'constructor'; + decorators?: Decorator[]; + accessibility?: Accessibility; + typeParameters?: TSTypeParameterDeclaration; +} + +interface TSHeritageBase extends BaseNode { + expression: Expression; + typeParameters?: TSTypeParameterInstantiation; +} + +interface UnaryExpressionBase extends BaseNode { + operator: string; + prefix: boolean; + argument: LeftHandSideExpression | Literal | UnaryExpression; +} + +/////////////// +// Typescript ESTree Nodes +// **Ensure you sort the interfaces alphabetically** +/////////////// + +export interface ArrayExpression extends BaseNode { + type: AST_NODE_TYPES.ArrayExpression; + elements: Expression[]; +} + +export interface ArrayPattern extends BaseNode { + type: AST_NODE_TYPES.ArrayPattern; + elements: Expression[]; + typeAnnotation?: TSTypeAnnotation; + optional?: boolean; +} + +export interface ArrowFunctionExpression extends BaseNode { + type: AST_NODE_TYPES.ArrowFunctionExpression; + generator: boolean; + id: null; + params: Parameter[]; + body: Expression | BlockStatement; + async: boolean; + expression: boolean; + returnType?: TSTypeAnnotation; + typeParameters?: TSTypeParameterDeclaration; +} + +export interface AssignmentExpression extends BinaryExpressionBase { + type: AST_NODE_TYPES.AssignmentExpression; +} + +export interface AssignmentPattern extends BaseNode { + type: AST_NODE_TYPES.AssignmentPattern; + left: BindingName; + right?: Expression; + typeAnnotation?: TSTypeAnnotation; + optional?: boolean; +} + +export interface AwaitExpression extends BaseNode { + type: AST_NODE_TYPES.AwaitExpression; + argument: TSUnaryExpression; +} + +export interface BigIntLiteral extends LiteralBase { + type: AST_NODE_TYPES.BigIntLiteral; +} + +export interface BinaryExpression extends BinaryExpressionBase { + type: AST_NODE_TYPES.BinaryExpression; +} + +export interface BlockStatement extends BaseNode { + type: AST_NODE_TYPES.BlockStatement; + body: Statement[]; +} + +export interface BreakStatement extends BaseNode { + type: AST_NODE_TYPES.BreakStatement; + label: Identifier | null; +} + +export interface CallExpression extends BaseNode { + type: AST_NODE_TYPES.CallExpression; + callee: LeftHandSideExpression; + arguments: Expression[]; + typeParameters?: TSTypeParameterInstantiation; +} + +export interface CatchClause extends BaseNode { + type: AST_NODE_TYPES.CatchClause; + param: BindingName | null; + body: BlockStatement; +} + +export interface ClassBody extends BaseNode { + type: AST_NODE_TYPES.ClassBody; + body: ClassElement[]; +} + +export interface ClassDeclaration extends ClassDeclarationBase { + type: AST_NODE_TYPES.ClassDeclaration; +} + +export interface ClassExpression extends ClassDeclarationBase { + type: AST_NODE_TYPES.ClassExpression; +} + +export interface ClassProperty extends ClassPropertyBase { + type: AST_NODE_TYPES.ClassProperty; +} + +export interface ConditionalExpression extends BaseNode { + type: AST_NODE_TYPES.ConditionalExpression; + test: Expression; + consequent: Expression; + alternate: Expression; +} + +export interface ContinueStatement extends BaseNode { + type: AST_NODE_TYPES.ContinueStatement; + label: Identifier | null; +} + +export interface DebuggerStatement extends BaseNode { + type: AST_NODE_TYPES.DebuggerStatement; +} + +export interface Decorator extends BaseNode { + type: AST_NODE_TYPES.Decorator; + expression: LeftHandSideExpression; +} + +export interface DoWhileStatement extends BaseNode { + type: AST_NODE_TYPES.DoWhileStatement; + test: Expression; + body: Statement; +} + +export interface EmptyStatement extends BaseNode { + type: AST_NODE_TYPES.EmptyStatement; +} + +export interface ExportAllDeclaration extends BaseNode { + type: AST_NODE_TYPES.ExportAllDeclaration; + source: Expression | null; +} + +export interface ExportDefaultDeclaration extends BaseNode { + type: AST_NODE_TYPES.ExportDefaultDeclaration; + declaration: ExportDeclaration; +} + +export interface ExportNamedDeclaration extends BaseNode { + type: AST_NODE_TYPES.ExportNamedDeclaration; + declaration: ExportDeclaration | null; + specifiers: ExportSpecifier[]; + source: Expression | null; +} + +export interface ExportSpecifier extends BaseNode { + type: AST_NODE_TYPES.ExportSpecifier; + local: Identifier; + exported: Identifier; +} + +export interface ExpressionStatement extends BaseNode { + type: AST_NODE_TYPES.ExpressionStatement; + expression: Expression; +} + +export interface ForInStatement extends BaseNode { + type: AST_NODE_TYPES.ForInStatement; + left: ForInitialiser; + right: Expression; + body: Statement; +} + +export interface ForOfStatement extends BaseNode { + type: AST_NODE_TYPES.ForOfStatement; + left: ForInitialiser; + right: Expression; + body: Statement; + await: boolean; +} + +export interface ForStatement extends BaseNode { + type: AST_NODE_TYPES.ForStatement; + init: Expression | ForInitialiser | null; + test: Expression | null; + update: Expression | null; + body: Statement; +} + +export interface FunctionDeclaration extends FunctionDeclarationBase { + type: AST_NODE_TYPES.FunctionDeclaration; +} + +export interface FunctionExpression extends FunctionDeclarationBase { + type: AST_NODE_TYPES.FunctionExpression; +} + +export interface Identifier extends BaseNode { + type: AST_NODE_TYPES.Identifier; + name: string; + typeAnnotation?: TSTypeAnnotation; + optional?: boolean; +} + +export interface IfStatement extends BaseNode { + type: AST_NODE_TYPES.IfStatement; + test: Expression; + consequent: Statement; + alternate: Statement | null; +} + +export interface Import extends BaseNode { + type: AST_NODE_TYPES.Import; +} + +export interface ImportDeclaration extends BaseNode { + type: AST_NODE_TYPES.ImportDeclaration; + source: Expression; + specifiers: ImportClause[]; +} + +export interface ImportDefaultSpecifier extends BaseNode { + type: AST_NODE_TYPES.ImportDefaultSpecifier; + local: Identifier; +} + +export interface ImportNamespaceSpecifier extends BaseNode { + type: AST_NODE_TYPES.ImportNamespaceSpecifier; + local: Identifier; +} + +export interface ImportSpecifier extends BaseNode { + type: AST_NODE_TYPES.ImportSpecifier; + local: Identifier; + imported: Identifier; +} + +export interface JSXAttribute extends BaseNode { + type: AST_NODE_TYPES.JSXAttribute; + name: JSXIdentifier; + value: Literal | JSXExpression | null; +} + +export interface JSXClosingElement extends BaseNode { + type: AST_NODE_TYPES.JSXClosingElement; + name: JSXTagNameExpression; +} + +export interface JSXClosingFragment extends BaseNode { + type: AST_NODE_TYPES.JSXClosingFragment; +} + +export interface JSXElement extends BaseNode { + type: AST_NODE_TYPES.JSXElement; + openingElement: JSXOpeningElement; + closingElement: JSXClosingElement | null; + children: JSXChild[]; +} + +export interface JSXEmptyExpression extends BaseNode { + type: AST_NODE_TYPES.JSXEmptyExpression; +} + +export interface JSXExpressionContainer extends BaseNode { + type: AST_NODE_TYPES.JSXExpressionContainer; + expression: Expression | JSXEmptyExpression; +} + +export interface JSXFragment extends BaseNode { + type: AST_NODE_TYPES.JSXFragment; + openingFragment: JSXOpeningFragment; + closingFragment: JSXClosingFragment; + children: JSXChild[]; +} + +export interface JSXIdentifier extends BaseNode { + type: AST_NODE_TYPES.JSXIdentifier; + name: string; +} + +export interface JSXMemberExpression extends BaseNode { + type: AST_NODE_TYPES.JSXMemberExpression; + object: JSXTagNameExpression; + property: JSXIdentifier; +} + +export interface JSXOpeningElement extends BaseNode { + type: AST_NODE_TYPES.JSXOpeningElement; + typeParameters?: TSTypeParameterInstantiation; + selfClosing: boolean; + name: JSXTagNameExpression; + attributes: JSXAttribute[]; +} + +export interface JSXOpeningFragment extends BaseNode { + type: AST_NODE_TYPES.JSXOpeningFragment; +} + +export interface JSXSpreadAttribute extends BaseNode { + type: AST_NODE_TYPES.JSXSpreadAttribute; + argument: Expression; +} + +export interface JSXSpreadChild extends BaseNode { + type: AST_NODE_TYPES.JSXSpreadChild; + expression: Expression | JSXEmptyExpression; +} + +export interface JSXText extends BaseNode { + type: AST_NODE_TYPES.JSXText; + value: string; + raw: string; +} + +export interface LabeledStatement extends BaseNode { + type: AST_NODE_TYPES.LabeledStatement; + label: Identifier; + body: Statement; +} + +export interface Literal extends LiteralBase { + type: AST_NODE_TYPES.Literal; +} + +export interface LogicalExpression extends BinaryExpressionBase { + type: AST_NODE_TYPES.LogicalExpression; +} + +export interface MemberExpression extends BaseNode { + type: AST_NODE_TYPES.MemberExpression; + object: LeftHandSideExpression; + property: Expression | Identifier; + computed?: boolean; +} + +export interface MetaProperty extends BaseNode { + type: AST_NODE_TYPES.MetaProperty; + meta: Identifier; + property: Identifier; +} + +export interface MethodDefinition extends MethodDefinitionBase { + type: AST_NODE_TYPES.MethodDefinition; +} + +export interface NewExpression extends BaseNode { + type: AST_NODE_TYPES.NewExpression; + callee: LeftHandSideExpression; + arguments: Expression[]; + typeParameters?: TSTypeParameterInstantiation; +} + +export interface ObjectExpression extends BaseNode { + type: AST_NODE_TYPES.ObjectExpression; + properties: ObjectLiteralElementLike[]; +} + +export interface ObjectPattern extends BaseNode { + type: AST_NODE_TYPES.ObjectPattern; + properties: ObjectLiteralElementLike[]; + typeAnnotation?: TSTypeAnnotation; + optional?: boolean; +} + +export interface Program extends BaseNode { + type: AST_NODE_TYPES.Program; + body: Statement[]; + sourceType: 'module' | 'script'; + comments?: Comment[]; + tokens?: Token[]; +} + +export interface Property extends BaseNode { + type: AST_NODE_TYPES.Property; + key: PropertyName; + value: Expression | AssignmentPattern | BindingName; + computed: boolean; + method: boolean; + shorthand: boolean; + kind: 'init'; + typeParameters?: TSTypeParameterDeclaration; +} + +export interface RestElement extends BaseNode { + type: AST_NODE_TYPES.RestElement; + argument: BindingName | Expression | PropertyName; + typeAnnotation?: TSTypeAnnotation; + optional?: boolean; + value?: AssignmentPattern; +} + +export interface ReturnStatement extends BaseNode { + type: AST_NODE_TYPES.ReturnStatement; + argument: Expression | null; +} + +export interface SequenceExpression extends BaseNode { + type: AST_NODE_TYPES.SequenceExpression; + expressions: Expression[]; +} + +export interface SpreadElement extends BaseNode { + type: AST_NODE_TYPES.SpreadElement; + argument: BindingName | Expression | PropertyName; +} + +export interface Super extends BaseNode { + type: AST_NODE_TYPES.Super; +} + +export interface SwitchCase extends BaseNode { + type: AST_NODE_TYPES.SwitchCase; + test: Expression; + consequent: Statement[]; +} + +export interface SwitchStatement extends BaseNode { + type: AST_NODE_TYPES.SwitchStatement; + discriminant: Expression; + cases: SwitchCase[]; +} + +export interface TaggedTemplateExpression extends BaseNode { + type: AST_NODE_TYPES.TaggedTemplateExpression; + typeParameters?: TSTypeParameterInstantiation; + tag: LeftHandSideExpression; + quasi: TemplateLiteral; +} + +export interface TemplateElement extends BaseNode { + type: AST_NODE_TYPES.TemplateElement; + value: { + raw: string; + cooked: string; + }; + tail: boolean; +} + +export interface TemplateLiteral extends BaseNode { + type: AST_NODE_TYPES.TemplateLiteral; + quasis: TemplateElement[]; + expressions: Expression[]; +} + +export interface ThisExpression extends BaseNode { + type: AST_NODE_TYPES.ThisExpression; +} + +export interface ThrowStatement extends BaseNode { + type: AST_NODE_TYPES.ThrowStatement; + argument: Statement | null; +} + +export interface TryStatement extends BaseNode { + type: AST_NODE_TYPES.TryStatement; + block: BlockStatement; + handler: CatchClause | null; + finalizer: BlockStatement; +} + +export interface TSAbstractClassProperty extends ClassPropertyBase { + type: AST_NODE_TYPES.TSAbstractClassProperty; +} + +export interface TSAbstractKeyword extends BaseNode { + type: AST_NODE_TYPES.TSAbstractKeyword; +} + +export interface TSAbstractMethodDefinition extends MethodDefinitionBase { + type: AST_NODE_TYPES.TSAbstractMethodDefinition; +} + +export interface TSAnyKeyword extends BaseNode { + type: AST_NODE_TYPES.TSAnyKeyword; +} + +export interface TSArrayType extends BaseNode { + type: AST_NODE_TYPES.TSArrayType; + elementType: TypeNode; +} + +export interface TSAsExpression extends BaseNode { + type: AST_NODE_TYPES.TSAsExpression; + expression: Expression; + typeAnnotation: TypeNode; +} + +export interface TSAsyncKeyword extends BaseNode { + type: AST_NODE_TYPES.TSAsyncKeyword; +} + +export interface TSBigIntKeyword extends BaseNode { + type: AST_NODE_TYPES.TSBigIntKeyword; +} + +export interface TSBooleanKeyword extends BaseNode { + type: AST_NODE_TYPES.TSBooleanKeyword; +} + +export interface TSCallSignatureDeclaration extends FunctionSignatureBase { + type: AST_NODE_TYPES.TSCallSignatureDeclaration; +} + +export interface TSClassImplements extends TSHeritageBase { + type: AST_NODE_TYPES.TSClassImplements; +} + +export interface TSConditionalType extends BaseNode { + type: AST_NODE_TYPES.TSConditionalType; + checkType: TypeNode; + extendsType: TypeNode; + trueType: TypeNode; + falseType: TypeNode; +} + +export interface TSConstructorType extends FunctionSignatureBase { + type: AST_NODE_TYPES.TSConstructorType; +} + +export interface TSConstructSignatureDeclaration extends FunctionSignatureBase { + type: AST_NODE_TYPES.TSConstructSignatureDeclaration; +} + +export interface TSDeclareFunction extends FunctionDeclarationBase { + type: AST_NODE_TYPES.TSDeclareFunction; +} + +export interface TSDeclareKeyword extends BaseNode { + type: AST_NODE_TYPES.TSDeclareKeyword; +} + +export interface TSEnumDeclaration extends BaseNode { + type: AST_NODE_TYPES.TSEnumDeclaration; + id: Identifier; + members: TSEnumMember[]; + const?: boolean; + declare?: boolean; + modifiers?: Modifier[]; + decorators?: Decorator[]; +} + +export interface TSEnumMember extends BaseNode { + type: AST_NODE_TYPES.TSEnumMember; + id: PropertyName; + initializer?: Expression; +} + +export interface TSExportAssignment extends BaseNode { + type: AST_NODE_TYPES.TSExportAssignment; + expression: Expression; +} + +export interface TSExportKeyword extends BaseNode { + type: AST_NODE_TYPES.TSExportKeyword; +} + +export interface TSExternalModuleReference extends BaseNode { + type: AST_NODE_TYPES.TSExternalModuleReference; + expression: Expression; +} + +export interface TSFunctionType extends FunctionSignatureBase { + type: AST_NODE_TYPES.TSFunctionType; +} + +export interface TSImportEqualsDeclaration extends BaseNode { + type: AST_NODE_TYPES.TSImportEqualsDeclaration; + id: Identifier; + moduleReference: EntityName | TSExternalModuleReference; + isExport: boolean; +} + +export interface TSImportType extends BaseNode { + type: AST_NODE_TYPES.TSImportType; + isTypeOf: boolean; + parameter: TypeNode; + qualifier: EntityName | null; + typeParameters: TSTypeParameterInstantiation | null; +} + +export interface TSIndexedAccessType extends BaseNode { + type: AST_NODE_TYPES.TSIndexedAccessType; + objectType: TypeNode; + indexType: TypeNode; +} + +export interface TSIndexSignature extends BaseNode { + type: AST_NODE_TYPES.TSIndexSignature; + parameters: Parameter[]; + typeAnnotation?: TSTypeAnnotation; + readonly?: boolean; + accessibility?: Accessibility; + export?: boolean; + static?: boolean; +} + +export interface TSInferType extends BaseNode { + type: AST_NODE_TYPES.TSInferType; + typeParameter: TSTypeParameterDeclaration; +} + +export interface TSInterfaceDeclaration extends BaseNode { + type: AST_NODE_TYPES.TSInterfaceDeclaration; + body: TSInterfaceBody; + id: Identifier; + typeParameters?: TSTypeParameterDeclaration; + extends?: ExpressionWithTypeArguments[]; + implements?: ExpressionWithTypeArguments[]; + decorators?: Decorator[]; + abstract?: boolean; + declare?: boolean; +} + +export interface TSInterfaceBody extends BaseNode { + type: AST_NODE_TYPES.TSInterfaceBody; + body: TypeElement[]; +} + +export interface TSInterfaceHeritage extends TSHeritageBase { + type: AST_NODE_TYPES.TSInterfaceHeritage; +} + +export interface TSIntersectionType extends BaseNode { + type: AST_NODE_TYPES.TSIntersectionType; + types: TypeNode[]; +} + +export interface TSLiteralType extends BaseNode { + type: AST_NODE_TYPES.TSLiteralType; + literal: LiteralExpression | UnaryExpression | UpdateExpression; +} + +export interface TSMappedType extends BaseNode { + type: AST_NODE_TYPES.TSMappedType; + typeParameter: TSTypeParameterDeclaration; + readonly?: boolean | '-' | '+'; + optional?: boolean | '-' | '+'; + typeAnnotation?: TypeNode; +} + +export interface TSMethodSignature extends BaseNode { + type: AST_NODE_TYPES.TSMethodSignature; + computed: boolean; + key: PropertyName; + params: Parameter[]; + optional?: boolean; + returnType?: TSTypeAnnotation; + readonly?: boolean; + typeParameters?: TSTypeParameterDeclaration; + accessibility?: Accessibility; + export?: boolean; + static?: boolean; +} + +export interface TSModuleBlock extends BaseNode { + type: AST_NODE_TYPES.TSModuleBlock; + body: Statement[]; +} + +export interface TSModuleDeclaration extends BaseNode { + type: AST_NODE_TYPES.TSModuleDeclaration; + id: Identifier | Literal; + body?: TSModuleBlock | Identifier; + global?: boolean; + declare?: boolean; + modifiers?: Modifier[]; +} + +export interface TSNamespaceExportDeclaration extends BaseNode { + type: AST_NODE_TYPES.TSNamespaceExportDeclaration; + id: Identifier; +} + +export interface TSNeverKeyword extends BaseNode { + type: AST_NODE_TYPES.TSNeverKeyword; +} + +export interface TSNonNullExpression extends BaseNode { + type: AST_NODE_TYPES.TSNonNullExpression; + expression: Expression; +} + +export interface TSNullKeyword extends BaseNode { + type: AST_NODE_TYPES.TSNullKeyword; +} + +export interface TSNumberKeyword extends BaseNode { + type: AST_NODE_TYPES.TSNumberKeyword; +} + +export interface TSObjectKeyword extends BaseNode { + type: AST_NODE_TYPES.TSObjectKeyword; +} + +export interface TSOptionalType extends BaseNode { + type: AST_NODE_TYPES.TSOptionalType; + typeAnnotation: TypeNode; +} + +export interface TSParameterProperty extends BaseNode { + type: AST_NODE_TYPES.TSParameterProperty; + accessibility?: Accessibility; + readonly?: boolean; + static?: boolean; + export?: boolean; + parameter: AssignmentPattern | BindingName | RestElement; +} + +export interface TSParenthesizedType extends BaseNode { + type: AST_NODE_TYPES.TSParenthesizedType; + typeAnnotation: TypeNode; +} + +export interface TSPropertySignature extends BaseNode { + type: AST_NODE_TYPES.TSPropertySignature; + optional?: boolean; + computed: boolean; + key: PropertyName; + typeAnnotation?: TSTypeAnnotation; + initializer?: Expression; + readonly?: boolean; + static?: boolean; + export?: boolean; + accessibility?: Accessibility; +} + +export interface TSPublicKeyword extends BaseNode { + type: AST_NODE_TYPES.TSPublicKeyword; +} + +export interface TSPrivateKeyword extends BaseNode { + type: AST_NODE_TYPES.TSPrivateKeyword; +} + +export interface TSProtectedKeyword extends BaseNode { + type: AST_NODE_TYPES.TSProtectedKeyword; +} + +export interface TSQualifiedName extends BaseNode { + type: AST_NODE_TYPES.TSQualifiedName; + left: EntityName; + right: Identifier; +} + +export interface TSReadonlyKeyword extends BaseNode { + type: AST_NODE_TYPES.TSReadonlyKeyword; +} + +export interface TSRestType extends BaseNode { + type: AST_NODE_TYPES.TSRestType; + typeAnnotation: TypeNode; +} + +export interface TSStaticKeyword extends BaseNode { + type: AST_NODE_TYPES.TSStaticKeyword; +} + +export interface TSStringKeyword extends BaseNode { + type: AST_NODE_TYPES.TSStringKeyword; +} + +export interface TSSymbolKeyword extends BaseNode { + type: AST_NODE_TYPES.TSSymbolKeyword; +} + +export interface TSThisType extends BaseNode { + type: AST_NODE_TYPES.TSThisType; +} + +export interface TSTupleType extends BaseNode { + type: AST_NODE_TYPES.TSTupleType; + elementTypes: TypeNode[]; +} + +export interface TSTypeAliasDeclaration extends BaseNode { + type: AST_NODE_TYPES.TSTypeAliasDeclaration; + id: Identifier; + typeAnnotation: TypeNode; + declare?: boolean; + typeParameters?: TSTypeParameterDeclaration; +} + +export interface TSTypeAnnotation extends BaseNode { + type: AST_NODE_TYPES.TSTypeAnnotation; + typeAnnotation: TypeNode; +} + +export interface TSTypeAssertion extends BaseNode { + type: AST_NODE_TYPES.TSTypeAssertion; + typeAnnotation: TypeNode; + expression: UnaryExpression; +} + +export interface TSTypeLiteral extends BaseNode { + type: AST_NODE_TYPES.TSTypeLiteral; + members: TypeElement[]; +} + +export interface TSTypeOperator extends BaseNode { + type: AST_NODE_TYPES.TSTypeOperator; + operator: 'keyof' | 'unique'; + typeAnnotation?: TSTypeAnnotation; +} + +export interface TSTypeParameter extends BaseNode { + type: AST_NODE_TYPES.TSTypeParameter; + name: Identifier; + constraint?: TypeNode; + default?: TypeNode; +} + +export interface TSTypeParameterDeclaration extends BaseNode { + type: AST_NODE_TYPES.TSTypeParameterDeclaration; + params: TSTypeParameter[]; +} + +export interface TSTypeParameterInstantiation extends BaseNode { + type: AST_NODE_TYPES.TSTypeParameterInstantiation; + params: TypeNode[]; +} + +export interface TSTypePredicate extends BaseNode { + type: AST_NODE_TYPES.TSTypePredicate; + parameterName: Identifier | TSThisType; + typeAnnotation: TSTypeAnnotation; +} + +export interface TSTypeQuery extends BaseNode { + type: AST_NODE_TYPES.TSTypeQuery; + exprName: EntityName; +} + +export interface TSTypeReference extends BaseNode { + type: AST_NODE_TYPES.TSTypeReference; + typeName: EntityName; + typeParameters?: TSTypeParameterInstantiation; +} + +export interface TSUndefinedKeyword extends BaseNode { + type: AST_NODE_TYPES.TSUndefinedKeyword; +} + +export interface TSUnionType extends BaseNode { + type: AST_NODE_TYPES.TSUnionType; + types: TypeNode[]; +} + +export interface TSUnknownKeyword extends BaseNode { + type: AST_NODE_TYPES.TSUnknownKeyword; +} + +export interface TSVoidKeyword extends BaseNode { + type: AST_NODE_TYPES.TSVoidKeyword; +} + +export interface UpdateExpression extends UnaryExpressionBase { + type: AST_NODE_TYPES.UpdateExpression; +} + +export interface UnaryExpression extends UnaryExpressionBase { + type: AST_NODE_TYPES.UnaryExpression; +} + +export interface VariableDeclaration extends BaseNode { + type: AST_NODE_TYPES.VariableDeclaration; + declarations: VariableDeclarator[]; + kind: 'let' | 'const' | 'var'; + declare?: boolean; +} + +export interface VariableDeclarator extends BaseNode { + type: AST_NODE_TYPES.VariableDeclarator; + id: BindingName; + init: Expression | null; + definite?: boolean; +} + +export interface WhileStatement extends BaseNode { + type: AST_NODE_TYPES.WhileStatement; + test: Expression; + body: Statement; +} + +export interface WithStatement extends BaseNode { + type: AST_NODE_TYPES.WithStatement; + object: Expression; + body: Statement; +} + +export interface YieldExpression extends BaseNode { + type: AST_NODE_TYPES.YieldExpression; + delegate: boolean; + argument?: Expression; +} diff --git a/packages/typescript-estree/tests/lib/comments.ts b/packages/typescript-estree/tests/lib/comments.ts index e469c39f00ef..1d02e2fa6715 100644 --- a/packages/typescript-estree/tests/lib/comments.ts +++ b/packages/typescript-estree/tests/lib/comments.ts @@ -8,7 +8,7 @@ import { readFileSync } from 'fs'; import glob from 'glob'; import { extname } from 'path'; -import { ParserOptions } from '../../src/temp-types-based-on-js-source'; +import { ParserOptions } from '../../src/parser-options'; import { createSnapshotTestBlock, formatSnapshotName diff --git a/packages/typescript-estree/tests/lib/javascript.ts b/packages/typescript-estree/tests/lib/javascript.ts index aca646998b3b..d254f8fd612c 100644 --- a/packages/typescript-estree/tests/lib/javascript.ts +++ b/packages/typescript-estree/tests/lib/javascript.ts @@ -7,7 +7,7 @@ */ import { readFileSync } from 'fs'; import glob from 'glob'; -import { ParserOptions } from '../../src/temp-types-based-on-js-source'; +import { ParserOptions } from '../../src/parser-options'; import { createSnapshotTestBlock, formatSnapshotName diff --git a/packages/typescript-estree/tests/lib/jsx.ts b/packages/typescript-estree/tests/lib/jsx.ts index 8b2f9f2c19de..b887911ab008 100644 --- a/packages/typescript-estree/tests/lib/jsx.ts +++ b/packages/typescript-estree/tests/lib/jsx.ts @@ -7,7 +7,7 @@ */ import { readFileSync } from 'fs'; import glob from 'glob'; -import { ParserOptions } from '../../src/temp-types-based-on-js-source'; +import { ParserOptions } from '../../src/parser-options'; import { createSnapshotTestBlock, formatSnapshotName diff --git a/packages/typescript-estree/tests/lib/parse.ts b/packages/typescript-estree/tests/lib/parse.ts index 6bed7ce8bcef..2f8463cc0a2b 100644 --- a/packages/typescript-estree/tests/lib/parse.ts +++ b/packages/typescript-estree/tests/lib/parse.ts @@ -7,7 +7,7 @@ */ import * as parser from '../../src/parser'; import * as astConverter from '../../src/ast-converter'; -import { ParserOptions } from '../../src/temp-types-based-on-js-source'; +import { ParserOptions } from '../../src/parser-options'; import { createSnapshotTestBlock } from '../../tools/test-utils'; //------------------------------------------------------------------------------ diff --git a/packages/typescript-estree/tests/lib/semanticInfo.ts b/packages/typescript-estree/tests/lib/semanticInfo.ts index f5612f191cc5..a164288ceb0f 100644 --- a/packages/typescript-estree/tests/lib/semanticInfo.ts +++ b/packages/typescript-estree/tests/lib/semanticInfo.ts @@ -11,7 +11,7 @@ import { readFileSync } from 'fs'; import glob from 'glob'; import { extname, join, resolve } from 'path'; import ts from 'typescript'; -import { ParserOptions } from '../../src/temp-types-based-on-js-source'; +import { ParserOptions } from '../../src/parser-options'; import { createSnapshotTestBlock, formatSnapshotName, diff --git a/packages/typescript-estree/tests/lib/tsx.ts b/packages/typescript-estree/tests/lib/tsx.ts index 8d4230a2c91f..21dbbd57efe0 100644 --- a/packages/typescript-estree/tests/lib/tsx.ts +++ b/packages/typescript-estree/tests/lib/tsx.ts @@ -7,7 +7,7 @@ import { readFileSync } from 'fs'; import glob from 'glob'; import { extname } from 'path'; -import { ParserOptions } from '../../src/temp-types-based-on-js-source'; +import { ParserOptions } from '../../src/parser-options'; import { createSnapshotTestBlock, formatSnapshotName diff --git a/packages/typescript-estree/tests/lib/typescript.ts b/packages/typescript-estree/tests/lib/typescript.ts index dabfac14def4..9740c4570e74 100644 --- a/packages/typescript-estree/tests/lib/typescript.ts +++ b/packages/typescript-estree/tests/lib/typescript.ts @@ -8,7 +8,7 @@ import { readFileSync } from 'fs'; import glob from 'glob'; import { extname } from 'path'; -import { ParserOptions } from '../../src/temp-types-based-on-js-source'; +import { ParserOptions } from '../../src/parser-options'; import { createSnapshotTestBlock, formatSnapshotName diff --git a/packages/typescript-estree/tools/test-utils.ts b/packages/typescript-estree/tools/test-utils.ts index 9191ae5e518a..c2d57246ca09 100644 --- a/packages/typescript-estree/tools/test-utils.ts +++ b/packages/typescript-estree/tools/test-utils.ts @@ -6,7 +6,7 @@ * MIT License */ import * as parser from '../src/parser'; -import { ParserOptions } from '../src/temp-types-based-on-js-source'; +import { ParserOptions } from '../src/parser-options'; /** * Returns a raw copy of the given AST From 2e5b46ec901edc9d855f2b75e49f19b5955a5563 Mon Sep 17 00:00:00 2001 From: Andrew Boyton Date: Tue, 5 Feb 2019 00:48:13 +1100 Subject: [PATCH 09/26] docs(eslint-plugin): add instructions for using Airbnb's config (#177) --- packages/eslint-plugin/README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md index 1ec6df216048..cacb6666fddf 100644 --- a/packages/eslint-plugin/README.md +++ b/packages/eslint-plugin/README.md @@ -84,6 +84,22 @@ Install [`eslint-config-prettier`](https://github.com/prettier/eslint-config-pre **Note: Make sure you have `eslint-config-prettier@4.0.0` or newer.** +## Usage with Airbnb + +Airbnb has two configs, a base one [`eslint-config-airbnb-base`](https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb-base) and one that includes rules for React [`eslint-config-airbnb`](https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb). + +First you'll need to install the config according to the instructions in one of the links above. `npx install-peerdeps --dev eslint-config-airbnb` or `npx install-peerdeps --dev eslint-config-airbnb-base` should work if you are using **npm 5+**. + +Then you should add `airbnb` (or `airbnb-base`) to your `extends` section of `.eslintrc`. You might also want to turn on `plugin:@typescript-eslint/recommended` as well to enable all of the recommended rules. + +```json +{ + "extends": ["airbnb-base", "plugin:@typescript-eslint/recommended"] +} +``` + +**Note: You can use Airbnb's rules alongside Prettier, see [Usage with Prettier](#usage-with-prettier)** + ## Supported Rules From e37a1edb66160e64a3a5b15db8c294905ccc6d02 Mon Sep 17 00:00:00 2001 From: Armano Date: Mon, 4 Feb 2019 14:48:54 +0100 Subject: [PATCH 10/26] fix(ts-estree): fix issue with nested jsx tag names (#197) --- .../tests/lib/__snapshots__/jsx.ts.snap | 50 +- packages/typescript-estree/src/convert.ts | 123 ++--- .../tests/ast-alignment/fixtures-to-test.ts | 7 +- .../tests/lib/__snapshots__/convert.ts.snap | 519 ++++++++++++++++++ .../tests/lib/__snapshots__/jsx.ts.snap | 50 +- .../typescript-estree/tests/lib/convert.ts | 128 +++++ 6 files changed, 736 insertions(+), 141 deletions(-) create mode 100644 packages/typescript-estree/tests/lib/__snapshots__/convert.ts.snap create mode 100644 packages/typescript-estree/tests/lib/convert.ts diff --git a/packages/parser/tests/lib/__snapshots__/jsx.ts.snap b/packages/parser/tests/lib/__snapshots__/jsx.ts.snap index 02d917e3fb56..a9b76778c344 100644 --- a/packages/parser/tests/lib/__snapshots__/jsx.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/jsx.ts.snap @@ -9526,7 +9526,6 @@ Object { }, }, "object": Object { - "computed": false, "loc": Object { "end": Object { "column": 41, @@ -9548,11 +9547,12 @@ Object { "line": 2, }, }, + "name": "this", "range": Array [ 45, 49, ], - "type": "ThisExpression", + "type": "JSXIdentifier", }, "property": Object { "loc": Object { @@ -9570,13 +9570,13 @@ Object { 50, 55, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "range": Array [ 45, 55, ], - "type": "MemberExpression", + "type": "JSXMemberExpression", }, "property": Object { "loc": Object { @@ -9677,7 +9677,6 @@ Object { }, }, "object": Object { - "computed": false, "loc": Object { "end": Object { "column": 13, @@ -9699,11 +9698,12 @@ Object { "line": 2, }, }, + "name": "this", "range": Array [ 17, 21, ], - "type": "ThisExpression", + "type": "JSXIdentifier", }, "property": Object { "loc": Object { @@ -9721,13 +9721,13 @@ Object { 22, 27, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "range": Array [ 17, 27, ], - "type": "MemberExpression", + "type": "JSXMemberExpression", }, "property": Object { "loc": Object { @@ -9846,7 +9846,6 @@ Object { }, }, "object": Object { - "computed": false, "loc": Object { "end": Object { "column": 9, @@ -9858,7 +9857,6 @@ Object { }, }, "object": Object { - "computed": false, "loc": Object { "end": Object { "column": 7, @@ -9870,7 +9868,6 @@ Object { }, }, "object": Object { - "computed": false, "loc": Object { "end": Object { "column": 5, @@ -9897,7 +9894,7 @@ Object { 74, 75, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "property": Object { "loc": Object { @@ -9915,13 +9912,13 @@ Object { 76, 77, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "range": Array [ 74, 77, ], - "type": "MemberExpression", + "type": "JSXMemberExpression", }, "property": Object { "loc": Object { @@ -9939,13 +9936,13 @@ Object { 78, 79, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "range": Array [ 74, 79, ], - "type": "MemberExpression", + "type": "JSXMemberExpression", }, "property": Object { "loc": Object { @@ -9963,13 +9960,13 @@ Object { 80, 81, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "range": Array [ 74, 81, ], - "type": "MemberExpression", + "type": "JSXMemberExpression", }, "property": Object { "loc": Object { @@ -10070,7 +10067,6 @@ Object { }, }, "object": Object { - "computed": false, "loc": Object { "end": Object { "column": 8, @@ -10082,7 +10078,6 @@ Object { }, }, "object": Object { - "computed": false, "loc": Object { "end": Object { "column": 6, @@ -10094,7 +10089,6 @@ Object { }, }, "object": Object { - "computed": false, "loc": Object { "end": Object { "column": 4, @@ -10121,7 +10115,7 @@ Object { 1, 2, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "property": Object { "loc": Object { @@ -10139,13 +10133,13 @@ Object { 3, 4, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "range": Array [ 1, 4, ], - "type": "MemberExpression", + "type": "JSXMemberExpression", }, "property": Object { "loc": Object { @@ -10163,13 +10157,13 @@ Object { 5, 6, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "range": Array [ 1, 6, ], - "type": "MemberExpression", + "type": "JSXMemberExpression", }, "property": Object { "loc": Object { @@ -10187,13 +10181,13 @@ Object { 7, 8, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "range": Array [ 1, 8, ], - "type": "MemberExpression", + "type": "JSXMemberExpression", }, "property": Object { "loc": Object { diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 8e2d6a876a15..2a1703920307 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -9,7 +9,6 @@ import ts from 'typescript'; import * as es from './typedefs'; import { canContainDirective, - convertToken, createError, findNextToken, fixExports, @@ -25,7 +24,6 @@ import { isComma, isComputedProperty, isESTreeClassMember, - isJSXToken, isOptional, unescapeStringLiteralText } from './node-utils'; @@ -369,50 +367,47 @@ export class Converter { /** * Converts a TypeScript JSX node.tagName into an ESTree node.name - * @param tagName the tagName object from a JSX ts.Node + * @param node the tagName object from a JSX ts.Node * @param parent * @returns the converted ESTree name object */ - private convertTypeScriptJSXTagNameToESTreeName( - tagName: ts.JsxTagNameExpression, + private convertJSXTagName( + node: ts.JsxTagNameExpression, parent: ts.Node ): es.JSXMemberExpression | es.JSXIdentifier { - // TODO: remove convertToken call - const tagNameToken = convertToken(tagName, this.ast); - - if (tagName.kind === SyntaxKind.PropertyAccessExpression) { - const isNestedMemberExpression = - tagName.expression.kind === SyntaxKind.PropertyAccessExpression; - - // Convert TSNode left and right objects into ESTreeNode object - // and property objects - const object = this.convertChild(tagName.expression, parent); - const property = this.convertChild(tagName.name, parent); - - // Assign the appropriate types - object.type = isNestedMemberExpression - ? AST_NODE_TYPES.JSXMemberExpression - : AST_NODE_TYPES.JSXIdentifier; - property.type = AST_NODE_TYPES.JSXIdentifier; - if ((tagName as any).expression.kind === SyntaxKind.ThisKeyword) { - object.name = 'this'; - } - - return this.createNode(tagName, { - type: AST_NODE_TYPES.JSXMemberExpression, - range: tagNameToken.range, - loc: tagNameToken.loc, - object: object, - property: property - }); - } else { - return this.createNode(tagName, { - type: AST_NODE_TYPES.JSXIdentifier, - range: tagNameToken.range, - loc: tagNameToken.loc, - name: tagNameToken.value - }); + let result: es.JSXMemberExpression | es.JSXIdentifier; + switch (node.kind) { + case SyntaxKind.PropertyAccessExpression: + result = this.createNode(node, { + type: AST_NODE_TYPES.JSXMemberExpression, + object: this.convertJSXTagName(node.expression, parent), + property: this.convertJSXTagName( + node.name, + parent + ) as es.JSXIdentifier + }); + break; + case SyntaxKind.ThisKeyword: + result = this.createNode(node, { + type: AST_NODE_TYPES.JSXIdentifier, + name: 'this' + }); + break; + case SyntaxKind.Identifier: + default: + result = this.createNode(node, { + type: AST_NODE_TYPES.JSXIdentifier, + name: node.text + }); + break; + } + + if (result && this.options.shouldProvideParserServices) { + this.tsNodeToESTreeNodeMap.set(node, result); + this.esTreeNodeToTSNodeMap.set(result, node); } + + return result; } /** @@ -1617,36 +1612,12 @@ export class Converter { } case SyntaxKind.PropertyAccessExpression: - if (isJSXToken(parent)) { - const jsxMemberExpression = this.createNode( - node, - { - type: AST_NODE_TYPES.MemberExpression, - object: this.convertChild(node.expression), - property: this.convertChild(node.name) - } - ); - // TODO: refactor this - const isNestedMemberExpression = - node.expression.kind === SyntaxKind.PropertyAccessExpression; - if (node.expression.kind === SyntaxKind.ThisKeyword) { - (jsxMemberExpression.object as any).name = 'this'; - } - - (jsxMemberExpression.object as any).type = isNestedMemberExpression - ? AST_NODE_TYPES.MemberExpression - : AST_NODE_TYPES.JSXIdentifier; - (jsxMemberExpression as any).property.type = - AST_NODE_TYPES.JSXIdentifier; - return jsxMemberExpression; - } else { - return this.createNode(node, { - type: AST_NODE_TYPES.MemberExpression, - object: this.convertChild(node.expression), - property: this.convertChild(node.name), - computed: false - }); - } + return this.createNode(node, { + type: AST_NODE_TYPES.MemberExpression, + object: this.convertChild(node.expression), + property: this.convertChild(node.name), + computed: false + }); case SyntaxKind.ElementAccessExpression: return this.createNode(node, { @@ -1844,10 +1815,7 @@ export class Converter { ? this.convertTypeArgumentsToTypeParameters(node.typeArguments) : undefined, selfClosing: true, - name: this.convertTypeScriptJSXTagNameToESTreeName( - node.tagName, - node - ), + name: this.convertJSXTagName(node.tagName, node), attributes: node.attributes.properties.map(el => this.convertChild(el) ), @@ -1865,10 +1833,7 @@ export class Converter { ? this.convertTypeArgumentsToTypeParameters(node.typeArguments) : undefined, selfClosing: false, - name: this.convertTypeScriptJSXTagNameToESTreeName( - node.tagName, - node - ), + name: this.convertJSXTagName(node.tagName, node), attributes: node.attributes.properties.map(el => this.convertChild(el) ) @@ -1877,7 +1842,7 @@ export class Converter { case SyntaxKind.JsxClosingElement: return this.createNode(node, { type: AST_NODE_TYPES.JSXClosingElement, - name: this.convertTypeScriptJSXTagNameToESTreeName(node.tagName, node) + name: this.convertJSXTagName(node.tagName, node) }); case SyntaxKind.JsxOpeningFragment: diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts index ede45e93fcda..e92f68f968f4 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -284,12 +284,7 @@ tester.addFixturePatternConfig('javascript/unicodeCodePointEscapes'); /* ================================================== */ tester.addFixturePatternConfig('jsx', { - ignore: jsxFilesWithKnownIssues.concat([ - /** - * ts-estree: nested jsx tag names are not correctly converted - */ - 'tag-names-with-multi-dots-multi' - ]) + ignore: jsxFilesWithKnownIssues }); tester.addFixturePatternConfig('jsx-useJSXTextNode'); diff --git a/packages/typescript-estree/tests/lib/__snapshots__/convert.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/convert.ts.snap new file mode 100644 index 000000000000..05a20300876e --- /dev/null +++ b/packages/typescript-estree/tests/lib/__snapshots__/convert.ts.snap @@ -0,0 +1,519 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`convert deeplyCopy should convert node correctly 1`] = ` +Object { + "body": Array [ + Object { + "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": 35, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 35, + ], + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 35, + ], + "transformFlags": undefined, + "type": "TSJSDocNullableType", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 35, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, + 35, + ], + "type": "TSUnionType", + "types": Array [ + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, + 18, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 12, + 15, + ], + "type": "Identifier", + }, + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 16, + 17, + ], + "type": "Identifier", + }, + "typeParameters": undefined, + }, + ], + "range": Array [ + 15, + 18, + ], + "type": "TSTypeParameterInstantiation", + }, + }, + Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 35, + ], + "transformFlags": undefined, + "type": "TSJSDocNullableType", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 35, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "range": Array [ + 22, + 35, + ], + "transformFlags": undefined, + "type": "TSJSDocNullableType", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 34, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "range": Array [ + 22, + 34, + ], + "type": "TSParenthesizedType", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 1, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 23, + 33, + ], + "returnType": Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 1, + }, + "start": Object { + "column": 26, + "line": 1, + }, + }, + "range": Array [ + 26, + 33, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 1, + }, + "start": Object { + "column": 29, + "line": 1, + }, + }, + "range": Array [ + 29, + 33, + ], + "type": "TSVoidKeyword", + }, + }, + "type": "TSFunctionType", + }, + }, + }, + }, + }, + }, + ], + }, + }, + }, + }, + ], + "loc": Object { + "end": Object { + "column": 35, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 35, + ], + "sourceType": "script", + "type": "Program", +} +`; + +exports[`convert deeplyCopy should convert node with decorators correctly 1`] = ` +Object { + "decorators": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "name": "test", + "range": Array [ + 1, + 5, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Decorator", + }, + ], + "heritageClauses": undefined, + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "members": Array [], + "modifiers": undefined, + "name": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 12, + 15, + ], + "type": "Identifier", + }, + "range": Array [ + 0, + 18, + ], + "transformFlags": undefined, + "type": "TSClassDeclaration", + "typeParameters": null, +} +`; + +exports[`convert deeplyCopy should convert node with type parameters correctly 1`] = ` +Object { + "heritageClauses": undefined, + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "members": Array [], + "name": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "range": Array [ + 0, + 15, + ], + "transformFlags": undefined, + "type": "TSClassDeclaration", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "params": Array [ + Object { + "constraint": undefined, + "default": undefined, + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "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, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 9, + 12, + ], + "type": "TSTypeParameterDeclaration", + }, +} +`; diff --git a/packages/typescript-estree/tests/lib/__snapshots__/jsx.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/jsx.ts.snap index cb1f698c267c..d0d092c78411 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/jsx.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/jsx.ts.snap @@ -9486,7 +9486,6 @@ Object { }, }, "object": Object { - "computed": false, "loc": Object { "end": Object { "column": 41, @@ -9508,11 +9507,12 @@ Object { "line": 2, }, }, + "name": "this", "range": Array [ 45, 49, ], - "type": "ThisExpression", + "type": "JSXIdentifier", }, "property": Object { "loc": Object { @@ -9530,13 +9530,13 @@ Object { 50, 55, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "range": Array [ 45, 55, ], - "type": "MemberExpression", + "type": "JSXMemberExpression", }, "property": Object { "loc": Object { @@ -9637,7 +9637,6 @@ Object { }, }, "object": Object { - "computed": false, "loc": Object { "end": Object { "column": 13, @@ -9659,11 +9658,12 @@ Object { "line": 2, }, }, + "name": "this", "range": Array [ 17, 21, ], - "type": "ThisExpression", + "type": "JSXIdentifier", }, "property": Object { "loc": Object { @@ -9681,13 +9681,13 @@ Object { 22, 27, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "range": Array [ 17, 27, ], - "type": "MemberExpression", + "type": "JSXMemberExpression", }, "property": Object { "loc": Object { @@ -9806,7 +9806,6 @@ Object { }, }, "object": Object { - "computed": false, "loc": Object { "end": Object { "column": 9, @@ -9818,7 +9817,6 @@ Object { }, }, "object": Object { - "computed": false, "loc": Object { "end": Object { "column": 7, @@ -9830,7 +9828,6 @@ Object { }, }, "object": Object { - "computed": false, "loc": Object { "end": Object { "column": 5, @@ -9857,7 +9854,7 @@ Object { 74, 75, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "property": Object { "loc": Object { @@ -9875,13 +9872,13 @@ Object { 76, 77, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "range": Array [ 74, 77, ], - "type": "MemberExpression", + "type": "JSXMemberExpression", }, "property": Object { "loc": Object { @@ -9899,13 +9896,13 @@ Object { 78, 79, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "range": Array [ 74, 79, ], - "type": "MemberExpression", + "type": "JSXMemberExpression", }, "property": Object { "loc": Object { @@ -9923,13 +9920,13 @@ Object { 80, 81, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "range": Array [ 74, 81, ], - "type": "MemberExpression", + "type": "JSXMemberExpression", }, "property": Object { "loc": Object { @@ -10030,7 +10027,6 @@ Object { }, }, "object": Object { - "computed": false, "loc": Object { "end": Object { "column": 8, @@ -10042,7 +10038,6 @@ Object { }, }, "object": Object { - "computed": false, "loc": Object { "end": Object { "column": 6, @@ -10054,7 +10049,6 @@ Object { }, }, "object": Object { - "computed": false, "loc": Object { "end": Object { "column": 4, @@ -10081,7 +10075,7 @@ Object { 1, 2, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "property": Object { "loc": Object { @@ -10099,13 +10093,13 @@ Object { 3, 4, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "range": Array [ 1, 4, ], - "type": "MemberExpression", + "type": "JSXMemberExpression", }, "property": Object { "loc": Object { @@ -10123,13 +10117,13 @@ Object { 5, 6, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "range": Array [ 1, 6, ], - "type": "MemberExpression", + "type": "JSXMemberExpression", }, "property": Object { "loc": Object { @@ -10147,13 +10141,13 @@ Object { 7, 8, ], - "type": "Identifier", + "type": "JSXIdentifier", }, "range": Array [ 1, 8, ], - "type": "MemberExpression", + "type": "JSXMemberExpression", }, "property": Object { "loc": Object { diff --git a/packages/typescript-estree/tests/lib/convert.ts b/packages/typescript-estree/tests/lib/convert.ts new file mode 100644 index 000000000000..ee2a44f7b7ce --- /dev/null +++ b/packages/typescript-estree/tests/lib/convert.ts @@ -0,0 +1,128 @@ +import { Converter } from '../../src/convert'; +import ts from 'typescript'; + +describe('convert', () => { + function convertCode(code: string): ts.SourceFile { + return ts.createSourceFile( + 'text.ts', + code, + ts.ScriptTarget.ESNext, + true, + ts.ScriptKind.TSX + ); + } + + it('deeplyCopy should convert node correctly', () => { + const ast = convertCode('type foo = ?foo | ?(() => void)?'); + + const instance = new Converter(ast, { + errorOnUnknownASTType: false, + useJSXTextNode: false, + shouldProvideParserServices: false + }); + expect(instance.convertProgram()).toMatchSnapshot(); + }); + + it('deeplyCopy should convert node with decorators correctly', () => { + const ast = convertCode('@test class foo {}'); + + const instance = new Converter(ast, { + errorOnUnknownASTType: false, + useJSXTextNode: false, + shouldProvideParserServices: false + }); + expect((instance as any).deeplyCopy(ast.statements[0])).toMatchSnapshot(); + }); + + it('deeplyCopy should convert node with type parameters correctly', () => { + const ast = convertCode('class foo {}'); + + const instance = new Converter(ast, { + errorOnUnknownASTType: false, + useJSXTextNode: false, + shouldProvideParserServices: false + }); + expect((instance as any).deeplyCopy(ast.statements[0])).toMatchSnapshot(); + }); + + it('deeplyCopy should fail on unknown node', () => { + const ast = convertCode('type foo = ?foo | ?(() => void)?'); + + const instance = new Converter(ast, { + errorOnUnknownASTType: true, + useJSXTextNode: false, + shouldProvideParserServices: false + }); + expect(() => instance.convertProgram()).toThrow( + 'Unknown AST_NODE_TYPE: "TSJSDocNullableType"' + ); + }); + + it('nodeMaps should contain basic nodes', () => { + const ast = convertCode(` + 'test'; + 2; + class foo {}; + type bar = {}; + `); + + const instance = new Converter(ast, { + errorOnUnknownASTType: false, + useJSXTextNode: false, + shouldProvideParserServices: true + }); + instance.convertProgram(); + const maps = instance.getASTMaps(); + + function checkMaps(child: any) { + child.forEachChild((node: any) => { + if ( + node.kind !== ts.SyntaxKind.EndOfFileToken && + node.kind !== ts.SyntaxKind.JsxAttributes && + node.kind !== ts.SyntaxKind.VariableDeclaration + ) { + expect(node).toBe( + maps.esTreeNodeToTSNodeMap.get(maps.tsNodeToESTreeNodeMap.get(node)) + ); + } + checkMaps(node); + }); + } + + expect(ast).toBe( + maps.esTreeNodeToTSNodeMap.get(maps.tsNodeToESTreeNodeMap.get(ast)) + ); + checkMaps(ast); + }); + + it('nodeMaps should contain jsx nodes', () => { + const ast = convertCode(``); + + const instance = new Converter(ast, { + errorOnUnknownASTType: false, + useJSXTextNode: false, + shouldProvideParserServices: true + }); + instance.convertProgram(); + const maps = instance.getASTMaps(); + + function checkMaps(child: any) { + child.forEachChild((node: any) => { + if ( + node.kind !== ts.SyntaxKind.EndOfFileToken && + node.kind !== ts.SyntaxKind.JsxAttributes + ) { + expect(node).toBe( + maps.esTreeNodeToTSNodeMap.get(maps.tsNodeToESTreeNodeMap.get(node)) + ); + } + checkMaps(node); + }); + } + + expect(ast).toBe( + maps.esTreeNodeToTSNodeMap.get(maps.tsNodeToESTreeNodeMap.get(ast)) + ); + checkMaps(ast); + }); +}); From f513a143f549f8ccc8ec4851f245364c4542af73 Mon Sep 17 00:00:00 2001 From: James Henry Date: Mon, 4 Feb 2019 11:49:05 -0500 Subject: [PATCH 11/26] feat(*): change TypeScript version range to >=3.2.1 <3.4.0 (#184) --- README.md | 8 +++++--- package.json | 2 +- packages/eslint-plugin/package.json | 2 +- packages/parser/README.md | 2 ++ packages/parser/src/parser-options.ts | 1 + packages/parser/src/parser.ts | 12 ++++++++++++ packages/parser/tests/lib/parser.ts | 21 +++++++++++++++++++++ packages/typescript-estree/package.json | 3 +-- packages/typescript-estree/src/parser.ts | 10 ++++++---- yarn.lock | 8 ++++---- 10 files changed, 54 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 75e75658d069..fb5dbbcababd 100644 --- a/README.md +++ b/README.md @@ -42,11 +42,13 @@ The `canary` (latest master) version is: ## Supported TypeScript Version -We will always endeavor to support the latest stable version of TypeScript. +We will always endeavor to support the latest stable version of TypeScript. Sometimes, but not always, changes in TypeScript will not require breaking changes in this project, and so we are able to support more than one version 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. +**The version range of TypeScript currently supported by this parser is `>=3.2.1 <3.4.0`.** -If you use a non-supported version of TypeScript, the parser will log a warning to the console. +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. If you want to disable this warning, you can configure this in your `parserOptions`. See: [`@typescript-eslint/parser`](./packages/parser/) and [`@typescript-eslint/typescript-estree`](./packages/typescript-estree/). **Please ensure that you are using a supported version before submitting any issues/bug reports.** diff --git a/package.json b/package.json index a95c4a1a5710..db01c0bf521c 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,6 @@ "rimraf": "^2.6.3", "ts-jest": "^23.10.4", "tslint": "^5.11.0", - "typescript": "~3.2.1" + "typescript": ">=3.2.1 <3.4.0" } } diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index b0bf9f288e0e..e710176c4250 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -34,6 +34,6 @@ }, "peerDependencies": { "eslint": "^5.0.0", - "typescript": "~3.2.1" + "typescript": "*" } } diff --git a/packages/parser/README.md b/packages/parser/README.md index d0a6879b4e57..78d17e6388fb 100644 --- a/packages/parser/README.md +++ b/packages/parser/README.md @@ -54,6 +54,8 @@ The following additional configuration options are available by specifying them - **`extraFileExtensions`** - default `undefined`. This option allows you to provide one or more additional file extensions which should be considered in the TypeScript Program compilation. E.g. a `.vue` file +- **`warnOnUnsupportedTypeScriptVersion`** - default `true`. This option allows you to toggle the warning that the parser will give you if you use a version of TypeScript which is not explicitly supported + ### .eslintrc.json ```json diff --git a/packages/parser/src/parser-options.ts b/packages/parser/src/parser-options.ts index 95d6e54c182c..d374ac57b912 100644 --- a/packages/parser/src/parser-options.ts +++ b/packages/parser/src/parser-options.ts @@ -17,4 +17,5 @@ export interface ParserOptions { errorOnTypeScriptSyntacticAndSemanticIssues?: boolean; tsconfigRootDir?: string; extraFileExtensions?: string[]; + warnOnUnsupportedTypeScriptVersion?: boolean; } diff --git a/packages/parser/src/parser.ts b/packages/parser/src/parser.ts index 2dd32b383625..be3c3e7506ef 100644 --- a/packages/parser/src/parser.ts +++ b/packages/parser/src/parser.ts @@ -75,6 +75,18 @@ export function parseForESLint( } } + /** + * Allow the user to suppress the warning from typescript-estree if they are using an unsupported + * version of TypeScript + */ + const warnOnUnsupportedTypeScriptVersion = validateBoolean( + options.warnOnUnsupportedTypeScriptVersion, + true + ); + if (!warnOnUnsupportedTypeScriptVersion) { + parserOptions.loggerFn = false; + } + const { ast, services } = parseAndGenerateServices(code, parserOptions); ast.sourceType = options.sourceType; diff --git a/packages/parser/tests/lib/parser.ts b/packages/parser/tests/lib/parser.ts index 332be8b6e43c..6a844baae22e 100644 --- a/packages/parser/tests/lib/parser.ts +++ b/packages/parser/tests/lib/parser.ts @@ -84,4 +84,25 @@ describe('parser', () => { `"Cannot assign to read only property 'ArrayExpression' of object '#'"` ); }); + + it('`warnOnUnsupportedTypeScriptVersion: false` should set `loggerFn: false` on typescript-estree', () => { + const code = 'const valid = true;'; + const spy = jest.spyOn(typescriptESTree, 'parseAndGenerateServices'); + parseForESLint(code, { warnOnUnsupportedTypeScriptVersion: true }); + expect(spy).toHaveBeenCalledWith(code, { + ecmaFeatures: {}, + jsx: false, + sourceType: 'script', + useJSXTextNode: true + }); + parseForESLint(code, { warnOnUnsupportedTypeScriptVersion: false }); + expect(spy).toHaveBeenCalledWith(code, { + ecmaFeatures: {}, + jsx: false, + sourceType: 'script', + useJSXTextNode: true, + loggerFn: false, + warnOnUnsupportedTypeScriptVersion: false + }); + }); }); diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index 5c7f52edf274..50432ba4d214 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -42,7 +42,6 @@ "typescript": "*" }, "devDependencies": { - "@typescript-eslint/shared-fixtures": "1.2.0", - "typescript": "~3.2.1" + "@typescript-eslint/shared-fixtures": "1.2.0" } } diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index 3c9680df06d4..ca3d27db77e1 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -18,9 +18,11 @@ import * as es from './typedefs'; import { Extra, ParserOptions } from './parser-options'; import { getFirstSemanticOrSyntacticError } from './semantic-errors'; -const packageJSON = require('../package.json'); - -const SUPPORTED_TYPESCRIPT_VERSIONS = packageJSON.devDependencies.typescript; +/** + * This needs to be kept in sync with the top-level README.md in the + * typescript-eslint monorepo + */ +const SUPPORTED_TYPESCRIPT_VERSIONS = '>=3.2.1 <3.4.0'; const ACTIVE_TYPESCRIPT_VERSION = ts.version; const isRunningSupportedTypeScriptVersion = semver.satisfies( ACTIVE_TYPESCRIPT_VERSION, @@ -287,7 +289,7 @@ interface ParseAndGenerateServicesResult { // Public //------------------------------------------------------------------------------ -export const version: string = packageJSON.version; +export const version: string = require('../package.json').version; export function parse( code: string, diff --git a/yarn.lock b/yarn.lock index 1969160e6c41..51d8518fb375 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7056,10 +7056,10 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@~3.2.1: - version "3.2.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5" - integrity sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg== +"typescript@>=3.2.1 <3.4.0": + version "3.3.1" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.3.1.tgz#6de14e1db4b8a006ac535e482c8ba018c55f750b" + integrity sha512-cTmIDFW7O0IHbn1DPYjkiebHxwtCMU+eTy30ZtJNBPF9j2O1ITu5XH2YnBeVRKWHqF+3JQwWJv0Q0aUgX8W7IA== uglify-js@^3.1.4: version "3.4.9" From d4dfa3bb78365222055fb18b266416439c40deaf Mon Sep 17 00:00:00 2001 From: Armano Date: Tue, 5 Feb 2019 00:49:48 +0100 Subject: [PATCH 12/26] fix(ts-estree): fix issues with typeParams in FunctionExpression (#208) --- .../lib/__snapshots__/typescript.ts.snap | 252 +++++++++--------- packages/typescript-estree/src/convert.ts | 52 ++-- packages/typescript-estree/src/typedefs.ts | 1 - .../tests/ast-alignment/utils.ts | 15 ++ .../lib/__snapshots__/typescript.ts.snap | 252 +++++++++--------- 5 files changed, 292 insertions(+), 280 deletions(-) diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index f57d7523a358..a6058f009bef 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -11047,13 +11047,13 @@ Object { "line": 2, }, "start": Object { - "column": 16, + "column": 13, "line": 2, }, }, "params": Array [], "range": Array [ - 26, + 23, 32, ], "type": "FunctionExpression", @@ -11180,13 +11180,13 @@ Object { "line": 4, }, "start": Object { - "column": 20, + "column": 17, "line": 4, }, }, "params": Array [], "range": Array [ - 54, + 51, 60, ], "type": "FunctionExpression", @@ -13831,13 +13831,13 @@ Object { "line": 2, }, "start": Object { - "column": 11, + "column": 8, "line": 2, }, }, "params": Array [], "range": Array [ - 23, + 20, 28, ], "type": "FunctionExpression", @@ -14260,13 +14260,13 @@ Object { "line": 2, }, "start": Object { - "column": 17, + "column": 8, "line": 2, }, }, "params": Array [], "range": Array [ - 29, + 20, 34, ], "type": "FunctionExpression", @@ -16112,13 +16112,13 @@ Object { "line": 3, }, "start": Object { - "column": 8, + "column": 5, "line": 3, }, }, "params": Array [], "range": Array [ - 38, + 35, 44, ], "type": "FunctionExpression", @@ -28360,13 +28360,13 @@ Object { "line": 3, }, "start": Object { - "column": 18, + "column": 15, "line": 2, }, }, "params": Array [], "range": Array [ - 28, + 25, 44, ], "returnType": Object { @@ -28527,13 +28527,13 @@ Object { "line": 6, }, "start": Object { - "column": 20, + "column": 17, "line": 5, }, }, "params": Array [], "range": Array [ - 66, + 63, 82, ], "returnType": Object { @@ -58372,60 +58372,6 @@ Object { ], "shorthand": false, "type": "Property", - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 18, - "line": 2, - }, - "start": Object { - "column": 15, - "line": 2, - }, - }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 2, - }, - "start": Object { - "column": 16, - "line": 2, - }, - }, - "name": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 2, - }, - "start": Object { - "column": 16, - "line": 2, - }, - }, - "name": "T", - "range": Array [ - 30, - 31, - ], - "type": "Identifier", - }, - "range": Array [ - 30, - 31, - ], - "type": "TSTypeParameter", - }, - ], - "range": Array [ - 29, - 32, - ], - "type": "TSTypeParameterDeclaration", - }, "value": Object { "async": false, "body": Object { @@ -58492,13 +58438,13 @@ Object { "line": 4, }, "start": Object { - "column": 18, + "column": 15, "line": 2, }, }, "params": Array [], "range": Array [ - 32, + 29, 61, ], "returnType": Object { @@ -58536,6 +58482,60 @@ Object { }, }, "type": "FunctionExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "name": "T", + "range": Array [ + 30, + 31, + ], + "type": "Identifier", + }, + "range": Array [ + 30, + 31, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 29, + 32, + ], + "type": "TSTypeParameterDeclaration", + }, }, }, Object { @@ -58576,60 +58576,6 @@ Object { ], "shorthand": false, "type": "Property", - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 8, - "line": 5, - }, - "start": Object { - "column": 5, - "line": 5, - }, - }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 7, - "line": 5, - }, - "start": Object { - "column": 6, - "line": 5, - }, - }, - "name": Object { - "loc": Object { - "end": Object { - "column": 7, - "line": 5, - }, - "start": Object { - "column": 6, - "line": 5, - }, - }, - "name": "T", - "range": Array [ - 69, - 70, - ], - "type": "Identifier", - }, - "range": Array [ - 69, - 70, - ], - "type": "TSTypeParameter", - }, - ], - "range": Array [ - 68, - 71, - ], - "type": "TSTypeParameterDeclaration", - }, "value": Object { "async": false, "body": Object { @@ -58696,13 +58642,13 @@ Object { "line": 7, }, "start": Object { - "column": 8, + "column": 5, "line": 5, }, }, "params": Array [], "range": Array [ - 71, + 68, 100, ], "returnType": Object { @@ -58740,6 +58686,60 @@ Object { }, }, "type": "FunctionExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 5, + }, + "start": Object { + "column": 5, + "line": 5, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "name": "T", + "range": Array [ + 69, + 70, + ], + "type": "Identifier", + }, + "range": Array [ + 69, + 70, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 68, + 71, + ], + "type": "TSTypeParameterDeclaration", + }, }, }, Object { diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 2a1703920307..6f9465c15139 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -468,20 +468,22 @@ export class Converter { } /** - * Uses the current TSNode's end location for its `type` to adjust the location data of the given - * ESTreeNode, which should be the parent of the final typeAnnotation node - * @param typeAnnotationParent The node that will have its location data mutated - * @param node + * Uses the provided range location to adjust the location data of the given Node + * @param result The node that will have its location data mutated + * @param childRange The child node range used to expand location */ - private fixTypeAnnotationParentLocation( - typeAnnotationParent: es.BaseNode, - node: ts.TypeNode + private fixParentLocation( + result: es.BaseNode, + childRange: [number, number] ): void { - typeAnnotationParent.range[1] = node.getEnd(); - typeAnnotationParent.loc.end = getLineAndCharacterFor( - typeAnnotationParent.range[1], - this.ast - ); + if (childRange[0] < result.range[0]) { + result.range[0] = childRange[0]; + result.loc.start = getLineAndCharacterFor(result.range[0], this.ast); + } + if (childRange[1] > result.range[1]) { + result.range[1] = childRange[1]; + result.loc.end = getLineAndCharacterFor(result.range[1], this.ast); + } } /** @@ -713,7 +715,7 @@ export class Converter { node.type, node ); - this.fixTypeAnnotationParentLocation(result.id, node.type); + this.fixParentLocation(result.id, result.id.typeAnnotation.range); } return result; } @@ -893,6 +895,14 @@ export class Converter { method.returnType = this.convertTypeAnnotation(node.type, node); } + // Process typeParameters + if (node.typeParameters && node.typeParameters.length) { + method.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( + node.typeParameters + ); + this.fixParentLocation(method, method.typeParameters.range); + } + let result: | es.Property | es.TSAbstractMethodDefinition @@ -970,19 +980,6 @@ export class Converter { ) { result.kind = 'constructor'; } - - // Process typeParameters - if (node.typeParameters && node.typeParameters.length) { - if (result.type !== AST_NODE_TYPES.Property) { - method.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( - node.typeParameters - ); - } else { - result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( - node.typeParameters - ); - } - } return result; } @@ -1009,6 +1006,7 @@ export class Converter { constructor.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( node.typeParameters ); + this.fixParentLocation(constructor, constructor.typeParameters.range); } // Process returnType @@ -1291,7 +1289,7 @@ export class Converter { node.type, node ); - this.fixTypeAnnotationParentLocation(parameter, node.type); + this.fixParentLocation(parameter, parameter.typeAnnotation.range); } if (node.questionToken) { diff --git a/packages/typescript-estree/src/typedefs.ts b/packages/typescript-estree/src/typedefs.ts index 140ed6e09a49..f5fecea9ef7f 100644 --- a/packages/typescript-estree/src/typedefs.ts +++ b/packages/typescript-estree/src/typedefs.ts @@ -893,7 +893,6 @@ export interface Property extends BaseNode { method: boolean; shorthand: boolean; kind: 'init'; - typeParameters?: TSTypeParameterDeclaration; } export interface RestElement extends BaseNode { diff --git a/packages/typescript-estree/tests/ast-alignment/utils.ts b/packages/typescript-estree/tests/ast-alignment/utils.ts index ee0a2b7d72f9..f00b7d9ad16b 100644 --- a/packages/typescript-estree/tests/ast-alignment/utils.ts +++ b/packages/typescript-estree/tests/ast-alignment/utils.ts @@ -251,6 +251,21 @@ export function preprocessBabylonAST(ast: any): any { ) { node.type = 'TSClassImplements'; } + }, + // https://github.com/prettier/prettier/issues/5817 + FunctionExpression(node: any, parent: any) { + if (parent.typeParameters && parent.type === 'Property') { + node.typeParameters = parent.typeParameters; + delete parent.typeParameters; + } + + /** + * babel issue: ranges of typeParameters are not included in FunctionExpression range + */ + if (node.typeParameters) { + node.range[0] = node.typeParameters.range[0]; + node.loc.start = Object.assign({}, node.typeParameters.loc.start); + } } } ); diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index 0c1e0c5afe60..b9d07faaa475 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -11023,13 +11023,13 @@ Object { "line": 2, }, "start": Object { - "column": 16, + "column": 13, "line": 2, }, }, "params": Array [], "range": Array [ - 26, + 23, 32, ], "type": "FunctionExpression", @@ -11156,13 +11156,13 @@ Object { "line": 4, }, "start": Object { - "column": 20, + "column": 17, "line": 4, }, }, "params": Array [], "range": Array [ - 54, + 51, 60, ], "type": "FunctionExpression", @@ -13801,13 +13801,13 @@ Object { "line": 2, }, "start": Object { - "column": 11, + "column": 8, "line": 2, }, }, "params": Array [], "range": Array [ - 23, + 20, 28, ], "type": "FunctionExpression", @@ -14229,13 +14229,13 @@ Object { "line": 2, }, "start": Object { - "column": 17, + "column": 8, "line": 2, }, }, "params": Array [], "range": Array [ - 29, + 20, 34, ], "type": "FunctionExpression", @@ -16076,13 +16076,13 @@ Object { "line": 3, }, "start": Object { - "column": 8, + "column": 5, "line": 3, }, }, "params": Array [], "range": Array [ - 38, + 35, 44, ], "type": "FunctionExpression", @@ -28309,13 +28309,13 @@ Object { "line": 3, }, "start": Object { - "column": 18, + "column": 15, "line": 2, }, }, "params": Array [], "range": Array [ - 28, + 25, 44, ], "returnType": Object { @@ -28476,13 +28476,13 @@ Object { "line": 6, }, "start": Object { - "column": 20, + "column": 17, "line": 5, }, }, "params": Array [], "range": Array [ - 66, + 63, 82, ], "returnType": Object { @@ -58224,60 +58224,6 @@ Object { ], "shorthand": false, "type": "Property", - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 18, - "line": 2, - }, - "start": Object { - "column": 15, - "line": 2, - }, - }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 2, - }, - "start": Object { - "column": 16, - "line": 2, - }, - }, - "name": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 2, - }, - "start": Object { - "column": 16, - "line": 2, - }, - }, - "name": "T", - "range": Array [ - 30, - 31, - ], - "type": "Identifier", - }, - "range": Array [ - 30, - 31, - ], - "type": "TSTypeParameter", - }, - ], - "range": Array [ - 29, - 32, - ], - "type": "TSTypeParameterDeclaration", - }, "value": Object { "async": false, "body": Object { @@ -58344,13 +58290,13 @@ Object { "line": 4, }, "start": Object { - "column": 18, + "column": 15, "line": 2, }, }, "params": Array [], "range": Array [ - 32, + 29, 61, ], "returnType": Object { @@ -58388,6 +58334,60 @@ Object { }, }, "type": "FunctionExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "name": "T", + "range": Array [ + 30, + 31, + ], + "type": "Identifier", + }, + "range": Array [ + 30, + 31, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 29, + 32, + ], + "type": "TSTypeParameterDeclaration", + }, }, }, Object { @@ -58428,60 +58428,6 @@ Object { ], "shorthand": false, "type": "Property", - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 8, - "line": 5, - }, - "start": Object { - "column": 5, - "line": 5, - }, - }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 7, - "line": 5, - }, - "start": Object { - "column": 6, - "line": 5, - }, - }, - "name": Object { - "loc": Object { - "end": Object { - "column": 7, - "line": 5, - }, - "start": Object { - "column": 6, - "line": 5, - }, - }, - "name": "T", - "range": Array [ - 69, - 70, - ], - "type": "Identifier", - }, - "range": Array [ - 69, - 70, - ], - "type": "TSTypeParameter", - }, - ], - "range": Array [ - 68, - 71, - ], - "type": "TSTypeParameterDeclaration", - }, "value": Object { "async": false, "body": Object { @@ -58548,13 +58494,13 @@ Object { "line": 7, }, "start": Object { - "column": 8, + "column": 5, "line": 5, }, }, "params": Array [], "range": Array [ - 71, + 68, 100, ], "returnType": Object { @@ -58592,6 +58538,60 @@ Object { }, }, "type": "FunctionExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 5, + }, + "start": Object { + "column": 5, + "line": 5, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "name": "T", + "range": Array [ + 69, + 70, + ], + "type": "Identifier", + }, + "range": Array [ + 69, + 70, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 68, + 71, + ], + "type": "TSTypeParameterDeclaration", + }, }, }, Object { From c1abae9cbe05a6ae750a3ea6dd21e9a71b56bf41 Mon Sep 17 00:00:00 2001 From: Armano Date: Tue, 5 Feb 2019 01:38:55 +0100 Subject: [PATCH 13/26] refactor(ts-estree): improve definition of parameters (#209) - add missing tests for decorators --- .../lib/__snapshots__/typescript.ts.snap | 4876 ++++++++++++----- .../parameter-array-pattern-decorator.src.ts | 3 + .../parameter-object-pattern-decorator.src.ts | 3 + .../parameter-rest-element-decorator.src.ts | 3 + .../decorator-on-function.src.ts | 2 + packages/typescript-estree/src/convert.ts | 15 +- packages/typescript-estree/src/typedefs.ts | 14 +- .../tests/ast-alignment/fixtures-to-test.ts | 10 +- .../semantic-diagnostics-enabled.ts.snap | 15 + .../lib/__snapshots__/typescript.ts.snap | 4872 +++++++++++----- 10 files changed, 7118 insertions(+), 2695 deletions(-) create mode 100644 packages/shared-fixtures/fixtures/typescript/decorators/parameter-decorators/parameter-array-pattern-decorator.src.ts create mode 100644 packages/shared-fixtures/fixtures/typescript/decorators/parameter-decorators/parameter-object-pattern-decorator.src.ts create mode 100644 packages/shared-fixtures/fixtures/typescript/decorators/parameter-decorators/parameter-rest-element-decorator.src.ts create mode 100644 packages/shared-fixtures/fixtures/typescript/errorRecovery/decorator-on-function.src.ts diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index a6058f009bef..6f4ae3ff2035 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -82288,7 +82288,7 @@ Object { } `; -exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-constructor.src 1`] = ` +exports[`typescript fixtures/decorators/parameter-decorators/parameter-array-pattern-decorator.src 1`] = ` Object { "body": Array [ Object { @@ -82299,198 +82299,55 @@ Object { "key": Object { "loc": Object { "end": Object { - "column": 15, + "column": 5, "line": 2, }, "start": Object { - "column": 4, + "column": 2, "line": 2, }, }, - "name": "constructor", + "name": "bar", "range": Array [ - 20, - 31, + 14, + 17, ], "type": "Identifier", }, - "kind": "constructor", + "kind": "method", "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 37, + "line": 2, }, "start": Object { - "column": 4, + "column": 2, "line": 2, }, }, "range": Array [ - 20, - 113, + 14, + 49, ], "static": false, "type": "MethodDefinition", "value": Object { "async": false, "body": Object { - "body": Array [ - Object { - "expression": Object { - "left": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 18, - "line": 3, - }, - "start": Object { - "column": 8, - "line": 3, - }, - }, - "object": Object { - "loc": Object { - "end": Object { - "column": 12, - "line": 3, - }, - "start": Object { - "column": 8, - "line": 3, - }, - }, - "range": Array [ - 81, - 85, - ], - "type": "ThisExpression", - }, - "property": Object { - "loc": Object { - "end": Object { - "column": 18, - "line": 3, - }, - "start": Object { - "column": 13, - "line": 3, - }, - }, - "name": "title", - "range": Array [ - 86, - 91, - ], - "type": "Identifier", - }, - "range": Array [ - 81, - 91, - ], - "type": "MemberExpression", - }, - "loc": Object { - "end": Object { - "column": 33, - "line": 3, - }, - "start": Object { - "column": 8, - "line": 3, - }, - }, - "operator": "=", - "range": Array [ - 81, - 106, - ], - "right": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 33, - "line": 3, - }, - "start": Object { - "column": 21, - "line": 3, - }, - }, - "object": Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 3, - }, - "start": Object { - "column": 21, - "line": 3, - }, - }, - "name": "config", - "range": Array [ - 94, - 100, - ], - "type": "Identifier", - }, - "property": Object { - "loc": Object { - "end": Object { - "column": 33, - "line": 3, - }, - "start": Object { - "column": 28, - "line": 3, - }, - }, - "name": "title", - "range": Array [ - 101, - 106, - ], - "type": "Identifier", - }, - "range": Array [ - 94, - 106, - ], - "type": "MemberExpression", - }, - "type": "AssignmentExpression", - }, - "loc": Object { - "end": Object { - "column": 34, - "line": 3, - }, - "start": Object { - "column": 8, - "line": 3, - }, - }, - "range": Array [ - 81, - 107, - ], - "type": "ExpressionStatement", - }, - ], + "body": Array [], "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 37, + "line": 2, }, "start": Object { - "column": 55, + "column": 35, "line": 2, }, }, "range": Array [ - 71, - 113, + 47, + 49, ], "type": "BlockStatement", }, @@ -82499,11 +82356,11 @@ Object { "id": null, "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 37, + "line": 2, }, "start": Object { - "column": 15, + "column": 5, "line": 2, }, }, @@ -82516,146 +82373,148 @@ Object { Object { "loc": Object { "end": Object { - "column": 34, + "column": 19, "line": 2, }, "start": Object { - "column": 24, + "column": 15, "line": 2, }, }, - "name": "APP_CONFIG", "range": Array [ - 40, - 50, + 27, + 31, ], - "type": "Identifier", + "raw": "true", + "type": "Literal", + "value": true, }, ], "callee": Object { "loc": Object { "end": Object { - "column": 23, + "column": 14, "line": 2, }, "start": Object { - "column": 17, + "column": 7, "line": 2, }, }, - "name": "Inject", + "name": "special", "range": Array [ - 33, - 39, + 19, + 26, ], "type": "Identifier", }, "loc": Object { "end": Object { - "column": 35, + "column": 20, "line": 2, }, "start": Object { - "column": 17, + "column": 7, "line": 2, }, }, "range": Array [ - 33, - 51, + 19, + 32, ], "type": "CallExpression", }, "loc": Object { "end": Object { - "column": 35, + "column": 20, "line": 2, }, "start": Object { - "column": 16, + "column": 6, "line": 2, }, }, "range": Array [ + 18, 32, - 51, ], "type": "Decorator", }, ], + "elements": Array [ + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "name": "bar", + "range": Array [ + 35, + 38, + ], + "type": "Identifier", + }, + ], "loc": Object { "end": Object { - "column": 53, + "column": 33, "line": 2, }, "start": Object { - "column": 36, + "column": 21, "line": 2, }, }, - "name": "config", "range": Array [ - 52, - 69, + 33, + 45, ], - "type": "Identifier", + "type": "ArrayPattern", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 53, + "column": 33, "line": 2, }, "start": Object { - "column": 42, + "column": 28, "line": 2, }, }, "range": Array [ - 58, - 69, + 40, + 45, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 53, + "column": 33, "line": 2, }, "start": Object { - "column": 44, + "column": 30, "line": 2, }, }, "range": Array [ - 60, - 69, + 42, + 45, ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 53, - "line": 2, - }, - "start": Object { - "column": 44, - "line": 2, - }, - }, - "name": "AppConfig", - "range": Array [ - 60, - 69, - ], - "type": "Identifier", - }, + "type": "TSAnyKeyword", }, }, }, ], "range": Array [ - 31, - 113, + 17, + 49, ], "type": "FunctionExpression", }, @@ -82664,23 +82523,23 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { - "column": 14, + "column": 10, "line": 1, }, }, "range": Array [ - 14, - 115, + 10, + 51, ], "type": "ClassBody", }, "id": Object { "loc": Object { "end": Object { - "column": 13, + "column": 9, "line": 1, }, "start": Object { @@ -82688,17 +82547,17 @@ Object { "line": 1, }, }, - "name": "Service", + "name": "Foo", "range": Array [ 6, - 13, + 9, ], "type": "Identifier", }, "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { "column": 0, @@ -82707,7 +82566,7 @@ Object { }, "range": Array [ 0, - 115, + 51, ], "superClass": null, "type": "ClassDeclaration", @@ -82717,7 +82576,7 @@ Object { "loc": Object { "end": Object { "column": 0, - "line": 6, + "line": 4, }, "start": Object { "column": 0, @@ -82726,7 +82585,7 @@ Object { }, "range": Array [ 0, - 116, + 52, ], "sourceType": "module", "tokens": Array [ @@ -82751,7 +82610,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 13, + "column": 9, "line": 1, }, "start": Object { @@ -82761,25 +82620,25 @@ Object { }, "range": Array [ 6, - 13, + 9, ], "type": "Identifier", - "value": "Service", + "value": "Foo", }, Object { "loc": Object { "end": Object { - "column": 15, + "column": 11, "line": 1, }, "start": Object { - "column": 14, + "column": 10, "line": 1, }, }, "range": Array [ - 14, - 15, + 10, + 11, ], "type": "Punctuator", "value": "{", @@ -82787,35 +82646,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 15, + "column": 5, "line": 2, }, "start": Object { - "column": 4, + "column": 2, "line": 2, }, }, "range": Array [ - 20, - 31, + 14, + 17, ], "type": "Identifier", - "value": "constructor", + "value": "bar", }, Object { "loc": Object { "end": Object { - "column": 16, + "column": 6, "line": 2, }, "start": Object { - "column": 15, + "column": 5, "line": 2, }, }, "range": Array [ - 31, - 32, + 17, + 18, ], "type": "Punctuator", "value": "(", @@ -82823,17 +82682,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 17, + "column": 7, "line": 2, }, "start": Object { - "column": 16, + "column": 6, "line": 2, }, }, "range": Array [ - 32, - 33, + 18, + 19, ], "type": "Punctuator", "value": "@", @@ -82841,35 +82700,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 23, + "column": 14, "line": 2, }, "start": Object { - "column": 17, + "column": 7, "line": 2, }, }, "range": Array [ - 33, - 39, + 19, + 26, ], "type": "Identifier", - "value": "Inject", + "value": "special", }, Object { "loc": Object { "end": Object { - "column": 24, + "column": 15, "line": 2, }, "start": Object { - "column": 23, + "column": 14, "line": 2, }, }, "range": Array [ - 39, - 40, + 26, + 27, ], "type": "Punctuator", "value": "(", @@ -82877,35 +82736,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 34, + "column": 19, "line": 2, }, "start": Object { - "column": 24, + "column": 15, "line": 2, }, }, "range": Array [ - 40, - 50, + 27, + 31, ], - "type": "Identifier", - "value": "APP_CONFIG", + "type": "Boolean", + "value": "true", }, Object { "loc": Object { "end": Object { - "column": 35, + "column": 20, "line": 2, }, "start": Object { - "column": 34, + "column": 19, "line": 2, }, }, "range": Array [ - 50, - 51, + 31, + 32, ], "type": "Punctuator", "value": ")", @@ -82913,251 +82772,2244 @@ Object { Object { "loc": Object { "end": Object { - "column": 42, + "column": 22, "line": 2, }, "start": Object { - "column": 36, + "column": 21, "line": 2, }, }, "range": Array [ - 52, - 58, + 33, + 34, ], - "type": "Identifier", - "value": "config", + "type": "Punctuator", + "value": "[", }, Object { "loc": Object { "end": Object { - "column": 43, + "column": 26, "line": 2, }, "start": Object { - "column": 42, + "column": 23, "line": 2, }, }, "range": Array [ - 58, - 59, + 35, + 38, ], - "type": "Punctuator", - "value": ":", + "type": "Identifier", + "value": "bar", }, Object { "loc": Object { "end": Object { - "column": 53, + "column": 28, "line": 2, }, "start": Object { - "column": 44, + "column": 27, "line": 2, }, }, "range": Array [ - 60, - 69, + 39, + 40, ], - "type": "Identifier", - "value": "AppConfig", + "type": "Punctuator", + "value": "]", }, Object { "loc": Object { "end": Object { - "column": 54, + "column": 29, "line": 2, }, "start": Object { - "column": 53, + "column": 28, "line": 2, }, }, "range": Array [ - 69, - 70, + 40, + 41, ], "type": "Punctuator", - "value": ")", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 56, + "column": 33, "line": 2, }, "start": Object { - "column": 55, + "column": 30, "line": 2, }, }, "range": Array [ - 71, - 72, + 42, + 45, ], - "type": "Punctuator", - "value": "{", + "type": "Identifier", + "value": "any", }, Object { "loc": Object { "end": Object { - "column": 12, - "line": 3, + "column": 34, + "line": 2, }, "start": Object { - "column": 8, - "line": 3, + "column": 33, + "line": 2, }, }, "range": Array [ - 81, - 85, + 45, + 46, ], - "type": "Keyword", - "value": "this", + "type": "Punctuator", + "value": ")", }, Object { "loc": Object { "end": Object { - "column": 13, - "line": 3, + "column": 36, + "line": 2, }, "start": Object { - "column": 12, - "line": 3, + "column": 35, + "line": 2, }, }, "range": Array [ - 85, - 86, + 47, + 48, ], "type": "Punctuator", - "value": ".", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 18, - "line": 3, + "column": 37, + "line": 2, }, "start": Object { - "column": 13, - "line": 3, + "column": 36, + "line": 2, }, }, "range": Array [ - 86, - 91, + 48, + 49, ], - "type": "Identifier", - "value": "title", + "type": "Punctuator", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 20, + "column": 1, "line": 3, }, "start": Object { - "column": 19, + "column": 0, "line": 3, }, }, "range": Array [ - 92, - 93, + 50, + 51, ], "type": "Punctuator", - "value": "=", + "value": "}", }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-constructor.src 1`] = ` +Object { + "body": Array [ Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 3, - }, + "body": Object { + "body": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "name": "constructor", + "range": Array [ + 20, + 31, + ], + "type": "Identifier", + }, + "kind": "constructor", + "loc": Object { + "end": Object { + "column": 5, + "line": 4, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 20, + 113, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [ + Object { + "expression": Object { + "left": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 81, + 85, + ], + "type": "ThisExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 13, + "line": 3, + }, + }, + "name": "title", + "range": Array [ + 86, + 91, + ], + "type": "Identifier", + }, + "range": Array [ + 81, + 91, + ], + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 33, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "operator": "=", + "range": Array [ + 81, + 106, + ], + "right": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 33, + "line": 3, + }, + "start": Object { + "column": 21, + "line": 3, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 3, + }, + "start": Object { + "column": 21, + "line": 3, + }, + }, + "name": "config", + "range": Array [ + 94, + 100, + ], + "type": "Identifier", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 3, + }, + "start": Object { + "column": 28, + "line": 3, + }, + }, + "name": "title", + "range": Array [ + 101, + 106, + ], + "type": "Identifier", + }, + "range": Array [ + 94, + 106, + ], + "type": "MemberExpression", + }, + "type": "AssignmentExpression", + }, + "loc": Object { + "end": Object { + "column": 34, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 81, + 107, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 5, + "line": 4, + }, + "start": Object { + "column": 55, + "line": 2, + }, + }, + "range": Array [ + 71, + 113, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 5, + "line": 4, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "params": Array [ + Object { + "decorators": Array [ + Object { + "expression": Object { + "arguments": Array [ + Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 2, + }, + "start": Object { + "column": 24, + "line": 2, + }, + }, + "name": "APP_CONFIG", + "range": Array [ + 40, + 50, + ], + "type": "Identifier", + }, + ], + "callee": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "name": "Inject", + "range": Array [ + 33, + 39, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 35, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 33, + 51, + ], + "type": "CallExpression", + }, + "loc": Object { + "end": Object { + "column": 35, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 32, + 51, + ], + "type": "Decorator", + }, + ], + "loc": Object { + "end": Object { + "column": 53, + "line": 2, + }, + "start": Object { + "column": 36, + "line": 2, + }, + }, + "name": "config", + "range": Array [ + 52, + 69, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 53, + "line": 2, + }, + "start": Object { + "column": 42, + "line": 2, + }, + }, + "range": Array [ + 58, + 69, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 53, + "line": 2, + }, + "start": Object { + "column": 44, + "line": 2, + }, + }, + "range": Array [ + 60, + 69, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 53, + "line": 2, + }, + "start": Object { + "column": 44, + "line": 2, + }, + }, + "name": "AppConfig", + "range": Array [ + 60, + 69, + ], + "type": "Identifier", + }, + }, + }, + }, + ], + "range": Array [ + 31, + 113, + ], + "type": "FunctionExpression", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 115, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "Service", + "range": Array [ + 6, + 13, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 115, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 6, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 116, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 13, + ], + "type": "Identifier", + "value": "Service", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 20, + 31, + ], + "type": "Identifier", + "value": "constructor", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 31, + 32, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 32, + 33, + ], + "type": "Punctuator", + "value": "@", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 33, + 39, + ], + "type": "Identifier", + "value": "Inject", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "range": Array [ + 39, + 40, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 2, + }, + "start": Object { + "column": 24, + "line": 2, + }, + }, + "range": Array [ + 40, + 50, + ], + "type": "Identifier", + "value": "APP_CONFIG", + }, + Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 2, + }, + "start": Object { + "column": 34, + "line": 2, + }, + }, + "range": Array [ + 50, + 51, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 2, + }, + "start": Object { + "column": 36, + "line": 2, + }, + }, + "range": Array [ + 52, + 58, + ], + "type": "Identifier", + "value": "config", + }, + Object { + "loc": Object { + "end": Object { + "column": 43, + "line": 2, + }, + "start": Object { + "column": 42, + "line": 2, + }, + }, + "range": Array [ + 58, + 59, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 53, + "line": 2, + }, + "start": Object { + "column": 44, + "line": 2, + }, + }, + "range": Array [ + 60, + 69, + ], + "type": "Identifier", + "value": "AppConfig", + }, + Object { + "loc": Object { + "end": Object { + "column": 54, + "line": 2, + }, + "start": Object { + "column": 53, + "line": 2, + }, + }, + "range": Array [ + 69, + 70, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 56, + "line": 2, + }, + "start": Object { + "column": 55, + "line": 2, + }, + }, + "range": Array [ + 71, + 72, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 81, + 85, + ], + "type": "Keyword", + "value": "this", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 12, + "line": 3, + }, + }, + "range": Array [ + 85, + 86, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 13, + "line": 3, + }, + }, + "range": Array [ + 86, + 91, + ], + "type": "Identifier", + "value": "title", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 3, + }, + "start": Object { + "column": 19, + "line": 3, + }, + }, + "range": Array [ + 92, + 93, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 3, + }, + "start": Object { + "column": 21, + "line": 3, + }, + }, + "range": Array [ + 94, + 100, + ], + "type": "Identifier", + "value": "config", + }, + Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 3, + }, + "start": Object { + "column": 27, + "line": 3, + }, + }, + "range": Array [ + 100, + 101, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 3, + }, + "start": Object { + "column": 28, + "line": 3, + }, + }, + "range": Array [ + 101, + 106, + ], + "type": "Identifier", + "value": "title", + }, + Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 3, + }, + "start": Object { + "column": 33, + "line": 3, + }, + }, + "range": Array [ + 106, + 107, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 4, + }, + "start": Object { + "column": 4, + "line": 4, + }, + }, + "range": Array [ + 112, + 113, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 5, + }, + }, + "range": Array [ + 114, + 115, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-decorator-instance-member.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "name": "bar", + "range": Array [ + 16, + 19, + ], + "type": "Identifier", + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 16, + 50, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 36, + "line": 2, + }, + }, + "range": Array [ + 48, + 50, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "params": Array [ + Object { + "decorators": Array [ + Object { + "expression": Object { + "arguments": Array [ + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 29, + 33, + ], + "raw": "true", + "type": "Literal", + "value": true, + }, + ], + "callee": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "name": "special", + "range": Array [ + 21, + 28, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 22, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 21, + 34, + ], + "type": "CallExpression", + }, + "loc": Object { + "end": Object { + "column": 22, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 20, + 34, + ], + "type": "Decorator", + }, + ], + "loc": Object { + "end": Object { + "column": 34, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "name": "baz", + "range": Array [ + 35, + 46, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 2, + }, + "start": Object { + "column": 26, + "line": 2, + }, + }, + "range": Array [ + 38, + 46, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 2, + }, + "start": Object { + "column": 28, + "line": 2, + }, + }, + "range": Array [ + 40, + 46, + ], + "type": "TSNumberKeyword", + }, + }, + }, + ], + "range": Array [ + 19, + 50, + ], + "type": "FunctionExpression", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 52, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "Foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 52, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 53, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "Foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 16, + 19, + ], + "type": "Identifier", + "value": "bar", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "range": Array [ + 19, + 20, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Punctuator", + "value": "@", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 21, + 28, + ], + "type": "Identifier", + "value": "special", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 28, + 29, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 29, + 33, + ], + "type": "Boolean", + "value": "true", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 2, + }, + "start": Object { + "column": 21, + "line": 2, + }, + }, + "range": Array [ + 33, + 34, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "range": Array [ + 35, + 38, + ], + "type": "Identifier", + "value": "baz", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 26, + "line": 2, + }, + }, + "range": Array [ + 38, + 39, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 2, + }, + "start": Object { + "column": 28, + "line": 2, + }, + }, + "range": Array [ + 40, + 46, + ], + "type": "Identifier", + "value": "number", + }, + Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 2, + }, + "start": Object { + "column": 34, + "line": 2, + }, + }, + "range": Array [ + 46, + 47, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 37, + "line": 2, + }, + "start": Object { + "column": 36, + "line": 2, + }, + }, + "range": Array [ + 48, + 49, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 37, + "line": 2, + }, + }, + "range": Array [ + 49, + 50, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 51, + 52, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-decorator-static-member.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "name": "bar", + "range": Array [ + 29, + 32, + ], + "type": "Identifier", + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 45, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 22, + 63, + ], + "static": true, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 45, + "line": 2, + }, + "start": Object { + "column": 43, + "line": 2, + }, + }, + "range": Array [ + 61, + 63, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 45, + "line": 2, + }, + "start": Object { + "column": 14, + "line": 2, + }, + }, + "params": Array [ + Object { + "decorators": Array [ + Object { + "expression": Object { + "arguments": Array [ + Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 2, + }, + "start": Object { + "column": 24, + "line": 2, + }, + }, + "range": Array [ + 42, + 46, + ], + "raw": "true", + "type": "Literal", + "value": true, + }, + ], + "callee": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "name": "special", + "range": Array [ + 34, + 41, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 29, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 34, + 47, + ], + "type": "CallExpression", + }, + "loc": Object { + "end": Object { + "column": 29, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 33, + 47, + ], + "type": "Decorator", + }, + ], + "loc": Object { + "end": Object { + "column": 41, + "line": 2, + }, + "start": Object { + "column": 30, + "line": 2, + }, + }, + "name": "baz", + "range": Array [ + 48, + 59, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 41, + "line": 2, + }, + "start": Object { + "column": 33, + "line": 2, + }, + }, + "range": Array [ + 51, + 59, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 41, + "line": 2, + }, + "start": Object { + "column": 35, + "line": 2, + }, + }, + "range": Array [ + 53, + 59, + ], + "type": "TSNumberKeyword", + }, + }, + }, + ], + "range": Array [ + 32, + 63, + ], + "type": "FunctionExpression", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 65, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "StaticFoo", + "range": Array [ + 6, + 15, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 65, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 66, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, "start": Object { - "column": 21, - "line": 3, + "column": 6, + "line": 1, }, }, "range": Array [ - 94, - 100, + 6, + 15, ], "type": "Identifier", - "value": "config", + "value": "StaticFoo", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 22, + 28, + ], + "type": "Keyword", + "value": "static", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "range": Array [ + 29, + 32, + ], + "type": "Identifier", + "value": "bar", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 14, + "line": 2, + }, + }, + "range": Array [ + 32, + 33, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 33, + 34, + ], + "type": "Punctuator", + "value": "@", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 34, + 41, + ], + "type": "Identifier", + "value": "special", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "range": Array [ + 41, + 42, + ], + "type": "Punctuator", + "value": "(", }, Object { "loc": Object { "end": Object { "column": 28, - "line": 3, + "line": 2, }, "start": Object { - "column": 27, - "line": 3, + "column": 24, + "line": 2, }, }, "range": Array [ - 100, - 101, + 42, + 46, + ], + "type": "Boolean", + "value": "true", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 2, + }, + "start": Object { + "column": 28, + "line": 2, + }, + }, + "range": Array [ + 46, + 47, ], "type": "Punctuator", - "value": ".", + "value": ")", }, Object { "loc": Object { "end": Object { "column": 33, - "line": 3, + "line": 2, }, "start": Object { - "column": 28, - "line": 3, + "column": 30, + "line": 2, }, }, "range": Array [ - 101, - 106, + 48, + 51, ], "type": "Identifier", - "value": "title", + "value": "baz", }, Object { "loc": Object { "end": Object { "column": 34, - "line": 3, + "line": 2, }, "start": Object { "column": 33, - "line": 3, + "line": 2, }, }, "range": Array [ - 106, - 107, + 51, + 52, ], "type": "Punctuator", - "value": ";", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 41, + "line": 2, + }, + "start": Object { + "column": 35, + "line": 2, + }, + }, + "range": Array [ + 53, + 59, + ], + "type": "Identifier", + "value": "number", + }, + Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 2, + }, + "start": Object { + "column": 41, + "line": 2, + }, + }, + "range": Array [ + 59, + 60, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 44, + "line": 2, + }, + "start": Object { + "column": 43, + "line": 2, + }, + }, + "range": Array [ + 61, + 62, + ], + "type": "Punctuator", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 45, + "line": 2, }, "start": Object { - "column": 4, - "line": 4, + "column": 44, + "line": 2, }, }, "range": Array [ - 112, - 113, + 62, + 63, ], "type": "Punctuator", "value": "}", @@ -83166,16 +85018,16 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { "column": 0, - "line": 5, + "line": 3, }, }, "range": Array [ - 114, - 115, + 64, + 65, ], "type": "Punctuator", "value": "}", @@ -83185,7 +85037,7 @@ Object { } `; -exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-decorator-instance-member.src 1`] = ` +exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-instance-member.src 1`] = ` Object { "body": Array [ Object { @@ -83196,7 +85048,7 @@ Object { "key": Object { "loc": Object { "end": Object { - "column": 7, + "column": 9, "line": 2, }, "start": Object { @@ -83204,18 +85056,18 @@ Object { "line": 2, }, }, - "name": "bar", + "name": "greet", "range": Array [ - 16, - 19, + 20, + 25, ], "type": "Identifier", }, "kind": "method", "loc": Object { "end": Object { - "column": 38, - "line": 2, + "column": 5, + "line": 4, }, "start": Object { "column": 4, @@ -83223,28 +85075,138 @@ Object { }, }, "range": Array [ - 16, - 50, + 20, + 95, ], "static": false, "type": "MethodDefinition", "value": Object { "async": false, "body": Object { - "body": Array [], + "body": Array [ + Object { + "argument": Object { + "left": Object { + "left": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "range": Array [ + 67, + 75, + ], + "raw": "\\"Hello \\"", + "type": "Literal", + "value": "Hello ", + }, + "loc": Object { + "end": Object { + "column": 30, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "operator": "+", + "range": Array [ + 67, + 82, + ], + "right": Object { + "loc": Object { + "end": Object { + "column": 30, + "line": 3, + }, + "start": Object { + "column": 26, + "line": 3, + }, + }, + "name": "name", + "range": Array [ + 78, + 82, + ], + "type": "Identifier", + }, + "type": "BinaryExpression", + }, + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "operator": "+", + "range": Array [ + 67, + 88, + ], + "right": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 33, + "line": 3, + }, + }, + "range": Array [ + 85, + 88, + ], + "raw": "\\"!\\"", + "type": "Literal", + "value": "!", + }, + "type": "BinaryExpression", + }, + "loc": Object { + "end": Object { + "column": 37, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 60, + 89, + ], + "type": "ReturnStatement", + }, + ], "loc": Object { "end": Object { - "column": 38, - "line": 2, + "column": 5, + "line": 4, }, "start": Object { - "column": 36, + "column": 34, "line": 2, }, }, "range": Array [ - 48, 50, + 95, ], "type": "BlockStatement", }, @@ -83253,11 +85215,11 @@ Object { "id": null, "loc": Object { "end": Object { - "column": 38, - "line": 2, + "column": 5, + "line": 4, }, "start": Object { - "column": 7, + "column": 9, "line": 2, }, }, @@ -83266,133 +85228,95 @@ Object { "decorators": Array [ Object { "expression": Object { - "arguments": Array [ - Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 2, - }, - "start": Object { - "column": 17, - "line": 2, - }, - }, - "range": Array [ - 29, - 33, - ], - "raw": "true", - "type": "Literal", - "value": true, - }, - ], - "callee": Object { - "loc": Object { - "end": Object { - "column": 16, - "line": 2, - }, - "start": Object { - "column": 9, - "line": 2, - }, - }, - "name": "special", - "range": Array [ - 21, - 28, - ], - "type": "Identifier", - }, "loc": Object { "end": Object { - "column": 22, + "column": 19, "line": 2, }, "start": Object { - "column": 9, + "column": 11, "line": 2, }, }, + "name": "required", "range": Array [ - 21, - 34, + 27, + 35, ], - "type": "CallExpression", + "type": "Identifier", }, "loc": Object { "end": Object { - "column": 22, + "column": 19, "line": 2, }, "start": Object { - "column": 8, + "column": 10, "line": 2, }, }, "range": Array [ - 20, - 34, + 26, + 35, ], "type": "Decorator", }, ], "loc": Object { "end": Object { - "column": 34, + "column": 32, "line": 2, }, "start": Object { - "column": 23, + "column": 20, "line": 2, }, }, - "name": "baz", + "name": "name", "range": Array [ - 35, - 46, + 36, + 48, ], "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 34, + "column": 32, "line": 2, }, "start": Object { - "column": 26, + "column": 24, "line": 2, }, }, "range": Array [ - 38, - 46, + 40, + 48, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 34, + "column": 32, "line": 2, }, "start": Object { - "column": 28, + "column": 26, "line": 2, }, }, "range": Array [ - 40, - 46, + 42, + 48, ], - "type": "TSNumberKeyword", + "type": "TSStringKeyword", }, }, }, ], "range": Array [ - 19, - 50, + 25, + 95, ], "type": "FunctionExpression", }, @@ -83401,23 +85325,23 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 3, + "line": 5, }, "start": Object { - "column": 10, + "column": 14, "line": 1, }, }, "range": Array [ - 10, - 52, + 14, + 97, ], "type": "ClassBody", }, "id": Object { "loc": Object { "end": Object { - "column": 9, + "column": 13, "line": 1, }, "start": Object { @@ -83425,17 +85349,17 @@ Object { "line": 1, }, }, - "name": "Foo", + "name": "Greeter", "range": Array [ 6, - 9, + 13, ], "type": "Identifier", }, "loc": Object { "end": Object { "column": 1, - "line": 3, + "line": 5, }, "start": Object { "column": 0, @@ -83444,7 +85368,7 @@ Object { }, "range": Array [ 0, - 52, + 97, ], "superClass": null, "type": "ClassDeclaration", @@ -83454,7 +85378,7 @@ Object { "loc": Object { "end": Object { "column": 0, - "line": 4, + "line": 6, }, "start": Object { "column": 0, @@ -83463,7 +85387,7 @@ Object { }, "range": Array [ 0, - 53, + 98, ], "sourceType": "module", "tokens": Array [ @@ -83488,7 +85412,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 9, + "column": 13, "line": 1, }, "start": Object { @@ -83498,25 +85422,25 @@ Object { }, "range": Array [ 6, - 9, + 13, ], "type": "Identifier", - "value": "Foo", + "value": "Greeter", }, Object { "loc": Object { "end": Object { - "column": 11, + "column": 15, "line": 1, }, "start": Object { - "column": 10, + "column": 14, "line": 1, }, }, "range": Array [ - 10, - 11, + 14, + 15, ], "type": "Punctuator", "value": "{", @@ -83524,7 +85448,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 7, + "column": 9, "line": 2, }, "start": Object { @@ -83533,26 +85457,26 @@ Object { }, }, "range": Array [ - 16, - 19, + 20, + 25, ], "type": "Identifier", - "value": "bar", + "value": "greet", }, Object { "loc": Object { "end": Object { - "column": 8, + "column": 10, "line": 2, }, "start": Object { - "column": 7, + "column": 9, "line": 2, }, }, "range": Array [ - 19, - 20, + 25, + 26, ], "type": "Punctuator", "value": "(", @@ -83560,17 +85484,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 9, + "column": 11, "line": 2, }, "start": Object { - "column": 8, + "column": 10, "line": 2, }, }, "range": Array [ - 20, - 21, + 26, + 27, ], "type": "Punctuator", "value": "@", @@ -83578,71 +85502,89 @@ Object { Object { "loc": Object { "end": Object { - "column": 16, + "column": 19, "line": 2, }, "start": Object { - "column": 9, + "column": 11, "line": 2, }, }, "range": Array [ - 21, - 28, + 27, + 35, ], "type": "Identifier", - "value": "special", + "value": "required", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 24, "line": 2, }, "start": Object { - "column": 16, + "column": 20, "line": 2, }, }, "range": Array [ - 28, - 29, + 36, + 40, + ], + "type": "Identifier", + "value": "name", + }, + Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 2, + }, + "start": Object { + "column": 24, + "line": 2, + }, + }, + "range": Array [ + 40, + 41, ], "type": "Punctuator", - "value": "(", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 21, + "column": 32, "line": 2, }, "start": Object { - "column": 17, + "column": 26, "line": 2, }, }, "range": Array [ - 29, - 33, + 42, + 48, ], - "type": "Boolean", - "value": "true", + "type": "Identifier", + "value": "string", }, Object { "loc": Object { "end": Object { - "column": 22, + "column": 33, "line": 2, }, "start": Object { - "column": 21, + "column": 32, "line": 2, }, }, "range": Array [ - 33, - 34, + 48, + 49, ], "type": "Punctuator", "value": ")", @@ -83650,107 +85592,161 @@ Object { Object { "loc": Object { "end": Object { - "column": 26, + "column": 35, "line": 2, }, "start": Object { - "column": 23, + "column": 34, "line": 2, }, }, "range": Array [ - 35, - 38, + 50, + 51, ], - "type": "Identifier", - "value": "baz", + "type": "Punctuator", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 27, - "line": 2, + "column": 14, + "line": 3, }, "start": Object { - "column": 26, - "line": 2, + "column": 8, + "line": 3, }, }, "range": Array [ - 38, - 39, + 60, + 66, + ], + "type": "Keyword", + "value": "return", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "range": Array [ + 67, + 75, + ], + "type": "String", + "value": "\\"Hello \\"", + }, + Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 3, + }, + "start": Object { + "column": 24, + "line": 3, + }, + }, + "range": Array [ + 76, + 77, ], "type": "Punctuator", - "value": ":", + "value": "+", }, Object { "loc": Object { "end": Object { - "column": 34, - "line": 2, + "column": 30, + "line": 3, }, "start": Object { - "column": 28, - "line": 2, + "column": 26, + "line": 3, }, }, "range": Array [ - 40, - 46, + 78, + 82, ], "type": "Identifier", - "value": "number", + "value": "name", }, Object { "loc": Object { "end": Object { - "column": 35, - "line": 2, + "column": 32, + "line": 3, }, "start": Object { - "column": 34, - "line": 2, + "column": 31, + "line": 3, }, }, "range": Array [ - 46, - 47, + 83, + 84, ], "type": "Punctuator", - "value": ")", + "value": "+", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 33, + "line": 3, + }, + }, + "range": Array [ + 85, + 88, + ], + "type": "String", + "value": "\\"!\\"", }, Object { "loc": Object { "end": Object { "column": 37, - "line": 2, + "line": 3, }, "start": Object { "column": 36, - "line": 2, + "line": 3, }, }, "range": Array [ - 48, - 49, + 88, + 89, ], "type": "Punctuator", - "value": "{", + "value": ";", }, Object { "loc": Object { "end": Object { - "column": 38, - "line": 2, + "column": 5, + "line": 4, }, "start": Object { - "column": 37, - "line": 2, + "column": 4, + "line": 4, }, }, "range": Array [ - 49, - 50, + 94, + 95, ], "type": "Punctuator", "value": "}", @@ -83759,16 +85755,16 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 3, + "line": 5, }, "start": Object { "column": 0, - "line": 3, + "line": 5, }, }, "range": Array [ - 51, - 52, + 96, + 97, ], "type": "Punctuator", "value": "}", @@ -83778,7 +85774,7 @@ Object { } `; -exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-decorator-static-member.src 1`] = ` +exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-static-member.src 1`] = ` Object { "body": Array [ Object { @@ -83789,7 +85785,7 @@ Object { "key": Object { "loc": Object { "end": Object { - "column": 14, + "column": 16, "line": 2, }, "start": Object { @@ -83797,18 +85793,18 @@ Object { "line": 2, }, }, - "name": "bar", + "name": "greet", "range": Array [ - 29, - 32, + 33, + 38, ], "type": "Identifier", }, "kind": "method", "loc": Object { "end": Object { - "column": 45, - "line": 2, + "column": 5, + "line": 4, }, "start": Object { "column": 4, @@ -83816,28 +85812,138 @@ Object { }, }, "range": Array [ - 22, - 63, + 26, + 108, ], "static": true, "type": "MethodDefinition", "value": Object { "async": false, "body": Object { - "body": Array [], + "body": Array [ + Object { + "argument": Object { + "left": Object { + "left": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "range": Array [ + 80, + 88, + ], + "raw": "\\"Hello \\"", + "type": "Literal", + "value": "Hello ", + }, + "loc": Object { + "end": Object { + "column": 30, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "operator": "+", + "range": Array [ + 80, + 95, + ], + "right": Object { + "loc": Object { + "end": Object { + "column": 30, + "line": 3, + }, + "start": Object { + "column": 26, + "line": 3, + }, + }, + "name": "name", + "range": Array [ + 91, + 95, + ], + "type": "Identifier", + }, + "type": "BinaryExpression", + }, + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "operator": "+", + "range": Array [ + 80, + 101, + ], + "right": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 33, + "line": 3, + }, + }, + "range": Array [ + 98, + 101, + ], + "raw": "\\"!\\"", + "type": "Literal", + "value": "!", + }, + "type": "BinaryExpression", + }, + "loc": Object { + "end": Object { + "column": 37, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 73, + 102, + ], + "type": "ReturnStatement", + }, + ], "loc": Object { "end": Object { - "column": 45, - "line": 2, + "column": 5, + "line": 4, }, "start": Object { - "column": 43, + "column": 41, "line": 2, }, }, "range": Array [ - 61, 63, + 108, ], "type": "BlockStatement", }, @@ -83846,11 +85952,11 @@ Object { "id": null, "loc": Object { "end": Object { - "column": 45, - "line": 2, + "column": 5, + "line": 4, }, "start": Object { - "column": 14, + "column": 16, "line": 2, }, }, @@ -83859,133 +85965,95 @@ Object { "decorators": Array [ Object { "expression": Object { - "arguments": Array [ - Object { - "loc": Object { - "end": Object { - "column": 28, - "line": 2, - }, - "start": Object { - "column": 24, - "line": 2, - }, - }, - "range": Array [ - 42, - 46, - ], - "raw": "true", - "type": "Literal", - "value": true, - }, - ], - "callee": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 2, - }, - "start": Object { - "column": 16, - "line": 2, - }, - }, - "name": "special", - "range": Array [ - 34, - 41, - ], - "type": "Identifier", - }, "loc": Object { "end": Object { - "column": 29, + "column": 26, "line": 2, }, "start": Object { - "column": 16, + "column": 18, "line": 2, }, }, + "name": "required", "range": Array [ - 34, - 47, + 40, + 48, ], - "type": "CallExpression", + "type": "Identifier", }, "loc": Object { "end": Object { - "column": 29, + "column": 26, "line": 2, }, "start": Object { - "column": 15, + "column": 17, "line": 2, }, }, "range": Array [ - 33, - 47, + 39, + 48, ], "type": "Decorator", }, ], "loc": Object { "end": Object { - "column": 41, + "column": 39, "line": 2, }, "start": Object { - "column": 30, + "column": 27, "line": 2, }, }, - "name": "baz", + "name": "name", "range": Array [ - 48, - 59, + 49, + 61, ], "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 41, + "column": 39, "line": 2, }, "start": Object { - "column": 33, + "column": 31, "line": 2, }, }, "range": Array [ - 51, - 59, + 53, + 61, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 41, + "column": 39, "line": 2, }, "start": Object { - "column": 35, + "column": 33, "line": 2, }, }, "range": Array [ - 53, - 59, + 55, + 61, ], - "type": "TSNumberKeyword", + "type": "TSStringKeyword", }, }, }, ], "range": Array [ - 32, - 63, + 38, + 108, ], "type": "FunctionExpression", }, @@ -83994,23 +86062,23 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 3, + "line": 5, }, "start": Object { - "column": 16, + "column": 20, "line": 1, }, }, "range": Array [ - 16, - 65, + 20, + 110, ], "type": "ClassBody", }, "id": Object { "loc": Object { "end": Object { - "column": 15, + "column": 19, "line": 1, }, "start": Object { @@ -84018,17 +86086,17 @@ Object { "line": 1, }, }, - "name": "StaticFoo", + "name": "StaticGreeter", "range": Array [ 6, - 15, + 19, ], "type": "Identifier", }, "loc": Object { "end": Object { "column": 1, - "line": 3, + "line": 5, }, "start": Object { "column": 0, @@ -84037,7 +86105,7 @@ Object { }, "range": Array [ 0, - 65, + 110, ], "superClass": null, "type": "ClassDeclaration", @@ -84047,7 +86115,7 @@ Object { "loc": Object { "end": Object { "column": 0, - "line": 4, + "line": 6, }, "start": Object { "column": 0, @@ -84056,7 +86124,7 @@ Object { }, "range": Array [ 0, - 66, + 111, ], "sourceType": "module", "tokens": Array [ @@ -84081,7 +86149,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 15, + "column": 19, "line": 1, }, "start": Object { @@ -84091,25 +86159,25 @@ Object { }, "range": Array [ 6, - 15, + 19, ], "type": "Identifier", - "value": "StaticFoo", + "value": "StaticGreeter", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 21, "line": 1, }, "start": Object { - "column": 16, + "column": 20, "line": 1, }, }, "range": Array [ - 16, - 17, + 20, + 21, ], "type": "Punctuator", "value": "{", @@ -84126,8 +86194,8 @@ Object { }, }, "range": Array [ - 22, - 28, + 26, + 32, ], "type": "Keyword", "value": "static", @@ -84135,7 +86203,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 14, + "column": 16, "line": 2, }, "start": Object { @@ -84144,26 +86212,26 @@ Object { }, }, "range": Array [ - 29, - 32, + 33, + 38, ], "type": "Identifier", - "value": "bar", + "value": "greet", }, Object { "loc": Object { "end": Object { - "column": 15, + "column": 17, "line": 2, }, "start": Object { - "column": 14, + "column": 16, "line": 2, }, }, "range": Array [ - 32, - 33, + 38, + 39, ], "type": "Punctuator", "value": "(", @@ -84171,17 +86239,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 16, + "column": 18, "line": 2, }, "start": Object { - "column": 15, + "column": 17, "line": 2, }, }, "range": Array [ - 33, - 34, + 39, + 40, ], "type": "Punctuator", "value": "@", @@ -84189,71 +86257,89 @@ Object { Object { "loc": Object { "end": Object { - "column": 23, + "column": 26, "line": 2, }, "start": Object { - "column": 16, + "column": 18, "line": 2, }, }, "range": Array [ - 34, - 41, + 40, + 48, ], "type": "Identifier", - "value": "special", + "value": "required", }, Object { "loc": Object { "end": Object { - "column": 24, + "column": 31, "line": 2, }, "start": Object { - "column": 23, + "column": 27, "line": 2, }, }, "range": Array [ - 41, - 42, + 49, + 53, + ], + "type": "Identifier", + "value": "name", + }, + Object { + "loc": Object { + "end": Object { + "column": 32, + "line": 2, + }, + "start": Object { + "column": 31, + "line": 2, + }, + }, + "range": Array [ + 53, + 54, ], "type": "Punctuator", - "value": "(", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 28, + "column": 39, "line": 2, }, "start": Object { - "column": 24, + "column": 33, "line": 2, }, }, "range": Array [ - 42, - 46, + 55, + 61, ], - "type": "Boolean", - "value": "true", + "type": "Identifier", + "value": "string", }, Object { "loc": Object { "end": Object { - "column": 29, + "column": 40, "line": 2, }, "start": Object { - "column": 28, + "column": 39, "line": 2, }, }, "range": Array [ - 46, - 47, + 61, + 62, ], "type": "Punctuator", "value": ")", @@ -84261,107 +86347,161 @@ Object { Object { "loc": Object { "end": Object { - "column": 33, + "column": 42, "line": 2, }, "start": Object { - "column": 30, + "column": 41, "line": 2, }, }, "range": Array [ - 48, - 51, + 63, + 64, ], - "type": "Identifier", - "value": "baz", + "type": "Punctuator", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 34, - "line": 2, + "column": 14, + "line": 3, }, "start": Object { - "column": 33, - "line": 2, + "column": 8, + "line": 3, }, }, "range": Array [ - 51, - 52, + 73, + 79, + ], + "type": "Keyword", + "value": "return", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "range": Array [ + 80, + 88, + ], + "type": "String", + "value": "\\"Hello \\"", + }, + Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 3, + }, + "start": Object { + "column": 24, + "line": 3, + }, + }, + "range": Array [ + 89, + 90, ], "type": "Punctuator", - "value": ":", + "value": "+", }, Object { "loc": Object { "end": Object { - "column": 41, - "line": 2, + "column": 30, + "line": 3, }, "start": Object { - "column": 35, - "line": 2, + "column": 26, + "line": 3, }, }, "range": Array [ - 53, - 59, + 91, + 95, ], "type": "Identifier", - "value": "number", + "value": "name", }, Object { "loc": Object { "end": Object { - "column": 42, - "line": 2, + "column": 32, + "line": 3, }, "start": Object { - "column": 41, - "line": 2, + "column": 31, + "line": 3, }, }, "range": Array [ - 59, - 60, + 96, + 97, ], "type": "Punctuator", - "value": ")", + "value": "+", }, Object { "loc": Object { "end": Object { - "column": 44, - "line": 2, + "column": 36, + "line": 3, }, "start": Object { - "column": 43, - "line": 2, + "column": 33, + "line": 3, }, }, "range": Array [ - 61, - 62, + 98, + 101, + ], + "type": "String", + "value": "\\"!\\"", + }, + Object { + "loc": Object { + "end": Object { + "column": 37, + "line": 3, + }, + "start": Object { + "column": 36, + "line": 3, + }, + }, + "range": Array [ + 101, + 102, ], "type": "Punctuator", - "value": "{", + "value": ";", }, Object { "loc": Object { "end": Object { - "column": 45, - "line": 2, + "column": 5, + "line": 4, }, "start": Object { - "column": 44, - "line": 2, + "column": 4, + "line": 4, }, }, "range": Array [ - 62, - 63, + 107, + 108, ], "type": "Punctuator", "value": "}", @@ -84370,16 +86510,16 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 3, + "line": 5, }, "start": Object { "column": 0, - "line": 3, + "line": 5, }, }, "range": Array [ - 64, - 65, + 109, + 110, ], "type": "Punctuator", "value": "}", @@ -84389,7 +86529,7 @@ Object { } `; -exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-instance-member.src 1`] = ` +exports[`typescript fixtures/decorators/parameter-decorators/parameter-object-pattern-decorator.src 1`] = ` Object { "body": Array [ Object { @@ -84400,165 +86540,55 @@ Object { "key": Object { "loc": Object { "end": Object { - "column": 9, + "column": 5, "line": 2, }, "start": Object { - "column": 4, + "column": 2, "line": 2, }, }, - "name": "greet", + "name": "bar", "range": Array [ - 20, - 25, + 14, + 17, ], "type": "Identifier", }, "kind": "method", "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 37, + "line": 2, }, "start": Object { - "column": 4, + "column": 2, "line": 2, }, }, "range": Array [ - 20, - 95, + 14, + 49, ], "static": false, "type": "MethodDefinition", "value": Object { "async": false, "body": Object { - "body": Array [ - Object { - "argument": Object { - "left": Object { - "left": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 3, - }, - "start": Object { - "column": 15, - "line": 3, - }, - }, - "range": Array [ - 67, - 75, - ], - "raw": "\\"Hello \\"", - "type": "Literal", - "value": "Hello ", - }, - "loc": Object { - "end": Object { - "column": 30, - "line": 3, - }, - "start": Object { - "column": 15, - "line": 3, - }, - }, - "operator": "+", - "range": Array [ - 67, - 82, - ], - "right": Object { - "loc": Object { - "end": Object { - "column": 30, - "line": 3, - }, - "start": Object { - "column": 26, - "line": 3, - }, - }, - "name": "name", - "range": Array [ - 78, - 82, - ], - "type": "Identifier", - }, - "type": "BinaryExpression", - }, - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 15, - "line": 3, - }, - }, - "operator": "+", - "range": Array [ - 67, - 88, - ], - "right": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 33, - "line": 3, - }, - }, - "range": Array [ - 85, - 88, - ], - "raw": "\\"!\\"", - "type": "Literal", - "value": "!", - }, - "type": "BinaryExpression", - }, - "loc": Object { - "end": Object { - "column": 37, - "line": 3, - }, - "start": Object { - "column": 8, - "line": 3, - }, - }, - "range": Array [ - 60, - 89, - ], - "type": "ReturnStatement", - }, - ], + "body": Array [], "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 37, + "line": 2, }, "start": Object { - "column": 34, + "column": 35, "line": 2, }, }, "range": Array [ - 50, - 95, + 47, + 49, ], "type": "BlockStatement", }, @@ -84567,11 +86597,11 @@ Object { "id": null, "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 37, + "line": 2, }, "start": Object { - "column": 9, + "column": 5, "line": 2, }, }, @@ -84580,95 +86610,191 @@ Object { "decorators": Array [ Object { "expression": Object { + "arguments": Array [ + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 27, + 31, + ], + "raw": "true", + "type": "Literal", + "value": true, + }, + ], + "callee": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "name": "special", + "range": Array [ + 19, + 26, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { - "column": 19, + "column": 20, "line": 2, }, "start": Object { - "column": 11, + "column": 7, "line": 2, }, }, - "name": "required", "range": Array [ - 27, - 35, + 19, + 32, ], - "type": "Identifier", + "type": "CallExpression", }, "loc": Object { "end": Object { - "column": 19, + "column": 20, "line": 2, }, "start": Object { - "column": 10, + "column": 6, "line": 2, }, }, "range": Array [ - 26, - 35, + 18, + 32, ], "type": "Decorator", }, ], "loc": Object { "end": Object { - "column": 32, + "column": 33, "line": 2, }, "start": Object { - "column": 20, + "column": 21, "line": 2, }, }, - "name": "name", + "properties": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "name": "bar", + "range": Array [ + 35, + 38, + ], + "type": "Identifier", + }, + "kind": "init", + "loc": Object { + "end": Object { + "column": 26, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "method": false, + "range": Array [ + 35, + 38, + ], + "shorthand": true, + "type": "Property", + "value": Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "name": "bar", + "range": Array [ + 35, + 38, + ], + "type": "Identifier", + }, + }, + ], "range": Array [ - 36, - 48, + 33, + 45, ], - "type": "Identifier", + "type": "ObjectPattern", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 32, + "column": 33, "line": 2, }, "start": Object { - "column": 24, + "column": 28, "line": 2, }, }, "range": Array [ 40, - 48, + 45, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 32, + "column": 33, "line": 2, }, "start": Object { - "column": 26, + "column": 30, "line": 2, }, }, "range": Array [ 42, - 48, + 45, ], - "type": "TSStringKeyword", + "type": "TSAnyKeyword", }, }, }, ], "range": Array [ - 25, - 95, + 17, + 49, ], "type": "FunctionExpression", }, @@ -84677,23 +86803,23 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { - "column": 14, + "column": 10, "line": 1, }, }, "range": Array [ - 14, - 97, + 10, + 51, ], "type": "ClassBody", }, "id": Object { "loc": Object { "end": Object { - "column": 13, + "column": 9, "line": 1, }, "start": Object { @@ -84701,17 +86827,17 @@ Object { "line": 1, }, }, - "name": "Greeter", + "name": "Foo", "range": Array [ 6, - 13, + 9, ], "type": "Identifier", }, "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { "column": 0, @@ -84720,7 +86846,7 @@ Object { }, "range": Array [ 0, - 97, + 51, ], "superClass": null, "type": "ClassDeclaration", @@ -84730,7 +86856,7 @@ Object { "loc": Object { "end": Object { "column": 0, - "line": 6, + "line": 4, }, "start": Object { "column": 0, @@ -84739,7 +86865,7 @@ Object { }, "range": Array [ 0, - 98, + 52, ], "sourceType": "module", "tokens": Array [ @@ -84764,7 +86890,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 13, + "column": 9, "line": 1, }, "start": Object { @@ -84774,25 +86900,25 @@ Object { }, "range": Array [ 6, - 13, + 9, ], "type": "Identifier", - "value": "Greeter", + "value": "Foo", }, Object { "loc": Object { "end": Object { - "column": 15, + "column": 11, "line": 1, }, "start": Object { - "column": 14, + "column": 10, "line": 1, }, }, "range": Array [ - 14, - 15, + 10, + 11, ], "type": "Punctuator", "value": "{", @@ -84800,35 +86926,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 9, + "column": 5, "line": 2, }, "start": Object { - "column": 4, + "column": 2, "line": 2, }, }, "range": Array [ - 20, - 25, + 14, + 17, ], "type": "Identifier", - "value": "greet", + "value": "bar", }, Object { "loc": Object { "end": Object { - "column": 10, + "column": 6, "line": 2, }, "start": Object { - "column": 9, + "column": 5, "line": 2, }, }, "range": Array [ - 25, - 26, + 17, + 18, ], "type": "Punctuator", "value": "(", @@ -84836,17 +86962,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 11, + "column": 7, "line": 2, }, "start": Object { - "column": 10, + "column": 6, "line": 2, }, }, "range": Array [ - 26, - 27, + 18, + 19, ], "type": "Punctuator", "value": "@", @@ -84854,89 +86980,71 @@ Object { Object { "loc": Object { "end": Object { - "column": 19, - "line": 2, - }, - "start": Object { - "column": 11, - "line": 2, - }, - }, - "range": Array [ - 27, - 35, - ], - "type": "Identifier", - "value": "required", - }, - Object { - "loc": Object { - "end": Object { - "column": 24, + "column": 14, "line": 2, }, "start": Object { - "column": 20, + "column": 7, "line": 2, }, }, "range": Array [ - 36, - 40, + 19, + 26, ], "type": "Identifier", - "value": "name", + "value": "special", }, Object { "loc": Object { "end": Object { - "column": 25, + "column": 15, "line": 2, }, "start": Object { - "column": 24, + "column": 14, "line": 2, }, }, "range": Array [ - 40, - 41, + 26, + 27, ], "type": "Punctuator", - "value": ":", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 32, + "column": 19, "line": 2, }, "start": Object { - "column": 26, + "column": 15, "line": 2, }, }, "range": Array [ - 42, - 48, + 27, + 31, ], - "type": "Identifier", - "value": "string", + "type": "Boolean", + "value": "true", }, Object { "loc": Object { "end": Object { - "column": 33, + "column": 20, "line": 2, }, "start": Object { - "column": 32, + "column": 19, "line": 2, }, }, "range": Array [ - 48, - 49, + 31, + 32, ], "type": "Punctuator", "value": ")", @@ -84944,17 +87052,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 35, + "column": 22, "line": 2, }, "start": Object { - "column": 34, + "column": 21, "line": 2, }, }, "range": Array [ - 50, - 51, + 33, + 34, ], "type": "Punctuator", "value": "{", @@ -84962,143 +87070,125 @@ Object { Object { "loc": Object { "end": Object { - "column": 14, - "line": 3, + "column": 26, + "line": 2, }, "start": Object { - "column": 8, - "line": 3, + "column": 23, + "line": 2, }, }, "range": Array [ - 60, - 66, + 35, + 38, ], - "type": "Keyword", - "value": "return", + "type": "Identifier", + "value": "bar", }, Object { "loc": Object { "end": Object { - "column": 23, - "line": 3, + "column": 28, + "line": 2, }, "start": Object { - "column": 15, - "line": 3, + "column": 27, + "line": 2, }, }, "range": Array [ - 67, - 75, + 39, + 40, ], - "type": "String", - "value": "\\"Hello \\"", + "type": "Punctuator", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 25, - "line": 3, + "column": 29, + "line": 2, }, "start": Object { - "column": 24, - "line": 3, + "column": 28, + "line": 2, }, }, "range": Array [ - 76, - 77, + 40, + 41, ], "type": "Punctuator", - "value": "+", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 30, - "line": 3, + "column": 33, + "line": 2, }, "start": Object { - "column": 26, - "line": 3, + "column": 30, + "line": 2, }, }, "range": Array [ - 78, - 82, + 42, + 45, ], "type": "Identifier", - "value": "name", + "value": "any", }, Object { "loc": Object { "end": Object { - "column": 32, - "line": 3, + "column": 34, + "line": 2, }, "start": Object { - "column": 31, - "line": 3, + "column": 33, + "line": 2, }, }, "range": Array [ - 83, - 84, + 45, + 46, ], "type": "Punctuator", - "value": "+", + "value": ")", }, Object { "loc": Object { "end": Object { "column": 36, - "line": 3, - }, - "start": Object { - "column": 33, - "line": 3, - }, - }, - "range": Array [ - 85, - 88, - ], - "type": "String", - "value": "\\"!\\"", - }, - Object { - "loc": Object { - "end": Object { - "column": 37, - "line": 3, + "line": 2, }, "start": Object { - "column": 36, - "line": 3, + "column": 35, + "line": 2, }, }, "range": Array [ - 88, - 89, + 47, + 48, ], "type": "Punctuator", - "value": ";", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 37, + "line": 2, }, - "start": Object { - "column": 4, - "line": 4, + "start": Object { + "column": 36, + "line": 2, }, }, "range": Array [ - 94, - 95, + 48, + 49, ], "type": "Punctuator", "value": "}", @@ -85107,16 +87197,16 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { "column": 0, - "line": 5, + "line": 3, }, }, "range": Array [ - 96, - 97, + 50, + 51, ], "type": "Punctuator", "value": "}", @@ -85126,7 +87216,7 @@ Object { } `; -exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-static-member.src 1`] = ` +exports[`typescript fixtures/decorators/parameter-decorators/parameter-rest-element-decorator.src 1`] = ` Object { "body": Array [ Object { @@ -85137,165 +87227,55 @@ Object { "key": Object { "loc": Object { "end": Object { - "column": 16, + "column": 5, "line": 2, }, "start": Object { - "column": 11, + "column": 2, "line": 2, }, }, - "name": "greet", + "name": "bar", "range": Array [ - 33, - 38, + 14, + 17, ], "type": "Identifier", }, "kind": "method", "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 36, + "line": 2, }, "start": Object { - "column": 4, + "column": 2, "line": 2, }, }, "range": Array [ - 26, - 108, + 14, + 48, ], - "static": true, + "static": false, "type": "MethodDefinition", "value": Object { "async": false, "body": Object { - "body": Array [ - Object { - "argument": Object { - "left": Object { - "left": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 3, - }, - "start": Object { - "column": 15, - "line": 3, - }, - }, - "range": Array [ - 80, - 88, - ], - "raw": "\\"Hello \\"", - "type": "Literal", - "value": "Hello ", - }, - "loc": Object { - "end": Object { - "column": 30, - "line": 3, - }, - "start": Object { - "column": 15, - "line": 3, - }, - }, - "operator": "+", - "range": Array [ - 80, - 95, - ], - "right": Object { - "loc": Object { - "end": Object { - "column": 30, - "line": 3, - }, - "start": Object { - "column": 26, - "line": 3, - }, - }, - "name": "name", - "range": Array [ - 91, - 95, - ], - "type": "Identifier", - }, - "type": "BinaryExpression", - }, - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 15, - "line": 3, - }, - }, - "operator": "+", - "range": Array [ - 80, - 101, - ], - "right": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 33, - "line": 3, - }, - }, - "range": Array [ - 98, - 101, - ], - "raw": "\\"!\\"", - "type": "Literal", - "value": "!", - }, - "type": "BinaryExpression", - }, - "loc": Object { - "end": Object { - "column": 37, - "line": 3, - }, - "start": Object { - "column": 8, - "line": 3, - }, - }, - "range": Array [ - 73, - 102, - ], - "type": "ReturnStatement", - }, - ], + "body": Array [], "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 36, + "line": 2, }, "start": Object { - "column": 41, + "column": 34, "line": 2, }, }, "range": Array [ - 63, - 108, + 46, + 48, ], "type": "BlockStatement", }, @@ -85304,108 +87284,163 @@ Object { "id": null, "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 36, + "line": 2, }, "start": Object { - "column": 16, + "column": 5, "line": 2, }, }, "params": Array [ Object { + "argument": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 24, + "line": 2, + }, + }, + "name": "foo", + "range": Array [ + 36, + 39, + ], + "type": "Identifier", + }, "decorators": Array [ Object { "expression": Object { + "arguments": Array [ + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 27, + 31, + ], + "raw": "true", + "type": "Literal", + "value": true, + }, + ], + "callee": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "name": "special", + "range": Array [ + 19, + 26, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { - "column": 26, + "column": 20, "line": 2, }, "start": Object { - "column": 18, + "column": 7, "line": 2, }, }, - "name": "required", "range": Array [ - 40, - 48, + 19, + 32, ], - "type": "Identifier", + "type": "CallExpression", }, "loc": Object { "end": Object { - "column": 26, + "column": 20, "line": 2, }, "start": Object { - "column": 17, + "column": 6, "line": 2, }, }, "range": Array [ - 39, - 48, + 18, + 32, ], "type": "Decorator", }, ], "loc": Object { "end": Object { - "column": 39, + "column": 32, "line": 2, }, "start": Object { - "column": 27, + "column": 6, "line": 2, }, }, - "name": "name", "range": Array [ - 49, - 61, + 18, + 44, ], - "type": "Identifier", + "type": "RestElement", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 39, + "column": 32, "line": 2, }, "start": Object { - "column": 31, + "column": 27, "line": 2, }, }, "range": Array [ - 53, - 61, + 39, + 44, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 39, + "column": 32, "line": 2, }, "start": Object { - "column": 33, + "column": 29, "line": 2, }, }, "range": Array [ - 55, - 61, + 41, + 44, ], - "type": "TSStringKeyword", + "type": "TSAnyKeyword", }, }, }, ], "range": Array [ - 38, - 108, + 17, + 48, ], "type": "FunctionExpression", }, @@ -85414,23 +87449,23 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { - "column": 20, + "column": 10, "line": 1, }, }, "range": Array [ - 20, - 110, + 10, + 50, ], "type": "ClassBody", }, "id": Object { "loc": Object { "end": Object { - "column": 19, + "column": 9, "line": 1, }, "start": Object { @@ -85438,17 +87473,17 @@ Object { "line": 1, }, }, - "name": "StaticGreeter", + "name": "Foo", "range": Array [ 6, - 19, + 9, ], "type": "Identifier", }, "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { "column": 0, @@ -85457,7 +87492,7 @@ Object { }, "range": Array [ 0, - 110, + 50, ], "superClass": null, "type": "ClassDeclaration", @@ -85467,7 +87502,7 @@ Object { "loc": Object { "end": Object { "column": 0, - "line": 6, + "line": 4, }, "start": Object { "column": 0, @@ -85476,7 +87511,7 @@ Object { }, "range": Array [ 0, - 111, + 51, ], "sourceType": "module", "tokens": Array [ @@ -85501,7 +87536,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 19, + "column": 9, "line": 1, }, "start": Object { @@ -85511,25 +87546,25 @@ Object { }, "range": Array [ 6, - 19, + 9, ], "type": "Identifier", - "value": "StaticGreeter", + "value": "Foo", }, Object { "loc": Object { "end": Object { - "column": 21, + "column": 11, "line": 1, }, "start": Object { - "column": 20, + "column": 10, "line": 1, }, }, "range": Array [ - 20, - 21, + 10, + 11, ], "type": "Punctuator", "value": "{", @@ -85537,53 +87572,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 10, - "line": 2, - }, - "start": Object { - "column": 4, - "line": 2, - }, - }, - "range": Array [ - 26, - 32, - ], - "type": "Keyword", - "value": "static", - }, - Object { - "loc": Object { - "end": Object { - "column": 16, + "column": 5, "line": 2, }, "start": Object { - "column": 11, + "column": 2, "line": 2, }, }, "range": Array [ - 33, - 38, + 14, + 17, ], "type": "Identifier", - "value": "greet", + "value": "bar", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 6, "line": 2, }, "start": Object { - "column": 16, + "column": 5, "line": 2, }, }, "range": Array [ - 38, - 39, + 17, + 18, ], "type": "Punctuator", "value": "(", @@ -85591,17 +87608,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 18, + "column": 7, "line": 2, }, "start": Object { - "column": 17, + "column": 6, "line": 2, }, }, "range": Array [ - 39, - 40, + 18, + 19, ], "type": "Punctuator", "value": "@", @@ -85609,89 +87626,71 @@ Object { Object { "loc": Object { "end": Object { - "column": 26, - "line": 2, - }, - "start": Object { - "column": 18, - "line": 2, - }, - }, - "range": Array [ - 40, - 48, - ], - "type": "Identifier", - "value": "required", - }, - Object { - "loc": Object { - "end": Object { - "column": 31, + "column": 14, "line": 2, }, "start": Object { - "column": 27, + "column": 7, "line": 2, }, }, "range": Array [ - 49, - 53, + 19, + 26, ], "type": "Identifier", - "value": "name", + "value": "special", }, Object { "loc": Object { "end": Object { - "column": 32, + "column": 15, "line": 2, }, "start": Object { - "column": 31, + "column": 14, "line": 2, }, }, "range": Array [ - 53, - 54, + 26, + 27, ], "type": "Punctuator", - "value": ":", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 39, + "column": 19, "line": 2, }, "start": Object { - "column": 33, + "column": 15, "line": 2, }, }, "range": Array [ - 55, - 61, + 27, + 31, ], - "type": "Identifier", - "value": "string", + "type": "Boolean", + "value": "true", }, Object { "loc": Object { "end": Object { - "column": 40, + "column": 20, "line": 2, }, "start": Object { - "column": 39, + "column": 19, "line": 2, }, }, "range": Array [ - 61, - 62, + 31, + 32, ], "type": "Punctuator", "value": ")", @@ -85699,161 +87698,125 @@ Object { Object { "loc": Object { "end": Object { - "column": 42, + "column": 24, "line": 2, }, "start": Object { - "column": 41, + "column": 21, "line": 2, }, }, "range": Array [ - 63, - 64, + 33, + 36, ], "type": "Punctuator", - "value": "{", - }, - Object { - "loc": Object { - "end": Object { - "column": 14, - "line": 3, - }, - "start": Object { - "column": 8, - "line": 3, - }, - }, - "range": Array [ - 73, - 79, - ], - "type": "Keyword", - "value": "return", + "value": "...", }, Object { "loc": Object { "end": Object { - "column": 23, - "line": 3, + "column": 27, + "line": 2, }, "start": Object { - "column": 15, - "line": 3, + "column": 24, + "line": 2, }, }, "range": Array [ - 80, - 88, + 36, + 39, ], - "type": "String", - "value": "\\"Hello \\"", + "type": "Identifier", + "value": "foo", }, Object { "loc": Object { "end": Object { - "column": 25, - "line": 3, + "column": 28, + "line": 2, }, "start": Object { - "column": 24, - "line": 3, + "column": 27, + "line": 2, }, }, "range": Array [ - 89, - 90, + 39, + 40, ], "type": "Punctuator", - "value": "+", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 30, - "line": 3, + "column": 32, + "line": 2, }, "start": Object { - "column": 26, - "line": 3, + "column": 29, + "line": 2, }, }, "range": Array [ - 91, - 95, + 41, + 44, ], "type": "Identifier", - "value": "name", + "value": "any", }, Object { "loc": Object { "end": Object { - "column": 32, - "line": 3, + "column": 33, + "line": 2, }, "start": Object { - "column": 31, - "line": 3, + "column": 32, + "line": 2, }, }, "range": Array [ - 96, - 97, + 44, + 45, ], "type": "Punctuator", - "value": "+", - }, - Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 33, - "line": 3, - }, - }, - "range": Array [ - 98, - 101, - ], - "type": "String", - "value": "\\"!\\"", + "value": ")", }, Object { "loc": Object { "end": Object { - "column": 37, - "line": 3, + "column": 35, + "line": 2, }, "start": Object { - "column": 36, - "line": 3, + "column": 34, + "line": 2, }, }, "range": Array [ - 101, - 102, + 46, + 47, ], "type": "Punctuator", - "value": ";", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 36, + "line": 2, }, "start": Object { - "column": 4, - "line": 4, + "column": 35, + "line": 2, }, }, "range": Array [ - 107, - 108, + 47, + 48, ], "type": "Punctuator", "value": "}", @@ -85862,16 +87825,16 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { "column": 0, - "line": 5, + "line": 3, }, }, "range": Array [ - 109, - 110, + 49, + 50, ], "type": "Punctuator", "value": "}", @@ -89263,6 +91226,233 @@ Object { } `; +exports[`typescript fixtures/errorRecovery/decorator-on-function.src 1`] = ` +Object { + "body": Array [ + Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 12, + "line": 2, + }, + }, + "range": Array [ + 17, + 19, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "name": "b", + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 0, + 19, + ], + "type": "FunctionDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 20, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 1, + ], + "type": "Punctuator", + "value": "@", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "range": Array [ + 1, + 4, + ], + "type": "Identifier", + "value": "dec", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 5, + 13, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + "value": "b", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 15, + 16, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 12, + "line": 2, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + exports[`typescript fixtures/errorRecovery/decorator-on-interface-declaration.src 1`] = ` Object { "body": Array [ diff --git a/packages/shared-fixtures/fixtures/typescript/decorators/parameter-decorators/parameter-array-pattern-decorator.src.ts b/packages/shared-fixtures/fixtures/typescript/decorators/parameter-decorators/parameter-array-pattern-decorator.src.ts new file mode 100644 index 000000000000..81dfc005fc92 --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/decorators/parameter-decorators/parameter-array-pattern-decorator.src.ts @@ -0,0 +1,3 @@ +class Foo { + bar(@special(true) [ bar ]: any) {} +} diff --git a/packages/shared-fixtures/fixtures/typescript/decorators/parameter-decorators/parameter-object-pattern-decorator.src.ts b/packages/shared-fixtures/fixtures/typescript/decorators/parameter-decorators/parameter-object-pattern-decorator.src.ts new file mode 100644 index 000000000000..dc9133b3deaf --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/decorators/parameter-decorators/parameter-object-pattern-decorator.src.ts @@ -0,0 +1,3 @@ +class Foo { + bar(@special(true) { bar }: any) {} +} diff --git a/packages/shared-fixtures/fixtures/typescript/decorators/parameter-decorators/parameter-rest-element-decorator.src.ts b/packages/shared-fixtures/fixtures/typescript/decorators/parameter-decorators/parameter-rest-element-decorator.src.ts new file mode 100644 index 000000000000..35b2ac60bc94 --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/decorators/parameter-decorators/parameter-rest-element-decorator.src.ts @@ -0,0 +1,3 @@ +class Foo { + bar(@special(true) ...foo: any) {} +} diff --git a/packages/shared-fixtures/fixtures/typescript/errorRecovery/decorator-on-function.src.ts b/packages/shared-fixtures/fixtures/typescript/errorRecovery/decorator-on-function.src.ts new file mode 100644 index 000000000000..72ed3035b15f --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/errorRecovery/decorator-on-function.src.ts @@ -0,0 +1,2 @@ +@dec +function b(){} diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 6f9465c15139..eb2e69a60ece 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -282,18 +282,19 @@ export class Converter { */ private convertParameters( parameters: ts.NodeArray - ): (es.TSParameterProperty | es.RestElement | es.AssignmentPattern)[] { + ): es.Parameter[] { if (!parameters || !parameters.length) { return []; } return parameters.map(param => { - const convertedParam = this.convertChild(param); - if (!param.decorators || !param.decorators.length) { - return convertedParam; + const convertedParam = this.convertChild(param) as es.Parameter; + + if (param.decorators && param.decorators.length) { + convertedParam.decorators = param.decorators.map(el => + this.convertChild(el) + ); } - return Object.assign(convertedParam, { - decorators: param.decorators.map(el => this.convertChild(el)) - }); + return convertedParam; }); } diff --git a/packages/typescript-estree/src/typedefs.ts b/packages/typescript-estree/src/typedefs.ts index f5fecea9ef7f..a9a100e64623 100644 --- a/packages/typescript-estree/src/typedefs.ts +++ b/packages/typescript-estree/src/typedefs.ts @@ -351,7 +351,13 @@ export type ObjectLiteralElementLike = | RestElement | SpreadElement | TSAbstractMethodDefinition; -export type Parameter = AssignmentPattern | RestElement | TSParameterProperty; +export type Parameter = + | AssignmentPattern + | RestElement + | ArrayPattern + | ObjectPattern + | Identifier + | TSParameterProperty; export type PrimaryExpression = | ArrayExpression | ArrayPattern @@ -541,6 +547,7 @@ export interface ArrayPattern extends BaseNode { elements: Expression[]; typeAnnotation?: TSTypeAnnotation; optional?: boolean; + decorators?: Decorator[]; } export interface ArrowFunctionExpression extends BaseNode { @@ -565,6 +572,7 @@ export interface AssignmentPattern extends BaseNode { right?: Expression; typeAnnotation?: TSTypeAnnotation; optional?: boolean; + decorators?: Decorator[]; } export interface AwaitExpression extends BaseNode { @@ -715,6 +723,7 @@ export interface Identifier extends BaseNode { name: string; typeAnnotation?: TSTypeAnnotation; optional?: boolean; + decorators?: Decorator[]; } export interface IfStatement extends BaseNode { @@ -875,6 +884,7 @@ export interface ObjectPattern extends BaseNode { properties: ObjectLiteralElementLike[]; typeAnnotation?: TSTypeAnnotation; optional?: boolean; + decorators?: Decorator[]; } export interface Program extends BaseNode { @@ -901,6 +911,7 @@ export interface RestElement extends BaseNode { typeAnnotation?: TSTypeAnnotation; optional?: boolean; value?: AssignmentPattern; + decorators?: Decorator[]; } export interface ReturnStatement extends BaseNode { @@ -1218,6 +1229,7 @@ export interface TSParameterProperty extends BaseNode { static?: boolean; export?: boolean; parameter: AssignmentPattern | BindingName | RestElement; + decorators?: Decorator[]; } export interface TSParenthesizedType extends BaseNode { diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts index e92f68f968f4..e8dcf0aca782 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -396,7 +396,15 @@ tester.addFixturePatternConfig('typescript/decorators/method-decorators', { fileType: 'ts' }); tester.addFixturePatternConfig('typescript/decorators/parameter-decorators', { - fileType: 'ts' + fileType: 'ts', + ignore: [ + /** + * babel does not support decorators on array and rest parameters + * TODO: report this to babel + */ + 'parameter-array-pattern-decorator', + 'parameter-rest-element-decorator' + ] }); tester.addFixturePatternConfig('typescript/decorators/property-decorators', { fileType: 'ts' diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap index 842757edb3df..dde844c7e15e 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap @@ -2236,6 +2236,8 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/method-decorators/method-decorator-static-member.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/parameter-decorators/parameter-array-pattern-decorator.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/parameter-decorators/parameter-decorator-constructor.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/parameter-decorators/parameter-decorator-decorator-instance-member.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; @@ -2246,6 +2248,10 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/parameter-decorators/parameter-decorator-static-member.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/parameter-decorators/parameter-object-pattern-decorator.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/parameter-decorators/parameter-rest-element-decorator.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/property-decorators/property-decorator-factory-instance-member.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/decorators/property-decorators/property-decorator-factory-static-member.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; @@ -2299,6 +2305,15 @@ Object { } `; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/decorator-on-function.src 1`] = ` +Object { + "column": 0, + "index": 0, + "lineNumber": 1, + "message": "Decorators are not valid here.", +} +`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/decorator-on-interface-declaration.src 1`] = ` Object { "column": 0, diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index b9d07faaa475..d1040b3b2957 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -81613,7 +81613,7 @@ Object { } `; -exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-constructor.src 1`] = ` +exports[`typescript fixtures/decorators/parameter-decorators/parameter-array-pattern-decorator.src 1`] = ` Object { "body": Array [ Object { @@ -81624,198 +81624,55 @@ Object { "key": Object { "loc": Object { "end": Object { - "column": 15, + "column": 5, "line": 2, }, "start": Object { - "column": 4, + "column": 2, "line": 2, }, }, - "name": "constructor", + "name": "bar", "range": Array [ - 20, - 31, + 14, + 17, ], "type": "Identifier", }, - "kind": "constructor", + "kind": "method", "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 37, + "line": 2, }, "start": Object { - "column": 4, + "column": 2, "line": 2, }, }, "range": Array [ - 20, - 113, + 14, + 49, ], "static": false, "type": "MethodDefinition", "value": Object { "async": false, "body": Object { - "body": Array [ - Object { - "expression": Object { - "left": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 18, - "line": 3, - }, - "start": Object { - "column": 8, - "line": 3, - }, - }, - "object": Object { - "loc": Object { - "end": Object { - "column": 12, - "line": 3, - }, - "start": Object { - "column": 8, - "line": 3, - }, - }, - "range": Array [ - 81, - 85, - ], - "type": "ThisExpression", - }, - "property": Object { - "loc": Object { - "end": Object { - "column": 18, - "line": 3, - }, - "start": Object { - "column": 13, - "line": 3, - }, - }, - "name": "title", - "range": Array [ - 86, - 91, - ], - "type": "Identifier", - }, - "range": Array [ - 81, - 91, - ], - "type": "MemberExpression", - }, - "loc": Object { - "end": Object { - "column": 33, - "line": 3, - }, - "start": Object { - "column": 8, - "line": 3, - }, - }, - "operator": "=", - "range": Array [ - 81, - 106, - ], - "right": Object { - "computed": false, - "loc": Object { - "end": Object { - "column": 33, - "line": 3, - }, - "start": Object { - "column": 21, - "line": 3, - }, - }, - "object": Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 3, - }, - "start": Object { - "column": 21, - "line": 3, - }, - }, - "name": "config", - "range": Array [ - 94, - 100, - ], - "type": "Identifier", - }, - "property": Object { - "loc": Object { - "end": Object { - "column": 33, - "line": 3, - }, - "start": Object { - "column": 28, - "line": 3, - }, - }, - "name": "title", - "range": Array [ - 101, - 106, - ], - "type": "Identifier", - }, - "range": Array [ - 94, - 106, - ], - "type": "MemberExpression", - }, - "type": "AssignmentExpression", - }, - "loc": Object { - "end": Object { - "column": 34, - "line": 3, - }, - "start": Object { - "column": 8, - "line": 3, - }, - }, - "range": Array [ - 81, - 107, - ], - "type": "ExpressionStatement", - }, - ], + "body": Array [], "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 37, + "line": 2, }, "start": Object { - "column": 55, + "column": 35, "line": 2, }, }, "range": Array [ - 71, - 113, + 47, + 49, ], "type": "BlockStatement", }, @@ -81824,11 +81681,11 @@ Object { "id": null, "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 37, + "line": 2, }, "start": Object { - "column": 15, + "column": 5, "line": 2, }, }, @@ -81841,146 +81698,148 @@ Object { Object { "loc": Object { "end": Object { - "column": 34, + "column": 19, "line": 2, }, "start": Object { - "column": 24, + "column": 15, "line": 2, }, }, - "name": "APP_CONFIG", "range": Array [ - 40, - 50, + 27, + 31, ], - "type": "Identifier", + "raw": "true", + "type": "Literal", + "value": true, }, ], "callee": Object { "loc": Object { "end": Object { - "column": 23, + "column": 14, "line": 2, }, "start": Object { - "column": 17, + "column": 7, "line": 2, }, }, - "name": "Inject", + "name": "special", "range": Array [ - 33, - 39, + 19, + 26, ], "type": "Identifier", }, "loc": Object { "end": Object { - "column": 35, + "column": 20, "line": 2, }, "start": Object { - "column": 17, + "column": 7, "line": 2, }, }, "range": Array [ - 33, - 51, + 19, + 32, ], "type": "CallExpression", }, "loc": Object { "end": Object { - "column": 35, + "column": 20, "line": 2, }, "start": Object { - "column": 16, + "column": 6, "line": 2, }, }, "range": Array [ + 18, 32, - 51, ], "type": "Decorator", }, ], + "elements": Array [ + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "name": "bar", + "range": Array [ + 35, + 38, + ], + "type": "Identifier", + }, + ], "loc": Object { "end": Object { - "column": 53, + "column": 33, "line": 2, }, "start": Object { - "column": 36, + "column": 21, "line": 2, }, }, - "name": "config", "range": Array [ - 52, - 69, + 33, + 45, ], - "type": "Identifier", + "type": "ArrayPattern", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 53, + "column": 33, "line": 2, }, "start": Object { - "column": 42, + "column": 28, "line": 2, }, }, "range": Array [ - 58, - 69, + 40, + 45, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 53, + "column": 33, "line": 2, }, "start": Object { - "column": 44, + "column": 30, "line": 2, }, }, "range": Array [ - 60, - 69, + 42, + 45, ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 53, - "line": 2, - }, - "start": Object { - "column": 44, - "line": 2, - }, - }, - "name": "AppConfig", - "range": Array [ - 60, - 69, - ], - "type": "Identifier", - }, + "type": "TSAnyKeyword", }, }, }, ], "range": Array [ - 31, - 113, + 17, + 49, ], "type": "FunctionExpression", }, @@ -81989,23 +81848,23 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { - "column": 14, + "column": 10, "line": 1, }, }, "range": Array [ - 14, - 115, + 10, + 51, ], "type": "ClassBody", }, "id": Object { "loc": Object { "end": Object { - "column": 13, + "column": 9, "line": 1, }, "start": Object { @@ -82013,17 +81872,17 @@ Object { "line": 1, }, }, - "name": "Service", + "name": "Foo", "range": Array [ 6, - 13, + 9, ], "type": "Identifier", }, "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { "column": 0, @@ -82032,7 +81891,7 @@ Object { }, "range": Array [ 0, - 115, + 51, ], "superClass": null, "type": "ClassDeclaration", @@ -82041,7 +81900,7 @@ Object { "loc": Object { "end": Object { "column": 0, - "line": 6, + "line": 4, }, "start": Object { "column": 0, @@ -82050,7 +81909,7 @@ Object { }, "range": Array [ 0, - 116, + 52, ], "sourceType": "script", "tokens": Array [ @@ -82075,7 +81934,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 13, + "column": 9, "line": 1, }, "start": Object { @@ -82085,25 +81944,25 @@ Object { }, "range": Array [ 6, - 13, + 9, ], "type": "Identifier", - "value": "Service", + "value": "Foo", }, Object { "loc": Object { "end": Object { - "column": 15, + "column": 11, "line": 1, }, "start": Object { - "column": 14, + "column": 10, "line": 1, }, }, "range": Array [ - 14, - 15, + 10, + 11, ], "type": "Punctuator", "value": "{", @@ -82111,35 +81970,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 15, + "column": 5, "line": 2, }, "start": Object { - "column": 4, + "column": 2, "line": 2, }, }, "range": Array [ - 20, - 31, + 14, + 17, ], "type": "Identifier", - "value": "constructor", + "value": "bar", }, Object { "loc": Object { "end": Object { - "column": 16, + "column": 6, "line": 2, }, "start": Object { - "column": 15, + "column": 5, "line": 2, }, }, "range": Array [ - 31, - 32, + 17, + 18, ], "type": "Punctuator", "value": "(", @@ -82147,17 +82006,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 17, + "column": 7, "line": 2, }, "start": Object { - "column": 16, + "column": 6, "line": 2, }, }, "range": Array [ - 32, - 33, + 18, + 19, ], "type": "Punctuator", "value": "@", @@ -82165,35 +82024,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 23, + "column": 14, "line": 2, }, "start": Object { - "column": 17, + "column": 7, "line": 2, }, }, "range": Array [ - 33, - 39, + 19, + 26, ], "type": "Identifier", - "value": "Inject", + "value": "special", }, Object { "loc": Object { "end": Object { - "column": 24, + "column": 15, "line": 2, }, "start": Object { - "column": 23, + "column": 14, "line": 2, }, }, "range": Array [ - 39, - 40, + 26, + 27, ], "type": "Punctuator", "value": "(", @@ -82201,35 +82060,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 34, + "column": 19, "line": 2, }, "start": Object { - "column": 24, + "column": 15, "line": 2, }, }, "range": Array [ - 40, - 50, + 27, + 31, ], - "type": "Identifier", - "value": "APP_CONFIG", + "type": "Boolean", + "value": "true", }, Object { "loc": Object { "end": Object { - "column": 35, + "column": 20, "line": 2, }, "start": Object { - "column": 34, + "column": 19, "line": 2, }, }, "range": Array [ - 50, - 51, + 31, + 32, ], "type": "Punctuator", "value": ")", @@ -82237,251 +82096,2241 @@ Object { Object { "loc": Object { "end": Object { - "column": 42, + "column": 22, "line": 2, }, "start": Object { - "column": 36, + "column": 21, "line": 2, }, }, "range": Array [ - 52, - 58, + 33, + 34, ], - "type": "Identifier", - "value": "config", + "type": "Punctuator", + "value": "[", }, Object { "loc": Object { "end": Object { - "column": 43, + "column": 26, "line": 2, }, "start": Object { - "column": 42, + "column": 23, "line": 2, }, }, "range": Array [ - 58, - 59, + 35, + 38, ], - "type": "Punctuator", - "value": ":", + "type": "Identifier", + "value": "bar", }, Object { "loc": Object { "end": Object { - "column": 53, + "column": 28, "line": 2, }, "start": Object { - "column": 44, + "column": 27, "line": 2, }, }, "range": Array [ - 60, - 69, + 39, + 40, ], - "type": "Identifier", - "value": "AppConfig", + "type": "Punctuator", + "value": "]", }, Object { "loc": Object { "end": Object { - "column": 54, + "column": 29, "line": 2, }, "start": Object { - "column": 53, + "column": 28, "line": 2, }, }, "range": Array [ - 69, - 70, + 40, + 41, ], "type": "Punctuator", - "value": ")", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 56, + "column": 33, "line": 2, }, "start": Object { - "column": 55, + "column": 30, "line": 2, }, }, "range": Array [ - 71, - 72, + 42, + 45, ], - "type": "Punctuator", - "value": "{", + "type": "Identifier", + "value": "any", }, Object { "loc": Object { "end": Object { - "column": 12, - "line": 3, + "column": 34, + "line": 2, }, "start": Object { - "column": 8, - "line": 3, + "column": 33, + "line": 2, }, }, "range": Array [ - 81, - 85, + 45, + 46, ], - "type": "Keyword", - "value": "this", + "type": "Punctuator", + "value": ")", }, Object { "loc": Object { "end": Object { - "column": 13, - "line": 3, + "column": 36, + "line": 2, }, "start": Object { - "column": 12, - "line": 3, + "column": 35, + "line": 2, }, }, "range": Array [ - 85, - 86, + 47, + 48, ], "type": "Punctuator", - "value": ".", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 18, - "line": 3, + "column": 37, + "line": 2, }, "start": Object { - "column": 13, - "line": 3, + "column": 36, + "line": 2, }, }, "range": Array [ - 86, - 91, + 48, + 49, ], - "type": "Identifier", - "value": "title", + "type": "Punctuator", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 20, + "column": 1, "line": 3, }, "start": Object { - "column": 19, + "column": 0, "line": 3, }, }, "range": Array [ - 92, - 93, + 50, + 51, ], "type": "Punctuator", - "value": "=", + "value": "}", }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-constructor.src 1`] = ` +Object { + "body": Array [ Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 3, - }, + "body": Object { + "body": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "name": "constructor", + "range": Array [ + 20, + 31, + ], + "type": "Identifier", + }, + "kind": "constructor", + "loc": Object { + "end": Object { + "column": 5, + "line": 4, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 20, + 113, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [ + Object { + "expression": Object { + "left": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 81, + 85, + ], + "type": "ThisExpression", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 13, + "line": 3, + }, + }, + "name": "title", + "range": Array [ + 86, + 91, + ], + "type": "Identifier", + }, + "range": Array [ + 81, + 91, + ], + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 33, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "operator": "=", + "range": Array [ + 81, + 106, + ], + "right": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 33, + "line": 3, + }, + "start": Object { + "column": 21, + "line": 3, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 3, + }, + "start": Object { + "column": 21, + "line": 3, + }, + }, + "name": "config", + "range": Array [ + 94, + 100, + ], + "type": "Identifier", + }, + "property": Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 3, + }, + "start": Object { + "column": 28, + "line": 3, + }, + }, + "name": "title", + "range": Array [ + 101, + 106, + ], + "type": "Identifier", + }, + "range": Array [ + 94, + 106, + ], + "type": "MemberExpression", + }, + "type": "AssignmentExpression", + }, + "loc": Object { + "end": Object { + "column": 34, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 81, + 107, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 5, + "line": 4, + }, + "start": Object { + "column": 55, + "line": 2, + }, + }, + "range": Array [ + 71, + 113, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 5, + "line": 4, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "params": Array [ + Object { + "decorators": Array [ + Object { + "expression": Object { + "arguments": Array [ + Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 2, + }, + "start": Object { + "column": 24, + "line": 2, + }, + }, + "name": "APP_CONFIG", + "range": Array [ + 40, + 50, + ], + "type": "Identifier", + }, + ], + "callee": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "name": "Inject", + "range": Array [ + 33, + 39, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 35, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 33, + 51, + ], + "type": "CallExpression", + }, + "loc": Object { + "end": Object { + "column": 35, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 32, + 51, + ], + "type": "Decorator", + }, + ], + "loc": Object { + "end": Object { + "column": 53, + "line": 2, + }, + "start": Object { + "column": 36, + "line": 2, + }, + }, + "name": "config", + "range": Array [ + 52, + 69, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 53, + "line": 2, + }, + "start": Object { + "column": 42, + "line": 2, + }, + }, + "range": Array [ + 58, + 69, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 53, + "line": 2, + }, + "start": Object { + "column": 44, + "line": 2, + }, + }, + "range": Array [ + 60, + 69, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 53, + "line": 2, + }, + "start": Object { + "column": 44, + "line": 2, + }, + }, + "name": "AppConfig", + "range": Array [ + 60, + 69, + ], + "type": "Identifier", + }, + }, + }, + }, + ], + "range": Array [ + 31, + 113, + ], + "type": "FunctionExpression", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 115, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "Service", + "range": Array [ + 6, + 13, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 115, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 6, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 116, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 13, + ], + "type": "Identifier", + "value": "Service", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 20, + 31, + ], + "type": "Identifier", + "value": "constructor", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 31, + 32, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 32, + 33, + ], + "type": "Punctuator", + "value": "@", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 33, + 39, + ], + "type": "Identifier", + "value": "Inject", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "range": Array [ + 39, + 40, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 2, + }, + "start": Object { + "column": 24, + "line": 2, + }, + }, + "range": Array [ + 40, + 50, + ], + "type": "Identifier", + "value": "APP_CONFIG", + }, + Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 2, + }, + "start": Object { + "column": 34, + "line": 2, + }, + }, + "range": Array [ + 50, + 51, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 2, + }, + "start": Object { + "column": 36, + "line": 2, + }, + }, + "range": Array [ + 52, + 58, + ], + "type": "Identifier", + "value": "config", + }, + Object { + "loc": Object { + "end": Object { + "column": 43, + "line": 2, + }, + "start": Object { + "column": 42, + "line": 2, + }, + }, + "range": Array [ + 58, + 59, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 53, + "line": 2, + }, + "start": Object { + "column": 44, + "line": 2, + }, + }, + "range": Array [ + 60, + 69, + ], + "type": "Identifier", + "value": "AppConfig", + }, + Object { + "loc": Object { + "end": Object { + "column": 54, + "line": 2, + }, + "start": Object { + "column": 53, + "line": 2, + }, + }, + "range": Array [ + 69, + 70, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 56, + "line": 2, + }, + "start": Object { + "column": 55, + "line": 2, + }, + }, + "range": Array [ + 71, + 72, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 81, + 85, + ], + "type": "Keyword", + "value": "this", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 12, + "line": 3, + }, + }, + "range": Array [ + 85, + 86, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 13, + "line": 3, + }, + }, + "range": Array [ + 86, + 91, + ], + "type": "Identifier", + "value": "title", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 3, + }, + "start": Object { + "column": 19, + "line": 3, + }, + }, + "range": Array [ + 92, + 93, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 3, + }, + "start": Object { + "column": 21, + "line": 3, + }, + }, + "range": Array [ + 94, + 100, + ], + "type": "Identifier", + "value": "config", + }, + Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 3, + }, + "start": Object { + "column": 27, + "line": 3, + }, + }, + "range": Array [ + 100, + 101, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 3, + }, + "start": Object { + "column": 28, + "line": 3, + }, + }, + "range": Array [ + 101, + 106, + ], + "type": "Identifier", + "value": "title", + }, + Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 3, + }, + "start": Object { + "column": 33, + "line": 3, + }, + }, + "range": Array [ + 106, + 107, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 4, + }, + "start": Object { + "column": 4, + "line": 4, + }, + }, + "range": Array [ + 112, + 113, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 5, + }, + }, + "range": Array [ + 114, + 115, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-decorator-instance-member.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "name": "bar", + "range": Array [ + 16, + 19, + ], + "type": "Identifier", + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 16, + 50, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 36, + "line": 2, + }, + }, + "range": Array [ + 48, + 50, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "params": Array [ + Object { + "decorators": Array [ + Object { + "expression": Object { + "arguments": Array [ + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 29, + 33, + ], + "raw": "true", + "type": "Literal", + "value": true, + }, + ], + "callee": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "name": "special", + "range": Array [ + 21, + 28, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 22, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 21, + 34, + ], + "type": "CallExpression", + }, + "loc": Object { + "end": Object { + "column": 22, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 20, + 34, + ], + "type": "Decorator", + }, + ], + "loc": Object { + "end": Object { + "column": 34, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "name": "baz", + "range": Array [ + 35, + 46, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 2, + }, + "start": Object { + "column": 26, + "line": 2, + }, + }, + "range": Array [ + 38, + 46, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 2, + }, + "start": Object { + "column": 28, + "line": 2, + }, + }, + "range": Array [ + 40, + 46, + ], + "type": "TSNumberKeyword", + }, + }, + }, + ], + "range": Array [ + 19, + 50, + ], + "type": "FunctionExpression", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 52, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "Foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 52, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 53, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "Foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 16, + 19, + ], + "type": "Identifier", + "value": "bar", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "range": Array [ + 19, + 20, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Punctuator", + "value": "@", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 21, + 28, + ], + "type": "Identifier", + "value": "special", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 28, + 29, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 29, + 33, + ], + "type": "Boolean", + "value": "true", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 2, + }, + "start": Object { + "column": 21, + "line": 2, + }, + }, + "range": Array [ + 33, + 34, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "range": Array [ + 35, + 38, + ], + "type": "Identifier", + "value": "baz", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 26, + "line": 2, + }, + }, + "range": Array [ + 38, + 39, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 2, + }, + "start": Object { + "column": 28, + "line": 2, + }, + }, + "range": Array [ + 40, + 46, + ], + "type": "Identifier", + "value": "number", + }, + Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 2, + }, + "start": Object { + "column": 34, + "line": 2, + }, + }, + "range": Array [ + 46, + 47, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 37, + "line": 2, + }, + "start": Object { + "column": 36, + "line": 2, + }, + }, + "range": Array [ + 48, + 49, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 2, + }, + "start": Object { + "column": 37, + "line": 2, + }, + }, + "range": Array [ + 49, + 50, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 51, + 52, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-decorator-static-member.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "name": "bar", + "range": Array [ + 29, + 32, + ], + "type": "Identifier", + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 45, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 22, + 63, + ], + "static": true, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 45, + "line": 2, + }, + "start": Object { + "column": 43, + "line": 2, + }, + }, + "range": Array [ + 61, + 63, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 45, + "line": 2, + }, + "start": Object { + "column": 14, + "line": 2, + }, + }, + "params": Array [ + Object { + "decorators": Array [ + Object { + "expression": Object { + "arguments": Array [ + Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 2, + }, + "start": Object { + "column": 24, + "line": 2, + }, + }, + "range": Array [ + 42, + 46, + ], + "raw": "true", + "type": "Literal", + "value": true, + }, + ], + "callee": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "name": "special", + "range": Array [ + 34, + 41, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 29, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 34, + 47, + ], + "type": "CallExpression", + }, + "loc": Object { + "end": Object { + "column": 29, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 33, + 47, + ], + "type": "Decorator", + }, + ], + "loc": Object { + "end": Object { + "column": 41, + "line": 2, + }, + "start": Object { + "column": 30, + "line": 2, + }, + }, + "name": "baz", + "range": Array [ + 48, + 59, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 41, + "line": 2, + }, + "start": Object { + "column": 33, + "line": 2, + }, + }, + "range": Array [ + 51, + 59, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 41, + "line": 2, + }, + "start": Object { + "column": 35, + "line": 2, + }, + }, + "range": Array [ + 53, + 59, + ], + "type": "TSNumberKeyword", + }, + }, + }, + ], + "range": Array [ + 32, + 63, + ], + "type": "FunctionExpression", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 65, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "StaticFoo", + "range": Array [ + 6, + 15, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 65, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 66, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, "start": Object { - "column": 21, - "line": 3, + "column": 6, + "line": 1, }, }, "range": Array [ - 94, - 100, + 6, + 15, ], "type": "Identifier", - "value": "config", + "value": "StaticFoo", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 22, + 28, + ], + "type": "Keyword", + "value": "static", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "range": Array [ + 29, + 32, + ], + "type": "Identifier", + "value": "bar", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 14, + "line": 2, + }, + }, + "range": Array [ + 32, + 33, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 33, + 34, + ], + "type": "Punctuator", + "value": "@", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 34, + 41, + ], + "type": "Identifier", + "value": "special", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "range": Array [ + 41, + 42, + ], + "type": "Punctuator", + "value": "(", }, Object { "loc": Object { "end": Object { "column": 28, - "line": 3, + "line": 2, }, "start": Object { - "column": 27, - "line": 3, + "column": 24, + "line": 2, }, }, "range": Array [ - 100, - 101, + 42, + 46, + ], + "type": "Boolean", + "value": "true", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 2, + }, + "start": Object { + "column": 28, + "line": 2, + }, + }, + "range": Array [ + 46, + 47, ], "type": "Punctuator", - "value": ".", + "value": ")", }, Object { "loc": Object { "end": Object { "column": 33, - "line": 3, + "line": 2, }, "start": Object { - "column": 28, - "line": 3, + "column": 30, + "line": 2, }, }, "range": Array [ - 101, - 106, + 48, + 51, ], "type": "Identifier", - "value": "title", + "value": "baz", }, Object { "loc": Object { "end": Object { "column": 34, - "line": 3, + "line": 2, }, "start": Object { "column": 33, - "line": 3, + "line": 2, }, }, "range": Array [ - 106, - 107, + 51, + 52, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 41, + "line": 2, + }, + "start": Object { + "column": 35, + "line": 2, + }, + }, + "range": Array [ + 53, + 59, + ], + "type": "Identifier", + "value": "number", + }, + Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 2, + }, + "start": Object { + "column": 41, + "line": 2, + }, + }, + "range": Array [ + 59, + 60, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 44, + "line": 2, + }, + "start": Object { + "column": 43, + "line": 2, + }, + }, + "range": Array [ + 61, + 62, ], "type": "Punctuator", - "value": ";", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 45, + "line": 2, }, "start": Object { - "column": 4, - "line": 4, + "column": 44, + "line": 2, }, }, "range": Array [ - 112, - 113, + 62, + 63, ], "type": "Punctuator", "value": "}", @@ -82490,16 +84339,16 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { "column": 0, - "line": 5, + "line": 3, }, }, "range": Array [ - 114, - 115, + 64, + 65, ], "type": "Punctuator", "value": "}", @@ -82509,7 +84358,7 @@ Object { } `; -exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-decorator-instance-member.src 1`] = ` +exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-instance-member.src 1`] = ` Object { "body": Array [ Object { @@ -82520,7 +84369,7 @@ Object { "key": Object { "loc": Object { "end": Object { - "column": 7, + "column": 9, "line": 2, }, "start": Object { @@ -82528,18 +84377,18 @@ Object { "line": 2, }, }, - "name": "bar", + "name": "greet", "range": Array [ - 16, - 19, + 20, + 25, ], "type": "Identifier", }, "kind": "method", "loc": Object { "end": Object { - "column": 38, - "line": 2, + "column": 5, + "line": 4, }, "start": Object { "column": 4, @@ -82547,28 +84396,138 @@ Object { }, }, "range": Array [ - 16, - 50, + 20, + 95, ], "static": false, "type": "MethodDefinition", "value": Object { "async": false, "body": Object { - "body": Array [], + "body": Array [ + Object { + "argument": Object { + "left": Object { + "left": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "range": Array [ + 67, + 75, + ], + "raw": "\\"Hello \\"", + "type": "Literal", + "value": "Hello ", + }, + "loc": Object { + "end": Object { + "column": 30, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "operator": "+", + "range": Array [ + 67, + 82, + ], + "right": Object { + "loc": Object { + "end": Object { + "column": 30, + "line": 3, + }, + "start": Object { + "column": 26, + "line": 3, + }, + }, + "name": "name", + "range": Array [ + 78, + 82, + ], + "type": "Identifier", + }, + "type": "BinaryExpression", + }, + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "operator": "+", + "range": Array [ + 67, + 88, + ], + "right": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 33, + "line": 3, + }, + }, + "range": Array [ + 85, + 88, + ], + "raw": "\\"!\\"", + "type": "Literal", + "value": "!", + }, + "type": "BinaryExpression", + }, + "loc": Object { + "end": Object { + "column": 37, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 60, + 89, + ], + "type": "ReturnStatement", + }, + ], "loc": Object { "end": Object { - "column": 38, - "line": 2, + "column": 5, + "line": 4, }, "start": Object { - "column": 36, + "column": 34, "line": 2, }, }, "range": Array [ - 48, 50, + 95, ], "type": "BlockStatement", }, @@ -82577,11 +84536,11 @@ Object { "id": null, "loc": Object { "end": Object { - "column": 38, - "line": 2, + "column": 5, + "line": 4, }, "start": Object { - "column": 7, + "column": 9, "line": 2, }, }, @@ -82590,133 +84549,95 @@ Object { "decorators": Array [ Object { "expression": Object { - "arguments": Array [ - Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 2, - }, - "start": Object { - "column": 17, - "line": 2, - }, - }, - "range": Array [ - 29, - 33, - ], - "raw": "true", - "type": "Literal", - "value": true, - }, - ], - "callee": Object { - "loc": Object { - "end": Object { - "column": 16, - "line": 2, - }, - "start": Object { - "column": 9, - "line": 2, - }, - }, - "name": "special", - "range": Array [ - 21, - 28, - ], - "type": "Identifier", - }, "loc": Object { "end": Object { - "column": 22, + "column": 19, "line": 2, }, "start": Object { - "column": 9, + "column": 11, "line": 2, }, }, + "name": "required", "range": Array [ - 21, - 34, + 27, + 35, ], - "type": "CallExpression", + "type": "Identifier", }, "loc": Object { "end": Object { - "column": 22, + "column": 19, "line": 2, }, "start": Object { - "column": 8, + "column": 10, "line": 2, }, }, "range": Array [ - 20, - 34, + 26, + 35, ], "type": "Decorator", }, ], "loc": Object { "end": Object { - "column": 34, + "column": 32, "line": 2, }, "start": Object { - "column": 23, + "column": 20, "line": 2, }, }, - "name": "baz", + "name": "name", "range": Array [ - 35, - 46, + 36, + 48, ], "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 34, + "column": 32, "line": 2, }, "start": Object { - "column": 26, + "column": 24, "line": 2, }, }, "range": Array [ - 38, - 46, + 40, + 48, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 34, + "column": 32, "line": 2, }, "start": Object { - "column": 28, + "column": 26, "line": 2, }, }, "range": Array [ - 40, - 46, + 42, + 48, ], - "type": "TSNumberKeyword", + "type": "TSStringKeyword", }, }, }, ], "range": Array [ - 19, - 50, + 25, + 95, ], "type": "FunctionExpression", }, @@ -82725,23 +84646,23 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 3, + "line": 5, }, "start": Object { - "column": 10, + "column": 14, "line": 1, }, }, "range": Array [ - 10, - 52, + 14, + 97, ], "type": "ClassBody", }, "id": Object { "loc": Object { "end": Object { - "column": 9, + "column": 13, "line": 1, }, "start": Object { @@ -82749,17 +84670,17 @@ Object { "line": 1, }, }, - "name": "Foo", + "name": "Greeter", "range": Array [ 6, - 9, + 13, ], "type": "Identifier", }, "loc": Object { "end": Object { "column": 1, - "line": 3, + "line": 5, }, "start": Object { "column": 0, @@ -82768,7 +84689,7 @@ Object { }, "range": Array [ 0, - 52, + 97, ], "superClass": null, "type": "ClassDeclaration", @@ -82777,7 +84698,7 @@ Object { "loc": Object { "end": Object { "column": 0, - "line": 4, + "line": 6, }, "start": Object { "column": 0, @@ -82786,7 +84707,7 @@ Object { }, "range": Array [ 0, - 53, + 98, ], "sourceType": "script", "tokens": Array [ @@ -82811,7 +84732,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 9, + "column": 13, "line": 1, }, "start": Object { @@ -82821,25 +84742,25 @@ Object { }, "range": Array [ 6, - 9, + 13, ], "type": "Identifier", - "value": "Foo", + "value": "Greeter", }, Object { "loc": Object { "end": Object { - "column": 11, + "column": 15, "line": 1, }, "start": Object { - "column": 10, + "column": 14, "line": 1, }, }, "range": Array [ - 10, - 11, + 14, + 15, ], "type": "Punctuator", "value": "{", @@ -82847,7 +84768,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 7, + "column": 9, "line": 2, }, "start": Object { @@ -82856,26 +84777,26 @@ Object { }, }, "range": Array [ - 16, - 19, + 20, + 25, ], "type": "Identifier", - "value": "bar", + "value": "greet", }, Object { "loc": Object { "end": Object { - "column": 8, + "column": 10, "line": 2, }, "start": Object { - "column": 7, + "column": 9, "line": 2, }, }, "range": Array [ - 19, - 20, + 25, + 26, ], "type": "Punctuator", "value": "(", @@ -82883,17 +84804,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 9, + "column": 11, "line": 2, }, "start": Object { - "column": 8, + "column": 10, "line": 2, }, }, "range": Array [ - 20, - 21, + 26, + 27, ], "type": "Punctuator", "value": "@", @@ -82901,71 +84822,89 @@ Object { Object { "loc": Object { "end": Object { - "column": 16, + "column": 19, "line": 2, }, "start": Object { - "column": 9, + "column": 11, "line": 2, }, }, "range": Array [ - 21, - 28, + 27, + 35, ], "type": "Identifier", - "value": "special", + "value": "required", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 24, "line": 2, }, "start": Object { - "column": 16, + "column": 20, "line": 2, }, }, "range": Array [ - 28, - 29, + 36, + 40, + ], + "type": "Identifier", + "value": "name", + }, + Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 2, + }, + "start": Object { + "column": 24, + "line": 2, + }, + }, + "range": Array [ + 40, + 41, ], "type": "Punctuator", - "value": "(", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 21, + "column": 32, "line": 2, }, "start": Object { - "column": 17, + "column": 26, "line": 2, }, }, "range": Array [ - 29, - 33, + 42, + 48, ], - "type": "Boolean", - "value": "true", + "type": "Identifier", + "value": "string", }, Object { "loc": Object { "end": Object { - "column": 22, + "column": 33, "line": 2, }, "start": Object { - "column": 21, + "column": 32, "line": 2, }, }, "range": Array [ - 33, - 34, + 48, + 49, ], "type": "Punctuator", "value": ")", @@ -82973,107 +84912,161 @@ Object { Object { "loc": Object { "end": Object { - "column": 26, + "column": 35, "line": 2, }, "start": Object { - "column": 23, + "column": 34, "line": 2, }, }, "range": Array [ - 35, - 38, + 50, + 51, ], - "type": "Identifier", - "value": "baz", + "type": "Punctuator", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 27, - "line": 2, + "column": 14, + "line": 3, }, "start": Object { - "column": 26, - "line": 2, + "column": 8, + "line": 3, }, }, "range": Array [ - 38, - 39, + 60, + 66, + ], + "type": "Keyword", + "value": "return", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "range": Array [ + 67, + 75, + ], + "type": "String", + "value": "\\"Hello \\"", + }, + Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 3, + }, + "start": Object { + "column": 24, + "line": 3, + }, + }, + "range": Array [ + 76, + 77, ], "type": "Punctuator", - "value": ":", + "value": "+", }, Object { "loc": Object { "end": Object { - "column": 34, - "line": 2, + "column": 30, + "line": 3, }, "start": Object { - "column": 28, - "line": 2, + "column": 26, + "line": 3, }, }, "range": Array [ - 40, - 46, + 78, + 82, ], "type": "Identifier", - "value": "number", + "value": "name", }, Object { "loc": Object { "end": Object { - "column": 35, - "line": 2, + "column": 32, + "line": 3, }, "start": Object { - "column": 34, - "line": 2, + "column": 31, + "line": 3, }, }, "range": Array [ - 46, - 47, + 83, + 84, ], "type": "Punctuator", - "value": ")", + "value": "+", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 33, + "line": 3, + }, + }, + "range": Array [ + 85, + 88, + ], + "type": "String", + "value": "\\"!\\"", }, Object { "loc": Object { "end": Object { "column": 37, - "line": 2, + "line": 3, }, "start": Object { "column": 36, - "line": 2, + "line": 3, }, }, "range": Array [ - 48, - 49, + 88, + 89, ], "type": "Punctuator", - "value": "{", + "value": ";", }, Object { "loc": Object { "end": Object { - "column": 38, - "line": 2, + "column": 5, + "line": 4, }, "start": Object { - "column": 37, - "line": 2, + "column": 4, + "line": 4, }, }, "range": Array [ - 49, - 50, + 94, + 95, ], "type": "Punctuator", "value": "}", @@ -83082,16 +85075,16 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 3, + "line": 5, }, "start": Object { "column": 0, - "line": 3, + "line": 5, }, }, "range": Array [ - 51, - 52, + 96, + 97, ], "type": "Punctuator", "value": "}", @@ -83101,7 +85094,7 @@ Object { } `; -exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-decorator-static-member.src 1`] = ` +exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-static-member.src 1`] = ` Object { "body": Array [ Object { @@ -83112,7 +85105,7 @@ Object { "key": Object { "loc": Object { "end": Object { - "column": 14, + "column": 16, "line": 2, }, "start": Object { @@ -83120,18 +85113,18 @@ Object { "line": 2, }, }, - "name": "bar", + "name": "greet", "range": Array [ - 29, - 32, + 33, + 38, ], "type": "Identifier", }, "kind": "method", "loc": Object { "end": Object { - "column": 45, - "line": 2, + "column": 5, + "line": 4, }, "start": Object { "column": 4, @@ -83139,28 +85132,138 @@ Object { }, }, "range": Array [ - 22, - 63, + 26, + 108, ], "static": true, "type": "MethodDefinition", "value": Object { "async": false, "body": Object { - "body": Array [], + "body": Array [ + Object { + "argument": Object { + "left": Object { + "left": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "range": Array [ + 80, + 88, + ], + "raw": "\\"Hello \\"", + "type": "Literal", + "value": "Hello ", + }, + "loc": Object { + "end": Object { + "column": 30, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "operator": "+", + "range": Array [ + 80, + 95, + ], + "right": Object { + "loc": Object { + "end": Object { + "column": 30, + "line": 3, + }, + "start": Object { + "column": 26, + "line": 3, + }, + }, + "name": "name", + "range": Array [ + 91, + 95, + ], + "type": "Identifier", + }, + "type": "BinaryExpression", + }, + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "operator": "+", + "range": Array [ + 80, + 101, + ], + "right": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 33, + "line": 3, + }, + }, + "range": Array [ + 98, + 101, + ], + "raw": "\\"!\\"", + "type": "Literal", + "value": "!", + }, + "type": "BinaryExpression", + }, + "loc": Object { + "end": Object { + "column": 37, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 73, + 102, + ], + "type": "ReturnStatement", + }, + ], "loc": Object { "end": Object { - "column": 45, - "line": 2, + "column": 5, + "line": 4, }, "start": Object { - "column": 43, + "column": 41, "line": 2, }, }, "range": Array [ - 61, 63, + 108, ], "type": "BlockStatement", }, @@ -83169,11 +85272,11 @@ Object { "id": null, "loc": Object { "end": Object { - "column": 45, - "line": 2, + "column": 5, + "line": 4, }, "start": Object { - "column": 14, + "column": 16, "line": 2, }, }, @@ -83182,133 +85285,95 @@ Object { "decorators": Array [ Object { "expression": Object { - "arguments": Array [ - Object { - "loc": Object { - "end": Object { - "column": 28, - "line": 2, - }, - "start": Object { - "column": 24, - "line": 2, - }, - }, - "range": Array [ - 42, - 46, - ], - "raw": "true", - "type": "Literal", - "value": true, - }, - ], - "callee": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 2, - }, - "start": Object { - "column": 16, - "line": 2, - }, - }, - "name": "special", - "range": Array [ - 34, - 41, - ], - "type": "Identifier", - }, "loc": Object { "end": Object { - "column": 29, + "column": 26, "line": 2, }, "start": Object { - "column": 16, + "column": 18, "line": 2, }, }, + "name": "required", "range": Array [ - 34, - 47, + 40, + 48, ], - "type": "CallExpression", + "type": "Identifier", }, "loc": Object { "end": Object { - "column": 29, + "column": 26, "line": 2, }, "start": Object { - "column": 15, + "column": 17, "line": 2, }, }, "range": Array [ - 33, - 47, + 39, + 48, ], "type": "Decorator", }, ], "loc": Object { "end": Object { - "column": 41, + "column": 39, "line": 2, }, "start": Object { - "column": 30, + "column": 27, "line": 2, }, }, - "name": "baz", + "name": "name", "range": Array [ - 48, - 59, + 49, + 61, ], "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 41, + "column": 39, "line": 2, }, "start": Object { - "column": 33, + "column": 31, "line": 2, }, }, "range": Array [ - 51, - 59, + 53, + 61, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 41, + "column": 39, "line": 2, }, "start": Object { - "column": 35, + "column": 33, "line": 2, }, }, "range": Array [ - 53, - 59, + 55, + 61, ], - "type": "TSNumberKeyword", + "type": "TSStringKeyword", }, }, }, ], "range": Array [ - 32, - 63, + 38, + 108, ], "type": "FunctionExpression", }, @@ -83317,23 +85382,23 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 3, + "line": 5, }, "start": Object { - "column": 16, + "column": 20, "line": 1, }, }, "range": Array [ - 16, - 65, + 20, + 110, ], "type": "ClassBody", }, "id": Object { "loc": Object { "end": Object { - "column": 15, + "column": 19, "line": 1, }, "start": Object { @@ -83341,17 +85406,17 @@ Object { "line": 1, }, }, - "name": "StaticFoo", + "name": "StaticGreeter", "range": Array [ 6, - 15, + 19, ], "type": "Identifier", }, "loc": Object { "end": Object { "column": 1, - "line": 3, + "line": 5, }, "start": Object { "column": 0, @@ -83360,7 +85425,7 @@ Object { }, "range": Array [ 0, - 65, + 110, ], "superClass": null, "type": "ClassDeclaration", @@ -83369,7 +85434,7 @@ Object { "loc": Object { "end": Object { "column": 0, - "line": 4, + "line": 6, }, "start": Object { "column": 0, @@ -83378,7 +85443,7 @@ Object { }, "range": Array [ 0, - 66, + 111, ], "sourceType": "script", "tokens": Array [ @@ -83403,7 +85468,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 15, + "column": 19, "line": 1, }, "start": Object { @@ -83413,25 +85478,25 @@ Object { }, "range": Array [ 6, - 15, + 19, ], "type": "Identifier", - "value": "StaticFoo", + "value": "StaticGreeter", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 21, "line": 1, }, "start": Object { - "column": 16, + "column": 20, "line": 1, }, }, "range": Array [ - 16, - 17, + 20, + 21, ], "type": "Punctuator", "value": "{", @@ -83448,8 +85513,8 @@ Object { }, }, "range": Array [ - 22, - 28, + 26, + 32, ], "type": "Keyword", "value": "static", @@ -83457,7 +85522,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 14, + "column": 16, "line": 2, }, "start": Object { @@ -83466,26 +85531,26 @@ Object { }, }, "range": Array [ - 29, - 32, + 33, + 38, ], "type": "Identifier", - "value": "bar", + "value": "greet", }, Object { "loc": Object { "end": Object { - "column": 15, + "column": 17, "line": 2, }, "start": Object { - "column": 14, + "column": 16, "line": 2, }, }, "range": Array [ - 32, - 33, + 38, + 39, ], "type": "Punctuator", "value": "(", @@ -83493,17 +85558,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 16, + "column": 18, "line": 2, }, "start": Object { - "column": 15, + "column": 17, "line": 2, }, }, "range": Array [ - 33, - 34, + 39, + 40, ], "type": "Punctuator", "value": "@", @@ -83511,71 +85576,89 @@ Object { Object { "loc": Object { "end": Object { - "column": 23, + "column": 26, "line": 2, }, "start": Object { - "column": 16, + "column": 18, "line": 2, }, }, "range": Array [ - 34, - 41, + 40, + 48, ], "type": "Identifier", - "value": "special", + "value": "required", }, Object { "loc": Object { "end": Object { - "column": 24, + "column": 31, "line": 2, }, "start": Object { - "column": 23, + "column": 27, "line": 2, }, }, "range": Array [ - 41, - 42, + 49, + 53, + ], + "type": "Identifier", + "value": "name", + }, + Object { + "loc": Object { + "end": Object { + "column": 32, + "line": 2, + }, + "start": Object { + "column": 31, + "line": 2, + }, + }, + "range": Array [ + 53, + 54, ], "type": "Punctuator", - "value": "(", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 28, + "column": 39, "line": 2, }, "start": Object { - "column": 24, + "column": 33, "line": 2, }, }, "range": Array [ - 42, - 46, + 55, + 61, ], - "type": "Boolean", - "value": "true", + "type": "Identifier", + "value": "string", }, Object { "loc": Object { "end": Object { - "column": 29, + "column": 40, "line": 2, }, "start": Object { - "column": 28, + "column": 39, "line": 2, }, }, "range": Array [ - 46, - 47, + 61, + 62, ], "type": "Punctuator", "value": ")", @@ -83583,107 +85666,161 @@ Object { Object { "loc": Object { "end": Object { - "column": 33, + "column": 42, "line": 2, }, "start": Object { - "column": 30, + "column": 41, "line": 2, }, }, "range": Array [ - 48, - 51, + 63, + 64, ], - "type": "Identifier", - "value": "baz", + "type": "Punctuator", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 34, - "line": 2, + "column": 14, + "line": 3, }, "start": Object { - "column": 33, - "line": 2, + "column": 8, + "line": 3, }, }, "range": Array [ - 51, - 52, + 73, + 79, + ], + "type": "Keyword", + "value": "return", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "range": Array [ + 80, + 88, + ], + "type": "String", + "value": "\\"Hello \\"", + }, + Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 3, + }, + "start": Object { + "column": 24, + "line": 3, + }, + }, + "range": Array [ + 89, + 90, ], "type": "Punctuator", - "value": ":", + "value": "+", }, Object { "loc": Object { "end": Object { - "column": 41, - "line": 2, + "column": 30, + "line": 3, }, "start": Object { - "column": 35, - "line": 2, + "column": 26, + "line": 3, }, }, "range": Array [ - 53, - 59, + 91, + 95, ], "type": "Identifier", - "value": "number", + "value": "name", }, Object { "loc": Object { "end": Object { - "column": 42, - "line": 2, + "column": 32, + "line": 3, }, "start": Object { - "column": 41, - "line": 2, + "column": 31, + "line": 3, }, }, "range": Array [ - 59, - 60, + 96, + 97, ], "type": "Punctuator", - "value": ")", + "value": "+", }, Object { "loc": Object { "end": Object { - "column": 44, - "line": 2, + "column": 36, + "line": 3, }, "start": Object { - "column": 43, - "line": 2, + "column": 33, + "line": 3, }, }, "range": Array [ - 61, - 62, + 98, + 101, + ], + "type": "String", + "value": "\\"!\\"", + }, + Object { + "loc": Object { + "end": Object { + "column": 37, + "line": 3, + }, + "start": Object { + "column": 36, + "line": 3, + }, + }, + "range": Array [ + 101, + 102, ], "type": "Punctuator", - "value": "{", + "value": ";", }, Object { "loc": Object { "end": Object { - "column": 45, - "line": 2, + "column": 5, + "line": 4, }, "start": Object { - "column": 44, - "line": 2, + "column": 4, + "line": 4, }, }, "range": Array [ - 62, - 63, + 107, + 108, ], "type": "Punctuator", "value": "}", @@ -83692,16 +85829,16 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 3, + "line": 5, }, "start": Object { "column": 0, - "line": 3, + "line": 5, }, }, "range": Array [ - 64, - 65, + 109, + 110, ], "type": "Punctuator", "value": "}", @@ -83711,7 +85848,7 @@ Object { } `; -exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-instance-member.src 1`] = ` +exports[`typescript fixtures/decorators/parameter-decorators/parameter-object-pattern-decorator.src 1`] = ` Object { "body": Array [ Object { @@ -83722,165 +85859,55 @@ Object { "key": Object { "loc": Object { "end": Object { - "column": 9, + "column": 5, "line": 2, }, "start": Object { - "column": 4, + "column": 2, "line": 2, }, }, - "name": "greet", + "name": "bar", "range": Array [ - 20, - 25, + 14, + 17, ], "type": "Identifier", }, "kind": "method", "loc": Object { - "end": Object { - "column": 5, - "line": 4, + "end": Object { + "column": 37, + "line": 2, }, "start": Object { - "column": 4, + "column": 2, "line": 2, }, }, "range": Array [ - 20, - 95, + 14, + 49, ], "static": false, "type": "MethodDefinition", "value": Object { "async": false, "body": Object { - "body": Array [ - Object { - "argument": Object { - "left": Object { - "left": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 3, - }, - "start": Object { - "column": 15, - "line": 3, - }, - }, - "range": Array [ - 67, - 75, - ], - "raw": "\\"Hello \\"", - "type": "Literal", - "value": "Hello ", - }, - "loc": Object { - "end": Object { - "column": 30, - "line": 3, - }, - "start": Object { - "column": 15, - "line": 3, - }, - }, - "operator": "+", - "range": Array [ - 67, - 82, - ], - "right": Object { - "loc": Object { - "end": Object { - "column": 30, - "line": 3, - }, - "start": Object { - "column": 26, - "line": 3, - }, - }, - "name": "name", - "range": Array [ - 78, - 82, - ], - "type": "Identifier", - }, - "type": "BinaryExpression", - }, - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 15, - "line": 3, - }, - }, - "operator": "+", - "range": Array [ - 67, - 88, - ], - "right": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 33, - "line": 3, - }, - }, - "range": Array [ - 85, - 88, - ], - "raw": "\\"!\\"", - "type": "Literal", - "value": "!", - }, - "type": "BinaryExpression", - }, - "loc": Object { - "end": Object { - "column": 37, - "line": 3, - }, - "start": Object { - "column": 8, - "line": 3, - }, - }, - "range": Array [ - 60, - 89, - ], - "type": "ReturnStatement", - }, - ], + "body": Array [], "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 37, + "line": 2, }, "start": Object { - "column": 34, + "column": 35, "line": 2, }, }, "range": Array [ - 50, - 95, + 47, + 49, ], "type": "BlockStatement", }, @@ -83889,11 +85916,11 @@ Object { "id": null, "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 37, + "line": 2, }, "start": Object { - "column": 9, + "column": 5, "line": 2, }, }, @@ -83902,95 +85929,191 @@ Object { "decorators": Array [ Object { "expression": Object { + "arguments": Array [ + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 27, + 31, + ], + "raw": "true", + "type": "Literal", + "value": true, + }, + ], + "callee": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "name": "special", + "range": Array [ + 19, + 26, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { - "column": 19, + "column": 20, "line": 2, }, "start": Object { - "column": 11, + "column": 7, "line": 2, }, }, - "name": "required", "range": Array [ - 27, - 35, + 19, + 32, ], - "type": "Identifier", + "type": "CallExpression", }, "loc": Object { "end": Object { - "column": 19, + "column": 20, "line": 2, }, "start": Object { - "column": 10, + "column": 6, "line": 2, }, }, "range": Array [ - 26, - 35, + 18, + 32, ], "type": "Decorator", }, ], "loc": Object { "end": Object { - "column": 32, + "column": 33, "line": 2, }, "start": Object { - "column": 20, + "column": 21, "line": 2, }, }, - "name": "name", + "properties": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "name": "bar", + "range": Array [ + 35, + 38, + ], + "type": "Identifier", + }, + "kind": "init", + "loc": Object { + "end": Object { + "column": 26, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "method": false, + "range": Array [ + 35, + 38, + ], + "shorthand": true, + "type": "Property", + "value": Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 2, + }, + "start": Object { + "column": 23, + "line": 2, + }, + }, + "name": "bar", + "range": Array [ + 35, + 38, + ], + "type": "Identifier", + }, + }, + ], "range": Array [ - 36, - 48, + 33, + 45, ], - "type": "Identifier", + "type": "ObjectPattern", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 32, + "column": 33, "line": 2, }, "start": Object { - "column": 24, + "column": 28, "line": 2, }, }, "range": Array [ 40, - 48, + 45, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 32, + "column": 33, "line": 2, }, "start": Object { - "column": 26, + "column": 30, "line": 2, }, }, "range": Array [ 42, - 48, + 45, ], - "type": "TSStringKeyword", + "type": "TSAnyKeyword", }, }, }, ], "range": Array [ - 25, - 95, + 17, + 49, ], "type": "FunctionExpression", }, @@ -83999,23 +86122,23 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { - "column": 14, + "column": 10, "line": 1, }, }, "range": Array [ - 14, - 97, + 10, + 51, ], "type": "ClassBody", }, "id": Object { "loc": Object { "end": Object { - "column": 13, + "column": 9, "line": 1, }, "start": Object { @@ -84023,17 +86146,17 @@ Object { "line": 1, }, }, - "name": "Greeter", + "name": "Foo", "range": Array [ 6, - 13, + 9, ], "type": "Identifier", }, "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { "column": 0, @@ -84042,7 +86165,7 @@ Object { }, "range": Array [ 0, - 97, + 51, ], "superClass": null, "type": "ClassDeclaration", @@ -84051,7 +86174,7 @@ Object { "loc": Object { "end": Object { "column": 0, - "line": 6, + "line": 4, }, "start": Object { "column": 0, @@ -84060,7 +86183,7 @@ Object { }, "range": Array [ 0, - 98, + 52, ], "sourceType": "script", "tokens": Array [ @@ -84085,7 +86208,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 13, + "column": 9, "line": 1, }, "start": Object { @@ -84095,25 +86218,25 @@ Object { }, "range": Array [ 6, - 13, + 9, ], "type": "Identifier", - "value": "Greeter", + "value": "Foo", }, Object { "loc": Object { "end": Object { - "column": 15, + "column": 11, "line": 1, }, "start": Object { - "column": 14, + "column": 10, "line": 1, }, }, "range": Array [ - 14, - 15, + 10, + 11, ], "type": "Punctuator", "value": "{", @@ -84121,35 +86244,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 9, + "column": 5, "line": 2, }, "start": Object { - "column": 4, + "column": 2, "line": 2, }, }, "range": Array [ - 20, - 25, + 14, + 17, ], "type": "Identifier", - "value": "greet", + "value": "bar", }, Object { "loc": Object { "end": Object { - "column": 10, + "column": 6, "line": 2, }, "start": Object { - "column": 9, + "column": 5, "line": 2, }, }, "range": Array [ - 25, - 26, + 17, + 18, ], "type": "Punctuator", "value": "(", @@ -84157,17 +86280,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 11, + "column": 7, "line": 2, }, "start": Object { - "column": 10, + "column": 6, "line": 2, }, }, "range": Array [ - 26, - 27, + 18, + 19, ], "type": "Punctuator", "value": "@", @@ -84175,89 +86298,71 @@ Object { Object { "loc": Object { "end": Object { - "column": 19, - "line": 2, - }, - "start": Object { - "column": 11, - "line": 2, - }, - }, - "range": Array [ - 27, - 35, - ], - "type": "Identifier", - "value": "required", - }, - Object { - "loc": Object { - "end": Object { - "column": 24, + "column": 14, "line": 2, }, "start": Object { - "column": 20, + "column": 7, "line": 2, }, }, "range": Array [ - 36, - 40, + 19, + 26, ], "type": "Identifier", - "value": "name", + "value": "special", }, Object { "loc": Object { "end": Object { - "column": 25, + "column": 15, "line": 2, }, "start": Object { - "column": 24, + "column": 14, "line": 2, }, }, "range": Array [ - 40, - 41, + 26, + 27, ], "type": "Punctuator", - "value": ":", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 32, + "column": 19, "line": 2, }, "start": Object { - "column": 26, + "column": 15, "line": 2, }, }, "range": Array [ - 42, - 48, + 27, + 31, ], - "type": "Identifier", - "value": "string", + "type": "Boolean", + "value": "true", }, Object { "loc": Object { "end": Object { - "column": 33, + "column": 20, "line": 2, }, "start": Object { - "column": 32, + "column": 19, "line": 2, }, }, "range": Array [ - 48, - 49, + 31, + 32, ], "type": "Punctuator", "value": ")", @@ -84265,17 +86370,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 35, + "column": 22, "line": 2, }, "start": Object { - "column": 34, + "column": 21, "line": 2, }, }, "range": Array [ - 50, - 51, + 33, + 34, ], "type": "Punctuator", "value": "{", @@ -84283,143 +86388,125 @@ Object { Object { "loc": Object { "end": Object { - "column": 14, - "line": 3, + "column": 26, + "line": 2, }, "start": Object { - "column": 8, - "line": 3, + "column": 23, + "line": 2, }, }, "range": Array [ - 60, - 66, + 35, + 38, ], - "type": "Keyword", - "value": "return", + "type": "Identifier", + "value": "bar", }, Object { "loc": Object { "end": Object { - "column": 23, - "line": 3, + "column": 28, + "line": 2, }, "start": Object { - "column": 15, - "line": 3, + "column": 27, + "line": 2, }, }, "range": Array [ - 67, - 75, + 39, + 40, ], - "type": "String", - "value": "\\"Hello \\"", + "type": "Punctuator", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 25, - "line": 3, + "column": 29, + "line": 2, }, "start": Object { - "column": 24, - "line": 3, + "column": 28, + "line": 2, }, }, "range": Array [ - 76, - 77, + 40, + 41, ], "type": "Punctuator", - "value": "+", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 30, - "line": 3, + "column": 33, + "line": 2, }, "start": Object { - "column": 26, - "line": 3, + "column": 30, + "line": 2, }, }, "range": Array [ - 78, - 82, + 42, + 45, ], "type": "Identifier", - "value": "name", + "value": "any", }, Object { "loc": Object { "end": Object { - "column": 32, - "line": 3, + "column": 34, + "line": 2, }, "start": Object { - "column": 31, - "line": 3, + "column": 33, + "line": 2, }, }, "range": Array [ - 83, - 84, + 45, + 46, ], "type": "Punctuator", - "value": "+", + "value": ")", }, Object { "loc": Object { "end": Object { "column": 36, - "line": 3, - }, - "start": Object { - "column": 33, - "line": 3, - }, - }, - "range": Array [ - 85, - 88, - ], - "type": "String", - "value": "\\"!\\"", - }, - Object { - "loc": Object { - "end": Object { - "column": 37, - "line": 3, + "line": 2, }, "start": Object { - "column": 36, - "line": 3, + "column": 35, + "line": 2, }, }, "range": Array [ - 88, - 89, + 47, + 48, ], "type": "Punctuator", - "value": ";", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 37, + "line": 2, }, "start": Object { - "column": 4, - "line": 4, + "column": 36, + "line": 2, }, }, "range": Array [ - 94, - 95, + 48, + 49, ], "type": "Punctuator", "value": "}", @@ -84428,16 +86515,16 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { "column": 0, - "line": 5, + "line": 3, }, }, "range": Array [ - 96, - 97, + 50, + 51, ], "type": "Punctuator", "value": "}", @@ -84447,7 +86534,7 @@ Object { } `; -exports[`typescript fixtures/decorators/parameter-decorators/parameter-decorator-static-member.src 1`] = ` +exports[`typescript fixtures/decorators/parameter-decorators/parameter-rest-element-decorator.src 1`] = ` Object { "body": Array [ Object { @@ -84458,165 +86545,55 @@ Object { "key": Object { "loc": Object { "end": Object { - "column": 16, + "column": 5, "line": 2, }, "start": Object { - "column": 11, + "column": 2, "line": 2, }, }, - "name": "greet", + "name": "bar", "range": Array [ - 33, - 38, + 14, + 17, ], "type": "Identifier", }, "kind": "method", "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 36, + "line": 2, }, "start": Object { - "column": 4, + "column": 2, "line": 2, }, }, "range": Array [ - 26, - 108, + 14, + 48, ], - "static": true, + "static": false, "type": "MethodDefinition", "value": Object { "async": false, "body": Object { - "body": Array [ - Object { - "argument": Object { - "left": Object { - "left": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 3, - }, - "start": Object { - "column": 15, - "line": 3, - }, - }, - "range": Array [ - 80, - 88, - ], - "raw": "\\"Hello \\"", - "type": "Literal", - "value": "Hello ", - }, - "loc": Object { - "end": Object { - "column": 30, - "line": 3, - }, - "start": Object { - "column": 15, - "line": 3, - }, - }, - "operator": "+", - "range": Array [ - 80, - 95, - ], - "right": Object { - "loc": Object { - "end": Object { - "column": 30, - "line": 3, - }, - "start": Object { - "column": 26, - "line": 3, - }, - }, - "name": "name", - "range": Array [ - 91, - 95, - ], - "type": "Identifier", - }, - "type": "BinaryExpression", - }, - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 15, - "line": 3, - }, - }, - "operator": "+", - "range": Array [ - 80, - 101, - ], - "right": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 33, - "line": 3, - }, - }, - "range": Array [ - 98, - 101, - ], - "raw": "\\"!\\"", - "type": "Literal", - "value": "!", - }, - "type": "BinaryExpression", - }, - "loc": Object { - "end": Object { - "column": 37, - "line": 3, - }, - "start": Object { - "column": 8, - "line": 3, - }, - }, - "range": Array [ - 73, - 102, - ], - "type": "ReturnStatement", - }, - ], + "body": Array [], "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 36, + "line": 2, }, "start": Object { - "column": 41, + "column": 34, "line": 2, }, }, "range": Array [ - 63, - 108, + 46, + 48, ], "type": "BlockStatement", }, @@ -84625,108 +86602,163 @@ Object { "id": null, "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 36, + "line": 2, }, "start": Object { - "column": 16, + "column": 5, "line": 2, }, }, "params": Array [ Object { + "argument": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 24, + "line": 2, + }, + }, + "name": "foo", + "range": Array [ + 36, + 39, + ], + "type": "Identifier", + }, "decorators": Array [ Object { "expression": Object { + "arguments": Array [ + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 27, + 31, + ], + "raw": "true", + "type": "Literal", + "value": true, + }, + ], + "callee": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "name": "special", + "range": Array [ + 19, + 26, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { - "column": 26, + "column": 20, "line": 2, }, "start": Object { - "column": 18, + "column": 7, "line": 2, }, }, - "name": "required", "range": Array [ - 40, - 48, + 19, + 32, ], - "type": "Identifier", + "type": "CallExpression", }, "loc": Object { "end": Object { - "column": 26, + "column": 20, "line": 2, }, "start": Object { - "column": 17, + "column": 6, "line": 2, }, }, "range": Array [ - 39, - 48, + 18, + 32, ], "type": "Decorator", }, ], "loc": Object { "end": Object { - "column": 39, + "column": 32, "line": 2, }, "start": Object { - "column": 27, + "column": 6, "line": 2, }, }, - "name": "name", "range": Array [ - 49, - 61, + 18, + 44, ], - "type": "Identifier", + "type": "RestElement", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 39, + "column": 32, "line": 2, }, "start": Object { - "column": 31, + "column": 27, "line": 2, }, }, "range": Array [ - 53, - 61, + 39, + 44, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 39, + "column": 32, "line": 2, }, "start": Object { - "column": 33, + "column": 29, "line": 2, }, }, "range": Array [ - 55, - 61, + 41, + 44, ], - "type": "TSStringKeyword", + "type": "TSAnyKeyword", }, }, }, ], "range": Array [ - 38, - 108, + 17, + 48, ], "type": "FunctionExpression", }, @@ -84735,23 +86767,23 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { - "column": 20, + "column": 10, "line": 1, }, }, "range": Array [ - 20, - 110, + 10, + 50, ], "type": "ClassBody", }, "id": Object { "loc": Object { "end": Object { - "column": 19, + "column": 9, "line": 1, }, "start": Object { @@ -84759,17 +86791,17 @@ Object { "line": 1, }, }, - "name": "StaticGreeter", + "name": "Foo", "range": Array [ 6, - 19, + 9, ], "type": "Identifier", }, "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { "column": 0, @@ -84778,7 +86810,7 @@ Object { }, "range": Array [ 0, - 110, + 50, ], "superClass": null, "type": "ClassDeclaration", @@ -84787,7 +86819,7 @@ Object { "loc": Object { "end": Object { "column": 0, - "line": 6, + "line": 4, }, "start": Object { "column": 0, @@ -84796,7 +86828,7 @@ Object { }, "range": Array [ 0, - 111, + 51, ], "sourceType": "script", "tokens": Array [ @@ -84821,7 +86853,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 19, + "column": 9, "line": 1, }, "start": Object { @@ -84831,25 +86863,25 @@ Object { }, "range": Array [ 6, - 19, + 9, ], "type": "Identifier", - "value": "StaticGreeter", + "value": "Foo", }, Object { "loc": Object { "end": Object { - "column": 21, + "column": 11, "line": 1, }, "start": Object { - "column": 20, + "column": 10, "line": 1, }, }, "range": Array [ - 20, - 21, + 10, + 11, ], "type": "Punctuator", "value": "{", @@ -84857,53 +86889,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 10, - "line": 2, - }, - "start": Object { - "column": 4, - "line": 2, - }, - }, - "range": Array [ - 26, - 32, - ], - "type": "Keyword", - "value": "static", - }, - Object { - "loc": Object { - "end": Object { - "column": 16, + "column": 5, "line": 2, }, "start": Object { - "column": 11, + "column": 2, "line": 2, }, }, "range": Array [ - 33, - 38, + 14, + 17, ], "type": "Identifier", - "value": "greet", + "value": "bar", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 6, "line": 2, }, "start": Object { - "column": 16, + "column": 5, "line": 2, }, }, "range": Array [ - 38, - 39, + 17, + 18, ], "type": "Punctuator", "value": "(", @@ -84911,17 +86925,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 18, + "column": 7, "line": 2, }, "start": Object { - "column": 17, + "column": 6, "line": 2, }, }, "range": Array [ - 39, - 40, + 18, + 19, ], "type": "Punctuator", "value": "@", @@ -84929,89 +86943,71 @@ Object { Object { "loc": Object { "end": Object { - "column": 26, - "line": 2, - }, - "start": Object { - "column": 18, - "line": 2, - }, - }, - "range": Array [ - 40, - 48, - ], - "type": "Identifier", - "value": "required", - }, - Object { - "loc": Object { - "end": Object { - "column": 31, + "column": 14, "line": 2, }, "start": Object { - "column": 27, + "column": 7, "line": 2, }, }, "range": Array [ - 49, - 53, + 19, + 26, ], "type": "Identifier", - "value": "name", + "value": "special", }, Object { "loc": Object { "end": Object { - "column": 32, + "column": 15, "line": 2, }, "start": Object { - "column": 31, + "column": 14, "line": 2, }, }, "range": Array [ - 53, - 54, + 26, + 27, ], "type": "Punctuator", - "value": ":", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 39, + "column": 19, "line": 2, }, "start": Object { - "column": 33, + "column": 15, "line": 2, }, }, "range": Array [ - 55, - 61, + 27, + 31, ], - "type": "Identifier", - "value": "string", + "type": "Boolean", + "value": "true", }, Object { "loc": Object { "end": Object { - "column": 40, + "column": 20, "line": 2, }, "start": Object { - "column": 39, + "column": 19, "line": 2, }, }, "range": Array [ - 61, - 62, + 31, + 32, ], "type": "Punctuator", "value": ")", @@ -85019,161 +87015,125 @@ Object { Object { "loc": Object { "end": Object { - "column": 42, + "column": 24, "line": 2, }, "start": Object { - "column": 41, + "column": 21, "line": 2, }, }, "range": Array [ - 63, - 64, + 33, + 36, ], "type": "Punctuator", - "value": "{", - }, - Object { - "loc": Object { - "end": Object { - "column": 14, - "line": 3, - }, - "start": Object { - "column": 8, - "line": 3, - }, - }, - "range": Array [ - 73, - 79, - ], - "type": "Keyword", - "value": "return", + "value": "...", }, Object { "loc": Object { "end": Object { - "column": 23, - "line": 3, + "column": 27, + "line": 2, }, "start": Object { - "column": 15, - "line": 3, + "column": 24, + "line": 2, }, }, "range": Array [ - 80, - 88, + 36, + 39, ], - "type": "String", - "value": "\\"Hello \\"", + "type": "Identifier", + "value": "foo", }, Object { "loc": Object { "end": Object { - "column": 25, - "line": 3, + "column": 28, + "line": 2, }, "start": Object { - "column": 24, - "line": 3, + "column": 27, + "line": 2, }, }, "range": Array [ - 89, - 90, + 39, + 40, ], "type": "Punctuator", - "value": "+", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 30, - "line": 3, + "column": 32, + "line": 2, }, "start": Object { - "column": 26, - "line": 3, + "column": 29, + "line": 2, }, }, "range": Array [ - 91, - 95, + 41, + 44, ], "type": "Identifier", - "value": "name", + "value": "any", }, Object { "loc": Object { "end": Object { - "column": 32, - "line": 3, + "column": 33, + "line": 2, }, "start": Object { - "column": 31, - "line": 3, + "column": 32, + "line": 2, }, }, "range": Array [ - 96, - 97, + 44, + 45, ], "type": "Punctuator", - "value": "+", - }, - Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 33, - "line": 3, - }, - }, - "range": Array [ - 98, - 101, - ], - "type": "String", - "value": "\\"!\\"", + "value": ")", }, Object { "loc": Object { "end": Object { - "column": 37, - "line": 3, + "column": 35, + "line": 2, }, "start": Object { - "column": 36, - "line": 3, + "column": 34, + "line": 2, }, }, "range": Array [ - 101, - 102, + 46, + 47, ], "type": "Punctuator", - "value": ";", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 5, - "line": 4, + "column": 36, + "line": 2, }, "start": Object { - "column": 4, - "line": 4, + "column": 35, + "line": 2, }, }, "range": Array [ - 107, - 108, + 47, + 48, ], "type": "Punctuator", "value": "}", @@ -85182,16 +87142,16 @@ Object { "loc": Object { "end": Object { "column": 1, - "line": 5, + "line": 3, }, "start": Object { "column": 0, - "line": 5, + "line": 3, }, }, "range": Array [ - 109, - 110, + 49, + 50, ], "type": "Punctuator", "value": "}", @@ -88574,6 +90534,232 @@ Object { } `; +exports[`typescript fixtures/errorRecovery/decorator-on-function.src 1`] = ` +Object { + "body": Array [ + Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 12, + "line": 2, + }, + }, + "range": Array [ + 17, + 19, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "name": "b", + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 0, + 19, + ], + "type": "FunctionDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 20, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 1, + ], + "type": "Punctuator", + "value": "@", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "range": Array [ + 1, + 4, + ], + "type": "Identifier", + "value": "dec", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 5, + 13, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Identifier", + "value": "b", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 15, + 16, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 12, + "line": 2, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + exports[`typescript fixtures/errorRecovery/decorator-on-interface-declaration.src 1`] = ` Object { "body": Array [ From fdac435e5cd53e4addc69619caa800be59c2ea0d Mon Sep 17 00:00:00 2001 From: Armano Date: Wed, 6 Feb 2019 02:45:52 +0100 Subject: [PATCH 14/26] test(parser): add missing test cases for parser options (#213) --- packages/typescript-estree/src/parser.ts | 2 +- .../tests/lib/__snapshots__/convert.ts.snap | 269 ++++++++++++++++++ .../typescript-estree/tests/lib/convert.ts | 24 ++ packages/typescript-estree/tests/lib/parse.ts | 33 +++ 4 files changed, 327 insertions(+), 1 deletion(-) diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index ca3d27db77e1..bad5cdd6fd50 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -107,7 +107,7 @@ function getASTAndDefaultProject(code: string, options: ParserOptions) { function createNewProgram(code: string) { const FILENAME = getFileName(extra); - const compilerHost = { + const compilerHost: ts.CompilerHost = { fileExists() { return true; }, diff --git a/packages/typescript-estree/tests/lib/__snapshots__/convert.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/convert.ts.snap index 05a20300876e..3049a51ae47a 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/convert.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/convert.ts.snap @@ -1,5 +1,179 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`convert deeplyCopy should convert array of nodes 1`] = ` +Object { + "amdDependencies": Array [], + "bindDiagnostics": Array [], + "bindSuggestionDiagnostics": undefined, + "checkJsDirective": undefined, + "endOfFileToken": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, + 12, + ], + "type": "TSEndOfFileToken", + }, + "externalModuleIndicator": undefined, + "fileName": "text.ts", + "hasNoDefaultLib": false, + "identifierCount": 2, + "identifiers": Map { + "foo" => "foo", + "T" => "T", + }, + "isDeclarationFile": false, + "languageVariant": 1, + "languageVersion": 6, + "libReferenceDirectives": Array [], + "lineMap": Array [ + null, + ], + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "nodeCount": 7, + "parseDiagnostics": Array [], + "pragmas": Map {}, + "range": Array [ + 0, + 12, + ], + "referencedFiles": Array [], + "scriptKind": 4, + "statements": Array [ + Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 4, + 7, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 12, + ], + "type": "NewExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "range": Array [ + 8, + 9, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 8, + 9, + ], + "type": "Identifier", + }, + "typeParameters": undefined, + }, + ], + "range": Array [ + 7, + 10, + ], + "type": "TSTypeParameterInstantiation", + }, + }, + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 12, + ], + "type": "ExpressionStatement", + }, + ], + "text": "new foo()", + "transformFlags": undefined, + "type": "TSSourceFile", + "typeReferenceDirectives": Array [], +} +`; + exports[`convert deeplyCopy should convert node correctly 1`] = ` Object { "body": Array [ @@ -421,6 +595,101 @@ Object { } `; +exports[`convert deeplyCopy should convert node with type arguments correctly 1`] = ` +Object { + "arguments": Array [], + "expression": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 4, + 7, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 12, + ], + "transformFlags": undefined, + "type": "TSNewExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "range": Array [ + 8, + 9, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 8, + 9, + ], + "type": "Identifier", + }, + "typeParameters": undefined, + }, + ], + "range": Array [ + 7, + 10, + ], + "type": "TSTypeParameterInstantiation", + }, +} +`; + exports[`convert deeplyCopy should convert node with type parameters correctly 1`] = ` Object { "heritageClauses": undefined, diff --git a/packages/typescript-estree/tests/lib/convert.ts b/packages/typescript-estree/tests/lib/convert.ts index ee2a44f7b7ce..6fb1077a4714 100644 --- a/packages/typescript-estree/tests/lib/convert.ts +++ b/packages/typescript-estree/tests/lib/convert.ts @@ -45,6 +45,30 @@ describe('convert', () => { expect((instance as any).deeplyCopy(ast.statements[0])).toMatchSnapshot(); }); + it('deeplyCopy should convert node with type arguments correctly', () => { + const ast = convertCode('new foo()'); + + const instance = new Converter(ast, { + errorOnUnknownASTType: false, + useJSXTextNode: false, + shouldProvideParserServices: false + }); + expect( + (instance as any).deeplyCopy((ast.statements[0] as any).expression) + ).toMatchSnapshot(); + }); + + it('deeplyCopy should convert array of nodes', () => { + const ast = convertCode('new foo()'); + + const instance = new Converter(ast, { + errorOnUnknownASTType: false, + useJSXTextNode: false, + shouldProvideParserServices: false + }); + expect((instance as any).deeplyCopy(ast)).toMatchSnapshot(); + }); + it('deeplyCopy should fail on unknown node', () => { const ast = convertCode('type foo = ?foo | ?(() => void)?'); diff --git a/packages/typescript-estree/tests/lib/parse.ts b/packages/typescript-estree/tests/lib/parse.ts index 2f8463cc0a2b..60aee02b1a06 100644 --- a/packages/typescript-estree/tests/lib/parse.ts +++ b/packages/typescript-estree/tests/lib/parse.ts @@ -104,4 +104,37 @@ describe('parse()', () => { ); }); }); + + describe('errorOnTypeScriptSyntacticAndSemanticIssues', () => { + const code = '@test const foo = 2'; + const options: ParserOptions = { + comment: true, + tokens: true, + range: true, + loc: true, + errorOnTypeScriptSyntacticAndSemanticIssues: true + }; + + it('should throw on invalid option when used in parse', () => { + expect(() => { + parser.parse(code, options); + }).toThrow( + `"errorOnTypeScriptSyntacticAndSemanticIssues" is only supported for parseAndGenerateServices()` + ); + }); + + it('should not throw when used in parseAndGenerateServices', () => { + expect(() => { + parser.parseAndGenerateServices(code, options); + }).not.toThrow( + `"errorOnTypeScriptSyntacticAndSemanticIssues" is only supported for parseAndGenerateServices()` + ); + }); + + it('should error on invalid code', () => { + expect(() => { + parser.parseAndGenerateServices(code, options); + }).toThrow('Decorators are not valid here.'); + }); + }); }); From 7777cae93e7020a606ffb8e58cba1b9020d61e73 Mon Sep 17 00:00:00 2001 From: Armano Date: Wed, 6 Feb 2019 02:51:17 +0100 Subject: [PATCH 15/26] test(ts-estree): upgrade babel to 7.3.2 (#217) --- package.json | 2 +- .../tests/ast-alignment/fixtures-to-test.ts | 30 +++++++++++++------ yarn.lock | 8 ++--- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index db01c0bf521c..301ec05cfdf1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ }, "devDependencies": { "@babel/code-frame": "7.0.0", - "@babel/parser": "7.3.0", + "@babel/parser": "7.3.2", "@commitlint/cli": "^7.1.2", "@commitlint/config-conventional": "^7.1.2", "@commitlint/travis-cli": "^7.1.2", diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts index e8dcf0aca782..ddda926b3201 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -164,7 +164,20 @@ tester.addFixturePatternConfig('javascript/arrowFunctions', { * with the same name, for example. */ 'error-dup-params', // babel parse errors - 'error-strict-dup-params' // babel parse errors + 'error-strict-dup-params', // babel parse errors + /** + * typescript reports TS1100 and babel errors on this + * TS1100: "Invalid use of '{0}' in strict mode." + * TODO: do we want TS1100 error code? + */ + 'error-strict-eval', // babel parse errors + 'error-strict-default-param-eval', + 'error-strict-eval-return', + 'error-strict-param-arguments', + 'error-strict-param-eval', + 'error-strict-param-names', + 'error-strict-param-no-paren-arguments', + 'error-strict-param-no-paren-eval' ] }); tester.addFixturePatternConfig('javascript/function', { @@ -236,7 +249,12 @@ tester.addFixturePatternConfig('javascript/modules', { */ 'invalid-export-named-default' // babel parse errors ], - ignoreSourceType: ['error-function', 'error-strict', 'error-delete'] + ignoreSourceType: [ + 'error-function', + 'error-strict', + 'error-delete', + 'invalid-await' + ] }); tester.addFixturePatternConfig('javascript/newTarget'); @@ -363,15 +381,9 @@ tester.addFixturePatternConfig('typescript/basics', { * https://github.com/babel/babel/issues/9324 */ 'type-assertion-arrow-function', - /** - * PR for range of declare keyword has been merged into Babel: https://github.com/babel/babel/pull/9406 - * TODO: remove me in next babel > 7.3.1 - */ - 'export-declare-const-named-enum', - 'export-declare-named-enum', /** * Babel does not include optional keyword into range parameter in arrow function - * TODO: report it to babel + * https://github.com/babel/babel/issues/9461 */ 'arrow-function-with-optional-parameter' ], diff --git a/yarn.lock b/yarn.lock index 51d8518fb375..00804abee1f8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18,10 +18,10 @@ esutils "^2.0.2" js-tokens "^4.0.0" -"@babel/parser@7.3.0": - version "7.3.0" - resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.3.0.tgz#930251fe6714df47ce540a919ccdf6dcfb652b61" - integrity sha512-8M30TzMpLHGmuthHZStm4F+az5wxyYeh8U+LWK7+b2qnlQ0anXBmOQ1I8DCMV1K981wPY3C3kWZ4SA1lR3Y3xQ== +"@babel/parser@7.3.2": + version "7.3.2" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.3.2.tgz#95cdeddfc3992a6ca2a1315191c1679ca32c55cd" + integrity sha512-QzNUC2RO1gadg+fs21fi0Uu0OuGNzRKEmgCxoLNzbCdoprLwjfmZwzUrpUNfJPaVRwBpDY47A17yYEGWyRelnQ== "@commitlint/cli@^7.1.2", "@commitlint/cli@^7.3.2": version "7.3.2" From 690bff322adbebe181b3efb33c46408e2b819b9d Mon Sep 17 00:00:00 2001 From: Armano Date: Wed, 6 Feb 2019 02:53:10 +0100 Subject: [PATCH 16/26] test(ts-estree): correct jsx for semantic-diagnostics tests (#218) --- .../tests/ast-alignment/fixtures-to-test.ts | 3 +- .../semantic-diagnostics-enabled.ts.snap | 477 ++++-------------- .../typescript-estree/tests/lib/comments.ts | 5 +- .../tests/lib/semantic-diagnostics-enabled.ts | 7 +- packages/typescript-estree/tests/lib/tsx.ts | 8 +- .../typescript-estree/tests/lib/typescript.ts | 9 +- .../typescript-estree/tools/test-utils.ts | 11 + 7 files changed, 140 insertions(+), 380 deletions(-) diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts index ddda926b3201..564a5ab6a1ab 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -3,6 +3,7 @@ import fs from 'fs'; import path from 'path'; import jsxKnownIssues from '../../../shared-fixtures/jsx-known-issues'; +import { isJSXFileType } from '../../tools/test-utils'; interface Fixture { filename: string; @@ -61,7 +62,7 @@ class FixturesTester { const ignore = config.ignore || []; const fileType = config.fileType || 'js'; const ignoreSourceType = config.ignoreSourceType || []; - const jsx = fileType === 'js' || fileType === 'jsx' || fileType === 'tsx'; + const jsx = isJSXFileType(fileType); /** * The TypeScript compiler gives us the "externalModuleIndicator" to allow typescript-estree do dynamically detect the "sourceType". diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap index dde844c7e15e..cfc83e85d3c2 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap @@ -8,77 +8,21 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/jsdoc-comment.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/jsx-block-comment.src 1`] = ` -Object { - "column": 10, - "index": 84, - "lineNumber": 5, - "message": "Unterminated regular expression literal.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/jsx-block-comment.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/jsx-comment-after-jsx.src 1`] = ` -Object { - "column": 14, - "index": 48, - "lineNumber": 3, - "message": "Type expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/jsx-comment-after-jsx.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/jsx-comment-after-self-closing-jsx.src 1`] = ` -Object { - "column": 13, - "index": 47, - "lineNumber": 3, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/jsx-comment-after-self-closing-jsx.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/jsx-tag-comments.src 1`] = ` -Object { - "column": 9, - "index": 113, - "lineNumber": 7, - "message": "Type expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/jsx-tag-comments.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/jsx-text-with-multiline-non-comment.src 1`] = ` -Object { - "column": 5, - "index": 81, - "lineNumber": 7, - "message": "Type expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/jsx-text-with-multiline-non-comment.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/jsx-text-with-url.src 1`] = ` -Object { - "column": 17, - "index": 17, - "lineNumber": 1, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/jsx-text-with-url.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/jsx-with-greather-than.src 1`] = ` -Object { - "column": 0, - "index": 69, - "lineNumber": 4, - "message": "Expression expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/jsx-with-greather-than.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/jsx-with-operators.src 1`] = ` -Object { - "column": 0, - "index": 69, - "lineNumber": 4, - "message": "Expression expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/jsx-with-operators.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/comments/line-comment-with-block-syntax.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; @@ -1330,120 +1274,71 @@ Object { } `; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/attributes.src 1`] = ` -Object { - "column": 5, - "index": 5, - "lineNumber": 1, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/attributes.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/element-keyword-name.src 1`] = ` -Object { - "column": 12, - "index": 18, - "lineNumber": 2, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/element-keyword-name.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/embedded-comment.src 1`] = ` -Object { - "column": 30, - "index": 30, - "lineNumber": 1, - "message": "Unterminated regular expression literal.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/embedded-comment.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/embedded-conditional.src 1`] = ` -Object { - "column": 3, - "index": 3, - "lineNumber": 1, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/embedded-conditional.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/embedded-invalid-js-identifier.src 1`] = ` -Object { - "column": 9, - "index": 9, - "lineNumber": 1, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/embedded-invalid-js-identifier.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/embedded-tags.src 1`] = ` Object { - "column": 11, - "index": 11, + "column": 16, + "index": 16, "lineNumber": 1, - "message": "'>' expected.", + "message": "'{' expected.", } `; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/empty-placeholder.src 1`] = ` -Object { - "column": 7, - "index": 7, - "lineNumber": 1, - "message": "Unterminated regular expression literal.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/empty-placeholder.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/escape-patterns.src 1`] = ` -Object { - "column": 3, - "index": 3, - "lineNumber": 1, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/escape-patterns.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-attribute.src 1`] = ` Object { - "column": 3, - "index": 3, + "column": 5, + "index": 5, "lineNumber": 1, - "message": "'>' expected.", + "message": "'{' expected.", } `; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-attribute-missing-equals.src 1`] = ` Object { - "column": 5, - "index": 5, + "column": 14, + "index": 14, "lineNumber": 1, - "message": "'>' expected.", + "message": "Identifier expected.", } `; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-broken-tag.src 1`] = ` Object { - "column": 3, - "index": 3, + "column": 12, + "index": 12, "lineNumber": 1, - "message": "'>' expected.", + "message": "Unterminated string literal.", } `; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-computed-end-tag-name.src 1`] = ` Object { - "column": 9, - "index": 9, + "column": 2, + "index": 2, "lineNumber": 1, - "message": "Type expected.", + "message": "Identifier expected.", } `; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-computed-string-end-tag-name.src 1`] = ` Object { - "column": 11, - "index": 11, + "column": 2, + "index": 2, "lineNumber": 1, - "message": "Type expected.", + "message": "Identifier expected.", } `; @@ -1452,23 +1347,23 @@ Object { "column": 9, "index": 9, "lineNumber": 1, - "message": "':' expected.", + "message": "'}' expected.", } `; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-leading-dot-tag-name.src 1`] = ` Object { - "column": 1, - "index": 1, + "column": 0, + "index": 0, "lineNumber": 1, - "message": "Type expected.", + "message": "Expression expected.", } `; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-matching-placeholder-in-closing-tag.src 1`] = ` Object { - "column": 5, - "index": 5, + "column": 27, + "index": 27, "lineNumber": 1, "message": "'>' expected.", } @@ -1476,28 +1371,28 @@ Object { exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-mismatched-closing-tag.src 1`] = ` Object { - "column": 4, - "index": 4, + "column": 3, + "index": 3, "lineNumber": 1, - "message": "Type expected.", + "message": "Expected corresponding JSX closing tag for 'a'.", } `; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-mismatched-closing-tags.src 1`] = ` Object { - "column": 6, - "index": 6, + "column": 1, + "index": 1, "lineNumber": 1, - "message": "'>' expected.", + "message": "JSX element 'a' has no corresponding closing tag.", } `; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-mismatched-dot-tag-name.src 1`] = ` Object { - "column": 8, - "index": 8, + "column": 7, + "index": 7, "lineNumber": 1, - "message": "Type expected.", + "message": "Expected corresponding JSX closing tag for 'a.b.c'.", } `; @@ -1506,34 +1401,34 @@ Object { "column": 2, "index": 2, "lineNumber": 1, - "message": "'>' expected.", + "message": "Identifier expected.", } `; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-missing-closing-tag.src 1`] = ` Object { - "column": 3, - "index": 3, + "column": 1, + "index": 1, "lineNumber": 1, - "message": "Expression expected.", + "message": "JSX element 'a' has no corresponding closing tag.", } `; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-missing-closing-tag-attribute-placeholder.src 1`] = ` Object { - "column": 3, - "index": 3, + "column": 1, + "index": 1, "lineNumber": 1, - "message": "'>' expected.", + "message": "JSX element 'a' has no corresponding closing tag.", } `; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-missing-namespace-name.src 1`] = ` Object { - "column": 1, - "index": 1, + "column": 0, + "index": 0, "lineNumber": 1, - "message": "Type expected.", + "message": "Expression expected.", } `; @@ -1542,16 +1437,16 @@ Object { "column": 2, "index": 2, "lineNumber": 1, - "message": "'>' expected.", + "message": "Identifier expected.", } `; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-missing-spread-operator.src 1`] = ` Object { - "column": 5, - "index": 5, + "column": 6, + "index": 6, "lineNumber": 1, - "message": "'>' expected.", + "message": "'...' expected.", } `; @@ -1560,7 +1455,7 @@ Object { "column": 4, "index": 4, "lineNumber": 1, - "message": "'>' expected.", + "message": "Identifier expected.", } `; @@ -1569,7 +1464,7 @@ Object { "column": 2, "index": 2, "lineNumber": 1, - "message": "'>' expected.", + "message": "Identifier expected.", } `; @@ -1578,43 +1473,43 @@ Object { "column": 36, "index": 36, "lineNumber": 1, - "message": "Expression expected.", + "message": "JSX expressions must have one parent element.", } `; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-no-common-parent-with-comment.src 1`] = ` Object { - "column": 38, - "index": 38, + "column": 63, + "index": 63, "lineNumber": 1, - "message": "',' expected.", + "message": "JSX expressions must have one parent element.", } `; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-no-tag-name.src 1`] = ` Object { - "column": 1, - "index": 1, + "column": 0, + "index": 0, "lineNumber": 1, - "message": "Type expected.", + "message": "Declaration or statement expected.", } `; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-placeholder-in-closing-tag.src 1`] = ` Object { - "column": 12, - "index": 12, + "column": 16, + "index": 16, "lineNumber": 1, - "message": "Unterminated regular expression literal.", + "message": "'>' expected.", } `; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-shorthand-fragment-no-closing.src 1`] = ` Object { - "column": 1, - "index": 1, + "column": 0, + "index": 0, "lineNumber": 1, - "message": "Type expected.", + "message": "JSX fragment has no corresponding closing tag.", } `; @@ -1629,64 +1524,29 @@ Object { exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-unexpected-comma.src 1`] = ` Object { - "column": 6, - "index": 6, + "column": 19, + "index": 19, "lineNumber": 1, - "message": "'>' expected.", + "message": "Identifier expected.", } `; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/japanese-characters.src 1`] = ` -Object { - "column": 6, - "index": 6, - "lineNumber": 1, - "message": "Type expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/japanese-characters.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/less-than-operator.src 1`] = ` -Object { - "column": 6, - "index": 6, - "lineNumber": 1, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/less-than-operator.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/member-expression.src 1`] = ` -Object { - "column": 6, - "index": 6, - "lineNumber": 1, - "message": "Type expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/member-expression.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/member-expression-this.src 1`] = ` -Object { - "column": 5, - "index": 5, - "lineNumber": 1, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/member-expression-this.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/multiple-blank-spaces.src 1`] = ` -Object { - "column": 8, - "index": 8, - "lineNumber": 1, - "message": "Type expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/multiple-blank-spaces.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/namespaced-attribute-and-value-inserted.src 1`] = ` Object { - "column": 3, - "index": 3, + "column": 4, + "index": 4, "lineNumber": 1, - "message": "'>' expected.", + "message": "Identifier expected.", } `; @@ -1695,36 +1555,22 @@ Object { "column": 2, "index": 2, "lineNumber": 1, - "message": "'>' expected.", + "message": "Identifier expected.", } `; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/newslines-and-entities.src 1`] = ` Object { - "column": 4, - "index": 4, + "column": 8, + "index": 8, "lineNumber": 1, - "message": "'>' expected.", + "message": "Invalid character.", } `; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/self-closing-tag.src 1`] = ` -Object { - "column": 3, - "index": 3, - "lineNumber": 1, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/self-closing-tag.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/self-closing-tag-inside-tag.src 1`] = ` -Object { - "column": 9, - "index": 15, - "lineNumber": 2, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/self-closing-tag-inside-tag.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/self-closing-tag-with-newline.src 1`] = ` Object { @@ -1735,140 +1581,35 @@ Object { } `; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/shorthand-fragment.src 1`] = ` -Object { - "column": 1, - "index": 1, - "lineNumber": 1, - "message": "Type expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/shorthand-fragment.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/shorthand-fragment-with-child.src 1`] = ` -Object { - "column": 1, - "index": 1, - "lineNumber": 1, - "message": "Type expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/shorthand-fragment-with-child.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/spread-child.src 1`] = ` -Object { - "column": 15, - "index": 15, - "lineNumber": 1, - "message": "Unterminated regular expression literal.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/spread-child.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/spread-operator-attribute-and-regular-attribute.src 1`] = ` -Object { - "column": 5, - "index": 5, - "lineNumber": 1, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/spread-operator-attribute-and-regular-attribute.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/spread-operator-attributes.src 1`] = ` -Object { - "column": 5, - "index": 5, - "lineNumber": 1, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/spread-operator-attributes.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/tag-names-with-dots.src 1`] = ` -Object { - "column": 6, - "index": 6, - "lineNumber": 1, - "message": "Type expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/tag-names-with-dots.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/tag-names-with-multi-dots.src 1`] = ` -Object { - "column": 8, - "index": 8, - "lineNumber": 1, - "message": "Type expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/tag-names-with-multi-dots.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/tag-names-with-multi-dots-multi.src 1`] = ` -Object { - "column": 7, - "index": 21, - "lineNumber": 2, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/tag-names-with-multi-dots-multi.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/test-content.src 1`] = ` -Object { - "column": 5, - "index": 5, - "lineNumber": 1, - "message": "Expression expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/test-content.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/trailing-spread-operator-attribute.src 1`] = ` -Object { - "column": 5, - "index": 5, - "lineNumber": 1, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/trailing-spread-operator-attribute.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/unknown-escape-pattern.src 1`] = ` -Object { - "column": 3, - "index": 3, - "lineNumber": 1, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/unknown-escape-pattern.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx-useJSXTextNode/self-closing-tag-inside-tag.src 1`] = ` -Object { - "column": 9, - "index": 15, - "lineNumber": 2, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx-useJSXTextNode/self-closing-tag-inside-tag.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx-useJSXTextNode/test-content.src 1`] = ` -Object { - "column": 5, - "index": 5, - "lineNumber": 1, - "message": "Expression expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx-useJSXTextNode/test-content.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/tsx/generic-jsx-element.src 1`] = ` -Object { - "column": 21, - "index": 21, - "lineNumber": 1, - "message": "'>' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/tsx/generic-jsx-element.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/tsx/react-typed-props.src 1`] = ` -Object { - "column": 12, - "index": 141, - "lineNumber": 9, - "message": "',' expected.", -} -`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/tsx/react-typed-props.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/babylon-convergence/type-parameter-whitespace-loc.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; diff --git a/packages/typescript-estree/tests/lib/comments.ts b/packages/typescript-estree/tests/lib/comments.ts index 1d02e2fa6715..63b53ce9047d 100644 --- a/packages/typescript-estree/tests/lib/comments.ts +++ b/packages/typescript-estree/tests/lib/comments.ts @@ -11,7 +11,8 @@ import { extname } from 'path'; import { ParserOptions } from '../../src/parser-options'; import { createSnapshotTestBlock, - formatSnapshotName + formatSnapshotName, + isJSXFileType } from '../../tools/test-utils'; //------------------------------------------------------------------------------ @@ -35,7 +36,7 @@ describe('Comments', () => { range: true, tokens: true, comment: true, - jsx: fileExtension === '.js' + jsx: isJSXFileType(fileExtension) }; it( formatSnapshotName(filename, FIXTURES_DIR, fileExtension), diff --git a/packages/typescript-estree/tests/lib/semantic-diagnostics-enabled.ts b/packages/typescript-estree/tests/lib/semantic-diagnostics-enabled.ts index 8231b96185df..2cd5555bce71 100644 --- a/packages/typescript-estree/tests/lib/semantic-diagnostics-enabled.ts +++ b/packages/typescript-estree/tests/lib/semantic-diagnostics-enabled.ts @@ -8,7 +8,7 @@ import { readFileSync } from 'fs'; import glob from 'glob'; import * as parser from '../../src/parser'; import { extname } from 'path'; -import { formatSnapshotName } from '../../tools/test-utils'; +import { formatSnapshotName, isJSXFileType } from '../../tools/test-utils'; //------------------------------------------------------------------------------ // Setup @@ -30,12 +30,13 @@ describe('Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" testFiles.forEach(filename => { const code = readFileSync(filename, 'utf8'); const fileExtension = extname(filename); - const config = { + const config: parser.ParserOptions = { loc: true, range: true, tokens: true, errorOnUnknownASTType: true, - errorOnTypeScriptSyntacticAndSemanticIssues: true + errorOnTypeScriptSyntacticAndSemanticIssues: true, + jsx: isJSXFileType(fileExtension) }; it(formatSnapshotName(filename, FIXTURES_DIR, fileExtension), () => { expect.assertions(1); diff --git a/packages/typescript-estree/tests/lib/tsx.ts b/packages/typescript-estree/tests/lib/tsx.ts index 21dbbd57efe0..c9409877b84f 100644 --- a/packages/typescript-estree/tests/lib/tsx.ts +++ b/packages/typescript-estree/tests/lib/tsx.ts @@ -10,7 +10,8 @@ import { extname } from 'path'; import { ParserOptions } from '../../src/parser-options'; import { createSnapshotTestBlock, - formatSnapshotName + formatSnapshotName, + isJSXFileType } from '../../tools/test-utils'; //------------------------------------------------------------------------------ @@ -28,16 +29,17 @@ const testFiles = glob.sync(`${FIXTURES_DIR}/**/*.src.tsx`); describe('TSX', () => { testFiles.forEach(filename => { const code = readFileSync(filename, 'utf8'); + const fileExtension = extname(filename); const config: ParserOptions = { loc: true, range: true, tokens: true, errorOnUnknownASTType: true, useJSXTextNode: true, - jsx: true + jsx: isJSXFileType(fileExtension) }; it( - formatSnapshotName(filename, FIXTURES_DIR, extname(filename)), + formatSnapshotName(filename, FIXTURES_DIR, fileExtension), createSnapshotTestBlock(code, config) ); }); diff --git a/packages/typescript-estree/tests/lib/typescript.ts b/packages/typescript-estree/tests/lib/typescript.ts index 9740c4570e74..2ccd8cb9786b 100644 --- a/packages/typescript-estree/tests/lib/typescript.ts +++ b/packages/typescript-estree/tests/lib/typescript.ts @@ -11,7 +11,8 @@ import { extname } from 'path'; import { ParserOptions } from '../../src/parser-options'; import { createSnapshotTestBlock, - formatSnapshotName + formatSnapshotName, + isJSXFileType } from '../../tools/test-utils'; //------------------------------------------------------------------------------ @@ -29,14 +30,16 @@ const testFiles = glob.sync(`${FIXTURES_DIR}/**/*.src.ts`); describe('typescript', () => { testFiles.forEach(filename => { const code = readFileSync(filename, 'utf8'); + const fileExtension = extname(filename); const config: ParserOptions = { loc: true, range: true, tokens: true, - errorOnUnknownASTType: true + errorOnUnknownASTType: true, + jsx: isJSXFileType(fileExtension) }; it( - formatSnapshotName(filename, FIXTURES_DIR, extname(filename)), + formatSnapshotName(filename, FIXTURES_DIR, fileExtension), createSnapshotTestBlock(code, config) ); }); diff --git a/packages/typescript-estree/tools/test-utils.ts b/packages/typescript-estree/tools/test-utils.ts index c2d57246ca09..d06d229a36ed 100644 --- a/packages/typescript-estree/tools/test-utils.ts +++ b/packages/typescript-estree/tools/test-utils.ts @@ -80,3 +80,14 @@ export function formatSnapshotName( .replace(fixturesDir + '/', '') .replace(fileExtension, '')}`; } + +/** + * Check if file extension is one used for jsx + * @param fileType + */ +export function isJSXFileType(fileType: string): boolean { + if (fileType.startsWith('.')) { + fileType = fileType.slice(1); + } + return fileType === 'js' || fileType === 'jsx' || fileType === 'tsx'; +} From 33061987c0cfd235014134dfd75e28c3eb4cfc2a Mon Sep 17 00:00:00 2001 From: Armano Date: Thu, 7 Feb 2019 02:17:44 +0100 Subject: [PATCH 17/26] fix(ts-estree): align typeArguments and typeParameters across nodes (#223) --- .../lib/__snapshots__/typescript.ts.snap | 2284 +++++++++++++++++ ...y-type-arguments-in-call-expression.src.ts | 1 + ...ty-type-arguments-in-new-expression.src.ts | 1 + ...y-type-parameters-in-arrow-function.src.ts | 1 + ...mpty-type-parameters-in-constructor.src.ts | 3 + ...e-parameters-in-function-expression.src.ts | 1 + ...type-parameters-in-method-signature.src.ts | 3 + .../empty-type-parameters-in-method.src.ts | 3 + .../empty-type-parameters.src.ts | 1 + packages/typescript-estree/src/convert.ts | 22 +- .../tests/ast-alignment/utils.ts | 5 +- .../semantic-diagnostics-enabled.ts.snap | 16 + .../lib/__snapshots__/typescript.ts.snap | 2276 ++++++++++++++++ 13 files changed, 4605 insertions(+), 12 deletions(-) create mode 100644 packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-arguments-in-call-expression.src.ts create mode 100644 packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-arguments-in-new-expression.src.ts create mode 100644 packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-arrow-function.src.ts create mode 100644 packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-constructor.src.ts create mode 100644 packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-function-expression.src.ts create mode 100644 packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-method-signature.src.ts create mode 100644 packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-method.src.ts create mode 100644 packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters.src.ts diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index 6f4ae3ff2035..ef757ac0453e 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -92235,6 +92235,2290 @@ Object { } `; +exports[`typescript fixtures/errorRecovery/empty-type-arguments-in-call-expression.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 0, + 3, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 7, + ], + "type": "CallExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 3, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 3, + 5, + ], + "type": "TSTypeParameterInstantiation", + }, + }, + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 8, + ], + "type": "ExpressionStatement", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 9, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 3, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 3, + "line": 1, + }, + }, + "range": Array [ + 3, + 4, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 5, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 6, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 7, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 8, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/errorRecovery/empty-type-arguments-in-new-expression.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "name": "Foo", + "range": Array [ + 4, + 7, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 11, + ], + "type": "NewExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 7, + 9, + ], + "type": "TSTypeParameterInstantiation", + }, + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 11, + ], + "type": "ExpressionStatement", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 12, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 3, + ], + "type": "Keyword", + "value": "new", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 7, + ], + "type": "Identifier", + "value": "Foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 8, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "range": Array [ + 8, + 9, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 10, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": ")", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/errorRecovery/empty-type-parameters.src 1`] = ` +Object { + "body": Array [ + Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 18, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "name": "f1", + "range": Array [ + 9, + 11, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 0, + 18, + ], + "type": "FunctionDeclaration", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 11, + 13, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 19, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 8, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 11, + ], + "type": "Identifier", + "value": "f1", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 12, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, + 13, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/errorRecovery/empty-type-parameters-in-arrow-function.src 1`] = ` +Object { + "body": Array [ + Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 18, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "name": "f1", + "range": Array [ + 9, + 11, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 0, + 18, + ], + "type": "FunctionDeclaration", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 11, + 13, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 19, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 8, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 11, + ], + "type": "Identifier", + "value": "f1", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 12, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, + 13, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/errorRecovery/empty-type-parameters-in-constructor.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "name": "constructor", + "range": Array [ + 14, + 25, + ], + "type": "Identifier", + }, + "kind": "constructor", + "loc": Object { + "end": Object { + "column": 20, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 14, + 32, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 20, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "range": Array [ + 30, + 32, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 20, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "params": Array [], + "range": Array [ + 25, + 32, + ], + "type": "FunctionExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "params": Array [], + "range": Array [ + 25, + 27, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 34, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 34, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 35, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 14, + 25, + ], + "type": "Identifier", + "value": "constructor", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "range": Array [ + 25, + 26, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 14, + "line": 2, + }, + }, + "range": Array [ + 26, + 27, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 27, + 28, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 28, + 29, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "range": Array [ + 30, + 31, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 2, + }, + "start": Object { + "column": 19, + "line": 2, + }, + }, + "range": Array [ + 31, + 32, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 33, + 34, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/errorRecovery/empty-type-parameters-in-function-expression.src 1`] = ` +Object { + "body": Array [ + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "init": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, + }, + "range": Array [ + 25, + 27, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 12, + 27, + ], + "type": "FunctionExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 20, + 22, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 27, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "const", + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 27, + ], + "type": "VariableDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 28, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, + 20, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Punctuator", + "value": "<", + }, + 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": 23, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "range": Array [ + 22, + 23, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "range": Array [ + 23, + 24, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, + }, + "range": Array [ + 25, + 26, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 26, + "line": 1, + }, + }, + "range": Array [ + 26, + 27, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/errorRecovery/empty-type-parameters-in-method.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "name": "test", + "range": Array [ + 14, + 18, + ], + "type": "Identifier", + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 14, + 25, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "range": Array [ + 23, + 25, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "params": Array [], + "range": Array [ + 18, + 25, + ], + "type": "FunctionExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "params": Array [], + "range": Array [ + 18, + 20, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 27, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 27, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 28, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 14, + 18, + ], + "type": "Identifier", + "value": "test", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "range": Array [ + 19, + 20, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 21, + 22, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "range": Array [ + 23, + 24, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 12, + "line": 2, + }, + }, + "range": Array [ + 24, + 25, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 26, + 27, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/errorRecovery/empty-type-parameters-in-method-signature.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "name": "test", + "range": Array [ + 18, + 22, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "params": Array [], + "range": Array [ + 18, + 27, + ], + "type": "TSMethodSignature", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "params": Array [], + "range": Array [ + 22, + 24, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 29, + ], + "type": "TSInterfaceBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 10, + 13, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 29, + ], + "type": "TSInterfaceDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 30, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 9, + ], + "type": "Keyword", + "value": "interface", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 13, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 18, + 22, + ], + "type": "Identifier", + "value": "test", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 22, + 23, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "range": Array [ + 23, + 24, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 24, + 25, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 25, + 26, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 26, + 27, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 28, + 29, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + exports[`typescript fixtures/errorRecovery/enum-with-keywords.src 1`] = ` Object { "body": Array [ diff --git a/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-arguments-in-call-expression.src.ts b/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-arguments-in-call-expression.src.ts new file mode 100644 index 000000000000..8370eae3584f --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-arguments-in-call-expression.src.ts @@ -0,0 +1 @@ +foo<>(); diff --git a/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-arguments-in-new-expression.src.ts b/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-arguments-in-new-expression.src.ts new file mode 100644 index 000000000000..58900f001ee1 --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-arguments-in-new-expression.src.ts @@ -0,0 +1 @@ +new Foo<>() diff --git a/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-arrow-function.src.ts b/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-arrow-function.src.ts new file mode 100644 index 000000000000..1dbabedb798c --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-arrow-function.src.ts @@ -0,0 +1 @@ +function f1<>() {} diff --git a/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-constructor.src.ts b/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-constructor.src.ts new file mode 100644 index 000000000000..1c24174dfb9d --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-constructor.src.ts @@ -0,0 +1,3 @@ +class foo { + constructor<>() {} +} diff --git a/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-function-expression.src.ts b/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-function-expression.src.ts new file mode 100644 index 000000000000..97b3b1bd5b97 --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-function-expression.src.ts @@ -0,0 +1 @@ +const foo = function<>() {} diff --git a/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-method-signature.src.ts b/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-method-signature.src.ts new file mode 100644 index 000000000000..266c7827325d --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-method-signature.src.ts @@ -0,0 +1,3 @@ +interface foo { + test<>(); +} diff --git a/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-method.src.ts b/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-method.src.ts new file mode 100644 index 000000000000..5544096856d7 --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters-in-method.src.ts @@ -0,0 +1,3 @@ +class foo { + test<>() {} +} diff --git a/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters.src.ts b/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters.src.ts new file mode 100644 index 000000000000..1dbabedb798c --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/errorRecovery/empty-type-parameters.src.ts @@ -0,0 +1 @@ +function f1<>() {} diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index eb2e69a60ece..da34cb8e7d8a 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -690,7 +690,7 @@ export class Converter { } // Process typeParameters - if (node.typeParameters && node.typeParameters.length) { + if (node.typeParameters) { result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( node.typeParameters ); @@ -897,7 +897,7 @@ export class Converter { } // Process typeParameters - if (node.typeParameters && node.typeParameters.length) { + if (node.typeParameters) { method.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( node.typeParameters ); @@ -1003,7 +1003,7 @@ export class Converter { }); // Process typeParameters - if (node.typeParameters && node.typeParameters.length) { + if (node.typeParameters) { constructor.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( node.typeParameters ); @@ -1060,7 +1060,7 @@ export class Converter { } // Process typeParameters - if (node.typeParameters && node.typeParameters.length) { + if (node.typeParameters) { result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( node.typeParameters ); @@ -1159,7 +1159,7 @@ export class Converter { } // Process typeParameters - if (node.typeParameters && node.typeParameters.length) { + if (node.typeParameters) { result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( node.typeParameters ); @@ -1368,7 +1368,7 @@ export class Converter { } } - if (node.typeParameters && node.typeParameters.length) { + if (node.typeParameters) { result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( node.typeParameters ); @@ -1640,7 +1640,7 @@ export class Converter { callee: this.convertChild(node.expression), arguments: node.arguments.map(el => this.convertChild(el)) }); - if (node.typeArguments && node.typeArguments.length) { + if (node.typeArguments) { result.typeParameters = this.convertTypeArgumentsToTypeParameters( node.typeArguments ); @@ -1656,7 +1656,7 @@ export class Converter { ? node.arguments.map(el => this.convertChild(el)) : [] }); - if (node.typeArguments && node.typeArguments.length) { + if (node.typeArguments) { result.typeParameters = this.convertTypeArgumentsToTypeParameters( node.typeArguments ); @@ -2060,7 +2060,7 @@ export class Converter { } // Process typeParameters - if (node.typeParameters && node.typeParameters.length) { + if (node.typeParameters) { result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( node.typeParameters ); @@ -2216,7 +2216,7 @@ export class Converter { expression: this.convertChild(node.expression) }); - if (node.typeArguments && node.typeArguments.length) { + if (node.typeArguments) { result.typeParameters = this.convertTypeArgumentsToTypeParameters( node.typeArguments ); @@ -2236,7 +2236,7 @@ export class Converter { id: this.convertChild(node.name) }); - if (node.typeParameters && node.typeParameters.length) { + if (node.typeParameters) { result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration( node.typeParameters ); diff --git a/packages/typescript-estree/tests/ast-alignment/utils.ts b/packages/typescript-estree/tests/ast-alignment/utils.ts index f00b7d9ad16b..3b9cdfd087c9 100644 --- a/packages/typescript-estree/tests/ast-alignment/utils.ts +++ b/packages/typescript-estree/tests/ast-alignment/utils.ts @@ -262,7 +262,10 @@ export function preprocessBabylonAST(ast: any): any { /** * babel issue: ranges of typeParameters are not included in FunctionExpression range */ - if (node.typeParameters) { + if ( + node.typeParameters && + node.typeParameters.range[0] < node.range[0] + ) { node.range[0] = node.typeParameters.range[0]; node.loc.start = Object.assign({}, node.typeParameters.loc.start); } diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap index cfc83e85d3c2..45c5544625ef 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap @@ -2075,6 +2075,22 @@ Object { exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-arguments.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-arguments-in-call-expression.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-arguments-in-new-expression.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-arrow-function.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-constructor.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-function-expression.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-method.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-method-signature.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/enum-with-keywords.src 1`] = ` Object { "column": 7, diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index d1040b3b2957..38bc1e93b184 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -91539,6 +91539,2282 @@ Object { } `; +exports[`typescript fixtures/errorRecovery/empty-type-arguments-in-call-expression.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 0, + 3, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 7, + ], + "type": "CallExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 3, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 3, + 5, + ], + "type": "TSTypeParameterInstantiation", + }, + }, + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 8, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 9, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 3, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 3, + "line": 1, + }, + }, + "range": Array [ + 3, + 4, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 5, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 6, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 7, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 8, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/errorRecovery/empty-type-arguments-in-new-expression.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "name": "Foo", + "range": Array [ + 4, + 7, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 11, + ], + "type": "NewExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 7, + 9, + ], + "type": "TSTypeParameterInstantiation", + }, + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 11, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 12, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 3, + ], + "type": "Keyword", + "value": "new", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 7, + ], + "type": "Identifier", + "value": "Foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 8, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "range": Array [ + 8, + 9, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 10, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": ")", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/errorRecovery/empty-type-parameters.src 1`] = ` +Object { + "body": Array [ + Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 18, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "name": "f1", + "range": Array [ + 9, + 11, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 0, + 18, + ], + "type": "FunctionDeclaration", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 11, + 13, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 19, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 8, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 11, + ], + "type": "Identifier", + "value": "f1", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 12, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, + 13, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/errorRecovery/empty-type-parameters-in-arrow-function.src 1`] = ` +Object { + "body": Array [ + Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 18, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "name": "f1", + "range": Array [ + 9, + 11, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 0, + 18, + ], + "type": "FunctionDeclaration", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 11, + 13, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 19, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 8, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 11, + ], + "type": "Identifier", + "value": "f1", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 12, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, + 13, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/errorRecovery/empty-type-parameters-in-constructor.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "name": "constructor", + "range": Array [ + 14, + 25, + ], + "type": "Identifier", + }, + "kind": "constructor", + "loc": Object { + "end": Object { + "column": 20, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 14, + 32, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 20, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "range": Array [ + 30, + 32, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 20, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "params": Array [], + "range": Array [ + 25, + 32, + ], + "type": "FunctionExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "params": Array [], + "range": Array [ + 25, + 27, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 34, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 34, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 35, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 14, + 25, + ], + "type": "Identifier", + "value": "constructor", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "range": Array [ + 25, + 26, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 14, + "line": 2, + }, + }, + "range": Array [ + 26, + 27, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 27, + 28, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 28, + 29, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "range": Array [ + 30, + 31, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 2, + }, + "start": Object { + "column": 19, + "line": 2, + }, + }, + "range": Array [ + 31, + 32, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 33, + 34, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/errorRecovery/empty-type-parameters-in-function-expression.src 1`] = ` +Object { + "body": Array [ + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "init": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, + }, + "range": Array [ + 25, + 27, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 12, + 27, + ], + "type": "FunctionExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 20, + 22, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 27, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "const", + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 27, + ], + "type": "VariableDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 28, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, + 20, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Punctuator", + "value": "<", + }, + 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": 23, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "range": Array [ + 22, + 23, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "range": Array [ + 23, + 24, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, + }, + "range": Array [ + 25, + 26, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 26, + "line": 1, + }, + }, + "range": Array [ + 26, + 27, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/errorRecovery/empty-type-parameters-in-method.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "name": "test", + "range": Array [ + 14, + 18, + ], + "type": "Identifier", + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 14, + 25, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "range": Array [ + 23, + 25, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "params": Array [], + "range": Array [ + 18, + 25, + ], + "type": "FunctionExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "params": Array [], + "range": Array [ + 18, + 20, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 27, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 27, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 28, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 14, + 18, + ], + "type": "Identifier", + "value": "test", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "range": Array [ + 19, + 20, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 21, + 22, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "range": Array [ + 23, + 24, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 12, + "line": 2, + }, + }, + "range": Array [ + 24, + 25, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 26, + 27, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/errorRecovery/empty-type-parameters-in-method-signature.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "name": "test", + "range": Array [ + 18, + 22, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "params": Array [], + "range": Array [ + 18, + 27, + ], + "type": "TSMethodSignature", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "params": Array [], + "range": Array [ + 22, + 24, + ], + "type": "TSTypeParameterDeclaration", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 29, + ], + "type": "TSInterfaceBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "name": "foo", + "range": Array [ + 10, + 13, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 29, + ], + "type": "TSInterfaceDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 30, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 9, + ], + "type": "Keyword", + "value": "interface", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 13, + ], + "type": "Identifier", + "value": "foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 18, + 22, + ], + "type": "Identifier", + "value": "test", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 22, + 23, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "range": Array [ + 23, + 24, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 24, + 25, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 25, + 26, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 26, + 27, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 28, + 29, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + exports[`typescript fixtures/errorRecovery/enum-with-keywords.src 1`] = ` Object { "body": Array [ From 7cd3bc2933bdda8239785a53f519127e0d082059 Mon Sep 17 00:00:00 2001 From: Armano Date: Thu, 7 Feb 2019 02:18:31 +0100 Subject: [PATCH 18/26] refactor(parser): add ast types to parser (#205) --- packages/eslint-plugin-tslint/src/index.ts | 10 +- packages/parser/package.json | 1 - packages/parser/src/analyze-scope.ts | 279 ++++++------- .../src/{typings.d.ts => eslint-scope.d.ts} | 275 ++++++------- packages/parser/src/parser.ts | 10 +- .../typescript-estree/src/convert-comments.ts | 18 +- packages/typescript-estree/src/convert.ts | 366 +++++++++--------- packages/typescript-estree/src/node-utils.ts | 25 +- .../typescript-estree/src/parser-options.ts | 14 +- packages/typescript-estree/src/parser.ts | 18 +- packages/typescript-estree/src/ts-estree.ts | 2 + packages/typescript-estree/src/typedefs.ts | 2 +- .../tests/lib/semanticInfo.ts | 8 +- yarn.lock | 2 +- 14 files changed, 492 insertions(+), 538 deletions(-) rename packages/parser/src/{typings.d.ts => eslint-scope.d.ts} (57%) create mode 100644 packages/typescript-estree/src/ts-estree.ts diff --git a/packages/eslint-plugin-tslint/src/index.ts b/packages/eslint-plugin-tslint/src/index.ts index 78e946af6294..f2ae0e55efd3 100644 --- a/packages/eslint-plugin-tslint/src/index.ts +++ b/packages/eslint-plugin-tslint/src/index.ts @@ -3,20 +3,12 @@ import memoize from 'lodash.memoize'; import { Configuration, RuleSeverity } from 'tslint'; import { Program } from 'typescript'; import { CustomLinter } from './custom-linter'; +import { ParserServices } from '@typescript-eslint/typescript-estree'; //------------------------------------------------------------------------------ // Plugin Definition //------------------------------------------------------------------------------ -/** - * @todo share types between packages - */ -interface ParserServices { - program: Program | undefined; - esTreeNodeToTSNodeMap: WeakMap | undefined; - tsNodeToESTreeNodeMap: WeakMap | undefined; -} - type RawRuleConfig = | null | undefined diff --git a/packages/parser/package.json b/packages/parser/package.json index 26de602491a7..8cadc1c74159 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -43,7 +43,6 @@ "devDependencies": { "@types/eslint": "^4.16.5", "@types/eslint-visitor-keys": "^1.0.0", - "@types/estree": "^0.0.39", "@typescript-eslint/shared-fixtures": "1.2.0" } } diff --git a/packages/parser/src/analyze-scope.ts b/packages/parser/src/analyze-scope.ts index 2e8ae2e0a3cd..f3a6b5f78ac1 100644 --- a/packages/parser/src/analyze-scope.ts +++ b/packages/parser/src/analyze-scope.ts @@ -11,7 +11,7 @@ import { PatternVisitorCallback, PatternVisitorOptions } from 'eslint-scope/lib/options'; -import { Node } from 'estree'; +import { TSESTree } from '@typescript-eslint/typescript-estree'; /** * Define the override function of `Scope#__define` for global augmentation. @@ -35,7 +35,7 @@ class EnumScope extends Scope { constructor( scopeManager: ScopeManager, upperScope: Scope, - block: Node | null + block: TSESTree.Node | null ) { // @ts-ignore super(scopeManager, 'enum', upperScope, block, false); @@ -51,7 +51,7 @@ class PatternVisitor extends OriginalPatternVisitor { super(options, rootPattern, callback); } - Identifier(node: any) { + Identifier(node: TSESTree.Identifier): void { super.Identifier(node); if (node.decorators) { this.rightHandNodes.push(...node.decorators); @@ -61,7 +61,7 @@ class PatternVisitor extends OriginalPatternVisitor { } } - ArrayPattern(node: any) { + ArrayPattern(node: TSESTree.ArrayPattern): void { node.elements.forEach(this.visit, this); if (node.decorators) { this.rightHandNodes.push(...node.decorators); @@ -71,7 +71,7 @@ class PatternVisitor extends OriginalPatternVisitor { } } - ObjectPattern(node: any) { + ObjectPattern(node: TSESTree.ObjectPattern): void { node.properties.forEach(this.visit, this); if (node.decorators) { this.rightHandNodes.push(...node.decorators); @@ -81,8 +81,11 @@ class PatternVisitor extends OriginalPatternVisitor { } } - RestElement(node: any) { + RestElement(node: TSESTree.RestElement): void { super.RestElement(node); + if (node.decorators) { + this.rightHandNodes.push(...node.decorators); + } if (node.typeAnnotation) { this.rightHandNodes.push(node.typeAnnotation); } @@ -99,16 +102,15 @@ class Referencer extends OriginalReferencer { /** * Override to use PatternVisitor we overrode. - * @param {Identifier} node The Identifier node to visit. - * @param {Object} [options] The flag to visit right-hand side nodes. - * @param {Function} callback The callback function for left-hand side nodes. - * @returns {void} + * @param node The Identifier node to visit. + * @param [options] The flag to visit right-hand side nodes. + * @param callback The callback function for left-hand side nodes. */ - visitPattern( - node: any, + visitPattern( + node: T, options: PatternVisitorOptions, callback: PatternVisitorCallback - ) { + ): void { if (!node) { return; } @@ -130,10 +132,14 @@ class Referencer extends OriginalReferencer { /** * Override. * Visit `node.typeParameters` and `node.returnType` additionally to find `typeof` expressions. - * @param {FunctionDeclaration|FunctionExpression|ArrowFunctionExpression} node The function node to visit. - * @returns {void} - */ - visitFunction(node: any) { + * @param node The function node to visit. + */ + visitFunction( + node: + | TSESTree.FunctionDeclaration + | TSESTree.FunctionExpression + | TSESTree.ArrowFunctionExpression + ): void { const { type, id, typeParameters, params, returnType, body } = node; const scopeManager = this.scopeManager; const upperScope = this.currentScope(); @@ -189,7 +195,7 @@ class Referencer extends OriginalReferencer { this.visit(returnType); // Process the body. - if (body.type === 'BlockStatement') { + if (body && body.type === 'BlockStatement') { this.visitChildren(body); } else { this.visit(body); @@ -202,10 +208,9 @@ class Referencer extends OriginalReferencer { /** * Override. * Visit decorators. - * @param {ClassDeclaration|ClassExpression} node The class node to visit. - * @returns {void} + * @param node The class node to visit. */ - visitClass(node: any) { + visitClass(node: TSESTree.ClassDeclaration | TSESTree.ClassExpression): void { this.visitDecorators(node.decorators); const upperTypeMode = this.typeMode; @@ -214,7 +219,7 @@ class Referencer extends OriginalReferencer { this.visit(node.superTypeParameters); } if (node.implements) { - this.visit(node.implements); + node.implements.forEach(this.visit, this); } this.typeMode = upperTypeMode; @@ -223,10 +228,13 @@ class Referencer extends OriginalReferencer { /** * Visit typeParameters. - * @param {*} node The node to visit. - * @returns {void} + * @param node The node to visit. */ - visitTypeParameters(node: any) { + visitTypeParameters(node: { + typeParameters?: + | TSESTree.TSTypeParameterDeclaration + | TSESTree.TSTypeParameterInstantiation; + }): void { if (node.typeParameters) { const upperTypeMode = this.typeMode; this.typeMode = true; @@ -238,7 +246,7 @@ class Referencer extends OriginalReferencer { /** * Override. */ - JSXOpeningElement(node: any) { + JSXOpeningElement(node: TSESTree.JSXOpeningElement): void { this.visit(node.name); this.visitTypeParameters(node); node.attributes.forEach(this.visit, this); @@ -247,10 +255,9 @@ class Referencer extends OriginalReferencer { /** * Override. * Don't create the reference object in the type mode. - * @param {Identifier} node The Identifier node to visit. - * @returns {void} + * @param node The Identifier node to visit. */ - Identifier(node: any) { + Identifier(node: TSESTree.Identifier): void { this.visitDecorators(node.decorators); if (!this.typeMode) { @@ -263,20 +270,22 @@ class Referencer extends OriginalReferencer { /** * Override. * Visit decorators. - * @param {MethodDefinition} node The MethodDefinition node to visit. - * @returns {void} + * @param node The MethodDefinition node to visit. */ - MethodDefinition(node: any) { + MethodDefinition( + node: TSESTree.MethodDefinition | TSESTree.TSAbstractMethodDefinition + ): void { this.visitDecorators(node.decorators); super.MethodDefinition(node); } /** * Don't create the reference object for the key if not computed. - * @param {ClassProperty} node The ClassProperty node to visit. - * @returns {void} + * @param node The ClassProperty node to visit. */ - ClassProperty(node: any) { + ClassProperty( + node: TSESTree.ClassProperty | TSESTree.TSAbstractClassProperty + ): void { const upperTypeMode = this.typeMode; const { computed, decorators, key, typeAnnotation, value } = node; @@ -295,39 +304,34 @@ class Referencer extends OriginalReferencer { /** * Visit new expression. - * @param {NewExpression} node The NewExpression node to visit. - * @returns {void} + * @param node The NewExpression node to visit. */ - NewExpression(node: any) { + NewExpression(node: TSESTree.NewExpression): void { this.visitTypeParameters(node); this.visit(node.callee); - if (node.arguments) { - node.arguments.forEach(this.visit, this); - } + + node.arguments.forEach(this.visit, this); } /** * Override. * Visit call expression. - * @param {CallExpression} node The CallExpression node to visit. - * @returns {void} + * @param node The CallExpression node to visit. */ - CallExpression(node: any) { + CallExpression(node: TSESTree.CallExpression): void { this.visitTypeParameters(node); this.visit(node.callee); - if (node.arguments) { - node.arguments.forEach(this.visit, this); - } + + node.arguments.forEach(this.visit, this); } /** * Define the variable of this function declaration only once. * Because to avoid confusion of `no-redeclare` rule by overloading. - * @param {TSDeclareFunction} node The TSDeclareFunction node to visit. - * @returns {void} + * @param node The TSDeclareFunction node to visit. */ - TSDeclareFunction(node: any) { + TSDeclareFunction(node: TSESTree.TSDeclareFunction): void { const upperTypeMode = this.typeMode; const scope = this.currentScope(); const { id, typeParameters, params, returnType } = node; @@ -355,10 +359,9 @@ class Referencer extends OriginalReferencer { /** * Create reference objects for the references in parameters and return type. - * @param {TSEmptyBodyFunctionExpression} node The TSEmptyBodyFunctionExpression node to visit. - * @returns {void} + * @param node The TSEmptyBodyFunctionExpression node to visit. */ - TSEmptyBodyFunctionExpression(node: any) { + TSEmptyBodyFunctionExpression(node: TSESTree.FunctionExpression): void { const upperTypeMode = this.typeMode; const { typeParameters, params, returnType } = node; @@ -372,39 +375,35 @@ class Referencer extends OriginalReferencer { /** * 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 {TSInterfaceDeclaration} node The TSInterfaceDeclaration node to visit. - * @returns {void} + * @param node The TSInterfaceDeclaration node to visit. */ - TSInterfaceDeclaration(node: any) { + TSInterfaceDeclaration(node: TSESTree.TSInterfaceDeclaration): void { 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} + * @param node The TSClassImplements node to visit. */ - TSClassImplements(node: any) { + TSClassImplements(node: TSESTree.TSClassImplements): void { 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} + * @param node The TSIndexSignature node to visit. */ - TSIndexSignature(node: any) { + TSIndexSignature(node: TSESTree.TSIndexSignature): void { this.visitTypeNodes(node); } /** * Visit type assertion. - * @param {TSTypeAssertion} node The TSTypeAssertion node to visit. - * @returns {void} + * @param node The TSTypeAssertion node to visit. */ - TSTypeAssertion(node: any) { + TSTypeAssertion(node: TSESTree.TSTypeAssertion): void { if (this.typeMode) { this.visit(node.typeAnnotation); } else { @@ -418,10 +417,9 @@ class Referencer extends OriginalReferencer { /** * Visit as expression. - * @param {TSAsExpression} node The TSAsExpression node to visit. - * @returns {void} + * @param node The TSAsExpression node to visit. */ - TSAsExpression(node: any) { + TSAsExpression(node: TSESTree.TSAsExpression): void { this.visit(node.expression); if (this.typeMode) { @@ -435,28 +433,25 @@ class Referencer extends OriginalReferencer { /** * 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. - * @returns {void} + * @param node The TSTypeAnnotation node to visit. */ - TSTypeAnnotation(node: any) { + TSTypeAnnotation(node: TSESTree.TSTypeAnnotation): void { this.visitTypeNodes(node); } /** * Switch to the type mode and visit child nodes to find `typeof x` expression in type declarations. - * @param {TSTypeParameterDeclaration} node The TSTypeParameterDeclaration node to visit. - * @returns {void} + * @param node The TSTypeParameterDeclaration node to visit. */ - TSTypeParameterDeclaration(node: any) { + TSTypeParameterDeclaration(node: TSESTree.TSTypeParameterDeclaration): void { this.visitTypeNodes(node); } /** * Create reference objects for the references in `typeof` expression. - * @param {TSTypeQuery} node The TSTypeQuery node to visit. - * @returns {void} + * @param node The TSTypeQuery node to visit. */ - TSTypeQuery(node: any) { + TSTypeQuery(node: TSESTree.TSTypeQuery): void { if (this.typeMode) { this.typeMode = false; this.visitChildren(node); @@ -467,124 +462,109 @@ class Referencer extends OriginalReferencer { } /** - * @param {TSTypeParameter} node The TSTypeParameter node to visit. - * @returns {void} + * @param node The TSTypeParameter node to visit. */ - TSTypeParameter(node: any) { + TSTypeParameter(node: TSESTree.TSTypeParameter): void { this.visitTypeNodes(node); } /** - * @param {TSInferType} node The TSInferType node to visit. - * @returns {void} + * @param node The TSInferType node to visit. */ - TSInferType(node: any) { + TSInferType(node: TSESTree.TSInferType): void { this.visitTypeNodes(node); } /** - * @param {TSTypeReference} node The TSTypeReference node to visit. - * @returns {void} + * @param node The TSTypeReference node to visit. */ - TSTypeReference(node: any) { + TSTypeReference(node: TSESTree.TSTypeReference): void { this.visitTypeNodes(node); } /** - * @param {TSTypeLiteral} node The TSTypeLiteral node to visit. - * @returns {void} + * @param node The TSTypeLiteral node to visit. */ - TSTypeLiteral(node: any) { + TSTypeLiteral(node: TSESTree.TSTypeLiteral): void { this.visitTypeNodes(node); } /** - * @param {TSLiteralType} node The TSLiteralType node to visit. - * @returns {void} + * @param node The TSLiteralType node to visit. */ - TSLiteralType(node: any) { + TSLiteralType(node: TSESTree.TSLiteralType): void { this.visitTypeNodes(node); } /** - * @param {TSIntersectionType} node The TSIntersectionType node to visit. - * @returns {void} + * @param node The TSIntersectionType node to visit. */ - TSIntersectionType(node: any) { + TSIntersectionType(node: TSESTree.TSIntersectionType): void { this.visitTypeNodes(node); } /** - * @param {TSConditionalType} node The TSConditionalType node to visit. - * @returns {void} + * @param node The TSConditionalType node to visit. */ - TSConditionalType(node: any) { + TSConditionalType(node: TSESTree.TSConditionalType): void { this.visitTypeNodes(node); } /** - * @param {TSIndexedAccessType} node The TSIndexedAccessType node to visit. - * @returns {void} + * @param node The TSIndexedAccessType node to visit. */ - TSIndexedAccessType(node: any) { + TSIndexedAccessType(node: TSESTree.TSIndexedAccessType): void { this.visitTypeNodes(node); } /** - * @param {TSMappedType} node The TSMappedType node to visit. - * @returns {void} + * @param node The TSMappedType node to visit. */ - TSMappedType(node: any) { + TSMappedType(node: TSESTree.TSMappedType): void { this.visitTypeNodes(node); } /** - * @param {TSOptionalType} node The TSOptionalType node to visit. - * @returns {void} + * @param node The TSOptionalType node to visit. */ - TSOptionalType(node: any) { + TSOptionalType(node: TSESTree.TSOptionalType): void { this.visitTypeNodes(node); } /** - * @param {TSParenthesizedType} node The TSParenthesizedType node to visit. - * @returns {void} + * @param node The TSParenthesizedType node to visit. */ - TSParenthesizedType(node: any) { + TSParenthesizedType(node: TSESTree.TSParenthesizedType): void { this.visitTypeNodes(node); } /** - * @param {TSRestType} node The TSRestType node to visit. - * @returns {void} + * @param node The TSRestType node to visit. */ - TSRestType(node: any) { + TSRestType(node: TSESTree.TSRestType): void { this.visitTypeNodes(node); } /** - * @param {TSTupleType} node The TSTupleType node to visit. - * @returns {void} + * @param node The TSTupleType node to visit. */ - TSTupleType(node: any) { + TSTupleType(node: TSESTree.TSTupleType): void { this.visitTypeNodes(node); } /** * Create reference objects for the object part. (This is `obj.prop`) - * @param {TSQualifiedName} node The TSQualifiedName node to visit. - * @returns {void} + * @param node The TSQualifiedName node to visit. */ - TSQualifiedName(node: any) { + TSQualifiedName(node: TSESTree.TSQualifiedName): void { this.visit(node.left); } /** * Create reference objects for the references in computed keys. - * @param {TSPropertySignature} node The TSPropertySignature node to visit. - * @returns {void} + * @param node The TSPropertySignature node to visit. */ - TSPropertySignature(node: any) { + TSPropertySignature(node: TSESTree.TSPropertySignature): void { const upperTypeMode = this.typeMode; const { computed, key, typeAnnotation, initializer } = node; @@ -604,10 +584,9 @@ class Referencer extends OriginalReferencer { /** * Create reference objects for the references in computed keys. - * @param {TSMethodSignature} node The TSMethodSignature node to visit. - * @returns {void} + * @param node The TSMethodSignature node to visit. */ - TSMethodSignature(node: any) { + TSMethodSignature(node: TSESTree.TSMethodSignature): void { const upperTypeMode = this.typeMode; const { computed, key, typeParameters, params, returnType } = node; @@ -641,10 +620,9 @@ class Referencer extends OriginalReferencer { * A = a // a is above constant. * } * - * @param {TSEnumDeclaration} node The TSEnumDeclaration node to visit. - * @returns {void} + * @param node The TSEnumDeclaration node to visit. */ - TSEnumDeclaration(node: any) { + TSEnumDeclaration(node: TSESTree.TSEnumDeclaration): void { const { id, members } = node; const scopeManager = this.scopeManager; const scope = this.currentScope(); @@ -664,10 +642,9 @@ class Referencer extends OriginalReferencer { * Create variable object for the enum member and create reference object for the initializer. * And visit the initializer. * - * @param {TSEnumMember} node The TSEnumMember node to visit. - * @returns {void} + * @param node The TSEnumMember node to visit. */ - TSEnumMember(node: any) { + TSEnumMember(node: TSESTree.TSEnumMember): void { const { id, initializer } = node; const scope = this.currentScope(); @@ -680,10 +657,9 @@ class Referencer extends OriginalReferencer { /** * Create the variable object for the module name, and visit children. - * @param {TSModuleDeclaration} node The TSModuleDeclaration node to visit. - * @returns {void} + * @param node The TSModuleDeclaration node to visit. */ - TSModuleDeclaration(node: any) { + TSModuleDeclaration(node: TSESTree.TSModuleDeclaration): void { const scope = this.currentScope(); const { id, body } = node; @@ -701,7 +677,7 @@ class Referencer extends OriginalReferencer { this.visit(body); } - TSTypeAliasDeclaration(node: any) { + TSTypeAliasDeclaration(node: TSESTree.TSTypeAliasDeclaration): void { this.typeMode = true; this.visitChildren(node); this.typeMode = false; @@ -709,28 +685,26 @@ class Referencer extends OriginalReferencer { /** * Process the module block. - * @param {TSModuleBlock} node The TSModuleBlock node to visit. - * @returns {void} + * @param node The TSModuleBlock node to visit. */ - TSModuleBlock(node: any) { + TSModuleBlock(node: TSESTree.TSModuleBlock): void { this.scopeManager.__nestBlockScope(node); this.visitChildren(node); this.close(node); } - TSAbstractClassProperty(node: any) { + TSAbstractClassProperty(node: TSESTree.TSAbstractClassProperty): void { this.ClassProperty(node); } - TSAbstractMethodDefinition(node: any) { + TSAbstractMethodDefinition(node: TSESTree.TSAbstractMethodDefinition): void { this.MethodDefinition(node); } /** * Process import equal declaration - * @param {TSImportEqualsDeclaration} node The TSImportEqualsDeclaration node to visit. - * @returns {void} + * @param node The TSImportEqualsDeclaration node to visit. */ - TSImportEqualsDeclaration(node: any) { + TSImportEqualsDeclaration(node: TSESTree.TSImportEqualsDeclaration): void { const { id, moduleReference } = node; if (id && id.type === 'Identifier') { this.currentScope().__define( @@ -745,10 +719,9 @@ class Referencer extends OriginalReferencer { * Process the global augmentation. * 1. Set the global scope as the current scope. * 2. Configure the global scope to set `variable.eslintUsed = true` for all defined variables. This means `no-unused-vars` doesn't warn those. - * @param {TSModuleDeclaration} node The TSModuleDeclaration node to visit. - * @returns {void} + * @param node The TSModuleDeclaration node to visit. */ - visitGlobalAugmentation(node: any) { + visitGlobalAugmentation(node: TSESTree.TSModuleDeclaration): void { const scopeManager = this.scopeManager; const currentScope = this.currentScope(); const globalScope = scopeManager.globalScope; @@ -758,8 +731,8 @@ class Referencer extends OriginalReferencer { scopeManager.__currentScope = globalScope; // Skip TSModuleBlock to avoid to create that block scope. - for (const moduleItem of node.body.body) { - this.visit(moduleItem); + if (node.body && node.body.type === 'TSModuleBlock') { + node.body.body.forEach(this.visit, this); } scopeManager.__currentScope = currentScope; @@ -768,10 +741,9 @@ class Referencer extends OriginalReferencer { /** * Process decorators. - * @param {Decorator[]|undefined} decorators The decorator nodes to visit. - * @returns {void} + * @param decorators The decorator nodes to visit. */ - visitDecorators(decorators?: any[]) { + visitDecorators(decorators?: TSESTree.Decorator[]): void { if (decorators) { decorators.forEach(this.visit, this); } @@ -779,10 +751,9 @@ class Referencer extends OriginalReferencer { /** * Process all child of type nodes - * @param {any} node node to be processed - * @returns {void} + * @param node node to be processed */ - visitTypeNodes(node: any) { + visitTypeNodes(node: TSESTree.Node): void { if (this.typeMode) { this.visitChildren(node); } else { diff --git a/packages/parser/src/typings.d.ts b/packages/parser/src/eslint-scope.d.ts similarity index 57% rename from packages/parser/src/typings.d.ts rename to packages/parser/src/eslint-scope.d.ts index 08f92526c823..28de7f8c759e 100644 --- a/packages/parser/src/typings.d.ts +++ b/packages/parser/src/eslint-scope.d.ts @@ -2,6 +2,7 @@ // Project: http://github.com/eslint/eslint-scope // Definitions by: Armano declare module 'eslint-scope/lib/options' { + import { TSESTree } from '@typescript-eslint/typescript-estree'; export type PatternVisitorCallback = (pattern: any, info: any) => void; export interface PatternVisitorOptions { @@ -9,76 +10,75 @@ declare module 'eslint-scope/lib/options' { } export abstract class Visitor { - visitChildren(node: Node): void; - visit(node: Node): void; + visitChildren( + node?: T + ): void; + visit(node?: T): void; } } declare module 'eslint-scope/lib/variable' { - import * as eslint from 'eslint'; - import { Identifier } from 'estree'; + import { TSESTree } from '@typescript-eslint/typescript-estree'; import Reference from 'eslint-scope/lib/reference'; + import { Definition } from 'eslint-scope/lib/definition'; - class Variable implements eslint.Scope.Variable { + export default class Variable { name: string; - identifiers: Identifier[]; + identifiers: TSESTree.Identifier[]; references: Reference[]; - defs: eslint.Scope.Definition[]; + defs: Definition[]; } - export default Variable; } declare module 'eslint-scope/lib/definition' { - import { Identifier, Node } from 'estree'; + import { TSESTree } from '@typescript-eslint/typescript-estree'; - class Definition { + export class Definition { type: string; - name: Identifier; - node: Node; - parent?: Node | null; + name: TSESTree.BindingName; + node: TSESTree.Node; + parent?: TSESTree.Node | null; index?: number | null; kind?: string | null; constructor( type: string, - name: Identifier, - node: Node, - parent?: Node | null, + name: TSESTree.BindingName | TSESTree.PropertyName, + node: TSESTree.Node, + parent?: TSESTree.Node | null, index?: number | null, kind?: string | null ); } - class ParameterDefinition extends Definition { + export class ParameterDefinition extends Definition { rest?: boolean; constructor( - name: Identifier, - node: Node, + name: TSESTree.BindingName | TSESTree.PropertyName, + node: TSESTree.Node, index?: number | null, rest?: boolean ); } - - export { ParameterDefinition, Definition }; } declare module 'eslint-scope/lib/pattern-visitor' { import ScopeManager from 'eslint-scope/lib/scope-manager'; - import { Node } from 'estree'; + import { TSESTree } from '@typescript-eslint/typescript-estree'; import { PatternVisitorCallback, PatternVisitorOptions, Visitor } from 'eslint-scope/lib/options'; - class PatternVisitor extends Visitor { + export default class PatternVisitor extends Visitor { protected options: any; protected scopeManager: ScopeManager; - protected parent?: Node; - public rightHandNodes: Node[]; + protected parent?: TSESTree.Node; + public rightHandNodes: TSESTree.Node[]; - static isPattern(node: Node): boolean; + static isPattern(node: TSESTree.Node): boolean; constructor( options: PatternVisitorOptions, @@ -86,41 +86,39 @@ declare module 'eslint-scope/lib/pattern-visitor' { callback: PatternVisitorCallback ); - Identifier(pattern: Node): void; - Property(property: Node): void; - ArrayPattern(pattern: Node): void; - AssignmentPattern(pattern: Node): void; - RestElement(pattern: Node): void; - MemberExpression(node: Node): void; - SpreadElement(node: Node): void; - ArrayExpression(node: Node): void; - AssignmentExpression(node: Node): void; - CallExpression(node: Node): void; + Identifier(pattern: TSESTree.Node): void; + Property(property: TSESTree.Node): void; + ArrayPattern(pattern: TSESTree.Node): void; + AssignmentPattern(pattern: TSESTree.Node): void; + RestElement(pattern: TSESTree.Node): void; + MemberExpression(node: TSESTree.Node): void; + SpreadElement(node: TSESTree.Node): void; + ArrayExpression(node: TSESTree.Node): void; + AssignmentExpression(node: TSESTree.Node): void; + CallExpression(node: TSESTree.Node): void; } - - export default PatternVisitor; } declare module 'eslint-scope/lib/referencer' { import { Scope } from 'eslint-scope/lib/scope'; import ScopeManager from 'eslint-scope/lib/scope-manager'; - import { Node } from 'estree'; + import { TSESTree } from '@typescript-eslint/typescript-estree'; import { PatternVisitorCallback, PatternVisitorOptions, Visitor } from 'eslint-scope/lib/options'; - class Referencer extends Visitor { + export default class Referencer extends Visitor { protected isInnerMethodDefinition: boolean; protected options: any; protected scopeManager: ScopeManager; - protected parent?: Node; + protected parent?: TSESTree.Node; constructor(options: any, scopeManager: ScopeManager); currentScope(): Scope; - close(node: Node): void; + close(node: TSESTree.Node): void; pushInnerMethodDefinition(isInnerMethodDefinition: boolean): boolean; popInnerMethodDefinition(isInnerMethodDefinition: boolean): void; @@ -131,66 +129,63 @@ declare module 'eslint-scope/lib/referencer' { init: boolean ): void; visitPattern( - node: Node, + node: TSESTree.Node, options: PatternVisitorOptions, callback: PatternVisitorCallback ): void; - visitFunction(node: Node): void; - visitClass(node: Node): void; - visitProperty(node: Node): void; - visitForIn(node: Node): void; + visitFunction(node: TSESTree.Node): void; + visitClass(node: TSESTree.Node): void; + visitProperty(node: TSESTree.Node): void; + visitForIn(node: TSESTree.Node): void; visitVariableDeclaration( variableTargetScope: any, type: any, - node: Node, + node: TSESTree.Node, index: any ): void; - AssignmentExpression(node: Node): void; - CatchClause(node: Node): void; - Program(node: Node): void; - Identifier(node: Node): void; - UpdateExpression(node: Node): void; - MemberExpression(node: Node): void; - Property(node: Node): void; - MethodDefinition(node: Node): void; + AssignmentExpression(node: TSESTree.Node): void; + CatchClause(node: TSESTree.Node): void; + Program(node: TSESTree.Node): void; + Identifier(node: TSESTree.Node): void; + UpdateExpression(node: TSESTree.Node): void; + MemberExpression(node: TSESTree.Node): void; + Property(node: TSESTree.Node): void; + MethodDefinition(node: TSESTree.Node): void; BreakStatement(): void; ContinueStatement(): void; - LabeledStatement(node: Node): void; - ForStatement(node: Node): void; - ClassExpression(node: Node): void; - ClassDeclaration(node: Node): void; - CallExpression(node: Node): void; - BlockStatement(node: Node): void; + LabeledStatement(node: TSESTree.Node): void; + ForStatement(node: TSESTree.Node): void; + ClassExpression(node: TSESTree.Node): void; + ClassDeclaration(node: TSESTree.Node): void; + CallExpression(node: TSESTree.Node): void; + BlockStatement(node: TSESTree.Node): void; ThisExpression(): void; - WithStatement(node: Node): void; - VariableDeclaration(node: Node): void; - SwitchStatement(node: Node): void; - FunctionDeclaration(node: Node): void; - FunctionExpression(node: Node): void; - ForOfStatement(node: Node): void; - ForInStatement(node: Node): void; - ArrowFunctionExpression(node: Node): void; - ImportDeclaration(node: Node): void; - visitExportDeclaration(node: Node): void; - ExportDeclaration(node: Node): void; - ExportNamedDeclaration(node: Node): void; - ExportSpecifier(node: Node): void; + WithStatement(node: TSESTree.Node): void; + VariableDeclaration(node: TSESTree.Node): void; + SwitchStatement(node: TSESTree.Node): void; + FunctionDeclaration(node: TSESTree.Node): void; + FunctionExpression(node: TSESTree.Node): void; + ForOfStatement(node: TSESTree.Node): void; + ForInStatement(node: TSESTree.Node): void; + ArrowFunctionExpression(node: TSESTree.Node): void; + ImportDeclaration(node: TSESTree.Node): void; + visitExportDeclaration(node: TSESTree.Node): void; + ExportDeclaration(node: TSESTree.Node): void; + ExportNamedDeclaration(node: TSESTree.Node): void; + ExportSpecifier(node: TSESTree.Node): void; MetaProperty(): void; } - - export default Referencer; } declare module 'eslint-scope/lib/scope' { - import * as eslint from 'eslint'; - import { Node } from 'estree'; + import { TSESTree } from '@typescript-eslint/typescript-estree'; import Reference from 'eslint-scope/lib/reference'; import Variable from 'eslint-scope/lib/variable'; import ScopeManager from 'eslint-scope/lib/scope-manager'; import { Definition } from 'eslint-scope/lib/definition'; - type ScopeType = + export type ScopeType = | 'block' | 'catch' | 'class' @@ -203,13 +198,13 @@ declare module 'eslint-scope/lib/scope' { | 'with' | 'TDZ'; - class Scope implements eslint.Scope.Scope { + export class Scope { type: ScopeType; isStrict: boolean; upper: Scope | null; childScopes: Scope[]; variableScope: Scope; - block: Node; + block: TSESTree.Node; variables: Variable[]; set: Map; references: Reference[]; @@ -221,7 +216,7 @@ declare module 'eslint-scope/lib/scope' { scopeManager: ScopeManager, type: ScopeType, upperScope: Scope | null, - block: Node | null, + block: TSESTree.Node | null, isMethodDefinition: boolean ); @@ -234,7 +229,7 @@ declare module 'eslint-scope/lib/scope' { __isValidResolution(ref: any, variable: any): boolean; __resolve(ref: any): boolean; __delegateToUpperScope(ref: any): void; - __addDeclaredVariablesOfNode(variable: any, node: Node): void; + __addDeclaredVariablesOfNode(variable: any, node: TSESTree.Node): void; __defineGeneric( name: any, set: any, @@ -243,12 +238,12 @@ declare module 'eslint-scope/lib/scope' { def: Definition ): void; - __define(node: Node, def: Definition): void; + __define(node: TSESTree.Node, def: Definition): void; __referencing( - node: Node, + node: TSESTree.Node, assign: number, - writeExpr: Node, + writeExpr: TSESTree.Node, maybeImplicitGlobal: any, partial: any, init: any @@ -263,7 +258,7 @@ declare module 'eslint-scope/lib/scope' { * @param {Espree.Identifier} ident - identifier to be resolved. * @returns {Reference} reference */ - resolve(ident: Node): Reference; + resolve(ident: TSESTree.Node): Reference; /** * returns this scope is static @@ -289,109 +284,94 @@ declare module 'eslint-scope/lib/scope' { isUsedName(name: any): boolean; } - class GlobalScope extends Scope { - constructor(scopeManager: ScopeManager, block: Node | null); + export class GlobalScope extends Scope { + constructor(scopeManager: ScopeManager, block: TSESTree.Node | null); } - class ModuleScope extends Scope { + export class ModuleScope extends Scope { constructor( scopeManager: ScopeManager, upperScope: Scope, - block: Node | null + block: TSESTree.Node | null ); } - class FunctionExpressionNameScope extends Scope { + export class FunctionExpressionNameScope extends Scope { constructor( scopeManager: ScopeManager, upperScope: Scope, - block: Node | null + block: TSESTree.Node | null ); } - class CatchScope extends Scope { + export class CatchScope extends Scope { constructor( scopeManager: ScopeManager, upperScope: Scope, - block: Node | null + block: TSESTree.Node | null ); } - class WithScope extends Scope { + export class WithScope extends Scope { constructor( scopeManager: ScopeManager, upperScope: Scope, - block: Node | null + block: TSESTree.Node | null ); } - class BlockScope extends Scope { + export class BlockScope extends Scope { constructor( scopeManager: ScopeManager, upperScope: Scope, - block: Node | null + block: TSESTree.Node | null ); } - class SwitchScope extends Scope { + export class SwitchScope extends Scope { constructor( scopeManager: ScopeManager, upperScope: Scope, - block: Node | null + block: TSESTree.Node | null ); } - class FunctionScope extends Scope { + export class FunctionScope extends Scope { constructor( scopeManager: ScopeManager, upperScope: Scope, - block: Node | null, + block: TSESTree.Node | null, isMethodDefinition: boolean ); } - class ForScope extends Scope { + export class ForScope extends Scope { constructor( scopeManager: ScopeManager, upperScope: Scope, - block: Node | null + block: TSESTree.Node | null ); } - class ClassScope extends Scope { + export class ClassScope extends Scope { constructor( scopeManager: ScopeManager, upperScope: Scope, - block: Node | null + block: TSESTree.Node | null ); } - - export { - Scope, - GlobalScope, - ModuleScope, - FunctionExpressionNameScope, - CatchScope, - WithScope, - BlockScope, - SwitchScope, - FunctionScope, - ForScope, - ClassScope - }; } declare module 'eslint-scope/lib/reference' { - import * as eslint from 'eslint'; - import { Identifier, Node } from 'estree'; + import { TSESTree } from '@typescript-eslint/typescript-estree'; import { Scope } from 'eslint-scope/lib/scope'; import Variable from 'eslint-scope/lib/variable'; - class Reference implements eslint.Scope.Reference { - identifier: Identifier; + export default class Reference { + identifier: TSESTree.Identifier; from: Scope; resolved: Variable | null; - writeExpr: Node | null; + writeExpr: TSESTree.Node | null; init: boolean; isWrite(): boolean; @@ -404,15 +384,14 @@ declare module 'eslint-scope/lib/reference' { static WRITE: 0x2; static RW: 0x3; } - export default Reference; } declare module 'eslint-scope/lib/scope-manager' { - import * as eslint from 'eslint'; + import { TSESTree } from '@typescript-eslint/typescript-estree'; import { Scope } from 'eslint-scope/lib/scope'; import Variable from 'eslint-scope/lib/variable'; - interface ScopeManagerOptions { + export interface ScopeManagerOptions { directive?: boolean; optimistic?: boolean; ignoreEval?: boolean; @@ -422,7 +401,7 @@ declare module 'eslint-scope/lib/scope-manager' { ecmaVersion?: number; } - class ScopeManager implements eslint.Scope.ScopeManager { + export default class ScopeManager { __options: ScopeManagerOptions; __currentScope: Scope; scopes: Scope[]; @@ -439,29 +418,31 @@ declare module 'eslint-scope/lib/scope-manager' { isStrictModeSupported(): boolean; // Returns appropriate scope for this node. - __get(node: Node): Scope; - getDeclaredVariables(node: {}): Variable[]; - acquire(node: {}, inner?: boolean): Scope | null; - acquireAll(node: Node): Scope | null; - release(node: Node, inner?: boolean): Scope | null; + __get(node: TSESTree.Node): Scope; + getDeclaredVariables(node: TSESTree.Node): Variable[]; + acquire(node: TSESTree.Node, inner?: boolean): Scope | null; + acquireAll(node: TSESTree.Node): Scope | null; + release(node: TSESTree.Node, inner?: boolean): Scope | null; attach(): void; detach(): void; __nestScope(scope: Scope): Scope; - __nestGlobalScope(node: Node): Scope; - __nestBlockScope(node: Node): Scope; - __nestFunctionScope(node: Node, isMethodDefinition: boolean): Scope; - __nestForScope(node: Node): Scope; - __nestCatchScope(node: Node): Scope; - __nestWithScope(node: Node): Scope; - __nestClassScope(node: Node): Scope; - __nestSwitchScope(node: Node): Scope; - __nestModuleScope(node: Node): Scope; - __nestFunctionExpressionNameScope(node: Node): Scope; + __nestGlobalScope(node: TSESTree.Node): Scope; + __nestBlockScope(node: TSESTree.Node): Scope; + __nestFunctionScope( + node: TSESTree.Node, + isMethodDefinition: boolean + ): Scope; + __nestForScope(node: TSESTree.Node): Scope; + __nestCatchScope(node: TSESTree.Node): Scope; + __nestWithScope(node: TSESTree.Node): Scope; + __nestClassScope(node: TSESTree.Node): Scope; + __nestSwitchScope(node: TSESTree.Node): Scope; + __nestModuleScope(node: TSESTree.Node): Scope; + __nestFunctionExpressionNameScope(node: TSESTree.Node): Scope; __isES6(): boolean; } - export default ScopeManager; } declare module 'eslint-scope' { diff --git a/packages/parser/src/parser.ts b/packages/parser/src/parser.ts index be3c3e7506ef..78d71197e9f9 100644 --- a/packages/parser/src/parser.ts +++ b/packages/parser/src/parser.ts @@ -2,21 +2,15 @@ import traverser from 'eslint/lib/util/traverser'; import { AST_NODE_TYPES, parseAndGenerateServices, - ParserOptions as ParserOptionsTsESTree + ParserOptions as ParserOptionsTsESTree, + ParserServices } from '@typescript-eslint/typescript-estree'; import { analyzeScope } from './analyze-scope'; import { ParserOptions } from './parser-options'; import { visitorKeys } from './visitor-keys'; -import { Program } from 'typescript'; const packageJSON = require('../package.json'); -interface ParserServices { - program: Program | undefined; - esTreeNodeToTSNodeMap: WeakMap | undefined; - tsNodeToESTreeNodeMap: WeakMap | undefined; -} - interface ParseForESLintResult { ast: any; services: ParserServices; diff --git a/packages/typescript-estree/src/convert-comments.ts b/packages/typescript-estree/src/convert-comments.ts index 59a2326122c8..1efff92648dc 100644 --- a/packages/typescript-estree/src/convert-comments.ts +++ b/packages/typescript-estree/src/convert-comments.ts @@ -7,7 +7,7 @@ import ts from 'typescript'; import { getLocFor, getNodeContainer } from './node-utils'; -import * as es from './typedefs'; +import { TSESTree } from './ts-estree'; /** * Converts a TypeScript comment to an Esprima comment. @@ -25,10 +25,10 @@ function convertTypeScriptCommentToEsprimaComment( text: string, start: number, end: number, - startLoc: es.LineAndColumnData, - endLoc: es.LineAndColumnData -): es.Comment { - const comment: es.OptionalRangeAndLoc = { + startLoc: TSESTree.LineAndColumnData, + endLoc: TSESTree.LineAndColumnData +): TSESTree.Comment { + const comment: TSESTree.OptionalRangeAndLoc = { type: block ? 'Block' : 'Line', value: text }; @@ -44,7 +44,7 @@ function convertTypeScriptCommentToEsprimaComment( }; } - return comment as es.Comment; + return comment as TSESTree.Comment; } /** @@ -59,7 +59,7 @@ function getCommentFromTriviaScanner( triviaScanner: ts.Scanner, ast: ts.SourceFile, code: string -): es.Comment { +): TSESTree.Comment { const kind = triviaScanner.getToken(); const isBlock = kind === ts.SyntaxKind.MultiLineCommentTrivia; const range = { @@ -94,8 +94,8 @@ function getCommentFromTriviaScanner( export function convertComments( ast: ts.SourceFile, code: string -): es.Comment[] { - const comments: es.Comment[] = []; +): TSESTree.Comment[] { + const comments: TSESTree.Comment[] = []; /** * Create a TypeScript Scanner, with skipTrivia set to false so that diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index da34cb8e7d8a..3686ba919150 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -6,7 +6,7 @@ * MIT License */ import ts from 'typescript'; -import * as es from './typedefs'; +import { TSESTree } from './ts-estree'; import { canContainDirective, createError, @@ -78,8 +78,8 @@ export class Converter { }; } - convertProgram(): es.Program { - return this.converter(this.ast) as es.Program; + convertProgram(): TSESTree.Program { + return this.converter(this.ast) as TSESTree.Program; } /** @@ -112,7 +112,7 @@ export class Converter { this.allowPattern = allowPattern; } - let result: es.BaseNode | null = this.convertNode( + let result: TSESTree.BaseNode | null = this.convertNode( node as TSNode, parent || node.parent ); @@ -157,9 +157,9 @@ export class Converter { return this.converter(child, parent, true, false); } - private createNode( + private createNode( node: ts.Node, - data: es.OptionalRangeAndLoc + data: TSESTree.OptionalRangeAndLoc ): T { const result = data; if (!result.range) { @@ -182,7 +182,7 @@ export class Converter { private convertTypeAnnotation( child: ts.TypeNode, parent: ts.Node - ): es.TSTypeAnnotation { + ): TSESTree.TSTypeAnnotation { // in FunctionType and ConstructorType typeAnnotation has 2 characters `=>` and in other places is just colon const offset = parent.kind === SyntaxKind.FunctionType || @@ -244,7 +244,7 @@ export class Converter { */ private convertTypeArgumentsToTypeParameters( typeArguments: ts.NodeArray - ): es.TSTypeParameterInstantiation { + ): TSESTree.TSTypeParameterInstantiation { const greaterThanToken = findNextToken(typeArguments, this.ast, this.ast)!; return { @@ -262,7 +262,7 @@ export class Converter { */ private convertTSTypeParametersToTypeParametersDeclaration( typeParameters: ts.NodeArray - ): es.TSTypeParameterDeclaration { + ): TSESTree.TSTypeParameterDeclaration { const greaterThanToken = findNextToken(typeParameters, this.ast, this.ast)!; return { @@ -282,12 +282,12 @@ export class Converter { */ private convertParameters( parameters: ts.NodeArray - ): es.Parameter[] { + ): TSESTree.Parameter[] { if (!parameters || !parameters.length) { return []; } return parameters.map(param => { - const convertedParam = this.convertChild(param) as es.Parameter; + const convertedParam = this.convertChild(param) as TSESTree.Parameter; if (param.decorators && param.decorators.length) { convertedParam.decorators = param.decorators.map(el => @@ -375,28 +375,28 @@ export class Converter { private convertJSXTagName( node: ts.JsxTagNameExpression, parent: ts.Node - ): es.JSXMemberExpression | es.JSXIdentifier { - let result: es.JSXMemberExpression | es.JSXIdentifier; + ): TSESTree.JSXMemberExpression | TSESTree.JSXIdentifier { + let result: TSESTree.JSXMemberExpression | TSESTree.JSXIdentifier; switch (node.kind) { case SyntaxKind.PropertyAccessExpression: - result = this.createNode(node, { + result = this.createNode(node, { type: AST_NODE_TYPES.JSXMemberExpression, object: this.convertJSXTagName(node.expression, parent), property: this.convertJSXTagName( node.name, parent - ) as es.JSXIdentifier + ) as TSESTree.JSXIdentifier }); break; case SyntaxKind.ThisKeyword: - result = this.createNode(node, { + result = this.createNode(node, { type: AST_NODE_TYPES.JSXIdentifier, name: 'this' }); break; case SyntaxKind.Identifier: default: - result = this.createNode(node, { + result = this.createNode(node, { type: AST_NODE_TYPES.JSXIdentifier, name: node.text }); @@ -419,7 +419,7 @@ export class Converter { * @deprecated This method adds not standardized `modifiers` property in nodes */ private applyModifiersToResult( - result: es.TSEnumDeclaration | es.TSModuleDeclaration, + result: TSESTree.TSEnumDeclaration | TSESTree.TSModuleDeclaration, modifiers?: ts.ModifiersArray ): void { if (!modifiers || !modifiers.length) { @@ -474,7 +474,7 @@ export class Converter { * @param childRange The child node range used to expand location */ private fixParentLocation( - result: es.BaseNode, + result: TSESTree.BaseNode, childRange: [number, number] ): void { if (childRange[0] < result.range[0]) { @@ -495,10 +495,10 @@ export class Converter { * @param parent parentNode * @returns the converted ESTree node */ - private convertNode(node: TSNode, parent: ts.Node): es.Node | null { + private convertNode(node: TSNode, parent: ts.Node): TSESTree.Node | null { switch (node.kind) { case SyntaxKind.SourceFile: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Program, body: this.convertBodyExpressions(node.statements, node), // externalModuleIndicator is internal field in TSC @@ -510,21 +510,21 @@ export class Converter { } case SyntaxKind.Block: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.BlockStatement, body: this.convertBodyExpressions(node.statements, node) }); } case SyntaxKind.Identifier: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Identifier, name: node.text }); } case SyntaxKind.WithStatement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.WithStatement, object: this.convertChild(node.expression), body: this.convertChild(node.statement) @@ -533,26 +533,26 @@ export class Converter { // Control Flow case SyntaxKind.ReturnStatement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ReturnStatement, argument: this.convertChild(node.expression) }); case SyntaxKind.LabeledStatement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.LabeledStatement, label: this.convertChild(node.label), body: this.convertChild(node.statement) }); case SyntaxKind.ContinueStatement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ContinueStatement, label: this.convertChild(node.label) }); case SyntaxKind.BreakStatement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.BreakStatement, label: this.convertChild(node.label) }); @@ -560,7 +560,7 @@ export class Converter { // Choice case SyntaxKind.IfStatement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.IfStatement, test: this.convertChild(node.expression), consequent: this.convertChild(node.thenStatement), @@ -568,7 +568,7 @@ export class Converter { }); case SyntaxKind.SwitchStatement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.SwitchStatement, discriminant: this.convertChild(node.expression), cases: node.caseBlock.clauses.map(el => this.convertChild(el)) @@ -576,7 +576,7 @@ export class Converter { case SyntaxKind.CaseClause: case SyntaxKind.DefaultClause: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.SwitchCase, // expression is present in case only test: @@ -589,13 +589,13 @@ export class Converter { // Exceptions case SyntaxKind.ThrowStatement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ThrowStatement, argument: this.convertChild(node.expression) }); case SyntaxKind.TryStatement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TryStatement, block: this.convertChild(node.tryBlock), handler: this.convertChild(node.catchClause), @@ -603,7 +603,7 @@ export class Converter { }); case SyntaxKind.CatchClause: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.CatchClause, param: node.variableDeclaration ? this.convertChild(node.variableDeclaration.name) @@ -614,7 +614,7 @@ export class Converter { // Loops case SyntaxKind.WhileStatement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.WhileStatement, test: this.convertChild(node.expression), body: this.convertChild(node.statement) @@ -625,14 +625,14 @@ export class Converter { * a "DoStatement" */ case SyntaxKind.DoStatement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.DoWhileStatement, test: this.convertChild(node.expression), body: this.convertChild(node.statement) }); case SyntaxKind.ForStatement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ForStatement, init: this.convertChild(node.initializer), test: this.convertChild(node.condition), @@ -641,7 +641,7 @@ export class Converter { }); case SyntaxKind.ForInStatement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ForInStatement, left: this.convertPattern(node.initializer), right: this.convertChild(node.expression), @@ -649,7 +649,7 @@ export class Converter { }); case SyntaxKind.ForOfStatement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ForOfStatement, left: this.convertPattern(node.initializer), right: this.convertChild(node.expression), @@ -666,7 +666,7 @@ export class Converter { const isDeclare = hasModifier(SyntaxKind.DeclareKeyword, node); const result = this.createNode< - es.TSDeclareFunction | es.FunctionDeclaration + TSESTree.TSDeclareFunction | TSESTree.FunctionDeclaration >(node, { type: isDeclare || !node.body @@ -701,7 +701,7 @@ export class Converter { } case SyntaxKind.VariableDeclaration: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.VariableDeclarator, id: this.convertPattern(node.name), init: this.convertChild(node.initializer) @@ -722,7 +722,7 @@ export class Converter { } case SyntaxKind.VariableStatement: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.VariableDeclaration, declarations: node.declarationList.declarations.map(el => this.convertChild(el) @@ -740,7 +740,7 @@ export class Converter { // mostly for for-of, for-in case SyntaxKind.VariableDeclarationList: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.VariableDeclaration, declarations: node.declarations.map(el => this.convertChild(el)), kind: getDeclarationKind(node) @@ -749,25 +749,25 @@ export class Converter { // Expressions case SyntaxKind.ExpressionStatement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ExpressionStatement, expression: this.convertChild(node.expression) }); case SyntaxKind.ThisKeyword: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ThisExpression }); case SyntaxKind.ArrayLiteralExpression: { // TypeScript uses ArrayLiteralExpression in destructuring assignment, too if (this.allowPattern) { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ArrayPattern, elements: node.elements.map(el => this.convertPattern(el)) }); } else { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ArrayExpression, elements: node.elements.map(el => this.convertChild(el)) }); @@ -777,12 +777,12 @@ export class Converter { case SyntaxKind.ObjectLiteralExpression: { // TypeScript uses ObjectLiteralExpression in destructuring assignment, too if (this.allowPattern) { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ObjectPattern, properties: node.properties.map(el => this.convertPattern(el)) }); } else { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ObjectExpression, properties: node.properties.map(el => this.convertChild(el)) }); @@ -790,7 +790,7 @@ export class Converter { } case SyntaxKind.PropertyAssignment: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Property, key: this.convertChild(node.name), value: this.converter( @@ -807,10 +807,10 @@ export class Converter { case SyntaxKind.ShorthandPropertyAssignment: { if (node.objectAssignmentInitializer) { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Property, key: this.convertChild(node.name), - value: this.createNode(node, { + value: this.createNode(node, { type: AST_NODE_TYPES.AssignmentPattern, left: this.convertPattern(node.name), right: this.convertChild(node.objectAssignmentInitializer) @@ -821,7 +821,7 @@ export class Converter { kind: 'init' }); } else { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Property, key: this.convertChild(node.name), value: this.convertChild(node.name), @@ -839,7 +839,7 @@ export class Converter { case SyntaxKind.PropertyDeclaration: { const isAbstract = hasModifier(SyntaxKind.AbstractKeyword, node); const result = this.createNode< - es.TSAbstractClassProperty | es.ClassProperty + TSESTree.TSAbstractClassProperty | TSESTree.ClassProperty >(node, { type: isAbstract ? AST_NODE_TYPES.TSAbstractClassProperty @@ -881,7 +881,7 @@ export class Converter { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.MethodDeclaration: { - const method = this.createNode(node, { + const method = this.createNode(node, { type: AST_NODE_TYPES.FunctionExpression, id: null, generator: !!node.asteriskToken, @@ -905,14 +905,14 @@ export class Converter { } let result: - | es.Property - | es.TSAbstractMethodDefinition - | es.MethodDefinition; + | TSESTree.Property + | TSESTree.TSAbstractMethodDefinition + | TSESTree.MethodDefinition; if (parent.kind === SyntaxKind.ObjectLiteralExpression) { method.params = node.parameters.map(el => this.convertChild(el)); - result = this.createNode(node, { + result = this.createNode(node, { type: AST_NODE_TYPES.Property, key: this.convertChild(node.name), value: method, @@ -940,7 +940,7 @@ export class Converter { : AST_NODE_TYPES.MethodDefinition; result = this.createNode< - es.TSAbstractMethodDefinition | es.MethodDefinition + TSESTree.TSAbstractMethodDefinition | TSESTree.MethodDefinition >(node, { type: methodDefinitionType, key: this.convertChild(node.name), @@ -974,7 +974,7 @@ export class Converter { } else if (node.kind === SyntaxKind.SetAccessor) { result.kind = 'set'; } else if ( - !(result as es.MethodDefinition).static && + !(result as TSESTree.MethodDefinition).static && node.name.kind === SyntaxKind.StringLiteral && node.name.text === 'constructor' && result.type !== AST_NODE_TYPES.Property @@ -991,7 +991,7 @@ export class Converter { (lastModifier && findNextToken(lastModifier, node, this.ast)) || node.getFirstToken()!; - const constructor = this.createNode(node, { + const constructor = this.createNode(node, { type: AST_NODE_TYPES.FunctionExpression, id: null, params: this.convertParameters(node.parameters), @@ -1015,7 +1015,7 @@ export class Converter { constructor.returnType = this.convertTypeAnnotation(node.type, node); } - const constructorKey = this.createNode(node, { + const constructorKey = this.createNode(node, { type: AST_NODE_TYPES.Identifier, name: 'constructor', range: [constructorToken.getStart(this.ast), constructorToken.end] @@ -1023,7 +1023,7 @@ export class Converter { const isStatic = hasModifier(SyntaxKind.StaticKeyword, node); const result = this.createNode< - es.TSAbstractMethodDefinition | es.MethodDefinition + TSESTree.TSAbstractMethodDefinition | TSESTree.MethodDefinition >(node, { type: hasModifier(SyntaxKind.AbstractKeyword, node) ? AST_NODE_TYPES.TSAbstractMethodDefinition @@ -1044,7 +1044,7 @@ export class Converter { } case SyntaxKind.FunctionExpression: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.FunctionExpression, id: this.convertChild(node.name), generator: !!node.asteriskToken, @@ -1069,12 +1069,12 @@ export class Converter { } case SyntaxKind.SuperKeyword: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Super }); case SyntaxKind.ArrayBindingPattern: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ArrayPattern, elements: node.elements.map(el => this.convertPattern(el)) }); @@ -1084,7 +1084,7 @@ export class Converter { return null; case SyntaxKind.ObjectBindingPattern: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ObjectPattern, properties: node.elements.map(el => this.convertPattern(el)) }); @@ -1094,13 +1094,13 @@ export class Converter { const arrayItem = this.convertChild(node.name, parent); if (node.initializer) { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.AssignmentPattern, left: arrayItem, right: this.convertChild(node.initializer) }); } else if (node.dotDotDotToken) { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.RestElement, argument: arrayItem }); @@ -1108,14 +1108,14 @@ export class Converter { return arrayItem; } } else if (parent.kind === SyntaxKind.ObjectBindingPattern) { - let result: es.RestElement | es.Property; + let result: TSESTree.RestElement | TSESTree.Property; if (node.dotDotDotToken) { - result = this.createNode(node, { + result = this.createNode(node, { type: AST_NODE_TYPES.RestElement, argument: this.convertChild(node.propertyName || node.name) }); } else { - result = this.createNode(node, { + result = this.createNode(node, { type: AST_NODE_TYPES.Property, key: this.convertChild(node.propertyName || node.name), value: this.convertChild(node.name), @@ -1130,7 +1130,7 @@ export class Converter { } if (node.initializer) { - result.value = this.createNode(node, { + result.value = this.createNode(node, { type: AST_NODE_TYPES.AssignmentPattern, left: this.convertChild(node.name), right: this.convertChild(node.initializer), @@ -1143,7 +1143,7 @@ export class Converter { } case SyntaxKind.ArrowFunction: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.ArrowFunctionExpression, generator: false, id: null, @@ -1168,14 +1168,14 @@ export class Converter { } case SyntaxKind.YieldExpression: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.YieldExpression, delegate: !!node.asteriskToken, argument: this.convertChild(node.expression) }); case SyntaxKind.AwaitExpression: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.AwaitExpression, argument: this.convertChild(node.expression) }); @@ -1183,10 +1183,10 @@ export class Converter { // Template Literals case SyntaxKind.NoSubstitutionTemplateLiteral: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TemplateLiteral, quasis: [ - this.createNode(node, { + this.createNode(node, { type: AST_NODE_TYPES.TemplateElement, value: { raw: this.ast.text.slice( @@ -1202,7 +1202,7 @@ export class Converter { }); case SyntaxKind.TemplateExpression: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.TemplateLiteral, quasis: [this.convertChild(node.head)], expressions: [] @@ -1216,7 +1216,7 @@ export class Converter { } case SyntaxKind.TaggedTemplateExpression: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TaggedTemplateExpression, typeParameters: node.typeArguments ? this.convertTypeArgumentsToTypeParameters(node.typeArguments) @@ -1229,7 +1229,7 @@ export class Converter { case SyntaxKind.TemplateMiddle: case SyntaxKind.TemplateTail: { const tail = node.kind === SyntaxKind.TemplateTail; - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TemplateElement, value: { raw: this.ast.text.slice( @@ -1247,12 +1247,12 @@ export class Converter { case SyntaxKind.SpreadAssignment: case SyntaxKind.SpreadElement: { if (this.allowPattern) { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.RestElement, argument: this.convertPattern(node.expression) }); } else { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.SpreadElement, argument: this.convertChild(node.expression) }); @@ -1261,16 +1261,16 @@ export class Converter { case SyntaxKind.Parameter: { let parameter: any; - let result: es.RestElement | es.AssignmentPattern; + let result: TSESTree.RestElement | TSESTree.AssignmentPattern; if (node.dotDotDotToken) { - parameter = result = this.createNode(node, { + parameter = result = this.createNode(node, { type: AST_NODE_TYPES.RestElement, argument: this.convertChild(node.name) }); } else if (node.initializer) { parameter = this.convertChild(node.name); - result = this.createNode(node, { + result = this.createNode(node, { type: AST_NODE_TYPES.AssignmentPattern, left: parameter, right: this.convertChild(node.initializer) @@ -1305,7 +1305,7 @@ export class Converter { } if (node.modifiers) { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSParameterProperty, accessibility: getTSNodeAccessibility(node) || undefined, readonly: @@ -1337,11 +1337,11 @@ export class Converter { ); const result = this.createNode< - es.ClassDeclaration | es.ClassExpression + TSESTree.ClassDeclaration | TSESTree.ClassExpression >(node, { type: classNodeType, id: this.convertChild(node.name), - body: this.createNode(node, { + body: this.createNode(node, { type: AST_NODE_TYPES.ClassBody, body: [], range: [node.members.pos - 1, node.end] @@ -1407,13 +1407,13 @@ export class Converter { // Modules case SyntaxKind.ModuleBlock: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSModuleBlock, body: this.convertBodyExpressions(node.statements, node) }); case SyntaxKind.ImportDeclaration: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.ImportDeclaration, source: this.convertChild(node.moduleSpecifier), specifiers: [] @@ -1445,20 +1445,20 @@ export class Converter { } case SyntaxKind.NamespaceImport: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ImportNamespaceSpecifier, local: this.convertChild(node.name) }); case SyntaxKind.ImportSpecifier: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ImportSpecifier, local: this.convertChild(node.name), imported: this.convertChild(node.propertyName || node.name) }); case SyntaxKind.ImportClause: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ImportDefaultSpecifier, local: this.convertChild(node.name), range: [node.getStart(this.ast), node.name!.end] @@ -1466,7 +1466,7 @@ export class Converter { case SyntaxKind.ExportDeclaration: if (node.exportClause) { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ExportNamedDeclaration, source: this.convertChild(node.moduleSpecifier), specifiers: node.exportClause.elements.map(el => @@ -1475,14 +1475,14 @@ export class Converter { declaration: null }); } else { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ExportAllDeclaration, source: this.convertChild(node.moduleSpecifier) }); } case SyntaxKind.ExportSpecifier: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ExportSpecifier, local: this.convertChild(node.propertyName || node.name), exported: this.convertChild(node.name) @@ -1490,12 +1490,12 @@ export class Converter { case SyntaxKind.ExportAssignment: if (node.isExportEquals) { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSExportAssignment, expression: this.convertChild(node.expression) }); } else { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ExportDefaultDeclaration, declaration: this.convertChild(node.expression) }); @@ -1510,14 +1510,14 @@ export class Converter { * ESTree uses UpdateExpression for ++/-- */ if (/^(?:\+\+|--)$/.test(operator)) { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.UpdateExpression, operator, prefix: node.kind === SyntaxKind.PrefixUnaryExpression, argument: this.convertChild(node.operand) }); } else { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.UnaryExpression, operator, prefix: node.kind === SyntaxKind.PrefixUnaryExpression, @@ -1527,7 +1527,7 @@ export class Converter { } case SyntaxKind.DeleteExpression: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.UnaryExpression, operator: 'delete', prefix: true, @@ -1535,7 +1535,7 @@ export class Converter { }); case SyntaxKind.VoidExpression: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.UnaryExpression, operator: 'void', prefix: true, @@ -1543,7 +1543,7 @@ export class Converter { }); case SyntaxKind.TypeOfExpression: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.UnaryExpression, operator: 'typeof', prefix: true, @@ -1551,7 +1551,7 @@ export class Converter { }); case SyntaxKind.TypeOperator: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSTypeOperator, operator: getTextForTokenKind(node.operator) as any, typeAnnotation: this.convertChild(node.type) @@ -1562,7 +1562,7 @@ export class Converter { case SyntaxKind.BinaryExpression: { // TypeScript uses BinaryExpression for sequences as well if (isComma(node.operatorToken)) { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.SequenceExpression, expressions: [] }); @@ -1588,14 +1588,16 @@ export class Converter { this.allowPattern && type === AST_NODE_TYPES.AssignmentExpression ) { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.AssignmentPattern, left: this.convertPattern(node.left, node), right: this.convertChild(node.right) }); } return this.createNode< - es.AssignmentExpression | es.LogicalExpression | es.BinaryExpression + | TSESTree.AssignmentExpression + | TSESTree.LogicalExpression + | TSESTree.BinaryExpression >(node, { type: type, operator: getTextForTokenKind(node.operatorToken.kind)!, @@ -1611,7 +1613,7 @@ export class Converter { } case SyntaxKind.PropertyAccessExpression: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.MemberExpression, object: this.convertChild(node.expression), property: this.convertChild(node.name), @@ -1619,7 +1621,7 @@ export class Converter { }); case SyntaxKind.ElementAccessExpression: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.MemberExpression, object: this.convertChild(node.expression), property: this.convertChild(node.argumentExpression), @@ -1627,7 +1629,7 @@ export class Converter { }); case SyntaxKind.ConditionalExpression: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.ConditionalExpression, test: this.convertChild(node.condition), consequent: this.convertChild(node.whenTrue), @@ -1635,7 +1637,7 @@ export class Converter { }); case SyntaxKind.CallExpression: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.CallExpression, callee: this.convertChild(node.expression), arguments: node.arguments.map(el => this.convertChild(el)) @@ -1649,7 +1651,7 @@ export class Converter { } case SyntaxKind.NewExpression: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.NewExpression, callee: this.convertChild(node.expression), arguments: node.arguments @@ -1665,9 +1667,9 @@ export class Converter { } case SyntaxKind.MetaProperty: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.MetaProperty, - meta: this.createNode(node.getFirstToken()!, { + meta: this.createNode(node.getFirstToken()!, { type: AST_NODE_TYPES.Identifier, name: getTextForTokenKind(node.keywordToken)! }), @@ -1676,7 +1678,7 @@ export class Converter { } case SyntaxKind.Decorator: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Decorator, expression: this.convertChild(node.expression) }); @@ -1685,7 +1687,7 @@ export class Converter { // Literals case SyntaxKind.StringLiteral: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.Literal, raw: '', value: '' @@ -1700,7 +1702,7 @@ export class Converter { } case SyntaxKind.NumericLiteral: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Literal, value: Number(node.text), raw: node.getText() @@ -1708,7 +1710,7 @@ export class Converter { } case SyntaxKind.BigIntLiteral: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.BigIntLiteral, raw: '', value: '' @@ -1729,7 +1731,7 @@ export class Converter { regex = null; } - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Literal, value: regex, raw: node.text, @@ -1741,14 +1743,14 @@ export class Converter { } case SyntaxKind.TrueKeyword: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Literal, value: true, raw: 'true' }); case SyntaxKind.FalseKeyword: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Literal, value: false, raw: 'false' @@ -1756,11 +1758,11 @@ export class Converter { case SyntaxKind.NullKeyword: { if (this.inTypeMode) { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSNullKeyword }); } else { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Literal, value: null, raw: 'null' @@ -1769,24 +1771,24 @@ export class Converter { } case SyntaxKind.ImportKeyword: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Import }); case SyntaxKind.EmptyStatement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.EmptyStatement }); case SyntaxKind.DebuggerStatement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.DebuggerStatement }); // JSX case SyntaxKind.JsxElement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.JSXElement, openingElement: this.convertChild(node.openingElement), closingElement: this.convertChild(node.closingElement), @@ -1794,7 +1796,7 @@ export class Converter { }); case SyntaxKind.JsxFragment: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.JSXFragment, openingFragment: this.convertChild(node.openingFragment), closingFragment: this.convertChild(node.closingFragment), @@ -1802,13 +1804,13 @@ export class Converter { }); case SyntaxKind.JsxSelfClosingElement: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.JSXElement, /** * Convert SyntaxKind.JsxSelfClosingElement to SyntaxKind.JsxOpeningElement, * TypeScript does not seem to have the idea of openingElement when tag is self-closing */ - openingElement: this.createNode(node, { + openingElement: this.createNode(node, { type: AST_NODE_TYPES.JSXOpeningElement, typeParameters: node.typeArguments ? this.convertTypeArgumentsToTypeParameters(node.typeArguments) @@ -1826,7 +1828,7 @@ export class Converter { } case SyntaxKind.JsxOpeningElement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.JSXOpeningElement, typeParameters: node.typeArguments ? this.convertTypeArgumentsToTypeParameters(node.typeArguments) @@ -1839,36 +1841,36 @@ export class Converter { }); case SyntaxKind.JsxClosingElement: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.JSXClosingElement, name: this.convertJSXTagName(node.tagName, node) }); case SyntaxKind.JsxOpeningFragment: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.JSXOpeningFragment }); case SyntaxKind.JsxClosingFragment: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.JSXClosingFragment }); case SyntaxKind.JsxExpression: { const expression = node.expression ? this.convertChild(node.expression) - : this.createNode(node, { + : this.createNode(node, { type: AST_NODE_TYPES.JSXEmptyExpression, range: [node.getStart(this.ast) + 1, node.getEnd() - 1] }); if (node.dotDotDotToken) { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.JSXSpreadChild, expression }); } else { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.JSXExpressionContainer, expression }); @@ -1879,7 +1881,7 @@ export class Converter { const attributeName = this.convertChild(node.name); attributeName.type = AST_NODE_TYPES.JSXIdentifier; - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.JSXAttribute, name: attributeName, value: this.convertChild(node.initializer) @@ -1897,14 +1899,14 @@ export class Converter { const end = node.getEnd(); if (this.options.useJSXTextNode) { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.JSXText, value: this.ast.text.slice(start, end), raw: this.ast.text.slice(start, end), range: [start, end] }); } else { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Literal, value: this.ast.text.slice(start, end), raw: this.ast.text.slice(start, end), @@ -1914,13 +1916,13 @@ export class Converter { } case SyntaxKind.JsxSpreadAttribute: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.JSXSpreadAttribute, argument: this.convertChild(node.expression) }); case SyntaxKind.QualifiedName: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSQualifiedName, left: this.convertChild(node.left), right: this.convertChild(node.right) @@ -1930,7 +1932,7 @@ export class Converter { // TypeScript specific case SyntaxKind.TypeReference: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSTypeReference, typeName: this.convertType(node.typeName), typeParameters: node.typeArguments @@ -1940,7 +1942,7 @@ export class Converter { } case SyntaxKind.TypeParameter: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSTypeParameter, name: this.convertType(node.name), constraint: node.constraint @@ -1968,28 +1970,28 @@ export class Converter { } case SyntaxKind.NonNullExpression: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSNonNullExpression, expression: this.convertChild(node.expression) }); } case SyntaxKind.TypeLiteral: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSTypeLiteral, members: node.members.map(el => this.convertChild(el)) }); } case SyntaxKind.ArrayType: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSArrayType, elementType: this.convertType(node.elementType) }); } case SyntaxKind.IndexedAccessType: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSIndexedAccessType, objectType: this.convertType(node.objectType), indexType: this.convertType(node.indexType) @@ -1997,7 +1999,7 @@ export class Converter { } case SyntaxKind.ConditionalType: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSConditionalType, checkType: this.convertType(node.checkType), extendsType: this.convertType(node.extendsType), @@ -2007,14 +2009,14 @@ export class Converter { } case SyntaxKind.TypeQuery: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSTypeQuery, exprName: this.convertType(node.exprName) }); } case SyntaxKind.MappedType: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.TSMappedType, typeParameter: this.convertType(node.typeParameter) }); @@ -2049,7 +2051,7 @@ export class Converter { return this.convertChild(node.expression, parent); case SyntaxKind.TypeAliasDeclaration: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.TSTypeAliasDeclaration, id: this.convertChild(node.name), typeAnnotation: this.convertType(node.type) @@ -2071,7 +2073,7 @@ export class Converter { } case SyntaxKind.MethodSignature: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.TSMethodSignature, computed: isComputedProperty(node.name), key: this.convertChild(node.name), @@ -2112,7 +2114,7 @@ export class Converter { } case SyntaxKind.PropertySignature: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.TSPropertySignature, optional: isOptional(node) || undefined, computed: isComputedProperty(node.name), @@ -2135,7 +2137,7 @@ export class Converter { } case SyntaxKind.IndexSignature: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.TSIndexSignature, parameters: node.parameters.map(el => this.convertChild(el)) }); @@ -2183,10 +2185,10 @@ export class Converter { break; } const result = this.createNode< - | es.TSConstructSignatureDeclaration - | es.TSCallSignatureDeclaration - | es.TSFunctionType - | es.TSConstructorType + | TSESTree.TSConstructSignatureDeclaration + | TSESTree.TSCallSignatureDeclaration + | TSESTree.TSFunctionType + | TSESTree.TSConstructorType >(node, { type: type, params: this.convertParameters(node.parameters) @@ -2207,7 +2209,7 @@ export class Converter { case SyntaxKind.ExpressionWithTypeArguments: { const result = this.createNode< - es.TSInterfaceHeritage | es.TSClassImplements + TSESTree.TSInterfaceHeritage | TSESTree.TSClassImplements >(node, { type: parent && parent.kind === SyntaxKind.InterfaceDeclaration @@ -2226,9 +2228,9 @@ export class Converter { case SyntaxKind.InterfaceDeclaration: { const interfaceHeritageClauses = node.heritageClauses || []; - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.TSInterfaceDeclaration, - body: this.createNode(node, { + body: this.createNode(node, { type: AST_NODE_TYPES.TSInterfaceBody, body: node.members.map(member => this.convertChild(member)), range: [node.members.pos - 1, node.end] @@ -2286,7 +2288,7 @@ export class Converter { } case SyntaxKind.FirstTypeNode: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.TSTypePredicate, parameterName: this.convertChild(node.parameterName), typeAnnotation: this.convertTypeAnnotation(node.type, node) @@ -2301,7 +2303,7 @@ export class Converter { } case SyntaxKind.ImportType: - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSImportType, isTypeOf: !!node.isTypeOf, parameter: this.convertChild(node.argument), @@ -2312,7 +2314,7 @@ export class Converter { }); case SyntaxKind.EnumDeclaration: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.TSEnumDeclaration, id: this.convertChild(node.name), members: node.members.map(el => this.convertChild(el)) @@ -2332,7 +2334,7 @@ export class Converter { } case SyntaxKind.EnumMember: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.TSEnumMember, id: this.convertChild(node.name) }); @@ -2343,7 +2345,7 @@ export class Converter { } case SyntaxKind.ModuleDeclaration: { - const result = this.createNode(node, { + const result = this.createNode(node, { type: AST_NODE_TYPES.TSModuleDeclaration, id: this.convertChild(node.name) }); @@ -2361,69 +2363,69 @@ export class Converter { // TypeScript specific types case SyntaxKind.OptionalType: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSOptionalType, typeAnnotation: this.convertType(node.type) }); } case SyntaxKind.ParenthesizedType: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSParenthesizedType, typeAnnotation: this.convertType(node.type) }); } case SyntaxKind.TupleType: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSTupleType, elementTypes: node.elementTypes.map(el => this.convertType(el)) }); } case SyntaxKind.UnionType: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSUnionType, types: node.types.map(el => this.convertType(el)) }); } case SyntaxKind.IntersectionType: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSIntersectionType, types: node.types.map(el => this.convertType(el)) }); } case SyntaxKind.RestType: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSRestType, typeAnnotation: this.convertType(node.type) }); } case SyntaxKind.AsExpression: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSAsExpression, expression: this.convertChild(node.expression), typeAnnotation: this.convertType(node.type) }); } case SyntaxKind.InferType: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSInferType, typeParameter: this.convertType(node.typeParameter) }); } case SyntaxKind.LiteralType: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSLiteralType, literal: this.convertType(node.literal) }); } case SyntaxKind.TypeAssertionExpression: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSTypeAssertion, typeAnnotation: this.convertType(node.type), expression: this.convertChild(node.expression) }); } case SyntaxKind.ImportEqualsDeclaration: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSImportEqualsDeclaration, id: this.convertChild(node.name), moduleReference: this.convertChild(node.moduleReference), @@ -2431,13 +2433,13 @@ export class Converter { }); } case SyntaxKind.ExternalModuleReference: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSExternalModuleReference, expression: this.convertChild(node.expression) }); } case SyntaxKind.NamespaceExportDeclaration: { - return this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.TSNamespaceExportDeclaration, id: this.convertChild(node.name) }); diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index aa5a10418c76..4ab71cf5e9a4 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -6,7 +6,7 @@ */ import ts from 'typescript'; import unescape from 'lodash.unescape'; -import * as es from './typedefs'; +import { TSESTree } from './ts-estree'; import { AST_NODE_TYPES } from './ast-node-types'; const SyntaxKind = ts.SyntaxKind; @@ -224,7 +224,7 @@ export function getBinaryExpressionType( export function getLineAndCharacterFor( pos: number, ast: ts.SourceFile -): es.LineAndColumnData { +): TSESTree.LineAndColumnData { const loc = ast.getLineAndCharacterOfPosition(pos); return { line: loc.line + 1, @@ -244,7 +244,7 @@ export function getLocFor( start: number, end: number, ast: ts.SourceFile -): es.SourceLocation { +): TSESTree.SourceLocation { return { start: getLineAndCharacterFor(start, ast), end: getLineAndCharacterFor(end, ast) @@ -455,11 +455,11 @@ export function isOptional(node: { * @param ast the AST * @returns the ESTreeNode with fixed exports */ -export function fixExports( +export function fixExports( node: ts.Node, result: T, ast: ts.SourceFile -): es.ExportDefaultDeclaration | es.ExportNamedDeclaration | T { +): TSESTree.ExportDefaultDeclaration | TSESTree.ExportNamedDeclaration | T { // check for exports if (node.modifiers && node.modifiers[0].kind === SyntaxKind.ExportKeyword) { const exportKeyword = node.modifiers[0]; @@ -501,7 +501,7 @@ export function fixExports( * @param token the ts.Token * @returns the token type */ -export function getTokenType(token: any): es.TokenType { +export function getTokenType(token: any): TSESTree.TokenType { // Need two checks for keywords since some are also identifiers if (token.originalKeywordKind) { switch (token.originalKeywordKind) { @@ -607,16 +607,19 @@ export function getTokenType(token: any): es.TokenType { * Extends and formats a given ts.Token, for a given AST * @param token the ts.Token * @param ast the AST object - * @returns the converted es.Token + * @returns the converted Token */ -export function convertToken(token: ts.Node, ast: ts.SourceFile): es.Token { +export function convertToken( + token: ts.Node, + ast: ts.SourceFile +): TSESTree.Token { const start = token.kind === SyntaxKind.JsxText ? token.getFullStart() : token.getStart(ast), end = token.getEnd(), value = ast.text.slice(start, end), - newToken: es.Token = { + newToken: TSESTree.Token = { type: getTokenType(token), value, range: [start, end], @@ -638,8 +641,8 @@ export function convertToken(token: ts.Node, ast: ts.SourceFile): es.Token { * @param ast the AST object * @returns the converted Tokens */ -export function convertTokens(ast: ts.SourceFile): es.Token[] { - const result: es.Token[] = []; +export function convertTokens(ast: ts.SourceFile): TSESTree.Token[] { + const result: TSESTree.Token[] = []; /** * @param node the ts.Node */ diff --git a/packages/typescript-estree/src/parser-options.ts b/packages/typescript-estree/src/parser-options.ts index a838db4af139..6ec07b902cd1 100644 --- a/packages/typescript-estree/src/parser-options.ts +++ b/packages/typescript-estree/src/parser-options.ts @@ -1,4 +1,6 @@ -import { Token, Comment } from './typedefs'; +import { Program } from 'typescript'; +import { Token, Comment, Node } from './typedefs'; +import { TSNode } from './ts-nodes'; export interface Extra { errorOnUnknownASTType: boolean; @@ -33,3 +35,13 @@ export interface ParserOptions { tsconfigRootDir?: string; extraFileExtensions?: string[]; } + +export interface ParserWeakMap { + get(key: TKey): TValue; +} + +export interface ParserServices { + program: Program | undefined; + esTreeNodeToTSNodeMap: ParserWeakMap | undefined; + tsNodeToESTreeNodeMap: ParserWeakMap | undefined; +} diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index bad5cdd6fd50..bb77a186171a 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -14,8 +14,8 @@ import ts from 'typescript'; import convert from './ast-converter'; import { convertError } from './convert'; import { firstDefined } from './node-utils'; -import * as es from './typedefs'; -import { Extra, ParserOptions } from './parser-options'; +import { TSESTree } from './ts-estree'; +import { Extra, ParserOptions, ParserServices } from './parser-options'; import { getFirstSemanticOrSyntacticError } from './semantic-errors'; /** @@ -271,18 +271,14 @@ function warnAboutTSVersion(): void { // Parser //------------------------------------------------------------------------------ -type AST = es.Program & +type AST = TSESTree.Program & (T['range'] extends true ? { range: [number, number] } : {}) & - (T['tokens'] extends true ? { tokens: es.Token[] } : {}) & - (T['comment'] extends true ? { comments: es.Comment[] } : {}); + (T['tokens'] extends true ? { tokens: TSESTree.Token[] } : {}) & + (T['comment'] extends true ? { comments: TSESTree.Comment[] } : {}); interface ParseAndGenerateServicesResult { ast: AST; - services: { - program: ts.Program | undefined; - esTreeNodeToTSNodeMap: WeakMap | undefined; - tsNodeToESTreeNodeMap: WeakMap | undefined; - }; + services: ParserServices; } //------------------------------------------------------------------------------ @@ -419,3 +415,5 @@ export function parseAndGenerateServices< export { AST_NODE_TYPES } from './ast-node-types'; export { ParserOptions }; +export { ParserServices }; +export { TSESTree }; diff --git a/packages/typescript-estree/src/ts-estree.ts b/packages/typescript-estree/src/ts-estree.ts new file mode 100644 index 000000000000..846392c54430 --- /dev/null +++ b/packages/typescript-estree/src/ts-estree.ts @@ -0,0 +1,2 @@ +import * as TSESTree from './typedefs'; +export { TSESTree }; diff --git a/packages/typescript-estree/src/typedefs.ts b/packages/typescript-estree/src/typedefs.ts index a9a100e64623..af8d17e0157a 100644 --- a/packages/typescript-estree/src/typedefs.ts +++ b/packages/typescript-estree/src/typedefs.ts @@ -1185,7 +1185,7 @@ export interface TSModuleBlock extends BaseNode { export interface TSModuleDeclaration extends BaseNode { type: AST_NODE_TYPES.TSModuleDeclaration; id: Identifier | Literal; - body?: TSModuleBlock | Identifier; + body?: TSModuleBlock | TSModuleDeclaration; global?: boolean; declare?: boolean; modifiers?: Modifier[]; diff --git a/packages/typescript-estree/tests/lib/semanticInfo.ts b/packages/typescript-estree/tests/lib/semanticInfo.ts index a164288ceb0f..531ab1a34d54 100644 --- a/packages/typescript-estree/tests/lib/semanticInfo.ts +++ b/packages/typescript-estree/tests/lib/semanticInfo.ts @@ -123,10 +123,10 @@ describe('semanticInfo', () => { arrayBoundName ); expect(tsArrayBoundName).toBeDefined(); - checkNumberArrayType(checker, tsArrayBoundName); + checkNumberArrayType(checker, tsArrayBoundName!); expect( - parseResult.services.tsNodeToESTreeNodeMap!.get(tsArrayBoundName) + parseResult.services.tsNodeToESTreeNodeMap!.get(tsArrayBoundName!) ).toBe(arrayBoundName); }); @@ -149,9 +149,9 @@ describe('semanticInfo', () => { ); expect(tsBoundName).toBeDefined(); - checkNumberArrayType(checker, tsBoundName); + checkNumberArrayType(checker, tsBoundName!); - expect(parseResult.services.tsNodeToESTreeNodeMap!.get(tsBoundName)).toBe( + expect(parseResult.services.tsNodeToESTreeNodeMap!.get(tsBoundName!)).toBe( boundName ); }); diff --git a/yarn.lock b/yarn.lock index 00804abee1f8..95f575e0097c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -816,7 +816,7 @@ "@types/estree" "*" "@types/json-schema" "*" -"@types/estree@*", "@types/estree@^0.0.39": +"@types/estree@*": version "0.0.39" resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== From 07e950eb877746ae34a7ce2f0afe4805178cbc43 Mon Sep 17 00:00:00 2001 From: Kanitkorn Sujautra Date: Thu, 7 Feb 2019 10:34:43 +0900 Subject: [PATCH 19/26] fix(eslint-plugin): fix false positive from adjacent-overload-signatures (#206) --- .../lib/rules/adjacent-overload-signatures.js | 35 +++++++++++++----- .../lib/rules/adjacent-overload-signatures.js | 37 +++++++++++++++++++ 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/packages/eslint-plugin/lib/rules/adjacent-overload-signatures.js b/packages/eslint-plugin/lib/rules/adjacent-overload-signatures.js index d8eb79509558..0c53769c0e8c 100644 --- a/packages/eslint-plugin/lib/rules/adjacent-overload-signatures.js +++ b/packages/eslint-plugin/lib/rules/adjacent-overload-signatures.js @@ -73,6 +73,17 @@ module.exports = { } } + /** + * Determine whether two methods are the same or not + * @param {{ name: string; static: boolean }} method1 a method to compare + * @param {{ name: string; static: boolean }} method2 another method to compare with + * @returns {boolean} true if two methods are the same + * @private + */ + function isSameMethod(method1, method2) { + return method1.name === method2.name && method1.static === method2.static; + } + /** * Check the body for overload methods. * @param {ASTNode} node the body to be inspected. @@ -83,28 +94,32 @@ module.exports = { const members = node.body || node.members; if (members) { - let name; - let index; - let lastName; - const seen = []; + let lastMethod; + const seenMethods = []; members.forEach(member => { - name = getMemberName(member); + const name = getMemberName(member); + const method = { + name, + static: member.static + }; - index = seen.indexOf(name); - if (index > -1 && lastName !== name) { + const index = seenMethods.findIndex(seenMethod => + isSameMethod(method, seenMethod) + ); + if (index > -1 && !isSameMethod(method, lastMethod)) { context.report({ node: member, messageId: 'adjacentSignature', data: { - name + name: (method.static ? 'static ' : '') + method.name } }); } else if (name && index === -1) { - seen.push(name); + seenMethods.push(method); } - lastName = name; + lastMethod = method; }); } } diff --git a/packages/eslint-plugin/tests/lib/rules/adjacent-overload-signatures.js b/packages/eslint-plugin/tests/lib/rules/adjacent-overload-signatures.js index 161ffd4035e6..fe42efd1015b 100644 --- a/packages/eslint-plugin/tests/lib/rules/adjacent-overload-signatures.js +++ b/packages/eslint-plugin/tests/lib/rules/adjacent-overload-signatures.js @@ -211,6 +211,23 @@ class Foo { foo(sn: string | number): void {} bar(): void {} baz(): void {} +} + `, + ` +class Foo { + name: string; + static foo(s: string): void; + static foo(n: number): void; + static foo(sn: string | number): void {} + bar(): void {} + baz(): void {} +} + `, + ` +class Test { + static test() {} + untest() {} + test() {} } `, // examples from https://github.com/nzakas/eslint-plugin-typescript/issues/138 @@ -789,6 +806,26 @@ class Foo { column: 5 } ] + }, + { + code: ` +class Foo { + static foo(s: string): void; + name: string; + static foo(n: number): void; + static foo(sn: string | number): void {} + bar(): void {} + baz(): void {} +} + `, + errors: [ + { + messageId: 'adjacentSignature', + data: { name: 'static foo' }, + line: 5, + column: 5 + } + ] } ] }); From 84162ba6167c21d57f0d5955b15b3135c9e3a438 Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Wed, 6 Feb 2019 17:47:23 -0800 Subject: [PATCH 20/26] feat(eslint-plugin): add new rule no-for-in-array (#155) --- packages/eslint-plugin/README.md | 1 + packages/eslint-plugin/ROADMAP.md | 12 +++- .../docs/rules/no-for-in-array.md | 44 ++++++++++++ .../lib/rules/no-for-in-array.js | 56 +++++++++++++++ packages/eslint-plugin/lib/util.js | 2 +- .../tests/lib/rules/no-for-in-array.js | 69 +++++++++++++++++++ 6 files changed, 180 insertions(+), 4 deletions(-) create mode 100644 packages/eslint-plugin/docs/rules/no-for-in-array.md create mode 100644 packages/eslint-plugin/lib/rules/no-for-in-array.js create mode 100644 packages/eslint-plugin/tests/lib/rules/no-for-in-array.js diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md index cacb6666fddf..3807877a073e 100644 --- a/packages/eslint-plugin/README.md +++ b/packages/eslint-plugin/README.md @@ -128,6 +128,7 @@ Then you should add `airbnb` (or `airbnb-base`) to your `extends` section of `.e | [`@typescript-eslint/no-empty-interface`](./docs/rules/no-empty-interface.md) | Disallow the declaration of empty interfaces (`no-empty-interface` from TSLint) | :heavy_check_mark: | | | [`@typescript-eslint/no-explicit-any`](./docs/rules/no-explicit-any.md) | Disallow usage of the `any` type (`no-any` from TSLint) | :heavy_check_mark: | | | [`@typescript-eslint/no-extraneous-class`](./docs/rules/no-extraneous-class.md) | Forbids the use of classes as namespaces (`no-unnecessary-class` from TSLint) | | | +| [`@typescript-eslint/no-for-in-array`](./docs/rules/no-for-in-array.md) | Disallow iterating over an array with a for-in loop (`no-for-in-array` from TSLint) | | | | [`@typescript-eslint/no-inferrable-types`](./docs/rules/no-inferrable-types.md) | Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean. (`no-inferrable-types` from TSLint) | :heavy_check_mark: | :wrench: | | [`@typescript-eslint/no-misused-new`](./docs/rules/no-misused-new.md) | Enforce valid definition of `new` and `constructor`. (`no-misused-new` from TSLint) | :heavy_check_mark: | | | [`@typescript-eslint/no-namespace`](./docs/rules/no-namespace.md) | Disallow the use of custom TypeScript modules and namespaces (`no-namespace` from TSLint) | :heavy_check_mark: | | diff --git a/packages/eslint-plugin/ROADMAP.md b/packages/eslint-plugin/ROADMAP.md index bd0480101cf1..5abf9e26d4ef 100644 --- a/packages/eslint-plugin/ROADMAP.md +++ b/packages/eslint-plugin/ROADMAP.md @@ -1,10 +1,15 @@ # Roadmap -✅ (29) = done
+ + +✅ (30) = done
🌟 (79) = in ESLint core
🔌 (33) = in another plugin
🌓 (16) = implementations differ or ESLint version is missing functionality
-🛑 (68) = unimplemented +🛑 (68) = unimplemented
## TSLint rules @@ -59,7 +64,7 @@ | [`no-empty`] | 🌟 | [`no-empty`][no-empty] | | [`no-eval`] | 🌟 | [`no-eval`][no-eval] | | [`no-floating-promises`] | 🛑 | N/A ([relevant plugin][plugin:promise]) | -| [`no-for-in-array`] | 🛑 | N/A | +| [`no-for-in-array`] | ✅ | [`@typescript-eslint/no-for-in-array`] | | [`no-implicit-dependencies`] | 🔌 | [`import/no-extraneous-dependencies`] | | [`no-inferred-empty-object-type`] | 🛑 | N/A | | [`no-invalid-template-strings`] | 🌟 | [`no-template-curly-in-string`][no-template-curly-in-string] | @@ -586,6 +591,7 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint- [`@typescript-eslint/member-delimiter-style`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-delimiter-style.md [`@typescript-eslint/prefer-interface`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-interface.md [`@typescript-eslint/no-array-constructor`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-array-constructor.md +[`@typescript-eslint/no-for-in-array`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-for-in-array.md diff --git a/packages/eslint-plugin/docs/rules/no-for-in-array.md b/packages/eslint-plugin/docs/rules/no-for-in-array.md new file mode 100644 index 000000000000..3a1cf2bdd370 --- /dev/null +++ b/packages/eslint-plugin/docs/rules/no-for-in-array.md @@ -0,0 +1,44 @@ +# Disallow iterating over an array with a for-in loop (no-for-in-array) + +This rule prohibits iterating over an array with a for-in loop. + +## Rule Details + +Rationale from TSLint: + +A for-in loop (`for (var k in o)`) iterates over the properties of an Object. +While it is legal to use for-in loops with array types, it is not common. +for-in will iterate over the indices of the array as strings, omitting any "holes" in +the array. +More common is to use for-of, which iterates over the values of an array. +If you want to iterate over the indices, alternatives include: + +```js +array.forEach((value, index) => { ... }); +for (const [index, value] of array.entries()) { ... } +for (let i = 0; i < array.length; i++) { ... } +``` + +Examples of **incorrect** code for this rule: + +```js +for (const x in [3, 4, 5]) { + console.log(x); +} +``` + +Examples of **correct** code for this rule: + +```js +for (const x in { a: 3, b: 4, c: 5 }) { + console.log(x); +} +``` + +## When Not To Use It + +If you want to iterate through a loop using the indices in an array as strings, you can turn off this rule. + +## Related to + +- TSLint: ['no-for-in-array'](https://palantir.github.io/tslint/rules/no-for-in-array/) diff --git a/packages/eslint-plugin/lib/rules/no-for-in-array.js b/packages/eslint-plugin/lib/rules/no-for-in-array.js new file mode 100644 index 000000000000..23a19732ac45 --- /dev/null +++ b/packages/eslint-plugin/lib/rules/no-for-in-array.js @@ -0,0 +1,56 @@ +/** + * @fileoverview Disallow iterating over an array with a for-in loop + * @author Benjamin Lichtman + */ +'use strict'; +const ts = require('typescript'); +const util = require('../util'); + +//------------------------------------------------------------------------------ +// Rule Definition +//------------------------------------------------------------------------------ + +/** + * @type {import("eslint").Rule.RuleModule} + */ +module.exports = { + meta: { + docs: { + description: 'Disallow iterating over an array with a for-in loop', + category: 'Functionality', + recommended: false, + extraDescription: [util.tslintRule('no-for-in-array')], + url: util.metaDocsUrl('no-for-in-array') + }, + fixable: null, + messages: { + forInViolation: + 'For-in loops over arrays are forbidden. Use for-of or array.forEach instead.' + }, + schema: [], + type: 'problem' + }, + + create(context) { + return { + ForInStatement(node) { + const parserServices = util.getParserServices(context); + const checker = parserServices.program.getTypeChecker(); + const originalNode = parserServices.esTreeNodeToTSNodeMap.get(node); + + const type = checker.getTypeAtLocation(originalNode.expression); + + if ( + (typeof type.symbol !== 'undefined' && + type.symbol.name === 'Array') || + (type.flags & ts.TypeFlags.StringLike) !== 0 + ) { + context.report({ + node, + messageId: 'forInViolation' + }); + } + } + }; + } +}; diff --git a/packages/eslint-plugin/lib/util.js b/packages/eslint-plugin/lib/util.js index dac41fe21bb7..6714e600ee65 100644 --- a/packages/eslint-plugin/lib/util.js +++ b/packages/eslint-plugin/lib/util.js @@ -109,7 +109,7 @@ exports.upperCaseFirst = str => str[0].toUpperCase() + str.slice(1); /** * Try to retrieve typescript parser service from context * @param {RuleContext} context Rule context - * @returns {{esTreeNodeToTSNodeMap}|{program}|Object|*} parserServices + * @returns {{program: Program, esTreeNodeToTSNodeMap: NodeMap}} parserServices */ exports.getParserServices = context => { if ( diff --git a/packages/eslint-plugin/tests/lib/rules/no-for-in-array.js b/packages/eslint-plugin/tests/lib/rules/no-for-in-array.js new file mode 100644 index 000000000000..91984453000d --- /dev/null +++ b/packages/eslint-plugin/tests/lib/rules/no-for-in-array.js @@ -0,0 +1,69 @@ +/** + * @fileoverview Disallow iterating over an array with a for-in loop + * @author Benjamin Lichtman + */ +'use strict'; + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +const rule = require('../../../lib/rules/no-for-in-array'), + RuleTester = require('eslint').RuleTester, + path = require('path'); + +//------------------------------------------------------------------------------ +// Tests +//------------------------------------------------------------------------------ + +const rootDir = path.join(process.cwd(), 'tests/fixtures/'); +const parserOptions = { + ecmaVersion: 2015, + tsconfigRootDir: rootDir, + project: './tsconfig.json' +}; +const ruleTester = new RuleTester({ + parserOptions, + parser: '@typescript-eslint/parser' +}); + +ruleTester.run('no-for-in-array', rule, { + valid: [ + ` +for (const x of [3, 4, 5]) { + console.log(x); +}`, + ` +for (const x in { a: 1, b: 2, c: 3 }) { + console.log(x); +}` + ], + + invalid: [ + { + code: ` +for (const x in [3, 4, 5]) { + console.log(x); +}`, + errors: [ + { + messageId: 'forInViolation', + type: 'ForInStatement' + } + ] + }, + { + code: ` +const z = [3, 4, 5]; +for (const x in z) { + console.log(x); +}`, + errors: [ + { + messageId: 'forInViolation', + type: 'ForInStatement' + } + ] + } + ] +}); From 0a1777fc900010f7fcd7fef725f57b02690b0535 Mon Sep 17 00:00:00 2001 From: James Henry Date: Wed, 6 Feb 2019 21:04:16 -0500 Subject: [PATCH 21/26] fix(ts-estree): convert decorators on var and fn decs (#211) --- .../lib/__snapshots__/typescript.ts.snap | 92 +++++++++++++++++++ packages/typescript-estree/src/convert.ts | 22 +++++ .../lib/__snapshots__/typescript.ts.snap | 92 +++++++++++++++++++ 3 files changed, 206 insertions(+) diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index ef757ac0453e..ac457ec0ca3d 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -91249,6 +91249,43 @@ Object { ], "type": "BlockStatement", }, + "decorators": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "name": "dec", + "range": Array [ + 1, + 4, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 4, + ], + "type": "Decorator", + }, + ], "expression": false, "generator": false, "id": Object { @@ -91791,6 +91828,61 @@ Object { "type": "VariableDeclarator", }, ], + "decorators": Array [ + Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "name": "deco", + "range": Array [ + 1, + 5, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "range": Array [ + 1, + 7, + ], + "type": "CallExpression", + }, + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 7, + ], + "type": "Decorator", + }, + ], "kind": "const", "loc": Object { "end": Object { diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 3686ba919150..bf121fa01bb0 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -696,6 +696,17 @@ export class Converter { ); } + /** + * Semantically, decorators are not allowed on function declarations, + * but the TypeScript compiler will parse them and produce a valid AST, + * so we handle them here too. + */ + if (node.decorators) { + (result as any).decorators = node.decorators.map(el => + this.convertChild(el) + ); + } + // check for exports return fixExports(node, result, this.ast); } @@ -730,6 +741,17 @@ export class Converter { kind: getDeclarationKind(node.declarationList) }); + /** + * Semantically, decorators are not allowed on variable declarations, + * but the TypeScript compiler will parse them and produce a valid AST, + * so we handle them here too. + */ + if (node.decorators) { + (result as any).decorators = node.decorators.map(el => + this.convertChild(el) + ); + } + if (hasModifier(SyntaxKind.DeclareKeyword, node)) { result.declare = true; } diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index 38bc1e93b184..9c0094cff37b 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -90557,6 +90557,43 @@ Object { ], "type": "BlockStatement", }, + "decorators": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "name": "dec", + "range": Array [ + 1, + 4, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 4, + ], + "type": "Decorator", + }, + ], "expression": false, "generator": false, "id": Object { @@ -91097,6 +91134,61 @@ Object { "type": "VariableDeclarator", }, ], + "decorators": Array [ + Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "name": "deco", + "range": Array [ + 1, + 5, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "range": Array [ + 1, + 7, + ], + "type": "CallExpression", + }, + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 7, + ], + "type": "Decorator", + }, + ], "kind": "const", "loc": Object { "end": Object { From a005541f0ba2f78e9f7b7000fb696db436e4c4d7 Mon Sep 17 00:00:00 2001 From: James Henry Date: Wed, 6 Feb 2019 21:13:16 -0500 Subject: [PATCH 22/26] docs(eslint-plugin): removed counts from ROADMAP (#225) --- packages/eslint-plugin/ROADMAP.md | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/eslint-plugin/ROADMAP.md b/packages/eslint-plugin/ROADMAP.md index 5abf9e26d4ef..48ccaa900b63 100644 --- a/packages/eslint-plugin/ROADMAP.md +++ b/packages/eslint-plugin/ROADMAP.md @@ -1,15 +1,10 @@ # Roadmap - - -✅ (30) = done
-🌟 (79) = in ESLint core
-🔌 (33) = in another plugin
-🌓 (16) = implementations differ or ESLint version is missing functionality
-🛑 (68) = unimplemented
+✅ = done
+🌟 = in ESLint core
+🔌 = in another plugin
+🌓 = implementations differ or ESLint version is missing functionality
+🛑 = unimplemented
## TSLint rules From fc50167d2a1b38edeab05a472010a63e3fbd8ef2 Mon Sep 17 00:00:00 2001 From: Armano Date: Thu, 7 Feb 2019 03:47:42 +0100 Subject: [PATCH 23/26] feat(ts-estree): enable errors 1098 and 1099 (#219) - add test cases for typed destruction - add test cases for anonymous function with returnType and typeParameters --- .../lib/__snapshots__/typescript.ts.snap | 11308 +++++++++------- ...ction-anonymus-with-type-parameters.src.ts | 3 + .../function-anynomus-with-return-type.src.ts | 2 + .../function-with-array-destruction.src.ts | 1 + .../function-with-object-destruction.src.ts | 1 + .../typescript-estree/src/semantic-errors.ts | 2 + .../tests/ast-alignment/fixtures-to-test.ts | 28 +- .../semantic-diagnostics-enabled.ts.snap | 89 +- .../lib/__snapshots__/typescript.ts.snap | 11304 ++++++++------- 9 files changed, 13199 insertions(+), 9539 deletions(-) create mode 100644 packages/shared-fixtures/fixtures/typescript/basics/function-anonymus-with-type-parameters.src.ts create mode 100644 packages/shared-fixtures/fixtures/typescript/basics/function-anynomus-with-return-type.src.ts create mode 100644 packages/shared-fixtures/fixtures/typescript/types/function-with-array-destruction.src.ts create mode 100644 packages/shared-fixtures/fixtures/typescript/types/function-with-object-destruction.src.ts diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index ac457ec0ca3d..876c8b3b43b1 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -39253,139 +39253,269 @@ Object { } `; -exports[`typescript fixtures/basics/function-overloads.src 1`] = ` +exports[`typescript fixtures/basics/function-anonymus-with-type-parameters.src 1`] = ` Object { "body": Array [ Object { - "declaration": Object { - "async": false, - "expression": false, - "generator": false, - "id": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 1, - }, - "start": Object { - "column": 16, - "line": 1, - }, - }, - "name": "f", - "range": Array [ - 16, - 17, - ], - "type": "Identifier", - }, - "loc": Object { - "end": Object { - "column": 37, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, - }, - }, - "params": Array [ - Object { + "declarations": Array [ + Object { + "id": Object { "loc": Object { "end": Object { - "column": 27, + "column": 7, "line": 1, }, "start": Object { - "column": 18, + "column": 4, "line": 1, }, }, - "name": "x", + "name": "obj", "range": Array [ - 18, - 27, + 4, + 7, ], "type": "Identifier", - "typeAnnotation": Object { + }, + "init": Object { + "async": false, + "body": Object { + "body": Array [ + Object { + "argument": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "name": "a", + "range": Array [ + 45, + 46, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 38, + 47, + ], + "type": "ReturnStatement", + }, + ], "loc": Object { "end": Object { - "column": 27, - "line": 1, + "column": 1, + "line": 3, }, "start": Object { - "column": 19, + "column": 34, "line": 1, }, }, "range": Array [ - 19, - 27, + 34, + 49, ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "params": Array [ + Object { "loc": Object { "end": Object { - "column": 27, + "column": 32, "line": 1, }, "start": Object { - "column": 21, + "column": 23, "line": 1, }, }, + "name": "a", "range": Array [ - 21, - 27, + 23, + 32, ], - "type": "TSNumberKeyword", + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 32, + "line": 1, + }, + "start": Object { + "column": 24, + "line": 1, + }, + }, + "range": Array [ + 24, + 32, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 32, + "line": 1, + }, + "start": Object { + "column": 26, + "line": 1, + }, + }, + "range": Array [ + 26, + 32, + ], + "type": "TSStringKeyword", + }, + }, + }, + ], + "range": Array [ + 10, + 49, + ], + "type": "FunctionExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 1, + }, + "start": Object { + "column": 19, + "line": 1, + }, }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 20, + 21, + ], + "type": "Identifier", + }, + "range": Array [ + 20, + 21, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 19, + 22, + ], + "type": "TSTypeParameterDeclaration", }, }, - ], - "range": Array [ - 7, - 37, - ], - "returnType": Object { "loc": Object { "end": Object { - "column": 36, - "line": 1, + "column": 1, + "line": 3, }, "start": Object { - "column": 28, + "column": 4, "line": 1, }, }, "range": Array [ - 28, - 36, + 4, + 49, ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 1, - }, - "start": Object { - "column": 30, - "line": 1, - }, - }, - "range": Array [ - 30, - 36, - ], - "type": "TSNumberKeyword", - }, + "type": "VariableDeclarator", + }, + ], + "kind": "var", + "loc": Object { + "end": Object { + "column": 2, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, }, - "type": "TSDeclareFunction", }, + "range": Array [ + 0, + 50, + ], + "type": "VariableDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 51, + ], + "sourceType": "module", + "tokens": Array [ + Object { "loc": Object { "end": Object { - "column": 37, + "column": 3, "line": 1, }, "start": Object { @@ -39395,514 +39525,133 @@ Object { }, "range": Array [ 0, - 37, + 3, ], - "source": null, - "specifiers": Array [], - "type": "ExportNamedDeclaration", + "type": "Keyword", + "value": "var", }, Object { - "declaration": Object { - "async": false, - "expression": false, - "generator": false, - "id": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 2, - }, - "start": Object { - "column": 16, - "line": 2, - }, - }, - "name": "f", - "range": Array [ - 54, - 55, - ], - "type": "Identifier", + "loc": Object { + "end": Object { + "column": 7, + "line": 1, }, - "loc": Object { - "end": Object { - "column": 37, - "line": 2, - }, - "start": Object { - "column": 7, - "line": 2, - }, + "start": Object { + "column": 4, + "line": 1, }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 2, - }, - "start": Object { - "column": 18, - "line": 2, - }, - }, - "name": "x", - "range": Array [ - 56, - 65, - ], - "type": "Identifier", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 2, - }, - "start": Object { - "column": 19, - "line": 2, - }, - }, - "range": Array [ - 57, - 65, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 2, - }, - "start": Object { - "column": 21, - "line": 2, - }, - }, - "range": Array [ - 59, - 65, - ], - "type": "TSStringKeyword", - }, - }, - }, - ], - "range": Array [ - 45, - 75, - ], - "returnType": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 2, - }, - "start": Object { - "column": 28, - "line": 2, - }, - }, - "range": Array [ - 66, - 74, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 2, - }, - "start": Object { - "column": 30, - "line": 2, - }, - }, - "range": Array [ - 68, - 74, - ], - "type": "TSStringKeyword", - }, + }, + "range": Array [ + 4, + 7, + ], + "type": "Identifier", + "value": "obj", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, }, - "type": "TSDeclareFunction", }, + "range": Array [ + 8, + 9, + ], + "type": "Punctuator", + "value": "=", + }, + Object { "loc": Object { "end": Object { - "column": 37, - "line": 2, + "column": 18, + "line": 1, }, "start": Object { - "column": 0, - "line": 2, + "column": 10, + "line": 1, }, }, "range": Array [ - 38, - 75, + 10, + 18, ], - "source": null, - "specifiers": Array [], - "type": "ExportNamedDeclaration", + "type": "Keyword", + "value": "function", }, - Object { - "declaration": Object { - "async": false, - "body": Object { - "body": Array [ - Object { - "argument": Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 4, - }, - "start": Object { - "column": 9, - "line": 4, - }, - }, - "name": "x", - "range": Array [ - 142, - 143, - ], - "type": "Identifier", - }, - "loc": Object { - "end": Object { - "column": 11, - "line": 4, - }, - "start": Object { - "column": 2, - "line": 4, - }, - }, - "range": Array [ - 135, - 144, - ], - "type": "ReturnStatement", - }, - ], - "loc": Object { - "end": Object { - "column": 1, - "line": 5, - }, - "start": Object { - "column": 55, - "line": 3, - }, - }, - "range": Array [ - 131, - 146, - ], - "type": "BlockStatement", - }, - "expression": false, - "generator": false, - "id": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 3, - }, - "start": Object { - "column": 16, - "line": 3, - }, - }, - "name": "f", - "range": Array [ - 92, - 93, - ], - "type": "Identifier", - }, - "loc": Object { - "end": Object { - "column": 1, - "line": 5, - }, - "start": Object { - "column": 7, - "line": 3, - }, - }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 18, - "line": 3, - }, - }, - "name": "x", - "range": Array [ - 94, - 112, - ], - "type": "Identifier", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 19, - "line": 3, - }, - }, - "range": Array [ - 95, - 112, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 21, - "line": 3, - }, - }, - "range": Array [ - 97, - 112, - ], - "type": "TSUnionType", - "types": Array [ - Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 3, - }, - "start": Object { - "column": 21, - "line": 3, - }, - }, - "range": Array [ - 97, - 103, - ], - "type": "TSStringKeyword", - }, - Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 30, - "line": 3, - }, - }, - "range": Array [ - 106, - 112, - ], - "type": "TSNumberKeyword", - }, - ], - }, - }, - }, - ], - "range": Array [ - 83, - 146, - ], - "returnType": Object { - "loc": Object { - "end": Object { - "column": 54, - "line": 3, - }, - "start": Object { - "column": 37, - "line": 3, - }, - }, - "range": Array [ - 113, - 130, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 54, - "line": 3, - }, - "start": Object { - "column": 39, - "line": 3, - }, - }, - "range": Array [ - 115, - 130, - ], - "type": "TSUnionType", - "types": Array [ - Object { - "loc": Object { - "end": Object { - "column": 45, - "line": 3, - }, - "start": Object { - "column": 39, - "line": 3, - }, - }, - "range": Array [ - 115, - 121, - ], - "type": "TSStringKeyword", - }, - Object { - "loc": Object { - "end": Object { - "column": 54, - "line": 3, - }, - "start": Object { - "column": 48, - "line": 3, - }, - }, - "range": Array [ - 124, - 130, - ], - "type": "TSNumberKeyword", - }, - ], - }, - }, - "type": "FunctionDeclaration", - }, - "loc": Object { - "end": Object { - "column": 1, - "line": 5, - }, - "start": Object { - "column": 0, - "line": 3, - }, - }, - "range": Array [ - 76, - 146, - ], - "source": null, - "specifiers": Array [], - "type": "ExportNamedDeclaration", - }, - ], - "comments": Array [], - "loc": Object { - "end": Object { - "column": 0, - "line": 6, - }, - "start": Object { - "column": 0, - "line": 1, - }, - }, - "range": Array [ - 0, - 147, - ], - "sourceType": "module", - "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 6, + "column": 20, "line": 1, }, "start": Object { - "column": 0, + "column": 19, "line": 1, }, }, "range": Array [ - 0, - 6, + 19, + 20, ], - "type": "Keyword", - "value": "export", + "type": "Punctuator", + "value": "<", }, Object { "loc": Object { "end": Object { - "column": 15, + "column": 21, "line": 1, }, "start": Object { - "column": 7, + "column": 20, "line": 1, }, }, "range": Array [ - 7, - 15, + 20, + 21, ], - "type": "Keyword", - "value": "function", + "type": "Identifier", + "value": "T", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 22, "line": 1, }, "start": Object { - "column": 16, + "column": 21, "line": 1, }, }, "range": Array [ - 16, - 17, + 21, + 22, ], - "type": "Identifier", - "value": "f", + "type": "Punctuator", + "value": ">", }, Object { "loc": Object { "end": Object { - "column": 18, + "column": 23, "line": 1, }, "start": Object { - "column": 17, + "column": 22, "line": 1, }, }, "range": Array [ - 17, - 18, + 22, + 23, ], "type": "Punctuator", "value": "(", @@ -39910,35 +39659,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 19, + "column": 24, "line": 1, }, "start": Object { - "column": 18, + "column": 23, "line": 1, }, }, "range": Array [ - 18, - 19, + 23, + 24, ], "type": "Identifier", - "value": "x", + "value": "a", }, Object { "loc": Object { "end": Object { - "column": 20, + "column": 25, "line": 1, }, "start": Object { - "column": 19, + "column": 24, "line": 1, }, }, "range": Array [ - 19, - 20, + 24, + 25, ], "type": "Punctuator", "value": ":", @@ -39946,35 +39695,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 27, + "column": 32, "line": 1, }, "start": Object { - "column": 21, + "column": 26, "line": 1, }, }, "range": Array [ - 21, - 27, + 26, + 32, ], "type": "Identifier", - "value": "number", + "value": "string", }, Object { "loc": Object { "end": Object { - "column": 28, + "column": 33, "line": 1, }, "start": Object { - "column": 27, + "column": 32, "line": 1, }, }, "range": Array [ - 27, - 28, + 32, + 33, ], "type": "Punctuator", "value": ")", @@ -39982,65 +39731,29 @@ Object { Object { "loc": Object { "end": Object { - "column": 29, - "line": 1, - }, - "start": Object { - "column": 28, - "line": 1, - }, - }, - "range": Array [ - 28, - 29, - ], - "type": "Punctuator", - "value": ":", - }, - Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 1, - }, - "start": Object { - "column": 30, - "line": 1, - }, - }, - "range": Array [ - 30, - 36, - ], - "type": "Identifier", - "value": "number", - }, - Object { - "loc": Object { - "end": Object { - "column": 37, + "column": 35, "line": 1, }, "start": Object { - "column": 36, + "column": 34, "line": 1, }, }, "range": Array [ - 36, - 37, + 34, + 35, ], "type": "Punctuator", - "value": ";", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 6, + "column": 8, "line": 2, }, "start": Object { - "column": 0, + "column": 2, "line": 2, }, }, @@ -40049,364 +39762,339 @@ Object { 44, ], "type": "Keyword", - "value": "export", + "value": "return", }, Object { "loc": Object { "end": Object { - "column": 15, + "column": 10, "line": 2, }, "start": Object { - "column": 7, + "column": 9, "line": 2, }, }, "range": Array [ 45, - 53, - ], - "type": "Keyword", - "value": "function", - }, - Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 2, - }, - "start": Object { - "column": 16, - "line": 2, - }, - }, - "range": Array [ - 54, - 55, - ], - "type": "Identifier", - "value": "f", - }, - Object { - "loc": Object { - "end": Object { - "column": 18, - "line": 2, - }, - "start": Object { - "column": 17, - "line": 2, - }, - }, - "range": Array [ - 55, - 56, - ], - "type": "Punctuator", - "value": "(", - }, - Object { - "loc": Object { - "end": Object { - "column": 19, - "line": 2, - }, - "start": Object { - "column": 18, - "line": 2, - }, - }, - "range": Array [ - 56, - 57, + 46, ], "type": "Identifier", - "value": "x", + "value": "a", }, Object { "loc": Object { "end": Object { - "column": 20, + "column": 11, "line": 2, }, "start": Object { - "column": 19, + "column": 10, "line": 2, }, }, "range": Array [ - 57, - 58, + 46, + 47, ], "type": "Punctuator", - "value": ":", - }, - Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 2, - }, - "start": Object { - "column": 21, - "line": 2, - }, - }, - "range": Array [ - 59, - 65, - ], - "type": "Identifier", - "value": "string", + "value": ";", }, Object { "loc": Object { "end": Object { - "column": 28, - "line": 2, + "column": 1, + "line": 3, }, "start": Object { - "column": 27, - "line": 2, + "column": 0, + "line": 3, }, }, "range": Array [ - 65, - 66, + 48, + 49, ], "type": "Punctuator", - "value": ")", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 29, - "line": 2, + "column": 2, + "line": 3, }, "start": Object { - "column": 28, - "line": 2, + "column": 1, + "line": 3, }, }, "range": Array [ - 66, - 67, + 49, + 50, ], "type": "Punctuator", - "value": ":", + "value": ";", }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/basics/function-anynomus-with-return-type.src 1`] = ` +Object { + "body": Array [ Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 2, - }, - "start": Object { - "column": 30, - "line": 2, + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "name": "obj", + "range": Array [ + 4, + 7, + ], + "type": "Identifier", + }, + "init": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 1, + "line": 2, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, + "range": Array [ + 28, + 31, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 1, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 10, + 31, + ], + "returnType": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 27, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "range": Array [ + 23, + 27, + ], + "type": "TSVoidKeyword", + }, + }, + "type": "FunctionExpression", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 31, + ], + "type": "VariableDeclarator", }, - }, - "range": Array [ - 68, - 74, ], - "type": "Identifier", - "value": "string", - }, - Object { + "kind": "var", "loc": Object { "end": Object { - "column": 37, + "column": 2, "line": 2, }, "start": Object { - "column": 36, - "line": 2, + "column": 0, + "line": 1, }, }, "range": Array [ - 74, - 75, + 0, + 32, ], - "type": "Punctuator", - "value": ";", + "type": "VariableDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, }, + }, + "range": Array [ + 0, + 33, + ], + "sourceType": "module", + "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 6, - "line": 3, + "column": 3, + "line": 1, }, "start": Object { "column": 0, - "line": 3, + "line": 1, }, }, "range": Array [ - 76, - 82, + 0, + 3, ], "type": "Keyword", - "value": "export", + "value": "var", }, Object { "loc": Object { "end": Object { - "column": 15, - "line": 3, - }, - "start": Object { "column": 7, - "line": 3, - }, - }, - "range": Array [ - 83, - 91, - ], - "type": "Keyword", - "value": "function", - }, - Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 3, + "line": 1, }, "start": Object { - "column": 16, - "line": 3, + "column": 4, + "line": 1, }, }, "range": Array [ - 92, - 93, + 4, + 7, ], "type": "Identifier", - "value": "f", + "value": "obj", }, Object { "loc": Object { "end": Object { - "column": 18, - "line": 3, + "column": 9, + "line": 1, }, "start": Object { - "column": 17, - "line": 3, + "column": 8, + "line": 1, }, }, "range": Array [ - 93, - 94, + 8, + 9, ], "type": "Punctuator", - "value": "(", + "value": "=", }, Object { "loc": Object { "end": Object { - "column": 19, - "line": 3, + "column": 18, + "line": 1, }, "start": Object { - "column": 18, - "line": 3, + "column": 10, + "line": 1, }, }, "range": Array [ - 94, - 95, + 10, + 18, ], - "type": "Identifier", - "value": "x", + "type": "Keyword", + "value": "function", }, Object { "loc": Object { "end": Object { "column": 20, - "line": 3, + "line": 1, }, "start": Object { "column": 19, - "line": 3, + "line": 1, }, }, "range": Array [ - 95, - 96, + 19, + 20, ], "type": "Punctuator", - "value": ":", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 27, - "line": 3, - }, - "start": Object { "column": 21, - "line": 3, - }, - }, - "range": Array [ - 97, - 103, - ], - "type": "Identifier", - "value": "string", - }, - Object { - "loc": Object { - "end": Object { - "column": 29, - "line": 3, - }, - "start": Object { - "column": 28, - "line": 3, - }, - }, - "range": Array [ - 104, - 105, - ], - "type": "Punctuator", - "value": "|", - }, - Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 30, - "line": 3, - }, - }, - "range": Array [ - 106, - 112, - ], - "type": "Identifier", - "value": "number", - }, - Object { - "loc": Object { - "end": Object { - "column": 37, - "line": 3, + "line": 1, }, "start": Object { - "column": 36, - "line": 3, + "column": 20, + "line": 1, }, }, "range": Array [ - 112, - 113, + 20, + 21, ], "type": "Punctuator", "value": ")", @@ -40414,17 +40102,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 38, - "line": 3, + "column": 22, + "line": 1, }, "start": Object { - "column": 37, - "line": 3, + "column": 21, + "line": 1, }, }, "range": Array [ - 113, - 114, + 21, + 22, ], "type": "Punctuator", "value": ":", @@ -40432,215 +40120,1468 @@ Object { Object { "loc": Object { "end": Object { - "column": 45, - "line": 3, + "column": 27, + "line": 1, }, "start": Object { - "column": 39, - "line": 3, + "column": 23, + "line": 1, }, }, "range": Array [ - 115, - 121, + 23, + 27, ], - "type": "Identifier", - "value": "string", + "type": "Keyword", + "value": "void", }, Object { "loc": Object { "end": Object { - "column": 47, - "line": 3, + "column": 29, + "line": 1, }, "start": Object { - "column": 46, - "line": 3, + "column": 28, + "line": 1, }, }, "range": Array [ - 122, - 123, + 28, + 29, ], "type": "Punctuator", - "value": "|", - }, - Object { - "loc": Object { - "end": Object { - "column": 54, - "line": 3, - }, - "start": Object { - "column": 48, - "line": 3, - }, - }, - "range": Array [ - 124, - 130, - ], - "type": "Identifier", - "value": "number", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 56, - "line": 3, + "column": 1, + "line": 2, }, "start": Object { - "column": 55, - "line": 3, + "column": 0, + "line": 2, }, }, "range": Array [ - 131, - 132, + 30, + 31, ], "type": "Punctuator", - "value": "{", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 8, - "line": 4, - }, - "start": Object { "column": 2, - "line": 4, - }, - }, - "range": Array [ - 135, - 141, - ], - "type": "Keyword", - "value": "return", - }, - Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 4, - }, - "start": Object { - "column": 9, - "line": 4, - }, - }, - "range": Array [ - 142, - 143, - ], - "type": "Identifier", - "value": "x", - }, - Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 4, + "line": 2, }, "start": Object { - "column": 10, - "line": 4, - }, - }, - "range": Array [ - 143, - 144, - ], - "type": "Punctuator", - "value": ";", - }, - Object { - "loc": Object { - "end": Object { "column": 1, - "line": 5, - }, - "start": Object { - "column": 0, - "line": 5, + "line": 2, }, }, "range": Array [ - 145, - 146, + 31, + 32, ], "type": "Punctuator", - "value": "}", + "value": ";", }, ], "type": "Program", } `; -exports[`typescript fixtures/basics/function-with-await.src 1`] = ` +exports[`typescript fixtures/basics/function-overloads.src 1`] = ` Object { "body": Array [ Object { - "async": true, - "body": Object { - "body": Array [ - Object { - "expression": Object { - "argument": Object { - "loc": Object { - "end": Object { - "column": 16, - "line": 2, - }, - "start": Object { - "column": 10, - "line": 2, - }, - }, - "name": "future", - "range": Array [ - 40, - 46, - ], - "type": "Identifier", - }, - "loc": Object { - "end": Object { - "column": 16, - "line": 2, - }, - "start": Object { - "column": 4, - "line": 2, - }, - }, - "range": Array [ - 34, - 46, - ], - "type": "AwaitExpression", + "declaration": Object { + "async": false, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, }, - "loc": Object { - "end": Object { - "column": 17, - "line": 2, - }, - "start": Object { - "column": 4, - "line": 2, - }, + "start": Object { + "column": 16, + "line": 1, }, - "range": Array [ - 34, - 47, - ], - "type": "ExpressionStatement", }, - ], + "name": "f", + "range": Array [ + 16, + 17, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { - "column": 1, + "column": 37, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "name": "x", + "range": Array [ + 18, + 27, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 19, + "line": 1, + }, + }, + "range": Array [ + 19, + 27, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 27, + ], + "type": "TSNumberKeyword", + }, + }, + }, + ], + "range": Array [ + 7, + 37, + ], + "returnType": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 1, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, + "range": Array [ + 28, + 36, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 1, + }, + "start": Object { + "column": 30, + "line": 1, + }, + }, + "range": Array [ + 30, + 36, + ], + "type": "TSNumberKeyword", + }, + }, + "type": "TSDeclareFunction", + }, + "loc": Object { + "end": Object { + "column": 37, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 37, + ], + "source": null, + "specifiers": Array [], + "type": "ExportNamedDeclaration", + }, + Object { + "declaration": Object { + "async": false, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "name": "f", + "range": Array [ + 54, + 55, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 37, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "name": "x", + "range": Array [ + 56, + 65, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 19, + "line": 2, + }, + }, + "range": Array [ + 57, + 65, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 21, + "line": 2, + }, + }, + "range": Array [ + 59, + 65, + ], + "type": "TSStringKeyword", + }, + }, + }, + ], + "range": Array [ + 45, + 75, + ], + "returnType": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 2, + }, + "start": Object { + "column": 28, + "line": 2, + }, + }, + "range": Array [ + 66, + 74, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 2, + }, + "start": Object { + "column": 30, + "line": 2, + }, + }, + "range": Array [ + 68, + 74, + ], + "type": "TSStringKeyword", + }, + }, + "type": "TSDeclareFunction", + }, + "loc": Object { + "end": Object { + "column": 37, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 38, + 75, + ], + "source": null, + "specifiers": Array [], + "type": "ExportNamedDeclaration", + }, + Object { + "declaration": Object { + "async": false, + "body": Object { + "body": Array [ + Object { + "argument": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 4, + }, + "start": Object { + "column": 9, + "line": 4, + }, + }, + "name": "x", + "range": Array [ + 142, + 143, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, + }, + }, + "range": Array [ + 135, + 144, + ], + "type": "ReturnStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 55, + "line": 3, + }, + }, + "range": Array [ + 131, + 146, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 3, + }, + "start": Object { + "column": 16, + "line": 3, + }, + }, + "name": "f", + "range": Array [ + 92, + 93, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 7, + "line": 3, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 18, + "line": 3, + }, + }, + "name": "x", + "range": Array [ + 94, + 112, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 19, + "line": 3, + }, + }, + "range": Array [ + 95, + 112, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 21, + "line": 3, + }, + }, + "range": Array [ + 97, + 112, + ], + "type": "TSUnionType", + "types": Array [ + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 3, + }, + "start": Object { + "column": 21, + "line": 3, + }, + }, + "range": Array [ + 97, + 103, + ], + "type": "TSStringKeyword", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 30, + "line": 3, + }, + }, + "range": Array [ + 106, + 112, + ], + "type": "TSNumberKeyword", + }, + ], + }, + }, + }, + ], + "range": Array [ + 83, + 146, + ], + "returnType": Object { + "loc": Object { + "end": Object { + "column": 54, + "line": 3, + }, + "start": Object { + "column": 37, + "line": 3, + }, + }, + "range": Array [ + 113, + 130, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 54, + "line": 3, + }, + "start": Object { + "column": 39, + "line": 3, + }, + }, + "range": Array [ + 115, + 130, + ], + "type": "TSUnionType", + "types": Array [ + Object { + "loc": Object { + "end": Object { + "column": 45, + "line": 3, + }, + "start": Object { + "column": 39, + "line": 3, + }, + }, + "range": Array [ + 115, + 121, + ], + "type": "TSStringKeyword", + }, + Object { + "loc": Object { + "end": Object { + "column": 54, + "line": 3, + }, + "start": Object { + "column": 48, + "line": 3, + }, + }, + "range": Array [ + 124, + 130, + ], + "type": "TSNumberKeyword", + }, + ], + }, + }, + "type": "FunctionDeclaration", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 76, + 146, + ], + "source": null, + "specifiers": Array [], + "type": "ExportNamedDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 6, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 147, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 15, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Identifier", + "value": "f", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 19, + "line": 1, + }, + }, + "range": Array [ + 19, + 20, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 27, + ], + "type": "Identifier", + "value": "number", + }, + Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 27, + "line": 1, + }, + }, + "range": Array [ + 27, + 28, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 1, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, + "range": Array [ + 28, + 29, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 1, + }, + "start": Object { + "column": 30, + "line": 1, + }, + }, + "range": Array [ + 30, + 36, + ], + "type": "Identifier", + "value": "number", + }, + Object { + "loc": Object { + "end": Object { + "column": 37, + "line": 1, + }, + "start": Object { + "column": 36, + "line": 1, + }, + }, + "range": Array [ + 36, + 37, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 38, + 44, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "range": Array [ + 45, + 53, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 54, + 55, + ], + "type": "Identifier", + "value": "f", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 55, + 56, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "range": Array [ + 56, + 57, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 2, + }, + "start": Object { + "column": 19, + "line": 2, + }, + }, + "range": Array [ + 57, + 58, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 21, + "line": 2, + }, + }, + "range": Array [ + 59, + 65, + ], + "type": "Identifier", + "value": "string", + }, + Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 2, + }, + "start": Object { + "column": 27, + "line": 2, + }, + }, + "range": Array [ + 65, + 66, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 2, + }, + "start": Object { + "column": 28, + "line": 2, + }, + }, + "range": Array [ + 66, + 67, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 2, + }, + "start": Object { + "column": 30, + "line": 2, + }, + }, + "range": Array [ + 68, + 74, + ], + "type": "Identifier", + "value": "string", + }, + Object { + "loc": Object { + "end": Object { + "column": 37, + "line": 2, + }, + "start": Object { + "column": 36, + "line": 2, + }, + }, + "range": Array [ + 74, + 75, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 76, + 82, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 7, + "line": 3, + }, + }, + "range": Array [ + 83, + 91, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 3, + }, + "start": Object { + "column": 16, + "line": 3, + }, + }, + "range": Array [ + 92, + 93, + ], + "type": "Identifier", + "value": "f", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 17, + "line": 3, + }, + }, + "range": Array [ + 93, + 94, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 3, + }, + "start": Object { + "column": 18, + "line": 3, + }, + }, + "range": Array [ + 94, + 95, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 3, + }, + "start": Object { + "column": 19, + "line": 3, + }, + }, + "range": Array [ + 95, + 96, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 3, + }, + "start": Object { + "column": 21, + "line": 3, + }, + }, + "range": Array [ + 97, + 103, + ], + "type": "Identifier", + "value": "string", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 3, + }, + "start": Object { + "column": 28, + "line": 3, + }, + }, + "range": Array [ + 104, + 105, + ], + "type": "Punctuator", + "value": "|", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 30, + "line": 3, + }, + }, + "range": Array [ + 106, + 112, + ], + "type": "Identifier", + "value": "number", + }, + Object { + "loc": Object { + "end": Object { + "column": 37, + "line": 3, + }, + "start": Object { + "column": 36, + "line": 3, + }, + }, + "range": Array [ + 112, + 113, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 3, + }, + "start": Object { + "column": 37, + "line": 3, + }, + }, + "range": Array [ + 113, + 114, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 45, + "line": 3, + }, + "start": Object { + "column": 39, + "line": 3, + }, + }, + "range": Array [ + 115, + 121, + ], + "type": "Identifier", + "value": "string", + }, + Object { + "loc": Object { + "end": Object { + "column": 47, + "line": 3, + }, + "start": Object { + "column": 46, + "line": 3, + }, + }, + "range": Array [ + 122, + 123, + ], + "type": "Punctuator", + "value": "|", + }, + Object { + "loc": Object { + "end": Object { + "column": 54, + "line": 3, + }, + "start": Object { + "column": 48, + "line": 3, + }, + }, + "range": Array [ + 124, + 130, + ], + "type": "Identifier", + "value": "number", + }, + Object { + "loc": Object { + "end": Object { + "column": 56, + "line": 3, + }, + "start": Object { + "column": 55, + "line": 3, + }, + }, + "range": Array [ + 131, + 132, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, + }, + }, + "range": Array [ + 135, + 141, + ], + "type": "Keyword", + "value": "return", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 4, + }, + "start": Object { + "column": 9, + "line": 4, + }, + }, + "range": Array [ + 142, + 143, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 4, + }, + "start": Object { + "column": 10, + "line": 4, + }, + }, + "range": Array [ + 143, + 144, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 5, + }, + }, + "range": Array [ + 145, + 146, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/basics/function-with-await.src 1`] = ` +Object { + "body": Array [ + Object { + "async": true, + "body": Object { + "body": Array [ + Object { + "expression": Object { + "argument": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "name": "future", + "range": Array [ + 40, + 46, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 34, + 46, + ], + "type": "AwaitExpression", + }, + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 34, + 47, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 1, "line": 3, }, "start": Object { @@ -107226,132 +108167,564 @@ Object { "line": 1, }, }, - "range": Array [ - 9, - 231, - ], - "type": "TSModuleBlock", + "range": Array [ + 9, + 231, + ], + "type": "TSModuleBlock", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "name": "A", + "range": Array [ + 7, + 8, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 12, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 231, + ], + "type": "TSModuleDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 1, + "line": 12, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 231, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Identifier", + "value": "module", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 8, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 10, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "range": Array [ + 16, + 22, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 3, + }, + "start": Object { + "column": 11, + "line": 3, + }, + }, + "range": Array [ + 23, + 26, + ], + "type": "Keyword", + "value": "var", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "range": Array [ + 27, + 28, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 17, + "line": 3, + }, + }, + "range": Array [ + 29, + 30, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 32, + "line": 3, + }, + "start": Object { + "column": 19, + "line": 3, + }, + }, + "range": Array [ + 31, + 44, + ], + "type": "String", + "value": "'hello world'", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 4, + }, + "start": Object { + "column": 4, + "line": 4, + }, }, - "id": Object { - "loc": Object { - "end": Object { - "column": 8, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, - }, + "range": Array [ + 49, + 55, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 4, + }, + "start": Object { + "column": 11, + "line": 4, }, - "name": "A", - "range": Array [ - 7, - 8, - ], - "type": "Identifier", }, + "range": Array [ + 56, + 61, + ], + "type": "Keyword", + "value": "class", + }, + Object { "loc": Object { "end": Object { - "column": 1, - "line": 12, + "column": 22, + "line": 4, }, "start": Object { - "column": 0, - "line": 1, + "column": 17, + "line": 4, }, }, "range": Array [ - 0, - 231, + 62, + 67, ], - "type": "TSModuleDeclaration", + "type": "Identifier", + "value": "Point", }, - ], - "comments": Array [], - "loc": Object { - "end": Object { - "column": 1, - "line": 12, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 4, + }, + "start": Object { + "column": 23, + "line": 4, + }, + }, + "range": Array [ + 68, + 69, + ], + "type": "Punctuator", + "value": "{", }, - "start": Object { - "column": 0, - "line": 1, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 5, + }, + "start": Object { + "column": 8, + "line": 5, + }, + }, + "range": Array [ + 78, + 89, + ], + "type": "Identifier", + "value": "constructor", }, - }, - "range": Array [ - 0, - 231, - ], - "sourceType": "module", - "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 6, - "line": 1, + "column": 20, + "line": 5, }, "start": Object { - "column": 0, - "line": 1, + "column": 19, + "line": 5, }, }, "range": Array [ - 0, - 6, + 89, + 90, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 5, + }, + "start": Object { + "column": 20, + "line": 5, + }, + }, + "range": Array [ + 90, + 96, + ], + "type": "Keyword", + "value": "public", + }, + Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 5, + }, + "start": Object { + "column": 27, + "line": 5, + }, + }, + "range": Array [ + 97, + 98, ], "type": "Identifier", - "value": "module", + "value": "x", }, Object { "loc": Object { "end": Object { - "column": 8, - "line": 1, + "column": 29, + "line": 5, }, "start": Object { - "column": 7, - "line": 1, + "column": 28, + "line": 5, }, }, "range": Array [ - 7, - 8, + 98, + 99, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 5, + }, + "start": Object { + "column": 30, + "line": 5, + }, + }, + "range": Array [ + 100, + 106, ], "type": "Identifier", - "value": "A", + "value": "number", }, Object { "loc": Object { "end": Object { - "column": 10, - "line": 1, + "column": 37, + "line": 5, }, "start": Object { - "column": 9, - "line": 1, + "column": 36, + "line": 5, }, }, "range": Array [ - 9, - 10, + 106, + 107, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 44, + "line": 5, + }, + "start": Object { + "column": 38, + "line": 5, + }, + }, + "range": Array [ + 108, + 114, + ], + "type": "Keyword", + "value": "public", + }, + Object { + "loc": Object { + "end": Object { + "column": 46, + "line": 5, + }, + "start": Object { + "column": 45, + "line": 5, + }, + }, + "range": Array [ + 115, + 116, + ], + "type": "Identifier", + "value": "y", + }, + Object { + "loc": Object { + "end": Object { + "column": 47, + "line": 5, + }, + "start": Object { + "column": 46, + "line": 5, + }, + }, + "range": Array [ + 116, + 117, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 54, + "line": 5, + }, + "start": Object { + "column": 48, + "line": 5, + }, + }, + "range": Array [ + 118, + 124, + ], + "type": "Identifier", + "value": "number", + }, + Object { + "loc": Object { + "end": Object { + "column": 55, + "line": 5, + }, + "start": Object { + "column": 54, + "line": 5, + }, + }, + "range": Array [ + 124, + 125, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 57, + "line": 5, + }, + "start": Object { + "column": 56, + "line": 5, + }, + }, + "range": Array [ + 126, + 127, ], "type": "Punctuator", "value": "{", }, + Object { + "loc": Object { + "end": Object { + "column": 59, + "line": 5, + }, + "start": Object { + "column": 58, + "line": 5, + }, + }, + "range": Array [ + 128, + 129, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "range": Array [ + 134, + 135, + ], + "type": "Punctuator", + "value": "}", + }, Object { "loc": Object { "end": Object { "column": 10, - "line": 3, + "line": 7, }, "start": Object { "column": 4, - "line": 3, + "line": 7, }, }, "range": Array [ - 16, - 22, + 140, + 146, ], "type": "Keyword", "value": "export", @@ -107359,593 +108732,935 @@ Object { Object { "loc": Object { "end": Object { - "column": 14, - "line": 3, + "column": 17, + "line": 7, }, "start": Object { "column": 11, - "line": 3, + "line": 7, }, }, "range": Array [ - 23, - 26, + 147, + 153, + ], + "type": "Identifier", + "value": "module", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 7, + }, + "start": Object { + "column": 18, + "line": 7, + }, + }, + "range": Array [ + 154, + 155, + ], + "type": "Identifier", + "value": "B", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 7, + }, + "start": Object { + "column": 20, + "line": 7, + }, + }, + "range": Array [ + 156, + 157, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 8, + }, + "start": Object { + "column": 8, + "line": 8, + }, + }, + "range": Array [ + 166, + 172, ], "type": "Keyword", - "value": "var", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 8, + }, + "start": Object { + "column": 15, + "line": 8, + }, + }, + "range": Array [ + 173, + 182, + ], + "type": "Keyword", + "value": "interface", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 8, + }, + "start": Object { + "column": 25, + "line": 8, + }, + }, + "range": Array [ + 183, + 185, + ], + "type": "Identifier", + "value": "Id", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 8, + }, + "start": Object { + "column": 28, + "line": 8, + }, + }, + "range": Array [ + 186, + 187, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 9, + }, + "start": Object { + "column": 12, + "line": 9, + }, + }, + "range": Array [ + 200, + 204, + ], + "type": "Identifier", + "value": "name", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 9, + }, + "start": Object { + "column": 16, + "line": 9, + }, + }, + "range": Array [ + 204, + 205, + ], + "type": "Punctuator", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 16, - "line": 3, + "column": 24, + "line": 9, }, "start": Object { - "column": 15, - "line": 3, + "column": 18, + "line": 9, }, }, "range": Array [ - 27, - 28, + 206, + 212, ], "type": "Identifier", - "value": "x", + "value": "string", }, Object { "loc": Object { "end": Object { - "column": 18, - "line": 3, + "column": 25, + "line": 9, }, "start": Object { - "column": 17, - "line": 3, + "column": 24, + "line": 9, }, }, "range": Array [ - 29, - 30, + 212, + 213, ], "type": "Punctuator", - "value": "=", + "value": ";", }, Object { "loc": Object { "end": Object { - "column": 32, - "line": 3, + "column": 9, + "line": 10, }, "start": Object { - "column": 19, - "line": 3, + "column": 8, + "line": 10, }, }, "range": Array [ - 31, - 44, + 222, + 223, ], - "type": "String", - "value": "'hello world'", + "type": "Punctuator", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 10, - "line": 4, + "column": 5, + "line": 11, }, "start": Object { "column": 4, - "line": 4, + "line": 11, }, }, "range": Array [ - 49, - 55, + 228, + 229, ], - "type": "Keyword", - "value": "export", + "type": "Punctuator", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 16, - "line": 4, + "column": 1, + "line": 12, }, "start": Object { - "column": 11, - "line": 4, + "column": 0, + "line": 12, }, }, "range": Array [ - 56, - 61, + 230, + 231, ], - "type": "Keyword", - "value": "class", + "type": "Punctuator", + "value": "}", }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/namespaces-and-modules/shorthand-ambient-module-declaration.src 1`] = ` +Object { + "body": Array [ Object { + "declare": true, + "id": Object { + "loc": Object { + "end": Object { + "column": 31, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 31, + ], + "raw": "\\"hot-new-module\\"", + "type": "Literal", + "value": "hot-new-module", + }, "loc": Object { "end": Object { - "column": 22, - "line": 4, + "column": 32, + "line": 1, }, "start": Object { - "column": 17, - "line": 4, + "column": 0, + "line": 1, }, }, "range": Array [ - 62, - 67, + 0, + 32, ], - "type": "Identifier", - "value": "Point", + "type": "TSModuleDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, }, + }, + "range": Array [ + 0, + 33, + ], + "sourceType": "module", + "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 24, - "line": 4, + "column": 7, + "line": 1, }, "start": Object { - "column": 23, - "line": 4, + "column": 0, + "line": 1, }, }, "range": Array [ - 68, - 69, + 0, + 7, ], - "type": "Punctuator", - "value": "{", + "type": "Identifier", + "value": "declare", }, Object { "loc": Object { "end": Object { - "column": 19, - "line": 5, + "column": 14, + "line": 1, }, "start": Object { "column": 8, - "line": 5, + "line": 1, }, }, "range": Array [ - 78, - 89, + 8, + 14, ], "type": "Identifier", - "value": "constructor", + "value": "module", }, Object { "loc": Object { "end": Object { - "column": 20, - "line": 5, + "column": 31, + "line": 1, }, "start": Object { - "column": 19, - "line": 5, + "column": 15, + "line": 1, }, }, "range": Array [ - 89, - 90, + 15, + 31, ], - "type": "Punctuator", - "value": "(", + "type": "String", + "value": "\\"hot-new-module\\"", }, Object { "loc": Object { "end": Object { - "column": 26, - "line": 5, + "column": 32, + "line": 1, }, "start": Object { - "column": 20, - "line": 5, + "column": 31, + "line": 1, }, }, "range": Array [ - 90, - 96, + 31, + 32, ], - "type": "Keyword", - "value": "public", + "type": "Punctuator", + "value": ";", }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/types/array-type.src 1`] = ` +Object { + "body": Array [ Object { + "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": 28, - "line": 5, + "column": 19, + "line": 1, }, "start": Object { - "column": 27, - "line": 5, + "column": 0, + "line": 1, }, }, "range": Array [ - 97, - 98, + 0, + 19, ], - "type": "Identifier", - "value": "x", + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "elementType": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 17, + ], + "type": "TSStringKeyword", + }, + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 19, + ], + "type": "TSArrayType", + }, + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 20, + ], + "sourceType": "module", + "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 29, - "line": 5, + "column": 4, + "line": 1, }, "start": Object { - "column": 28, - "line": 5, + "column": 0, + "line": 1, }, }, "range": Array [ - 98, - 99, + 0, + 4, ], - "type": "Punctuator", - "value": ":", + "type": "Identifier", + "value": "type", }, Object { "loc": Object { "end": Object { - "column": 36, - "line": 5, + "column": 8, + "line": 1, }, "start": Object { - "column": 30, - "line": 5, + "column": 5, + "line": 1, }, }, "range": Array [ - 100, - 106, + 5, + 8, ], "type": "Identifier", - "value": "number", + "value": "Foo", }, Object { "loc": Object { "end": Object { - "column": 37, - "line": 5, + "column": 10, + "line": 1, }, "start": Object { - "column": 36, - "line": 5, + "column": 9, + "line": 1, }, }, "range": Array [ - 106, - 107, + 9, + 10, ], "type": "Punctuator", - "value": ",", + "value": "=", }, Object { "loc": Object { "end": Object { - "column": 44, - "line": 5, + "column": 17, + "line": 1, }, "start": Object { - "column": 38, - "line": 5, + "column": 11, + "line": 1, }, }, "range": Array [ - 108, - 114, + 11, + 17, ], - "type": "Keyword", - "value": "public", + "type": "Identifier", + "value": "string", }, Object { "loc": Object { "end": Object { - "column": 46, - "line": 5, + "column": 18, + "line": 1, }, "start": Object { - "column": 45, - "line": 5, + "column": 17, + "line": 1, }, }, "range": Array [ - 115, - 116, + 17, + 18, ], - "type": "Identifier", - "value": "y", + "type": "Punctuator", + "value": "[", }, Object { "loc": Object { "end": Object { - "column": 47, - "line": 5, + "column": 19, + "line": 1, }, "start": Object { - "column": 46, - "line": 5, + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Punctuator", + "value": "]", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/types/conditional.src 1`] = ` +Object { + "body": Array [ + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 47, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "name": "x", + "range": Array [ + 4, + 47, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 47, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 47, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "checkType": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 13, + ], + "type": "TSNumberKeyword", + }, + "extendsType": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "range": Array [ + 22, + 28, + ], + "type": "TSStringKeyword", + }, + "falseType": Object { + "loc": Object { + "end": Object { + "column": 47, + "line": 1, + }, + "start": Object { + "column": 41, + "line": 1, + }, + }, + "range": Array [ + 41, + 47, + ], + "type": "TSStringKeyword", + }, + "loc": Object { + "end": Object { + "column": 47, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 47, + ], + "trueType": Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 1, + }, + "start": Object { + "column": 31, + "line": 1, + }, + }, + "range": Array [ + 31, + 38, + ], + "type": "TSBooleanKeyword", + }, + "type": "TSConditionalType", + }, + }, + }, + "init": null, + "loc": Object { + "end": Object { + "column": 47, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 47, + ], + "type": "VariableDeclarator", }, - }, - "range": Array [ - 116, - 117, ], - "type": "Punctuator", - "value": ":", - }, - Object { + "kind": "let", "loc": Object { "end": Object { - "column": 54, - "line": 5, - }, - "start": Object { "column": 48, - "line": 5, - }, - }, - "range": Array [ - 118, - 124, - ], - "type": "Identifier", - "value": "number", - }, - Object { - "loc": Object { - "end": Object { - "column": 55, - "line": 5, + "line": 1, }, "start": Object { - "column": 54, - "line": 5, + "column": 0, + "line": 1, }, }, "range": Array [ - 124, - 125, + 0, + 48, ], - "type": "Punctuator", - "value": ")", + "type": "VariableDeclaration", }, - Object { - "loc": Object { - "end": Object { - "column": 57, - "line": 5, - }, - "start": Object { - "column": 56, - "line": 5, - }, - }, - "range": Array [ - 126, - 127, - ], - "type": "Punctuator", - "value": "{", + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, }, - Object { - "loc": Object { - "end": Object { - "column": 59, - "line": 5, - }, - "start": Object { - "column": 58, - "line": 5, - }, - }, - "range": Array [ - 128, - 129, - ], - "type": "Punctuator", - "value": "}", + "start": Object { + "column": 0, + "line": 1, }, + }, + "range": Array [ + 0, + 49, + ], + "sourceType": "module", + "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 5, - "line": 6, + "column": 3, + "line": 1, }, "start": Object { - "column": 4, - "line": 6, + "column": 0, + "line": 1, }, }, "range": Array [ - 134, - 135, + 0, + 3, ], - "type": "Punctuator", - "value": "}", + "type": "Keyword", + "value": "let", }, Object { "loc": Object { "end": Object { - "column": 10, - "line": 7, + "column": 5, + "line": 1, }, "start": Object { "column": 4, - "line": 7, + "line": 1, }, }, "range": Array [ - 140, - 146, + 4, + 5, ], - "type": "Keyword", - "value": "export", + "type": "Identifier", + "value": "x", }, Object { "loc": Object { "end": Object { - "column": 17, - "line": 7, + "column": 6, + "line": 1, }, "start": Object { - "column": 11, - "line": 7, + "column": 5, + "line": 1, }, }, "range": Array [ - 147, - 153, + 5, + 6, ], - "type": "Identifier", - "value": "module", + "type": "Punctuator", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 19, - "line": 7, + "column": 13, + "line": 1, }, "start": Object { - "column": 18, - "line": 7, + "column": 7, + "line": 1, }, }, "range": Array [ - 154, - 155, + 7, + 13, ], "type": "Identifier", - "value": "B", + "value": "number", }, Object { "loc": Object { "end": Object { "column": 21, - "line": 7, + "line": 1, }, "start": Object { - "column": 20, - "line": 7, - }, - }, - "range": Array [ - 156, - 157, - ], - "type": "Punctuator", - "value": "{", - }, - Object { - "loc": Object { - "end": Object { "column": 14, - "line": 8, - }, - "start": Object { - "column": 8, - "line": 8, - }, - }, - "range": Array [ - 166, - 172, - ], - "type": "Keyword", - "value": "export", - }, - Object { - "loc": Object { - "end": Object { - "column": 24, - "line": 8, - }, - "start": Object { - "column": 15, - "line": 8, + "line": 1, }, }, "range": Array [ - 173, - 182, + 14, + 21, ], "type": "Keyword", - "value": "interface", + "value": "extends", }, Object { "loc": Object { "end": Object { - "column": 27, - "line": 8, + "column": 28, + "line": 1, }, "start": Object { - "column": 25, - "line": 8, + "column": 22, + "line": 1, }, }, "range": Array [ - 183, - 185, + 22, + 28, ], "type": "Identifier", - "value": "Id", + "value": "string", }, Object { "loc": Object { "end": Object { - "column": 29, - "line": 8, + "column": 30, + "line": 1, }, "start": Object { - "column": 28, - "line": 8, + "column": 29, + "line": 1, }, }, "range": Array [ - 186, - 187, + 29, + 30, ], "type": "Punctuator", - "value": "{", + "value": "?", }, Object { "loc": Object { "end": Object { - "column": 16, - "line": 9, + "column": 38, + "line": 1, }, "start": Object { - "column": 12, - "line": 9, + "column": 31, + "line": 1, }, }, "range": Array [ - 200, - 204, + 31, + 38, ], "type": "Identifier", - "value": "name", + "value": "boolean", }, Object { "loc": Object { "end": Object { - "column": 17, - "line": 9, + "column": 40, + "line": 1, }, "start": Object { - "column": 16, - "line": 9, + "column": 39, + "line": 1, }, }, "range": Array [ - 204, - 205, + 39, + 40, ], "type": "Punctuator", "value": ":", @@ -107953,17 +109668,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 24, - "line": 9, + "column": 47, + "line": 1, }, "start": Object { - "column": 18, - "line": 9, + "column": 41, + "line": 1, }, }, "range": Array [ - 206, - 212, + 41, + 47, ], "type": "Identifier", "value": "string", @@ -107971,142 +109686,51 @@ Object { Object { "loc": Object { "end": Object { - "column": 25, - "line": 9, + "column": 48, + "line": 1, }, "start": Object { - "column": 24, - "line": 9, + "column": 47, + "line": 1, }, }, "range": Array [ - 212, - 213, + 47, + 48, ], "type": "Punctuator", "value": ";", }, - Object { - "loc": Object { - "end": Object { - "column": 9, - "line": 10, - }, - "start": Object { - "column": 8, - "line": 10, - }, - }, - "range": Array [ - 222, - 223, - ], - "type": "Punctuator", - "value": "}", - }, - Object { - "loc": Object { - "end": Object { - "column": 5, - "line": 11, - }, - "start": Object { - "column": 4, - "line": 11, - }, - }, - "range": Array [ - 228, - 229, - ], - "type": "Punctuator", - "value": "}", - }, - Object { - "loc": Object { - "end": Object { - "column": 1, - "line": 12, - }, - "start": Object { - "column": 0, - "line": 12, - }, - }, - "range": Array [ - 230, - 231, - ], - "type": "Punctuator", - "value": "}", - }, ], "type": "Program", } `; -exports[`typescript fixtures/namespaces-and-modules/shorthand-ambient-module-declaration.src 1`] = ` +exports[`typescript fixtures/types/conditional-infer.src 1`] = ` Object { "body": Array [ Object { - "declare": true, "id": Object { "loc": Object { "end": Object { - "column": 31, + "column": 12, "line": 1, }, "start": Object { - "column": 15, + "column": 5, "line": 1, }, }, + "name": "Element", "range": Array [ - 15, - 31, + 5, + 12, ], - "raw": "\\"hot-new-module\\"", - "type": "Literal", - "value": "hot-new-module", - }, - "loc": Object { - "end": Object { - "column": 32, - "line": 1, - }, - "start": Object { - "column": 0, - "line": 1, - }, + "type": "Identifier", }, - "range": Array [ - 0, - 32, - ], - "type": "TSModuleDeclaration", - }, - ], - "comments": Array [], - "loc": Object { - "end": Object { - "column": 0, - "line": 2, - }, - "start": Object { - "column": 0, - "line": 1, - }, - }, - "range": Array [ - 0, - 33, - ], - "sourceType": "module", - "tokens": Array [ - Object { "loc": Object { "end": Object { - "column": 7, + "column": 48, "line": 1, }, "start": Object { @@ -108116,140 +109740,270 @@ Object { }, "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, + 48, ], - "type": "Identifier", - "value": "module", - }, - Object { - "loc": Object { - "end": Object { - "column": 31, - "line": 1, - }, - "start": Object { - "column": 15, - "line": 1, + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "checkType": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 18, + 19, + ], + "type": "Identifier", + }, }, - }, - "range": Array [ - 15, - 31, - ], - "type": "String", - "value": "\\"hot-new-module\\"", - }, - Object { - "loc": Object { - "end": Object { - "column": 32, - "line": 1, + "extendsType": Object { + "elementType": Object { + "loc": Object { + "end": Object { + "column": 37, + "line": 1, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, + "range": Array [ + 28, + 37, + ], + "type": "TSParenthesizedType", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 1, + }, + "start": Object { + "column": 29, + "line": 1, + }, + }, + "range": Array [ + 29, + 36, + ], + "type": "TSInferType", + "typeParameter": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 1, + }, + "start": Object { + "column": 35, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 1, + }, + "start": Object { + "column": 35, + "line": 1, + }, + }, + "name": "U", + "range": Array [ + 35, + 36, + ], + "type": "Identifier", + }, + "range": Array [ + 35, + 36, + ], + "type": "TSTypeParameter", + }, + }, + }, + "loc": Object { + "end": Object { + "column": 39, + "line": 1, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, + "range": Array [ + 28, + 39, + ], + "type": "TSArrayType", }, - "start": Object { - "column": 31, - "line": 1, + "falseType": Object { + "loc": Object { + "end": Object { + "column": 47, + "line": 1, + }, + "start": Object { + "column": 46, + "line": 1, + }, + }, + "range": Array [ + 46, + 47, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 47, + "line": 1, + }, + "start": Object { + "column": 46, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 46, + 47, + ], + "type": "Identifier", + }, }, - }, - "range": Array [ - 31, - 32, - ], - "type": "Punctuator", - "value": ";", - }, - ], - "type": "Program", -} -`; - -exports[`typescript fixtures/types/array-type.src 1`] = ` -Object { - "body": Array [ - Object { - "id": Object { "loc": Object { "end": Object { - "column": 8, + "column": 47, "line": 1, }, "start": Object { - "column": 5, + "column": 18, "line": 1, }, }, - "name": "Foo", "range": Array [ - 5, - 8, + 18, + 47, ], - "type": "Identifier", - }, - "loc": Object { - "end": Object { - "column": 19, - "line": 1, - }, - "start": Object { - "column": 0, - "line": 1, - }, - }, - "range": Array [ - 0, - 19, - ], - "type": "TSTypeAliasDeclaration", - "typeAnnotation": Object { - "elementType": Object { + "trueType": Object { "loc": Object { "end": Object { - "column": 17, + "column": 43, "line": 1, }, "start": Object { - "column": 11, + "column": 42, "line": 1, }, }, "range": Array [ - 11, - 17, + 42, + 43, ], - "type": "TSStringKeyword", + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 43, + "line": 1, + }, + "start": Object { + "column": 42, + "line": 1, + }, + }, + "name": "U", + "range": Array [ + 42, + 43, + ], + "type": "Identifier", + }, }, + "type": "TSConditionalType", + }, + "typeParameters": Object { "loc": Object { "end": Object { - "column": 19, + "column": 15, "line": 1, }, "start": Object { - "column": 11, + "column": 12, "line": 1, }, }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "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, + ], + "type": "TSTypeParameter", + }, + ], "range": Array [ - 11, - 19, + 12, + 15, ], - "type": "TSArrayType", + "type": "TSTypeParameterDeclaration", }, }, ], @@ -108266,7 +110020,7 @@ Object { }, "range": Array [ 0, - 20, + 49, ], "sourceType": "module", "tokens": Array [ @@ -108291,7 +110045,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 8, + "column": 12, "line": 1, }, "start": Object { @@ -108301,64 +110055,82 @@ Object { }, "range": Array [ 5, - 8, + 12, ], "type": "Identifier", - "value": "Foo", + "value": "Element", }, Object { "loc": Object { "end": Object { - "column": 10, + "column": 13, "line": 1, }, "start": Object { - "column": 9, + "column": 12, "line": 1, }, }, "range": Array [ - 9, - 10, + 12, + 13, ], "type": "Punctuator", - "value": "=", + "value": "<", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 14, "line": 1, }, "start": Object { - "column": 11, + "column": 13, "line": 1, }, }, "range": Array [ - 11, - 17, + 13, + 14, ], "type": "Identifier", - "value": "string", + "value": "T", }, Object { "loc": Object { "end": Object { - "column": 18, + "column": 15, "line": 1, }, "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { "column": 17, "line": 1, }, + "start": Object { + "column": 16, + "line": 1, + }, }, "range": Array [ + 16, 17, - 18, ], "type": "Punctuator", - "value": "[", + "value": "=", }, Object { "loc": Object { @@ -108375,315 +110147,149 @@ Object { 18, 19, ], - "type": "Punctuator", - "value": "]", + "type": "Identifier", + "value": "T", }, - ], - "type": "Program", -} -`; - -exports[`typescript fixtures/types/conditional.src 1`] = ` -Object { - "body": Array [ Object { - "declarations": Array [ - Object { - "id": Object { - "loc": Object { - "end": Object { - "column": 47, - "line": 1, - }, - "start": Object { - "column": 4, - "line": 1, - }, - }, - "name": "x", - "range": Array [ - 4, - 47, - ], - "type": "Identifier", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 47, - "line": 1, - }, - "start": Object { - "column": 5, - "line": 1, - }, - }, - "range": Array [ - 5, - 47, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "checkType": Object { - "loc": Object { - "end": Object { - "column": 13, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, - }, - }, - "range": Array [ - 7, - 13, - ], - "type": "TSNumberKeyword", - }, - "extendsType": Object { - "loc": Object { - "end": Object { - "column": 28, - "line": 1, - }, - "start": Object { - "column": 22, - "line": 1, - }, - }, - "range": Array [ - 22, - 28, - ], - "type": "TSStringKeyword", - }, - "falseType": Object { - "loc": Object { - "end": Object { - "column": 47, - "line": 1, - }, - "start": Object { - "column": 41, - "line": 1, - }, - }, - "range": Array [ - 41, - 47, - ], - "type": "TSStringKeyword", - }, - "loc": Object { - "end": Object { - "column": 47, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, - }, - }, - "range": Array [ - 7, - 47, - ], - "trueType": Object { - "loc": Object { - "end": Object { - "column": 38, - "line": 1, - }, - "start": Object { - "column": 31, - "line": 1, - }, - }, - "range": Array [ - 31, - 38, - ], - "type": "TSBooleanKeyword", - }, - "type": "TSConditionalType", - }, - }, - }, - "init": null, - "loc": Object { - "end": Object { - "column": 47, - "line": 1, - }, - "start": Object { - "column": 4, - "line": 1, - }, - }, - "range": Array [ - 4, - 47, - ], - "type": "VariableDeclarator", - }, - ], - "kind": "let", "loc": Object { "end": Object { - "column": 48, + "column": 27, "line": 1, }, "start": Object { - "column": 0, + "column": 20, "line": 1, }, }, "range": Array [ - 0, - 48, + 20, + 27, ], - "type": "VariableDeclaration", - }, - ], - "comments": Array [], - "loc": Object { - "end": Object { - "column": 0, - "line": 2, - }, - "start": Object { - "column": 0, - "line": 1, + "type": "Keyword", + "value": "extends", }, - }, - "range": Array [ - 0, - 49, - ], - "sourceType": "module", - "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 3, + "column": 29, "line": 1, }, "start": Object { - "column": 0, + "column": 28, "line": 1, }, }, "range": Array [ - 0, - 3, + 28, + 29, ], - "type": "Keyword", - "value": "let", + "type": "Punctuator", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 5, + "column": 34, "line": 1, }, "start": Object { - "column": 4, + "column": 29, "line": 1, }, }, "range": Array [ - 4, - 5, + 29, + 34, ], "type": "Identifier", - "value": "x", + "value": "infer", }, Object { "loc": Object { "end": Object { - "column": 6, + "column": 36, "line": 1, }, "start": Object { - "column": 5, + "column": 35, "line": 1, }, }, "range": Array [ - 5, - 6, + 35, + 36, ], - "type": "Punctuator", - "value": ":", + "type": "Identifier", + "value": "U", }, Object { "loc": Object { "end": Object { - "column": 13, + "column": 37, "line": 1, }, "start": Object { - "column": 7, + "column": 36, "line": 1, }, }, "range": Array [ - 7, - 13, + 36, + 37, ], - "type": "Identifier", - "value": "number", + "type": "Punctuator", + "value": ")", }, Object { "loc": Object { "end": Object { - "column": 21, + "column": 38, "line": 1, }, "start": Object { - "column": 14, + "column": 37, "line": 1, }, }, "range": Array [ - 14, - 21, + 37, + 38, ], - "type": "Keyword", - "value": "extends", + "type": "Punctuator", + "value": "[", }, Object { "loc": Object { "end": Object { - "column": 28, + "column": 39, "line": 1, }, "start": Object { - "column": 22, + "column": 38, "line": 1, }, }, "range": Array [ - 22, - 28, + 38, + 39, ], - "type": "Identifier", - "value": "string", + "type": "Punctuator", + "value": "]", }, Object { "loc": Object { "end": Object { - "column": 30, + "column": 41, "line": 1, }, "start": Object { - "column": 29, + "column": 40, "line": 1, }, }, "range": Array [ - 29, - 30, + 40, + 41, ], "type": "Punctuator", "value": "?", @@ -108691,35 +110297,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 38, + "column": 43, "line": 1, }, "start": Object { - "column": 31, + "column": 42, "line": 1, }, }, "range": Array [ - 31, - 38, + 42, + 43, ], "type": "Identifier", - "value": "boolean", + "value": "U", }, Object { "loc": Object { "end": Object { - "column": 40, + "column": 45, "line": 1, }, "start": Object { - "column": 39, + "column": 44, "line": 1, }, }, "range": Array [ - 39, - 40, + 44, + 45, ], "type": "Punctuator", "value": ":", @@ -108731,16 +110337,16 @@ Object { "line": 1, }, "start": Object { - "column": 41, + "column": 46, "line": 1, }, }, "range": Array [ - 41, + 46, 47, ], "type": "Identifier", - "value": "string", + "value": "T", }, Object { "loc": Object { @@ -108765,14 +110371,14 @@ Object { } `; -exports[`typescript fixtures/types/conditional-infer.src 1`] = ` +exports[`typescript fixtures/types/conditional-infer-nested.src 1`] = ` Object { "body": Array [ Object { "id": Object { "loc": Object { "end": Object { - "column": 12, + "column": 13, "line": 1, }, "start": Object { @@ -108780,17 +110386,17 @@ Object { "line": 1, }, }, - "name": "Element", + "name": "Unpacked", "range": Array [ 5, - 12, + 13, ], "type": "Identifier", }, "loc": Object { "end": Object { - "column": 48, - "line": 1, + "column": 10, + "line": 5, }, "start": Object { "column": 0, @@ -108799,41 +110405,41 @@ Object { }, "range": Array [ 0, - 48, + 126, ], "type": "TSTypeAliasDeclaration", "typeAnnotation": Object { "checkType": Object { "loc": Object { "end": Object { - "column": 19, - "line": 1, + "column": 3, + "line": 2, }, "start": Object { - "column": 18, - "line": 1, + "column": 2, + "line": 2, }, }, "range": Array [ - 18, - 19, + 21, + 22, ], "type": "TSTypeReference", "typeName": Object { "loc": Object { "end": Object { - "column": 19, - "line": 1, + "column": 3, + "line": 2, }, "start": Object { - "column": 18, - "line": 1, + "column": 2, + "line": 2, }, }, "name": "T", "range": Array [ - 18, - 19, + 21, + 22, ], "type": "Identifier", }, @@ -108842,67 +110448,67 @@ Object { "elementType": Object { "loc": Object { "end": Object { - "column": 37, - "line": 1, + "column": 21, + "line": 2, }, "start": Object { - "column": 28, - "line": 1, + "column": 12, + "line": 2, }, }, "range": Array [ - 28, - 37, + 31, + 40, ], "type": "TSParenthesizedType", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 36, - "line": 1, + "column": 20, + "line": 2, }, "start": Object { - "column": 29, - "line": 1, + "column": 13, + "line": 2, }, }, "range": Array [ - 29, - 36, + 32, + 39, ], "type": "TSInferType", "typeParameter": Object { "loc": Object { "end": Object { - "column": 36, - "line": 1, + "column": 20, + "line": 2, }, "start": Object { - "column": 35, - "line": 1, + "column": 19, + "line": 2, }, }, "name": Object { "loc": Object { "end": Object { - "column": 36, - "line": 1, + "column": 20, + "line": 2, }, "start": Object { - "column": 35, - "line": 1, + "column": 19, + "line": 2, }, }, "name": "U", "range": Array [ - 35, - 36, + 38, + 39, ], "type": "Identifier", }, "range": Array [ - 35, - 36, + 38, + 39, ], "type": "TSTypeParameter", }, @@ -108910,100 +110516,432 @@ Object { }, "loc": Object { "end": Object { - "column": 39, - "line": 1, + "column": 23, + "line": 2, }, "start": Object { - "column": 28, - "line": 1, + "column": 12, + "line": 2, }, }, "range": Array [ - 28, - 39, + 31, + 42, ], "type": "TSArrayType", }, "falseType": Object { + "checkType": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "range": Array [ + 53, + 54, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "name": "T", + "range": Array [ + 53, + 54, + ], + "type": "Identifier", + }, + }, + "extendsType": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 3, + }, + "start": Object { + "column": 14, + "line": 3, + }, + }, + "range": Array [ + 63, + 70, + ], + "type": "TSInferType", + "typeParameter": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 3, + }, + "start": Object { + "column": 20, + "line": 3, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 3, + }, + "start": Object { + "column": 20, + "line": 3, + }, + }, + "name": "U", + "range": Array [ + 69, + 70, + ], + "type": "Identifier", + }, + "range": Array [ + 69, + 70, + ], + "type": "TSTypeParameter", + }, + }, + "falseType": Object { + "checkType": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 4, + }, + "start": Object { + "column": 6, + "line": 4, + }, + }, + "range": Array [ + 83, + 84, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 4, + }, + "start": Object { + "column": 6, + "line": 4, + }, + }, + "name": "T", + "range": Array [ + 83, + 84, + ], + "type": "Identifier", + }, + }, + "extendsType": Object { + "loc": Object { + "end": Object { + "column": 32, + "line": 4, + }, + "start": Object { + "column": 16, + "line": 4, + }, + }, + "range": Array [ + 93, + 109, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 4, + }, + "start": Object { + "column": 16, + "line": 4, + }, + }, + "name": "Promise", + "range": Array [ + 93, + 100, + ], + "type": "Identifier", + }, + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 32, + "line": 4, + }, + "start": Object { + "column": 23, + "line": 4, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 31, + "line": 4, + }, + "start": Object { + "column": 24, + "line": 4, + }, + }, + "range": Array [ + 101, + 108, + ], + "type": "TSInferType", + "typeParameter": Object { + "loc": Object { + "end": Object { + "column": 31, + "line": 4, + }, + "start": Object { + "column": 30, + "line": 4, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 31, + "line": 4, + }, + "start": Object { + "column": 30, + "line": 4, + }, + }, + "name": "U", + "range": Array [ + 107, + 108, + ], + "type": "Identifier", + }, + "range": Array [ + 107, + 108, + ], + "type": "TSTypeParameter", + }, + }, + ], + "range": Array [ + 100, + 109, + ], + "type": "TSTypeParameterInstantiation", + }, + }, + "falseType": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 5, + }, + "start": Object { + "column": 8, + "line": 5, + }, + }, + "range": Array [ + 124, + 125, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 5, + }, + "start": Object { + "column": 8, + "line": 5, + }, + }, + "name": "T", + "range": Array [ + 124, + 125, + ], + "type": "Identifier", + }, + }, + "loc": Object { + "end": Object { + "column": 9, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 4, + }, + }, + "range": Array [ + 83, + 125, + ], + "trueType": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 4, + }, + "start": Object { + "column": 35, + "line": 4, + }, + }, + "range": Array [ + 112, + 113, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 4, + }, + "start": Object { + "column": 35, + "line": 4, + }, + }, + "name": "U", + "range": Array [ + 112, + 113, + ], + "type": "Identifier", + }, + }, + "type": "TSConditionalType", + }, "loc": Object { "end": Object { - "column": 47, - "line": 1, + "column": 9, + "line": 5, }, "start": Object { - "column": 46, - "line": 1, + "column": 4, + "line": 3, }, }, "range": Array [ - 46, - 47, + 53, + 125, ], - "type": "TSTypeReference", - "typeName": Object { + "trueType": Object { "loc": Object { "end": Object { - "column": 47, - "line": 1, + "column": 25, + "line": 3, }, "start": Object { - "column": 46, - "line": 1, + "column": 24, + "line": 3, }, }, - "name": "T", "range": Array [ - 46, - 47, + 73, + 74, ], - "type": "Identifier", + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 3, + }, + "start": Object { + "column": 24, + "line": 3, + }, + }, + "name": "U", + "range": Array [ + 73, + 74, + ], + "type": "Identifier", + }, }, + "type": "TSConditionalType", }, "loc": Object { "end": Object { - "column": 47, - "line": 1, + "column": 9, + "line": 5, }, "start": Object { - "column": 18, - "line": 1, + "column": 2, + "line": 2, }, }, "range": Array [ - 18, - 47, + 21, + 125, ], "trueType": Object { "loc": Object { "end": Object { - "column": 43, - "line": 1, + "column": 27, + "line": 2, }, "start": Object { - "column": 42, - "line": 1, + "column": 26, + "line": 2, }, }, "range": Array [ - 42, - 43, + 45, + 46, ], "type": "TSTypeReference", "typeName": Object { "loc": Object { "end": Object { - "column": 43, - "line": 1, + "column": 27, + "line": 2, }, "start": Object { - "column": 42, - "line": 1, + "column": 26, + "line": 2, }, }, "name": "U", "range": Array [ - 42, - 43, + 45, + 46, ], "type": "Identifier", }, @@ -109013,11 +110951,11 @@ Object { "typeParameters": Object { "loc": Object { "end": Object { - "column": 15, + "column": 16, "line": 1, }, "start": Object { - "column": 12, + "column": 13, "line": 1, }, }, @@ -109025,42 +110963,42 @@ Object { Object { "loc": Object { "end": Object { - "column": 14, + "column": 15, "line": 1, }, "start": Object { - "column": 13, + "column": 14, "line": 1, }, }, "name": Object { "loc": Object { "end": Object { - "column": 14, + "column": 15, "line": 1, }, "start": Object { - "column": 13, + "column": 14, "line": 1, }, }, "name": "T", "range": Array [ - 13, 14, + 15, ], "type": "Identifier", }, "range": Array [ - 13, 14, + 15, ], "type": "TSTypeParameter", }, ], "range": Array [ - 12, - 15, + 13, + 16, ], "type": "TSTypeParameterDeclaration", }, @@ -109070,7 +111008,7 @@ Object { "loc": Object { "end": Object { "column": 0, - "line": 2, + "line": 6, }, "start": Object { "column": 0, @@ -109079,7 +111017,7 @@ Object { }, "range": Array [ 0, - 49, + 127, ], "sourceType": "module", "tokens": Array [ @@ -109104,7 +111042,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 12, + "column": 13, "line": 1, }, "start": Object { @@ -109114,25 +111052,25 @@ Object { }, "range": Array [ 5, - 12, + 13, ], "type": "Identifier", - "value": "Element", + "value": "Unpacked", }, Object { "loc": Object { "end": Object { - "column": 13, + "column": 14, "line": 1, }, "start": Object { - "column": 12, + "column": 13, "line": 1, }, }, "range": Array [ - 12, 13, + 14, ], "type": "Punctuator", "value": "<", @@ -109140,17 +111078,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 14, + "column": 15, "line": 1, }, "start": Object { - "column": 13, + "column": 14, "line": 1, }, }, "range": Array [ - 13, 14, + 15, ], "type": "Identifier", "value": "T", @@ -109158,17 +111096,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 15, + "column": 16, "line": 1, }, "start": Object { - "column": 14, + "column": 15, "line": 1, }, }, "range": Array [ - 14, 15, + 16, ], "type": "Punctuator", "value": ">", @@ -109176,17 +111114,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 17, + "column": 18, "line": 1, }, "start": Object { - "column": 16, + "column": 17, "line": 1, }, }, "range": Array [ - 16, 17, + 18, ], "type": "Punctuator", "value": "=", @@ -109194,17 +111132,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 19, - "line": 1, + "column": 3, + "line": 2, }, "start": Object { - "column": 18, - "line": 1, + "column": 2, + "line": 2, }, }, "range": Array [ - 18, - 19, + 21, + 22, ], "type": "Identifier", "value": "T", @@ -109212,17 +111150,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 27, - "line": 1, + "column": 11, + "line": 2, }, "start": Object { - "column": 20, - "line": 1, + "column": 4, + "line": 2, }, }, "range": Array [ - 20, - 27, + 23, + 30, ], "type": "Keyword", "value": "extends", @@ -109230,17 +111168,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 29, - "line": 1, + "column": 13, + "line": 2, }, "start": Object { - "column": 28, - "line": 1, + "column": 12, + "line": 2, }, }, "range": Array [ - 28, - 29, + 31, + 32, ], "type": "Punctuator", "value": "(", @@ -109248,17 +111186,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 34, - "line": 1, + "column": 18, + "line": 2, }, "start": Object { - "column": 29, - "line": 1, + "column": 13, + "line": 2, }, }, "range": Array [ - 29, - 34, + 32, + 37, ], "type": "Identifier", "value": "infer", @@ -109266,17 +111204,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 36, - "line": 1, + "column": 20, + "line": 2, }, "start": Object { - "column": 35, - "line": 1, + "column": 19, + "line": 2, }, }, "range": Array [ - 35, - 36, + 38, + 39, ], "type": "Identifier", "value": "U", @@ -109284,17 +111222,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 37, - "line": 1, + "column": 21, + "line": 2, }, "start": Object { - "column": 36, - "line": 1, + "column": 20, + "line": 2, }, }, "range": Array [ - 36, - 37, + 39, + 40, ], "type": "Punctuator", "value": ")", @@ -109302,17 +111240,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 38, - "line": 1, + "column": 22, + "line": 2, }, "start": Object { - "column": 37, - "line": 1, + "column": 21, + "line": 2, }, }, "range": Array [ - 37, - 38, + 40, + 41, ], "type": "Punctuator", "value": "[", @@ -109320,17 +111258,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 39, - "line": 1, + "column": 23, + "line": 2, }, "start": Object { - "column": 38, - "line": 1, + "column": 22, + "line": 2, }, }, "range": Array [ - 38, - 39, + 41, + 42, ], "type": "Punctuator", "value": "]", @@ -109338,17 +111276,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 41, - "line": 1, + "column": 25, + "line": 2, }, "start": Object { - "column": 40, - "line": 1, + "column": 24, + "line": 2, }, }, "range": Array [ - 40, - 41, + 43, + 44, ], "type": "Punctuator", "value": "?", @@ -109356,17 +111294,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 43, - "line": 1, + "column": 27, + "line": 2, }, "start": Object { - "column": 42, - "line": 1, + "column": 26, + "line": 2, }, }, "range": Array [ - 42, - 43, + 45, + 46, ], "type": "Identifier", "value": "U", @@ -109374,17 +111312,323 @@ Object { Object { "loc": Object { "end": Object { - "column": 45, - "line": 1, + "column": 29, + "line": 2, }, "start": Object { - "column": 44, - "line": 1, + "column": 28, + "line": 2, + }, + }, + "range": Array [ + 47, + 48, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "range": Array [ + 53, + 54, + ], + "type": "Identifier", + "value": "T", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 6, + "line": 3, + }, + }, + "range": Array [ + 55, + 62, + ], + "type": "Keyword", + "value": "extends", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 3, + }, + "start": Object { + "column": 14, + "line": 3, + }, + }, + "range": Array [ + 63, + 68, + ], + "type": "Identifier", + "value": "infer", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 3, + }, + "start": Object { + "column": 20, + "line": 3, + }, + }, + "range": Array [ + 69, + 70, + ], + "type": "Identifier", + "value": "U", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 22, + "line": 3, + }, + }, + "range": Array [ + 71, + 72, + ], + "type": "Punctuator", + "value": "?", + }, + Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 3, + }, + "start": Object { + "column": 24, + "line": 3, + }, + }, + "range": Array [ + 73, + 74, + ], + "type": "Identifier", + "value": "U", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 3, + }, + "start": Object { + "column": 26, + "line": 3, + }, + }, + "range": Array [ + 75, + 76, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 4, + }, + "start": Object { + "column": 6, + "line": 4, + }, + }, + "range": Array [ + 83, + 84, + ], + "type": "Identifier", + "value": "T", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 4, + }, + "start": Object { + "column": 8, + "line": 4, + }, + }, + "range": Array [ + 85, + 92, + ], + "type": "Keyword", + "value": "extends", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 4, + }, + "start": Object { + "column": 16, + "line": 4, + }, + }, + "range": Array [ + 93, + 100, + ], + "type": "Identifier", + "value": "Promise", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 4, + }, + "start": Object { + "column": 23, + "line": 4, + }, + }, + "range": Array [ + 100, + 101, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 4, + }, + "start": Object { + "column": 24, + "line": 4, + }, + }, + "range": Array [ + 101, + 106, + ], + "type": "Identifier", + "value": "infer", + }, + Object { + "loc": Object { + "end": Object { + "column": 31, + "line": 4, + }, + "start": Object { + "column": 30, + "line": 4, + }, + }, + "range": Array [ + 107, + 108, + ], + "type": "Identifier", + "value": "U", + }, + Object { + "loc": Object { + "end": Object { + "column": 32, + "line": 4, + }, + "start": Object { + "column": 31, + "line": 4, + }, + }, + "range": Array [ + 108, + 109, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 4, + }, + "start": Object { + "column": 33, + "line": 4, + }, + }, + "range": Array [ + 110, + 111, + ], + "type": "Punctuator", + "value": "?", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 4, + }, + "start": Object { + "column": 35, + "line": 4, + }, + }, + "range": Array [ + 112, + 113, + ], + "type": "Identifier", + "value": "U", + }, + Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 4, + }, + "start": Object { + "column": 37, + "line": 4, }, }, "range": Array [ - 44, - 45, + 114, + 115, ], "type": "Punctuator", "value": ":", @@ -109392,17 +111636,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 47, - "line": 1, + "column": 9, + "line": 5, }, "start": Object { - "column": 46, - "line": 1, + "column": 8, + "line": 5, }, }, "range": Array [ - 46, - 47, + 124, + 125, ], "type": "Identifier", "value": "T", @@ -109410,17 +111654,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 48, - "line": 1, + "column": 10, + "line": 5, }, "start": Object { - "column": 47, - "line": 1, + "column": 9, + "line": 5, }, }, "range": Array [ - 47, - 48, + 125, + 126, ], "type": "Punctuator", "value": ";", @@ -109430,14 +111674,14 @@ Object { } `; -exports[`typescript fixtures/types/conditional-infer-nested.src 1`] = ` +exports[`typescript fixtures/types/conditional-infer-simple.src 1`] = ` Object { "body": Array [ Object { "id": Object { "loc": Object { "end": Object { - "column": 13, + "column": 8, "line": 1, }, "start": Object { @@ -109445,17 +111689,17 @@ Object { "line": 1, }, }, - "name": "Unpacked", + "name": "Foo", "range": Array [ 5, - 13, + 8, ], "type": "Identifier", }, "loc": Object { "end": Object { - "column": 10, - "line": 5, + "column": 63, + "line": 1, }, "start": Object { "column": 0, @@ -109464,543 +111708,336 @@ Object { }, "range": Array [ 0, - 126, + 63, ], "type": "TSTypeAliasDeclaration", "typeAnnotation": Object { "checkType": Object { "loc": Object { "end": Object { - "column": 3, - "line": 2, + "column": 15, + "line": 1, }, "start": Object { - "column": 2, - "line": 2, + "column": 14, + "line": 1, }, }, "range": Array [ - 21, - 22, + 14, + 15, ], "type": "TSTypeReference", "typeName": Object { "loc": Object { "end": Object { - "column": 3, - "line": 2, + "column": 15, + "line": 1, }, "start": Object { - "column": 2, - "line": 2, + "column": 14, + "line": 1, }, }, "name": "T", "range": Array [ - 21, - 22, + 14, + 15, ], "type": "Identifier", }, }, "extendsType": Object { - "elementType": Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 2, - }, - "start": Object { - "column": 12, - "line": 2, - }, - }, - "range": Array [ - 31, - 40, - ], - "type": "TSParenthesizedType", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 20, - "line": 2, - }, - "start": Object { - "column": 13, - "line": 2, - }, - }, - "range": Array [ - 32, - 39, - ], - "type": "TSInferType", - "typeParameter": Object { - "loc": Object { - "end": Object { - "column": 20, - "line": 2, - }, - "start": Object { - "column": 19, - "line": 2, - }, - }, - "name": Object { - "loc": Object { - "end": Object { - "column": 20, - "line": 2, - }, - "start": Object { - "column": 19, - "line": 2, - }, - }, - "name": "U", - "range": Array [ - 38, - 39, - ], - "type": "Identifier", - }, - "range": Array [ - 38, - 39, - ], - "type": "TSTypeParameter", - }, - }, - }, "loc": Object { "end": Object { - "column": 23, - "line": 2, + "column": 50, + "line": 1, }, "start": Object { - "column": 12, - "line": 2, - }, - }, - "range": Array [ - 31, - 42, - ], - "type": "TSArrayType", - }, - "falseType": Object { - "checkType": Object { - "loc": Object { - "end": Object { - "column": 5, - "line": 3, - }, - "start": Object { - "column": 4, - "line": 3, - }, - }, - "range": Array [ - 53, - 54, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 5, - "line": 3, - }, - "start": Object { - "column": 4, - "line": 3, - }, - }, - "name": "T", - "range": Array [ - 53, - 54, - ], - "type": "Identifier", - }, - }, - "extendsType": Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 3, - }, - "start": Object { - "column": 14, - "line": 3, - }, - }, - "range": Array [ - 63, - 70, - ], - "type": "TSInferType", - "typeParameter": Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 3, - }, - "start": Object { - "column": 20, - "line": 3, - }, - }, - "name": Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 3, - }, - "start": Object { - "column": 20, - "line": 3, - }, - }, - "name": "U", - "range": Array [ - 69, - 70, - ], - "type": "Identifier", - }, - "range": Array [ - 69, - 70, - ], - "type": "TSTypeParameter", + "column": 24, + "line": 1, }, }, - "falseType": Object { - "checkType": Object { - "loc": Object { - "end": Object { - "column": 7, - "line": 4, - }, - "start": Object { - "column": 6, - "line": 4, - }, - }, - "range": Array [ - 83, - 84, - ], - "type": "TSTypeReference", - "typeName": Object { + "members": Array [ + Object { + "computed": false, + "key": Object { "loc": Object { "end": Object { - "column": 7, - "line": 4, + "column": 27, + "line": 1, }, "start": Object { - "column": 6, - "line": 4, + "column": 26, + "line": 1, }, }, - "name": "T", + "name": "a", "range": Array [ - 83, - 84, + 26, + 27, ], "type": "Identifier", }, - }, - "extendsType": Object { "loc": Object { "end": Object { - "column": 32, - "line": 4, + "column": 37, + "line": 1, }, "start": Object { - "column": 16, - "line": 4, + "column": 26, + "line": 1, }, }, "range": Array [ - 93, - 109, + 26, + 37, ], - "type": "TSTypeReference", - "typeName": Object { + "type": "TSPropertySignature", + "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 23, - "line": 4, + "column": 36, + "line": 1, }, "start": Object { - "column": 16, - "line": 4, + "column": 27, + "line": 1, }, }, - "name": "Promise", "range": Array [ - 93, - 100, + 27, + 36, ], - "type": "Identifier", - }, - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 32, - "line": 4, - }, - "start": Object { - "column": 23, - "line": 4, + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 1, + }, + "start": Object { + "column": 29, + "line": 1, + }, }, - }, - "params": Array [ - Object { + "range": Array [ + 29, + 36, + ], + "type": "TSInferType", + "typeParameter": Object { "loc": Object { "end": Object { - "column": 31, - "line": 4, + "column": 36, + "line": 1, }, "start": Object { - "column": 24, - "line": 4, + "column": 35, + "line": 1, }, }, - "range": Array [ - 101, - 108, - ], - "type": "TSInferType", - "typeParameter": Object { + "name": Object { "loc": Object { "end": Object { - "column": 31, - "line": 4, + "column": 36, + "line": 1, }, "start": Object { - "column": 30, - "line": 4, - }, - }, - "name": Object { - "loc": Object { - "end": Object { - "column": 31, - "line": 4, - }, - "start": Object { - "column": 30, - "line": 4, - }, + "column": 35, + "line": 1, }, - "name": "U", - "range": Array [ - 107, - 108, - ], - "type": "Identifier", }, + "name": "U", "range": Array [ - 107, - 108, + 35, + 36, ], - "type": "TSTypeParameter", + "type": "Identifier", }, + "range": Array [ + 35, + 36, + ], + "type": "TSTypeParameter", }, - ], - "range": Array [ - 100, - 109, - ], - "type": "TSTypeParameterInstantiation", - }, - }, - "falseType": Object { - "loc": Object { - "end": Object { - "column": 9, - "line": 5, - }, - "start": Object { - "column": 8, - "line": 5, }, }, - "range": Array [ - 124, - 125, - ], - "type": "TSTypeReference", - "typeName": Object { + }, + Object { + "computed": false, + "key": Object { "loc": Object { "end": Object { - "column": 9, - "line": 5, + "column": 39, + "line": 1, }, "start": Object { - "column": 8, - "line": 5, + "column": 38, + "line": 1, }, }, - "name": "T", + "name": "b", "range": Array [ - 124, - 125, + 38, + 39, ], "type": "Identifier", }, - }, - "loc": Object { - "end": Object { - "column": 9, - "line": 5, - }, - "start": Object { - "column": 6, - "line": 4, - }, - }, - "range": Array [ - 83, - 125, - ], - "trueType": Object { "loc": Object { "end": Object { - "column": 36, - "line": 4, + "column": 48, + "line": 1, }, "start": Object { - "column": 35, - "line": 4, + "column": 38, + "line": 1, }, }, "range": Array [ - 112, - 113, + 38, + 48, ], - "type": "TSTypeReference", - "typeName": Object { + "type": "TSPropertySignature", + "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 36, - "line": 4, + "column": 48, + "line": 1, }, "start": Object { - "column": 35, - "line": 4, + "column": 39, + "line": 1, + }, + }, + "range": Array [ + 39, + 48, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 48, + "line": 1, + }, + "start": Object { + "column": 41, + "line": 1, + }, + }, + "range": Array [ + 41, + 48, + ], + "type": "TSInferType", + "typeParameter": Object { + "loc": Object { + "end": Object { + "column": 48, + "line": 1, + }, + "start": Object { + "column": 47, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 48, + "line": 1, + }, + "start": Object { + "column": 47, + "line": 1, + }, + }, + "name": "U", + "range": Array [ + 47, + 48, + ], + "type": "Identifier", + }, + "range": Array [ + 47, + 48, + ], + "type": "TSTypeParameter", }, }, - "name": "U", - "range": Array [ - 112, - 113, - ], - "type": "Identifier", }, }, - "type": "TSConditionalType", - }, + ], + "range": Array [ + 24, + 50, + ], + "type": "TSTypeLiteral", + }, + "falseType": Object { "loc": Object { "end": Object { - "column": 9, - "line": 5, + "column": 62, + "line": 1, }, "start": Object { - "column": 4, - "line": 3, + "column": 57, + "line": 1, }, }, "range": Array [ - 53, - 125, + 57, + 62, ], - "trueType": Object { - "loc": Object { - "end": Object { - "column": 25, - "line": 3, - }, - "start": Object { - "column": 24, - "line": 3, - }, - }, - "range": Array [ - 73, - 74, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 25, - "line": 3, - }, - "start": Object { - "column": 24, - "line": 3, - }, - }, - "name": "U", - "range": Array [ - 73, - 74, - ], - "type": "Identifier", - }, - }, - "type": "TSConditionalType", + "type": "TSNeverKeyword", }, "loc": Object { "end": Object { - "column": 9, - "line": 5, + "column": 62, + "line": 1, }, "start": Object { - "column": 2, - "line": 2, + "column": 14, + "line": 1, }, }, "range": Array [ - 21, - 125, + 14, + 62, ], "trueType": Object { "loc": Object { "end": Object { - "column": 27, - "line": 2, + "column": 54, + "line": 1, }, "start": Object { - "column": 26, - "line": 2, + "column": 53, + "line": 1, }, }, "range": Array [ - 45, - 46, + 53, + 54, ], "type": "TSTypeReference", "typeName": Object { "loc": Object { "end": Object { - "column": 27, - "line": 2, + "column": 54, + "line": 1, }, "start": Object { - "column": 26, - "line": 2, + "column": 53, + "line": 1, }, }, "name": "U", "range": Array [ - 45, - 46, + 53, + 54, ], "type": "Identifier", }, @@ -110010,11 +112047,11 @@ Object { "typeParameters": Object { "loc": Object { "end": Object { - "column": 16, + "column": 11, "line": 1, }, "start": Object { - "column": 13, + "column": 8, "line": 1, }, }, @@ -110022,42 +112059,42 @@ Object { Object { "loc": Object { "end": Object { - "column": 15, + "column": 10, "line": 1, }, "start": Object { - "column": 14, + "column": 9, "line": 1, }, }, "name": Object { "loc": Object { "end": Object { - "column": 15, + "column": 10, "line": 1, }, "start": Object { - "column": 14, + "column": 9, "line": 1, }, }, "name": "T", "range": Array [ - 14, - 15, + 9, + 10, ], "type": "Identifier", }, "range": Array [ - 14, - 15, + 9, + 10, ], "type": "TSTypeParameter", }, ], "range": Array [ - 13, - 16, + 8, + 11, ], "type": "TSTypeParameterDeclaration", }, @@ -110067,7 +112104,7 @@ Object { "loc": Object { "end": Object { "column": 0, - "line": 6, + "line": 2, }, "start": Object { "column": 0, @@ -110076,7 +112113,7 @@ Object { }, "range": Array [ 0, - 127, + 64, ], "sourceType": "module", "tokens": Array [ @@ -110101,7 +112138,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 13, + "column": 8, "line": 1, }, "start": Object { @@ -110111,25 +112148,25 @@ Object { }, "range": Array [ 5, - 13, + 8, ], "type": "Identifier", - "value": "Unpacked", + "value": "Foo", }, Object { "loc": Object { "end": Object { - "column": 14, + "column": 9, "line": 1, }, "start": Object { - "column": 13, + "column": 8, "line": 1, }, }, "range": Array [ - 13, - 14, + 8, + 9, ], "type": "Punctuator", "value": "<", @@ -110137,17 +112174,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 15, + "column": 10, "line": 1, }, "start": Object { - "column": 14, + "column": 9, "line": 1, }, }, "range": Array [ - 14, - 15, + 9, + 10, ], "type": "Identifier", "value": "T", @@ -110155,17 +112192,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 16, + "column": 11, "line": 1, }, "start": Object { - "column": 15, + "column": 10, "line": 1, }, }, "range": Array [ - 15, - 16, + 10, + 11, ], "type": "Punctuator", "value": ">", @@ -110173,17 +112210,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 18, + "column": 13, "line": 1, }, "start": Object { - "column": 17, + "column": 12, "line": 1, }, }, "range": Array [ - 17, - 18, + 12, + 13, ], "type": "Punctuator", "value": "=", @@ -110191,17 +112228,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 3, - "line": 2, + "column": 15, + "line": 1, }, "start": Object { - "column": 2, - "line": 2, + "column": 14, + "line": 1, }, }, "range": Array [ - 21, - 22, + 14, + 15, ], "type": "Identifier", "value": "T", @@ -110209,179 +112246,71 @@ Object { Object { "loc": Object { "end": Object { - "column": 11, - "line": 2, + "column": 23, + "line": 1, }, "start": Object { - "column": 4, - "line": 2, + "column": 16, + "line": 1, }, }, "range": Array [ + 16, 23, - 30, ], "type": "Keyword", "value": "extends", }, - Object { - "loc": Object { - "end": Object { - "column": 13, - "line": 2, - }, - "start": Object { - "column": 12, - "line": 2, - }, - }, - "range": Array [ - 31, - 32, - ], - "type": "Punctuator", - "value": "(", - }, - Object { - "loc": Object { - "end": Object { - "column": 18, - "line": 2, - }, - "start": Object { - "column": 13, - "line": 2, - }, - }, - "range": Array [ - 32, - 37, - ], - "type": "Identifier", - "value": "infer", - }, - Object { - "loc": Object { - "end": Object { - "column": 20, - "line": 2, - }, - "start": Object { - "column": 19, - "line": 2, - }, - }, - "range": Array [ - 38, - 39, - ], - "type": "Identifier", - "value": "U", - }, - Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 2, - }, - "start": Object { - "column": 20, - "line": 2, - }, - }, - "range": Array [ - 39, - 40, - ], - "type": "Punctuator", - "value": ")", - }, - Object { - "loc": Object { - "end": Object { - "column": 22, - "line": 2, - }, - "start": Object { - "column": 21, - "line": 2, - }, - }, - "range": Array [ - 40, - 41, - ], - "type": "Punctuator", - "value": "[", - }, - Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 2, - }, - "start": Object { - "column": 22, - "line": 2, - }, - }, - "range": Array [ - 41, - 42, - ], - "type": "Punctuator", - "value": "]", - }, Object { "loc": Object { "end": Object { "column": 25, - "line": 2, + "line": 1, }, "start": Object { "column": 24, - "line": 2, + "line": 1, }, }, "range": Array [ - 43, - 44, + 24, + 25, ], "type": "Punctuator", - "value": "?", + "value": "{", }, Object { "loc": Object { "end": Object { "column": 27, - "line": 2, + "line": 1, }, "start": Object { "column": 26, - "line": 2, + "line": 1, }, }, "range": Array [ - 45, - 46, + 26, + 27, ], "type": "Identifier", - "value": "U", + "value": "a", }, Object { "loc": Object { "end": Object { - "column": 29, - "line": 2, + "column": 28, + "line": 1, }, "start": Object { - "column": 28, - "line": 2, + "column": 27, + "line": 1, }, }, "range": Array [ - 47, - 48, + 27, + 28, ], "type": "Punctuator", "value": ":", @@ -110389,53 +112318,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 5, - "line": 3, - }, - "start": Object { - "column": 4, - "line": 3, - }, - }, - "range": Array [ - 53, - 54, - ], - "type": "Identifier", - "value": "T", - }, - Object { - "loc": Object { - "end": Object { - "column": 13, - "line": 3, - }, - "start": Object { - "column": 6, - "line": 3, - }, - }, - "range": Array [ - 55, - 62, - ], - "type": "Keyword", - "value": "extends", - }, - Object { - "loc": Object { - "end": Object { - "column": 19, - "line": 3, + "column": 34, + "line": 1, }, "start": Object { - "column": 14, - "line": 3, + "column": 29, + "line": 1, }, }, "range": Array [ - 63, - 68, + 29, + 34, ], "type": "Identifier", "value": "infer", @@ -110443,53 +112336,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 21, - "line": 3, - }, - "start": Object { - "column": 20, - "line": 3, - }, - }, - "range": Array [ - 69, - 70, - ], - "type": "Identifier", - "value": "U", - }, - Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 3, - }, - "start": Object { - "column": 22, - "line": 3, - }, - }, - "range": Array [ - 71, - 72, - ], - "type": "Punctuator", - "value": "?", - }, - Object { - "loc": Object { - "end": Object { - "column": 25, - "line": 3, + "column": 36, + "line": 1, }, "start": Object { - "column": 24, - "line": 3, + "column": 35, + "line": 1, }, }, "range": Array [ - 73, - 74, + 35, + 36, ], "type": "Identifier", "value": "U", @@ -110497,107 +112354,71 @@ Object { Object { "loc": Object { "end": Object { - "column": 27, - "line": 3, + "column": 37, + "line": 1, }, "start": Object { - "column": 26, - "line": 3, + "column": 36, + "line": 1, }, }, "range": Array [ - 75, - 76, + 36, + 37, ], "type": "Punctuator", - "value": ":", - }, - Object { - "loc": Object { - "end": Object { - "column": 7, - "line": 4, - }, - "start": Object { - "column": 6, - "line": 4, - }, - }, - "range": Array [ - 83, - 84, - ], - "type": "Identifier", - "value": "T", - }, - Object { - "loc": Object { - "end": Object { - "column": 15, - "line": 4, - }, - "start": Object { - "column": 8, - "line": 4, - }, - }, - "range": Array [ - 85, - 92, - ], - "type": "Keyword", - "value": "extends", + "value": ",", }, Object { "loc": Object { "end": Object { - "column": 23, - "line": 4, + "column": 39, + "line": 1, }, "start": Object { - "column": 16, - "line": 4, + "column": 38, + "line": 1, }, }, "range": Array [ - 93, - 100, + 38, + 39, ], "type": "Identifier", - "value": "Promise", + "value": "b", }, Object { "loc": Object { "end": Object { - "column": 24, - "line": 4, + "column": 40, + "line": 1, }, - "start": Object { - "column": 23, - "line": 4, + "start": Object { + "column": 39, + "line": 1, }, }, "range": Array [ - 100, - 101, + 39, + 40, ], "type": "Punctuator", - "value": "<", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 29, - "line": 4, + "column": 46, + "line": 1, }, "start": Object { - "column": 24, - "line": 4, + "column": 41, + "line": 1, }, }, "range": Array [ - 101, - 106, + 41, + 46, ], "type": "Identifier", "value": "infer", @@ -110605,17 +112426,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 31, - "line": 4, + "column": 48, + "line": 1, }, "start": Object { - "column": 30, - "line": 4, + "column": 47, + "line": 1, }, }, "range": Array [ - 107, - 108, + 47, + 48, ], "type": "Identifier", "value": "U", @@ -110623,35 +112444,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 32, - "line": 4, + "column": 50, + "line": 1, }, "start": Object { - "column": 31, - "line": 4, + "column": 49, + "line": 1, }, }, "range": Array [ - 108, - 109, + 49, + 50, ], "type": "Punctuator", - "value": ">", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 34, - "line": 4, + "column": 52, + "line": 1, }, "start": Object { - "column": 33, - "line": 4, + "column": 51, + "line": 1, }, }, "range": Array [ - 110, - 111, + 51, + 52, ], "type": "Punctuator", "value": "?", @@ -110659,17 +112480,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 36, - "line": 4, + "column": 54, + "line": 1, }, "start": Object { - "column": 35, - "line": 4, + "column": 53, + "line": 1, }, }, "range": Array [ - 112, - 113, + 53, + 54, ], "type": "Identifier", "value": "U", @@ -110677,17 +112498,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 38, - "line": 4, + "column": 56, + "line": 1, }, "start": Object { - "column": 37, - "line": 4, + "column": 55, + "line": 1, }, }, "range": Array [ - 114, - 115, + 55, + 56, ], "type": "Punctuator", "value": ":", @@ -110695,35 +112516,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 9, - "line": 5, + "column": 62, + "line": 1, }, "start": Object { - "column": 8, - "line": 5, + "column": 57, + "line": 1, }, }, "range": Array [ - 124, - 125, + 57, + 62, ], "type": "Identifier", - "value": "T", + "value": "never", }, Object { "loc": Object { "end": Object { - "column": 10, - "line": 5, + "column": 63, + "line": 1, }, "start": Object { - "column": 9, - "line": 5, + "column": 62, + "line": 1, }, }, "range": Array [ - 125, - 126, + 62, + 63, ], "type": "Punctuator", "value": ";", @@ -110733,430 +112554,166 @@ Object { } `; -exports[`typescript fixtures/types/conditional-infer-simple.src 1`] = ` +exports[`typescript fixtures/types/conditional-with-null.src 1`] = ` Object { "body": Array [ Object { - "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": 63, - "line": 1, - }, - "start": Object { - "column": 0, - "line": 1, - }, - }, - "range": Array [ - 0, - 63, - ], - "type": "TSTypeAliasDeclaration", - "typeAnnotation": Object { - "checkType": Object { - "loc": Object { - "end": Object { - "column": 15, - "line": 1, - }, - "start": Object { - "column": 14, - "line": 1, - }, - }, - "range": Array [ - 14, - 15, - ], - "type": "TSTypeReference", - "typeName": Object { + "declarations": Array [ + Object { + "id": Object { "loc": Object { "end": Object { - "column": 15, + "column": 45, "line": 1, }, "start": Object { - "column": 14, + "column": 4, "line": 1, }, }, - "name": "T", + "name": "x", "range": Array [ - 14, - 15, + 4, + 45, ], "type": "Identifier", - }, - }, - "extendsType": Object { - "loc": Object { - "end": Object { - "column": 50, - "line": 1, - }, - "start": Object { - "column": 24, - "line": 1, - }, - }, - "members": Array [ - Object { - "computed": false, - "key": Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 1, - }, - "start": Object { - "column": 26, - "line": 1, - }, - }, - "name": "a", - "range": Array [ - 26, - 27, - ], - "type": "Identifier", - }, + "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 37, + "column": 45, "line": 1, }, "start": Object { - "column": 26, + "column": 5, "line": 1, }, }, "range": Array [ - 26, - 37, + 5, + 45, ], - "type": "TSPropertySignature", + "type": "TSTypeAnnotation", "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 1, - }, - "start": Object { - "column": 27, - "line": 1, - }, - }, - "range": Array [ - 27, - 36, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { + "checkType": Object { "loc": Object { "end": Object { - "column": 36, + "column": 13, "line": 1, }, "start": Object { - "column": 29, + "column": 7, "line": 1, }, }, "range": Array [ - 29, - 36, + 7, + 13, ], - "type": "TSInferType", - "typeParameter": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 1, - }, - "start": Object { - "column": 35, - "line": 1, - }, + "type": "TSNumberKeyword", + }, + "extendsType": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, }, - "name": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 1, - }, - "start": Object { - "column": 35, - "line": 1, - }, - }, - "name": "U", - "range": Array [ - 35, - 36, - ], - "type": "Identifier", + "start": Object { + "column": 22, + "line": 1, }, - "range": Array [ - 35, - 36, - ], - "type": "TSTypeParameter", }, + "range": Array [ + 22, + 28, + ], + "type": "TSStringKeyword", }, - }, - }, - Object { - "computed": false, - "key": Object { - "loc": Object { - "end": Object { - "column": 39, - "line": 1, - }, - "start": Object { - "column": 38, - "line": 1, + "falseType": Object { + "loc": Object { + "end": Object { + "column": 45, + "line": 1, + }, + "start": Object { + "column": 41, + "line": 1, + }, }, + "range": Array [ + 41, + 45, + ], + "type": "TSNullKeyword", }, - "name": "b", - "range": Array [ - 38, - 39, - ], - "type": "Identifier", - }, - "loc": Object { - "end": Object { - "column": 48, - "line": 1, - }, - "start": Object { - "column": 38, - "line": 1, - }, - }, - "range": Array [ - 38, - 48, - ], - "type": "TSPropertySignature", - "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 48, + "column": 45, "line": 1, }, "start": Object { - "column": 39, + "column": 7, "line": 1, }, }, "range": Array [ - 39, - 48, + 7, + 45, ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { + "trueType": Object { "loc": Object { "end": Object { - "column": 48, - "line": 1, - }, - "start": Object { - "column": 41, + "column": 38, "line": 1, }, - }, - "range": Array [ - 41, - 48, - ], - "type": "TSInferType", - "typeParameter": Object { - "loc": Object { - "end": Object { - "column": 48, - "line": 1, - }, - "start": Object { - "column": 47, - "line": 1, - }, - }, - "name": Object { - "loc": Object { - "end": Object { - "column": 48, - "line": 1, - }, - "start": Object { - "column": 47, - "line": 1, - }, - }, - "name": "U", - "range": Array [ - 47, - 48, - ], - "type": "Identifier", - }, - "range": Array [ - 47, - 48, - ], - "type": "TSTypeParameter", - }, - }, - }, - }, - ], - "range": Array [ - 24, - 50, - ], - "type": "TSTypeLiteral", - }, - "falseType": Object { - "loc": Object { - "end": Object { - "column": 62, - "line": 1, - }, - "start": Object { - "column": 57, - "line": 1, - }, - }, - "range": Array [ - 57, - 62, - ], - "type": "TSNeverKeyword", - }, - "loc": Object { - "end": Object { - "column": 62, - "line": 1, - }, - "start": Object { - "column": 14, - "line": 1, - }, - }, - "range": Array [ - 14, - 62, - ], - "trueType": Object { - "loc": Object { - "end": Object { - "column": 54, - "line": 1, - }, - "start": Object { - "column": 53, - "line": 1, - }, - }, - "range": Array [ - 53, - 54, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 54, - "line": 1, - }, - "start": Object { - "column": 53, - "line": 1, - }, - }, - "name": "U", - "range": Array [ - 53, - 54, - ], - "type": "Identifier", - }, - }, - "type": "TSConditionalType", - }, - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 1, - }, - "start": Object { - "column": 8, - "line": 1, - }, - }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 1, - }, - "start": Object { - "column": 9, - "line": 1, - }, - }, - "name": Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 1, - }, - "start": Object { - "column": 9, - "line": 1, + "start": Object { + "column": 31, + "line": 1, + }, + }, + "range": Array [ + 31, + 38, + ], + "type": "TSBooleanKeyword", }, + "type": "TSConditionalType", }, - "name": "T", - "range": Array [ - 9, - 10, - ], - "type": "Identifier", }, - "range": Array [ - 9, - 10, - ], - "type": "TSTypeParameter", }, - ], - "range": Array [ - 8, - 11, - ], - "type": "TSTypeParameterDeclaration", + "init": null, + "loc": Object { + "end": Object { + "column": 45, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 45, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "let", + "loc": Object { + "end": Object { + "column": 46, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, }, + "range": Array [ + 0, + 46, + ], + "type": "VariableDeclaration", }, ], "comments": Array [], @@ -111172,14 +112729,14 @@ Object { }, "range": Array [ 0, - 64, + 47, ], "sourceType": "module", "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 4, + "column": 3, "line": 1, }, "start": Object { @@ -111189,15 +112746,33 @@ Object { }, "range": Array [ 0, + 3, + ], + "type": "Keyword", + "value": "let", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ 4, + 5, ], "type": "Identifier", - "value": "type", + "value": "x", }, Object { "loc": Object { "end": Object { - "column": 8, + "column": 6, "line": 1, }, "start": Object { @@ -111207,169 +112782,462 @@ Object { }, "range": Array [ 5, - 8, + 6, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 13, ], "type": "Identifier", - "value": "Foo", + "value": "number", }, Object { "loc": Object { "end": Object { - "column": 9, + "column": 21, "line": 1, }, "start": Object { - "column": 8, + "column": 14, "line": 1, }, }, "range": Array [ - 8, - 9, + 14, + 21, ], - "type": "Punctuator", - "value": "<", + "type": "Keyword", + "value": "extends", }, Object { "loc": Object { "end": Object { - "column": 10, + "column": 28, "line": 1, }, "start": Object { - "column": 9, + "column": 22, "line": 1, }, }, "range": Array [ - 9, - 10, + 22, + 28, ], "type": "Identifier", - "value": "T", + "value": "string", }, Object { "loc": Object { "end": Object { - "column": 11, + "column": 30, "line": 1, }, "start": Object { - "column": 10, + "column": 29, "line": 1, }, }, "range": Array [ - 10, - 11, + 29, + 30, ], "type": "Punctuator", - "value": ">", + "value": "?", }, Object { "loc": Object { "end": Object { - "column": 13, + "column": 38, "line": 1, }, "start": Object { - "column": 12, + "column": 31, "line": 1, }, }, "range": Array [ - 12, - 13, + 31, + 38, ], - "type": "Punctuator", - "value": "=", + "type": "Identifier", + "value": "boolean", }, Object { "loc": Object { "end": Object { - "column": 15, + "column": 40, "line": 1, }, "start": Object { - "column": 14, + "column": 39, "line": 1, }, }, "range": Array [ - 14, - 15, + 39, + 40, ], - "type": "Identifier", - "value": "T", + "type": "Punctuator", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 23, + "column": 45, "line": 1, }, "start": Object { - "column": 16, + "column": 41, "line": 1, }, }, "range": Array [ - 16, - 23, + 41, + 45, ], "type": "Keyword", - "value": "extends", + "value": "null", }, Object { "loc": Object { "end": Object { - "column": 25, + "column": 46, "line": 1, }, "start": Object { - "column": 24, + "column": 45, "line": 1, }, }, "range": Array [ - 24, - 25, + 45, + 46, ], "type": "Punctuator", - "value": "{", + "value": ";", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/types/constructor.src 1`] = ` +Object { + "body": Array [ + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "name": "f", + "range": Array [ + 4, + 42, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 42, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "name": "a", + "range": Array [ + 12, + 21, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 21, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 21, + ], + "type": "TSNumberKeyword", + }, + }, + }, + Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 1, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "name": "b", + "optional": true, + "range": Array [ + 23, + 33, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, + }, + "range": Array [ + 25, + 33, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 1, + }, + "start": Object { + "column": 27, + "line": 1, + }, + }, + "range": Array [ + 27, + 33, + ], + "type": "TSNumberKeyword", + }, + }, + }, + ], + "range": Array [ + 7, + 42, + ], + "returnType": Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 1, + }, + "start": Object { + "column": 35, + "line": 1, + }, + }, + "range": Array [ + 35, + 42, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 1, + }, + "start": Object { + "column": 38, + "line": 1, + }, + }, + "range": Array [ + 38, + 42, + ], + "type": "TSVoidKeyword", + }, + }, + "type": "TSConstructorType", + }, + }, + }, + "init": null, + "loc": Object { + "end": Object { + "column": 42, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 42, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "let", + "loc": Object { + "end": Object { + "column": 43, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 43, + ], + "type": "VariableDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, }, + }, + "range": Array [ + 0, + 44, + ], + "sourceType": "module", + "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 27, + "column": 3, "line": 1, }, "start": Object { - "column": 26, + "column": 0, "line": 1, }, }, "range": Array [ - 26, - 27, + 0, + 3, + ], + "type": "Keyword", + "value": "let", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 5, ], "type": "Identifier", - "value": "a", + "value": "f", }, Object { "loc": Object { "end": Object { - "column": 28, + "column": 6, "line": 1, }, "start": Object { - "column": 27, + "column": 5, "line": 1, }, }, "range": Array [ - 27, - 28, + 5, + 6, ], "type": "Punctuator", "value": ":", @@ -111377,233 +113245,251 @@ Object { Object { "loc": Object { "end": Object { - "column": 34, + "column": 10, "line": 1, }, "start": Object { - "column": 29, + "column": 7, "line": 1, }, }, "range": Array [ - 29, - 34, + 7, + 10, ], - "type": "Identifier", - "value": "infer", + "type": "Keyword", + "value": "new", }, Object { "loc": Object { "end": Object { - "column": 36, + "column": 12, "line": 1, }, "start": Object { - "column": 35, + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 12, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 12, "line": 1, }, }, "range": Array [ - 35, - 36, + 12, + 13, ], "type": "Identifier", - "value": "U", + "value": "a", }, Object { "loc": Object { "end": Object { - "column": 37, + "column": 14, "line": 1, }, "start": Object { - "column": 36, + "column": 13, "line": 1, }, }, "range": Array [ - 36, - 37, + 13, + 14, ], "type": "Punctuator", - "value": ",", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 39, + "column": 21, "line": 1, }, "start": Object { - "column": 38, + "column": 15, "line": 1, }, }, "range": Array [ - 38, - 39, + 15, + 21, ], "type": "Identifier", - "value": "b", + "value": "number", }, Object { "loc": Object { "end": Object { - "column": 40, + "column": 22, "line": 1, }, "start": Object { - "column": 39, + "column": 21, "line": 1, }, }, "range": Array [ - 39, - 40, + 21, + 22, ], "type": "Punctuator", - "value": ":", + "value": ",", }, Object { "loc": Object { "end": Object { - "column": 46, + "column": 24, "line": 1, }, "start": Object { - "column": 41, + "column": 23, "line": 1, }, }, "range": Array [ - 41, - 46, + 23, + 24, ], "type": "Identifier", - "value": "infer", + "value": "b", }, Object { "loc": Object { "end": Object { - "column": 48, + "column": 25, "line": 1, }, "start": Object { - "column": 47, + "column": 24, "line": 1, }, }, "range": Array [ - 47, - 48, + 24, + 25, ], - "type": "Identifier", - "value": "U", + "type": "Punctuator", + "value": "?", }, Object { "loc": Object { "end": Object { - "column": 50, + "column": 26, "line": 1, }, "start": Object { - "column": 49, + "column": 25, "line": 1, }, }, "range": Array [ - 49, - 50, + 25, + 26, ], "type": "Punctuator", - "value": "}", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 52, + "column": 33, "line": 1, }, "start": Object { - "column": 51, + "column": 27, "line": 1, }, }, "range": Array [ - 51, - 52, + 27, + 33, ], - "type": "Punctuator", - "value": "?", + "type": "Identifier", + "value": "number", }, Object { "loc": Object { "end": Object { - "column": 54, + "column": 34, "line": 1, }, "start": Object { - "column": 53, + "column": 33, "line": 1, }, }, "range": Array [ - 53, - 54, + 33, + 34, ], - "type": "Identifier", - "value": "U", + "type": "Punctuator", + "value": ")", }, Object { "loc": Object { "end": Object { - "column": 56, + "column": 37, "line": 1, }, "start": Object { - "column": 55, + "column": 35, "line": 1, }, }, "range": Array [ - 55, - 56, + 35, + 37, ], "type": "Punctuator", - "value": ":", + "value": "=>", }, Object { "loc": Object { "end": Object { - "column": 62, + "column": 42, "line": 1, }, "start": Object { - "column": 57, + "column": 38, "line": 1, }, }, "range": Array [ - 57, - 62, + 38, + 42, ], - "type": "Identifier", - "value": "never", + "type": "Keyword", + "value": "void", }, Object { "loc": Object { "end": Object { - "column": 63, + "column": 43, "line": 1, }, "start": Object { - "column": 62, + "column": 42, "line": 1, }, }, "range": Array [ - 62, - 63, + 42, + 43, ], "type": "Punctuator", "value": ";", @@ -111613,7 +113499,7 @@ Object { } `; -exports[`typescript fixtures/types/conditional-with-null.src 1`] = ` +exports[`typescript fixtures/types/constructor-generic.src 1`] = ` Object { "body": Array [ Object { @@ -111622,7 +113508,7 @@ Object { "id": Object { "loc": Object { "end": Object { - "column": 45, + "column": 25, "line": 1, }, "start": Object { @@ -111630,16 +113516,16 @@ Object { "line": 1, }, }, - "name": "x", + "name": "f", "range": Array [ 4, - 45, + 25, ], "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 45, + "column": 25, "line": 1, }, "start": Object { @@ -111649,100 +113535,210 @@ Object { }, "range": Array [ 5, - 45, + 25, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { - "checkType": Object { - "loc": Object { - "end": Object { - "column": 13, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, - }, + "loc": Object { + "end": Object { + "column": 25, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, }, - "range": Array [ - 7, - 13, - ], - "type": "TSNumberKeyword", }, - "extendsType": Object { - "loc": Object { - "end": Object { - "column": 28, - "line": 1, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, }, - "start": Object { - "column": 22, - "line": 1, + "name": "a", + "range": Array [ + 15, + 19, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 19, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 18, + 19, + ], + "type": "Identifier", + }, + }, }, }, - "range": Array [ - 22, - 28, - ], - "type": "TSStringKeyword", - }, - "falseType": Object { + ], + "range": Array [ + 7, + 25, + ], + "returnType": Object { "loc": Object { "end": Object { - "column": 45, + "column": 25, "line": 1, }, "start": Object { - "column": 41, + "column": 21, "line": 1, }, }, "range": Array [ - 41, - 45, + 21, + 25, ], - "type": "TSNullKeyword", - }, - "loc": Object { - "end": Object { - "column": 45, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 1, + }, + "start": Object { + "column": 24, + "line": 1, + }, + }, + "range": Array [ + 24, + 25, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 1, + }, + "start": Object { + "column": 24, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 24, + 25, + ], + "type": "Identifier", + }, }, }, - "range": Array [ - 7, - 45, - ], - "trueType": Object { + "type": "TSConstructorType", + "typeParameters": Object { "loc": Object { "end": Object { - "column": 38, + "column": 14, "line": 1, }, "start": Object { - "column": 31, + "column": 11, "line": 1, }, }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "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, + ], + "type": "TSTypeParameter", + }, + ], "range": Array [ - 31, - 38, + 11, + 14, ], - "type": "TSBooleanKeyword", + "type": "TSTypeParameterDeclaration", }, - "type": "TSConditionalType", }, }, }, "init": null, "loc": Object { "end": Object { - "column": 45, + "column": 25, "line": 1, }, "start": Object { @@ -111752,7 +113748,7 @@ Object { }, "range": Array [ 4, - 45, + 25, ], "type": "VariableDeclarator", }, @@ -111760,7 +113756,7 @@ Object { "kind": "let", "loc": Object { "end": Object { - "column": 46, + "column": 26, "line": 1, }, "start": Object { @@ -111770,7 +113766,7 @@ Object { }, "range": Array [ 0, - 46, + 26, ], "type": "VariableDeclaration", }, @@ -111788,7 +113784,7 @@ Object { }, "range": Array [ 0, - 47, + 27, ], "sourceType": "module", "tokens": Array [ @@ -111826,7 +113822,7 @@ Object { 5, ], "type": "Identifier", - "value": "x", + "value": "f", }, Object { "loc": Object { @@ -111849,7 +113845,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 13, + "column": 10, "line": 1, }, "start": Object { @@ -111859,15 +113855,69 @@ Object { }, "range": Array [ 7, + 10, + ], + "type": "Keyword", + "value": "new", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 12, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, 13, ], "type": "Identifier", - "value": "number", + "value": "T", }, Object { "loc": Object { "end": Object { - "column": 21, + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, "line": 1, }, "start": Object { @@ -111877,115 +113927,133 @@ Object { }, "range": Array [ 14, - 21, + 15, ], - "type": "Keyword", - "value": "extends", + "type": "Punctuator", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 28, + "column": 16, "line": 1, }, "start": Object { - "column": 22, + "column": 15, "line": 1, }, }, "range": Array [ - 22, - 28, + 15, + 16, ], "type": "Identifier", - "value": "string", + "value": "a", }, Object { "loc": Object { "end": Object { - "column": 30, + "column": 17, "line": 1, }, "start": Object { - "column": 29, + "column": 16, "line": 1, }, }, "range": Array [ - 29, - 30, + 16, + 17, ], "type": "Punctuator", - "value": "?", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 38, + "column": 19, "line": 1, }, "start": Object { - "column": 31, + "column": 18, "line": 1, }, }, "range": Array [ - 31, - 38, + 18, + 19, ], "type": "Identifier", - "value": "boolean", + "value": "T", }, Object { "loc": Object { "end": Object { - "column": 40, + "column": 20, "line": 1, }, "start": Object { - "column": 39, + "column": 19, "line": 1, }, }, "range": Array [ - 39, - 40, + 19, + 20, ], "type": "Punctuator", - "value": ":", + "value": ")", }, Object { "loc": Object { "end": Object { - "column": 45, + "column": 23, "line": 1, }, "start": Object { - "column": 41, + "column": 21, "line": 1, }, }, "range": Array [ - 41, - 45, + 21, + 23, ], - "type": "Keyword", - "value": "null", + "type": "Punctuator", + "value": "=>", }, Object { "loc": Object { "end": Object { - "column": 46, + "column": 25, "line": 1, }, "start": Object { - "column": 45, + "column": 24, "line": 1, }, }, "range": Array [ - 45, - 46, + 24, + 25, + ], + "type": "Identifier", + "value": "T", + }, + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, + }, + "range": Array [ + 25, + 26, ], "type": "Punctuator", "value": ";", @@ -111995,7 +114063,7 @@ Object { } `; -exports[`typescript fixtures/types/constructor.src 1`] = ` +exports[`typescript fixtures/types/constructor-in-generic.src 1`] = ` Object { "body": Array [ Object { @@ -112004,7 +114072,7 @@ Object { "id": Object { "loc": Object { "end": Object { - "column": 42, + "column": 30, "line": 1, }, "start": Object { @@ -112012,16 +114080,16 @@ Object { "line": 1, }, }, - "name": "f", + "name": "x", "range": Array [ 4, - 42, + 30, ], "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 42, + "column": 30, "line": 1, }, "start": Object { @@ -112031,13 +114099,13 @@ Object { }, "range": Array [ 5, - 42, + 30, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 42, + "column": 30, "line": 1, }, "start": Object { @@ -112045,28 +114113,45 @@ Object { "line": 1, }, }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 1, - }, - "start": Object { - "column": 12, - "line": 1, - }, + "range": Array [ + 7, + 30, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, }, - "name": "a", - "range": Array [ - 12, - 21, - ], - "type": "Identifier", - "typeAnnotation": Object { + "start": Object { + "column": 7, + "line": 1, + }, + }, + "name": "Array", + "range": Array [ + 7, + 12, + ], + "type": "Identifier", + }, + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 30, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "params": Array [ + Object { "loc": Object { "end": Object { - "column": 21, + "column": 29, "line": 1, }, "start": Object { @@ -112074,130 +114159,61 @@ Object { "line": 1, }, }, + "params": Array [], "range": Array [ 13, - 21, + 29, ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { - "column": 21, + "column": 29, "line": 1, }, "start": Object { - "column": 15, + "column": 20, "line": 1, }, }, "range": Array [ - 15, - 21, + 20, + 29, ], - "type": "TSNumberKeyword", - }, - }, - }, - Object { - "loc": Object { - "end": Object { - "column": 33, - "line": 1, - }, - "start": Object { - "column": 23, - "line": 1, - }, - }, - "name": "b", - "optional": true, - "range": Array [ - 23, - 33, - ], - "type": "Identifier", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 33, - "line": 1, - }, - "start": Object { - "column": 25, - "line": 1, - }, - }, - "range": Array [ - 25, - 33, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 33, - "line": 1, - }, - "start": Object { - "column": 27, - "line": 1, + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 1, + }, + "start": Object { + "column": 23, + "line": 1, + }, }, + "range": Array [ + 23, + 29, + ], + "type": "TSStringKeyword", }, - "range": Array [ - 27, - 33, - ], - "type": "TSNumberKeyword", }, + "type": "TSConstructorType", }, - }, - ], - "range": Array [ - 7, - 42, - ], - "returnType": Object { - "loc": Object { - "end": Object { - "column": 42, - "line": 1, - }, - "start": Object { - "column": 35, - "line": 1, - }, - }, + ], "range": Array [ - 35, - 42, + 12, + 30, ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 42, - "line": 1, - }, - "start": Object { - "column": 38, - "line": 1, - }, - }, - "range": Array [ - 38, - 42, - ], - "type": "TSVoidKeyword", - }, + "type": "TSTypeParameterInstantiation", }, - "type": "TSConstructorType", }, }, }, "init": null, "loc": Object { "end": Object { - "column": 42, + "column": 30, "line": 1, }, "start": Object { @@ -112207,7 +114223,7 @@ Object { }, "range": Array [ 4, - 42, + 30, ], "type": "VariableDeclarator", }, @@ -112215,7 +114231,7 @@ Object { "kind": "let", "loc": Object { "end": Object { - "column": 43, + "column": 31, "line": 1, }, "start": Object { @@ -112225,7 +114241,7 @@ Object { }, "range": Array [ 0, - 43, + 31, ], "type": "VariableDeclaration", }, @@ -112243,7 +114259,7 @@ Object { }, "range": Array [ 0, - 44, + 32, ], "sourceType": "module", "tokens": Array [ @@ -112281,7 +114297,7 @@ Object { 5, ], "type": "Identifier", - "value": "f", + "value": "x", }, Object { "loc": Object { @@ -112304,7 +114320,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 10, + "column": 12, "line": 1, }, "start": Object { @@ -112314,28 +114330,10 @@ Object { }, "range": Array [ 7, - 10, - ], - "type": "Keyword", - "value": "new", - }, - Object { - "loc": Object { - "end": Object { - "column": 12, - "line": 1, - }, - "start": Object { - "column": 11, - "line": 1, - }, - }, - "range": Array [ - 11, 12, ], - "type": "Punctuator", - "value": "(", + "type": "Identifier", + "value": "Array", }, Object { "loc": Object { @@ -112352,13 +114350,13 @@ Object { 12, 13, ], - "type": "Identifier", - "value": "a", + "type": "Punctuator", + "value": "<", }, Object { "loc": Object { "end": Object { - "column": 14, + "column": 16, "line": 1, }, "start": Object { @@ -112368,187 +114366,115 @@ Object { }, "range": Array [ 13, - 14, - ], - "type": "Punctuator", - "value": ":", - }, - Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 1, - }, - "start": Object { - "column": 15, - "line": 1, - }, - }, - "range": Array [ - 15, - 21, + 16, ], - "type": "Identifier", - "value": "number", + "type": "Keyword", + "value": "new", }, Object { "loc": Object { "end": Object { - "column": 22, + "column": 18, "line": 1, }, "start": Object { - "column": 21, + "column": 17, "line": 1, }, }, "range": Array [ - 21, - 22, + 17, + 18, ], "type": "Punctuator", - "value": ",", - }, - Object { - "loc": Object { - "end": Object { - "column": 24, - "line": 1, - }, - "start": Object { - "column": 23, - "line": 1, - }, - }, - "range": Array [ - 23, - 24, - ], - "type": "Identifier", - "value": "b", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 25, + "column": 19, "line": 1, }, "start": Object { - "column": 24, + "column": 18, "line": 1, }, }, "range": Array [ - 24, - 25, + 18, + 19, ], "type": "Punctuator", - "value": "?", + "value": ")", }, Object { "loc": Object { "end": Object { - "column": 26, + "column": 22, "line": 1, }, "start": Object { - "column": 25, + "column": 20, "line": 1, }, }, "range": Array [ - 25, - 26, + 20, + 22, ], "type": "Punctuator", - "value": ":", + "value": "=>", }, Object { "loc": Object { "end": Object { - "column": 33, + "column": 29, "line": 1, }, "start": Object { - "column": 27, + "column": 23, "line": 1, }, }, "range": Array [ - 27, - 33, + 23, + 29, ], "type": "Identifier", - "value": "number", - }, - Object { - "loc": Object { - "end": Object { - "column": 34, - "line": 1, - }, - "start": Object { - "column": 33, - "line": 1, - }, - }, - "range": Array [ - 33, - 34, - ], - "type": "Punctuator", - "value": ")", + "value": "string", }, Object { "loc": Object { "end": Object { - "column": 37, + "column": 30, "line": 1, }, "start": Object { - "column": 35, + "column": 29, "line": 1, }, }, "range": Array [ - 35, - 37, + 29, + 30, ], "type": "Punctuator", - "value": "=>", - }, - Object { - "loc": Object { - "end": Object { - "column": 42, - "line": 1, - }, - "start": Object { - "column": 38, - "line": 1, - }, - }, - "range": Array [ - 38, - 42, - ], - "type": "Keyword", - "value": "void", + "value": ">", }, Object { "loc": Object { "end": Object { - "column": 43, + "column": 31, "line": 1, }, "start": Object { - "column": 42, + "column": 30, "line": 1, }, }, "range": Array [ - 42, - 43, + 30, + 31, ], "type": "Punctuator", "value": ";", @@ -112558,7 +114484,7 @@ Object { } `; -exports[`typescript fixtures/types/constructor-generic.src 1`] = ` +exports[`typescript fixtures/types/constructor-with-rest.src 1`] = ` Object { "body": Array [ Object { @@ -112567,7 +114493,7 @@ Object { "id": Object { "loc": Object { "end": Object { - "column": 25, + "column": 35, "line": 1, }, "start": Object { @@ -112578,13 +114504,13 @@ Object { "name": "f", "range": Array [ 4, - 25, + 35, ], "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 25, + "column": 35, "line": 1, }, "start": Object { @@ -112594,13 +114520,13 @@ Object { }, "range": Array [ 5, - 25, + 35, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 25, + "column": 35, "line": 1, }, "start": Object { @@ -112610,194 +114536,138 @@ Object { }, "params": Array [ Object { - "loc": Object { - "end": Object { - "column": 19, - "line": 1, - }, - "start": Object { - "column": 15, - "line": 1, - }, - }, - "name": "a", - "range": Array [ - 15, - 19, - ], - "type": "Identifier", - "typeAnnotation": Object { + "argument": Object { "loc": Object { "end": Object { - "column": 19, + "column": 16, "line": 1, }, "start": Object { - "column": 16, + "column": 15, "line": 1, }, }, + "name": "a", "range": Array [ + 15, 16, - 19, ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 19, - "line": 1, - }, - "start": Object { - "column": 18, - "line": 1, - }, - }, - "range": Array [ - 18, - 19, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 19, - "line": 1, - }, - "start": Object { - "column": 18, - "line": 1, - }, - }, - "name": "T", - "range": Array [ - 18, - 19, - ], - "type": "Identifier", - }, - }, - }, - }, - ], - "range": Array [ - 7, - 25, - ], - "returnType": Object { - "loc": Object { - "end": Object { - "column": 25, - "line": 1, - }, - "start": Object { - "column": 21, - "line": 1, + "type": "Identifier", }, - }, - "range": Array [ - 21, - 25, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 25, + "column": 26, "line": 1, }, "start": Object { - "column": 24, + "column": 12, "line": 1, }, }, "range": Array [ - 24, - 25, + 12, + 26, ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 25, - "line": 1, - }, - "start": Object { - "column": 24, - "line": 1, - }, - }, - "name": "T", - "range": Array [ - 24, - 25, - ], - "type": "Identifier", - }, - }, - }, - "type": "TSConstructorType", - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 14, - "line": 1, - }, - "start": Object { - "column": 11, - "line": 1, - }, - }, - "params": Array [ - Object { + "type": "RestElement", + "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 13, + "column": 26, "line": 1, }, "start": Object { - "column": 12, + "column": 16, "line": 1, }, }, - "name": Object { + "range": Array [ + 16, + 26, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "elementType": Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 24, + ], + "type": "TSNumberKeyword", + }, "loc": Object { "end": Object { - "column": 13, + "column": 26, "line": 1, }, "start": Object { - "column": 12, + "column": 18, "line": 1, }, }, - "name": "T", "range": Array [ - 12, - 13, + 18, + 26, ], - "type": "Identifier", + "type": "TSArrayType", }, - "range": Array [ - 12, - 13, - ], - "type": "TSTypeParameter", }, - ], + }, + ], + "range": Array [ + 7, + 35, + ], + "returnType": Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 1, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, "range": Array [ - 11, - 14, + 28, + 35, ], - "type": "TSTypeParameterDeclaration", + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 1, + }, + "start": Object { + "column": 31, + "line": 1, + }, + }, + "range": Array [ + 31, + 35, + ], + "type": "TSVoidKeyword", + }, }, + "type": "TSConstructorType", }, }, }, "init": null, "loc": Object { "end": Object { - "column": 25, + "column": 35, "line": 1, }, "start": Object { @@ -112807,7 +114677,7 @@ Object { }, "range": Array [ 4, - 25, + 35, ], "type": "VariableDeclarator", }, @@ -112815,7 +114685,7 @@ Object { "kind": "let", "loc": Object { "end": Object { - "column": 26, + "column": 36, "line": 1, }, "start": Object { @@ -112825,7 +114695,7 @@ Object { }, "range": Array [ 0, - 26, + 36, ], "type": "VariableDeclaration", }, @@ -112843,7 +114713,7 @@ Object { }, "range": Array [ 0, - 27, + 37, ], "sourceType": "module", "tokens": Array [ @@ -112935,12 +114805,12 @@ Object { 12, ], "type": "Punctuator", - "value": "<", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 13, + "column": 15, "line": 1, }, "start": Object { @@ -112950,115 +114820,115 @@ Object { }, "range": Array [ 12, - 13, + 15, ], - "type": "Identifier", - "value": "T", + "type": "Punctuator", + "value": "...", }, Object { "loc": Object { "end": Object { - "column": 14, + "column": 16, "line": 1, }, "start": Object { - "column": 13, + "column": 15, "line": 1, }, }, "range": Array [ - 13, - 14, + 15, + 16, ], - "type": "Punctuator", - "value": ">", + "type": "Identifier", + "value": "a", }, Object { "loc": Object { "end": Object { - "column": 15, + "column": 17, "line": 1, }, "start": Object { - "column": 14, + "column": 16, "line": 1, }, }, "range": Array [ - 14, - 15, + 16, + 17, ], "type": "Punctuator", - "value": "(", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 16, + "column": 24, "line": 1, }, "start": Object { - "column": 15, + "column": 18, "line": 1, }, }, "range": Array [ - 15, - 16, + 18, + 24, ], "type": "Identifier", - "value": "a", + "value": "number", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 25, "line": 1, }, "start": Object { - "column": 16, + "column": 24, "line": 1, }, }, "range": Array [ - 16, - 17, + 24, + 25, ], "type": "Punctuator", - "value": ":", + "value": "[", }, Object { "loc": Object { "end": Object { - "column": 19, + "column": 26, "line": 1, }, "start": Object { - "column": 18, + "column": 25, "line": 1, }, }, "range": Array [ - 18, - 19, + 25, + 26, ], - "type": "Identifier", - "value": "T", + "type": "Punctuator", + "value": "]", }, Object { "loc": Object { "end": Object { - "column": 20, + "column": 27, "line": 1, }, "start": Object { - "column": 19, + "column": 26, "line": 1, }, }, "range": Array [ - 19, - 20, + 26, + 27, ], "type": "Punctuator", "value": ")", @@ -113066,17 +114936,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 23, + "column": 30, "line": 1, }, "start": Object { - "column": 21, + "column": 28, "line": 1, }, }, "range": Array [ - 21, - 23, + 28, + 30, ], "type": "Punctuator", "value": "=>", @@ -113084,35 +114954,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 25, + "column": 35, "line": 1, }, "start": Object { - "column": 24, + "column": 31, "line": 1, }, }, "range": Array [ - 24, - 25, + 31, + 35, ], - "type": "Identifier", - "value": "T", + "type": "Keyword", + "value": "void", }, Object { "loc": Object { "end": Object { - "column": 26, + "column": 36, "line": 1, }, "start": Object { - "column": 25, + "column": 35, "line": 1, }, }, "range": Array [ - 25, - 26, + 35, + 36, ], "type": "Punctuator", "value": ";", @@ -113122,7 +114992,7 @@ Object { } `; -exports[`typescript fixtures/types/constructor-in-generic.src 1`] = ` +exports[`typescript fixtures/types/function.src 1`] = ` Object { "body": Array [ Object { @@ -113131,7 +115001,7 @@ Object { "id": Object { "loc": Object { "end": Object { - "column": 30, + "column": 38, "line": 1, }, "start": Object { @@ -113139,16 +115009,16 @@ Object { "line": 1, }, }, - "name": "x", + "name": "f", "range": Array [ 4, - 30, + 38, ], "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 30, + "column": 38, "line": 1, }, "start": Object { @@ -113158,13 +115028,13 @@ Object { }, "range": Array [ 5, - 30, + 38, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 30, + "column": 38, "line": 1, }, "start": Object { @@ -113172,107 +115042,159 @@ Object { "line": 1, }, }, - "range": Array [ - 7, - 30, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 12, - "line": 1, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, }, - "start": Object { - "column": 7, - "line": 1, + "name": "a", + "range": Array [ + 8, + 17, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 17, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 17, + ], + "type": "TSNumberKeyword", + }, }, }, - "name": "Array", - "range": Array [ - 7, - 12, - ], - "type": "Identifier", - }, - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 30, - "line": 1, - }, - "start": Object { - "column": 12, - "line": 1, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 1, + }, + "start": Object { + "column": 19, + "line": 1, + }, }, - }, - "params": Array [ - Object { + "name": "b", + "optional": true, + "range": Array [ + 19, + 29, + ], + "type": "Identifier", + "typeAnnotation": Object { "loc": Object { "end": Object { "column": 29, "line": 1, }, "start": Object { - "column": 13, + "column": 21, "line": 1, }, }, - "params": Array [], "range": Array [ - 13, + 21, 29, ], - "returnType": Object { + "type": "TSTypeAnnotation", + "typeAnnotation": Object { "loc": Object { "end": Object { "column": 29, "line": 1, }, "start": Object { - "column": 20, + "column": 23, "line": 1, }, }, "range": Array [ - 20, + 23, 29, ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 29, - "line": 1, - }, - "start": Object { - "column": 23, - "line": 1, - }, - }, - "range": Array [ - 23, - 29, - ], - "type": "TSStringKeyword", - }, + "type": "TSNumberKeyword", }, - "type": "TSConstructorType", }, - ], + }, + ], + "range": Array [ + 7, + 38, + ], + "returnType": Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 1, + }, + "start": Object { + "column": 31, + "line": 1, + }, + }, "range": Array [ - 12, - 30, + 31, + 38, ], - "type": "TSTypeParameterInstantiation", + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 1, + }, + "start": Object { + "column": 34, + "line": 1, + }, + }, + "range": Array [ + 34, + 38, + ], + "type": "TSVoidKeyword", + }, }, + "type": "TSFunctionType", }, }, }, "init": null, "loc": Object { "end": Object { - "column": 30, + "column": 38, "line": 1, }, "start": Object { @@ -113282,7 +115204,7 @@ Object { }, "range": Array [ 4, - 30, + 38, ], "type": "VariableDeclarator", }, @@ -113290,7 +115212,7 @@ Object { "kind": "let", "loc": Object { "end": Object { - "column": 31, + "column": 39, "line": 1, }, "start": Object { @@ -113300,7 +115222,7 @@ Object { }, "range": Array [ 0, - 31, + 39, ], "type": "VariableDeclaration", }, @@ -113318,7 +115240,7 @@ Object { }, "range": Array [ 0, - 32, + 40, ], "sourceType": "module", "tokens": Array [ @@ -113356,7 +115278,7 @@ Object { 5, ], "type": "Identifier", - "value": "x", + "value": "f", }, Object { "loc": Object { @@ -113379,7 +115301,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 12, + "column": 8, "line": 1, }, "start": Object { @@ -113389,46 +115311,64 @@ Object { }, "range": Array [ 7, - 12, + 8, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "range": Array [ + 8, + 9, ], "type": "Identifier", - "value": "Array", + "value": "a", }, Object { "loc": Object { "end": Object { - "column": 13, + "column": 10, "line": 1, }, "start": Object { - "column": 12, + "column": 9, "line": 1, }, }, "range": Array [ - 12, - 13, + 9, + 10, ], "type": "Punctuator", - "value": "<", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 16, + "column": 17, "line": 1, }, "start": Object { - "column": 13, + "column": 11, "line": 1, }, }, "range": Array [ - 13, - 16, + 11, + 17, ], - "type": "Keyword", - "value": "new", + "type": "Identifier", + "value": "number", }, Object { "loc": Object { @@ -113446,30 +115386,30 @@ Object { 18, ], "type": "Punctuator", - "value": "(", + "value": ",", }, Object { "loc": Object { "end": Object { - "column": 19, + "column": 20, "line": 1, }, "start": Object { - "column": 18, + "column": 19, "line": 1, }, }, "range": Array [ - 18, 19, + 20, ], - "type": "Punctuator", - "value": ")", + "type": "Identifier", + "value": "b", }, Object { "loc": Object { "end": Object { - "column": 22, + "column": 21, "line": 1, }, "start": Object { @@ -113479,10 +115419,28 @@ Object { }, "range": Array [ 20, + 21, + ], + "type": "Punctuator", + "value": "?", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, 22, ], "type": "Punctuator", - "value": "=>", + "value": ":", }, Object { "loc": Object { @@ -113500,7 +115458,7 @@ Object { 29, ], "type": "Identifier", - "value": "string", + "value": "number", }, Object { "loc": Object { @@ -113517,23 +115475,59 @@ Object { 29, 30, ], - "type": "Punctuator", - "value": ">", + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 1, + }, + "start": Object { + "column": 31, + "line": 1, + }, + }, + "range": Array [ + 31, + 33, + ], + "type": "Punctuator", + "value": "=>", + }, + Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 1, + }, + "start": Object { + "column": 34, + "line": 1, + }, + }, + "range": Array [ + 34, + 38, + ], + "type": "Keyword", + "value": "void", }, Object { "loc": Object { "end": Object { - "column": 31, + "column": 39, "line": 1, }, "start": Object { - "column": 30, + "column": 38, "line": 1, }, }, "range": Array [ - 30, - 31, + 38, + 39, ], "type": "Punctuator", "value": ";", @@ -113543,7 +115537,7 @@ Object { } `; -exports[`typescript fixtures/types/constructor-with-rest.src 1`] = ` +exports[`typescript fixtures/types/function-generic.src 1`] = ` Object { "body": Array [ Object { @@ -113552,7 +115546,7 @@ Object { "id": Object { "loc": Object { "end": Object { - "column": 35, + "column": 21, "line": 1, }, "start": Object { @@ -113563,13 +115557,13 @@ Object { "name": "f", "range": Array [ 4, - 35, + 21, ], "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 35, + "column": 21, "line": 1, }, "start": Object { @@ -113579,13 +115573,13 @@ Object { }, "range": Array [ 5, - 35, + 21, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 35, + "column": 21, "line": 1, }, "start": Object { @@ -113595,138 +115589,194 @@ Object { }, "params": Array [ Object { - "argument": Object { - "loc": Object { - "end": Object { - "column": 16, - "line": 1, - }, - "start": Object { - "column": 15, - "line": 1, - }, - }, - "name": "a", - "range": Array [ - 15, - 16, - ], - "type": "Identifier", - }, "loc": Object { "end": Object { - "column": 26, + "column": 15, "line": 1, }, "start": Object { - "column": 12, + "column": 11, "line": 1, }, }, + "name": "a", "range": Array [ - 12, - 26, + 11, + 15, ], - "type": "RestElement", + "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 26, + "column": 15, "line": 1, }, "start": Object { - "column": 16, + "column": 12, "line": 1, }, }, "range": Array [ - 16, - 26, + 12, + 15, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { - "elementType": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "TSTypeReference", + "typeName": Object { "loc": Object { "end": Object { - "column": 24, + "column": 15, "line": 1, }, "start": Object { - "column": 18, + "column": 14, "line": 1, }, }, + "name": "T", "range": Array [ - 18, - 24, + 14, + 15, ], - "type": "TSNumberKeyword", - }, - "loc": Object { - "end": Object { - "column": 26, - "line": 1, - }, - "start": Object { - "column": 18, - "line": 1, - }, + "type": "Identifier", }, - "range": Array [ - 18, - 26, - ], - "type": "TSArrayType", }, }, }, ], "range": Array [ 7, - 35, + 21, ], "returnType": Object { "loc": Object { "end": Object { - "column": 35, + "column": 21, "line": 1, }, "start": Object { - "column": 28, + "column": 17, "line": 1, }, }, "range": Array [ - 28, - 35, + 17, + 21, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 35, + "column": 21, "line": 1, }, "start": Object { - "column": 31, + "column": 20, "line": 1, }, }, "range": Array [ - 31, - 35, + 20, + 21, ], - "type": "TSVoidKeyword", + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 20, + 21, + ], + "type": "Identifier", + }, }, }, - "type": "TSConstructorType", + "type": "TSFunctionType", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 8, + 9, + ], + "type": "Identifier", + }, + "range": Array [ + 8, + 9, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 7, + 10, + ], + "type": "TSTypeParameterDeclaration", + }, }, }, }, "init": null, "loc": Object { "end": Object { - "column": 35, + "column": 21, "line": 1, }, "start": Object { @@ -113736,7 +115786,7 @@ Object { }, "range": Array [ 4, - 35, + 21, ], "type": "VariableDeclarator", }, @@ -113744,7 +115794,7 @@ Object { "kind": "let", "loc": Object { "end": Object { - "column": 36, + "column": 22, "line": 1, }, "start": Object { @@ -113754,7 +115804,7 @@ Object { }, "range": Array [ 0, - 36, + 22, ], "type": "VariableDeclaration", }, @@ -113772,7 +115822,7 @@ Object { }, "range": Array [ 0, - 37, + 23, ], "sourceType": "module", "tokens": Array [ @@ -113833,7 +115883,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 10, + "column": 8, "line": 1, }, "start": Object { @@ -113843,151 +115893,133 @@ Object { }, "range": Array [ 7, - 10, - ], - "type": "Keyword", - "value": "new", - }, - Object { - "loc": Object { - "end": Object { - "column": 12, - "line": 1, - }, - "start": Object { - "column": 11, - "line": 1, - }, - }, - "range": Array [ - 11, - 12, + 8, ], "type": "Punctuator", - "value": "(", + "value": "<", }, Object { "loc": Object { "end": Object { - "column": 15, + "column": 9, "line": 1, }, "start": Object { - "column": 12, + "column": 8, "line": 1, }, }, "range": Array [ - 12, - 15, + 8, + 9, ], - "type": "Punctuator", - "value": "...", + "type": "Identifier", + "value": "T", }, Object { "loc": Object { "end": Object { - "column": 16, + "column": 10, "line": 1, }, "start": Object { - "column": 15, + "column": 9, "line": 1, }, }, "range": Array [ - 15, - 16, + 9, + 10, ], - "type": "Identifier", - "value": "a", + "type": "Punctuator", + "value": ">", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 11, "line": 1, }, "start": Object { - "column": 16, + "column": 10, "line": 1, }, }, "range": Array [ - 16, - 17, + 10, + 11, ], "type": "Punctuator", - "value": ":", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 24, + "column": 12, "line": 1, }, "start": Object { - "column": 18, + "column": 11, "line": 1, }, }, "range": Array [ - 18, - 24, + 11, + 12, ], "type": "Identifier", - "value": "number", + "value": "a", }, Object { "loc": Object { "end": Object { - "column": 25, + "column": 13, "line": 1, }, "start": Object { - "column": 24, + "column": 12, "line": 1, }, }, "range": Array [ - 24, - 25, + 12, + 13, ], "type": "Punctuator", - "value": "[", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 26, + "column": 15, "line": 1, }, "start": Object { - "column": 25, + "column": 14, "line": 1, }, }, "range": Array [ - 25, - 26, + 14, + 15, ], - "type": "Punctuator", - "value": "]", + "type": "Identifier", + "value": "T", }, Object { "loc": Object { "end": Object { - "column": 27, + "column": 16, "line": 1, }, "start": Object { - "column": 26, + "column": 15, "line": 1, }, }, "range": Array [ - 26, - 27, + 15, + 16, ], "type": "Punctuator", "value": ")", @@ -113995,17 +116027,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 30, + "column": 19, "line": 1, }, "start": Object { - "column": 28, + "column": 17, "line": 1, }, }, "range": Array [ - 28, - 30, + 17, + 19, ], "type": "Punctuator", "value": "=>", @@ -114013,35 +116045,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 35, + "column": 21, "line": 1, }, "start": Object { - "column": 31, + "column": 20, "line": 1, }, }, "range": Array [ - 31, - 35, + 20, + 21, ], - "type": "Keyword", - "value": "void", + "type": "Identifier", + "value": "T", }, Object { "loc": Object { "end": Object { - "column": 36, + "column": 22, "line": 1, }, "start": Object { - "column": 35, + "column": 21, "line": 1, }, }, "range": Array [ - 35, - 36, + 21, + 22, ], "type": "Punctuator", "value": ";", @@ -114051,7 +116083,7 @@ Object { } `; -exports[`typescript fixtures/types/function.src 1`] = ` +exports[`typescript fixtures/types/function-in-generic.src 1`] = ` Object { "body": Array [ Object { @@ -114060,7 +116092,7 @@ Object { "id": Object { "loc": Object { "end": Object { - "column": 38, + "column": 24, "line": 1, }, "start": Object { @@ -114068,16 +116100,16 @@ Object { "line": 1, }, }, - "name": "f", + "name": "x", "range": Array [ 4, - 38, + 24, ], "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 38, + "column": 24, "line": 1, }, "start": Object { @@ -114087,13 +116119,13 @@ Object { }, "range": Array [ 5, - 38, + 24, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 38, + "column": 24, "line": 1, }, "start": Object { @@ -114101,159 +116133,107 @@ Object { "line": 1, }, }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 1, - }, - "start": Object { - "column": 8, - "line": 1, - }, + "range": Array [ + 7, + 24, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, }, - "name": "a", - "range": Array [ - 8, - 17, - ], - "type": "Identifier", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 1, - }, - "start": Object { - "column": 9, - "line": 1, - }, - }, - "range": Array [ - 9, - 17, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 1, - }, - "start": Object { - "column": 11, - "line": 1, - }, - }, - "range": Array [ - 11, - 17, - ], - "type": "TSNumberKeyword", - }, + "start": Object { + "column": 7, + "line": 1, }, }, - Object { - "loc": Object { - "end": Object { - "column": 29, - "line": 1, - }, - "start": Object { - "column": 19, - "line": 1, - }, + "name": "Array", + "range": Array [ + 7, + 12, + ], + "type": "Identifier", + }, + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 1, }, - "name": "b", - "optional": true, - "range": Array [ - 19, - 29, - ], - "type": "Identifier", - "typeAnnotation": Object { + "start": Object { + "column": 12, + "line": 1, + }, + }, + "params": Array [ + Object { "loc": Object { "end": Object { - "column": 29, + "column": 23, "line": 1, }, "start": Object { - "column": 21, + "column": 13, "line": 1, }, }, + "params": Array [], "range": Array [ - 21, - 29, + 13, + 23, ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { - "column": 29, + "column": 23, "line": 1, }, "start": Object { - "column": 23, + "column": 16, "line": 1, }, }, "range": Array [ + 16, 23, - 29, ], - "type": "TSNumberKeyword", - }, - }, - }, - ], - "range": Array [ - 7, - 38, - ], - "returnType": Object { - "loc": Object { - "end": Object { - "column": 38, - "line": 1, - }, - "start": Object { - "column": 31, - "line": 1, - }, - }, - "range": Array [ - 31, - 38, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 38, - "line": 1, - }, - "start": Object { - "column": 34, - "line": 1, + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 19, + "line": 1, + }, + }, + "range": Array [ + 19, + 23, + ], + "type": "TSVoidKeyword", + }, }, + "type": "TSFunctionType", }, - "range": Array [ - 34, - 38, - ], - "type": "TSVoidKeyword", - }, + ], + "range": Array [ + 12, + 24, + ], + "type": "TSTypeParameterInstantiation", }, - "type": "TSFunctionType", }, }, }, "init": null, "loc": Object { "end": Object { - "column": 38, + "column": 24, "line": 1, }, "start": Object { @@ -114263,7 +116243,7 @@ Object { }, "range": Array [ 4, - 38, + 24, ], "type": "VariableDeclarator", }, @@ -114271,7 +116251,7 @@ Object { "kind": "let", "loc": Object { "end": Object { - "column": 39, + "column": 25, "line": 1, }, "start": Object { @@ -114281,7 +116261,7 @@ Object { }, "range": Array [ 0, - 39, + 25, ], "type": "VariableDeclaration", }, @@ -114299,7 +116279,7 @@ Object { }, "range": Array [ 0, - 40, + 26, ], "sourceType": "module", "tokens": Array [ @@ -114337,7 +116317,7 @@ Object { 5, ], "type": "Identifier", - "value": "f", + "value": "x", }, Object { "loc": Object { @@ -114360,7 +116340,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 8, + "column": 12, "line": 1, }, "start": Object { @@ -114370,64 +116350,64 @@ Object { }, "range": Array [ 7, - 8, + 12, ], - "type": "Punctuator", - "value": "(", + "type": "Identifier", + "value": "Array", }, Object { "loc": Object { "end": Object { - "column": 9, + "column": 13, "line": 1, }, "start": Object { - "column": 8, + "column": 12, "line": 1, }, }, "range": Array [ - 8, - 9, + 12, + 13, ], - "type": "Identifier", - "value": "a", + "type": "Punctuator", + "value": "<", }, Object { "loc": Object { "end": Object { - "column": 10, + "column": 14, "line": 1, }, "start": Object { - "column": 9, + "column": 13, "line": 1, }, }, "range": Array [ - 9, - 10, + 13, + 14, ], "type": "Punctuator", - "value": ":", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 15, "line": 1, }, "start": Object { - "column": 11, + "column": 14, "line": 1, }, }, "range": Array [ - 11, - 17, + 14, + 15, ], - "type": "Identifier", - "value": "number", + "type": "Punctuator", + "value": ")", }, Object { "loc": Object { @@ -114436,21 +116416,21 @@ Object { "line": 1, }, "start": Object { - "column": 17, + "column": 16, "line": 1, }, }, "range": Array [ - 17, + 16, 18, ], "type": "Punctuator", - "value": ",", + "value": "=>", }, Object { "loc": Object { "end": Object { - "column": 20, + "column": 23, "line": 1, }, "start": Object { @@ -114460,51 +116440,15 @@ Object { }, "range": Array [ 19, - 20, - ], - "type": "Identifier", - "value": "b", - }, - Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 1, - }, - "start": Object { - "column": 20, - "line": 1, - }, - }, - "range": Array [ - 20, - 21, - ], - "type": "Punctuator", - "value": "?", - }, - Object { - "loc": Object { - "end": Object { - "column": 22, - "line": 1, - }, - "start": Object { - "column": 21, - "line": 1, - }, - }, - "range": Array [ - 21, - 22, + 23, ], - "type": "Punctuator", - "value": ":", + "type": "Keyword", + "value": "void", }, Object { "loc": Object { "end": Object { - "column": 29, + "column": 24, "line": 1, }, "start": Object { @@ -114514,358 +116458,195 @@ Object { }, "range": Array [ 23, - 29, - ], - "type": "Identifier", - "value": "number", - }, - Object { - "loc": Object { - "end": Object { - "column": 30, - "line": 1, - }, - "start": Object { - "column": 29, - "line": 1, - }, - }, - "range": Array [ - 29, - 30, + 24, ], "type": "Punctuator", - "value": ")", + "value": ">", }, Object { "loc": Object { "end": Object { - "column": 33, + "column": 25, "line": 1, }, "start": Object { - "column": 31, + "column": 24, "line": 1, }, }, "range": Array [ - 31, - 33, + 24, + 25, ], "type": "Punctuator", - "value": "=>", + "value": ";", }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/types/function-with-array-destruction.src 1`] = ` +Object { + "body": Array [ Object { - "loc": Object { - "end": Object { - "column": 38, - "line": 1, - }, - "start": Object { - "column": 34, - "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", }, - "range": Array [ - 34, - 38, - ], - "type": "Keyword", - "value": "void", - }, - Object { "loc": Object { "end": Object { - "column": 39, + "column": 28, "line": 1, }, "start": Object { - "column": 38, + "column": 0, "line": 1, }, }, "range": Array [ - 38, - 39, + 0, + 28, ], - "type": "Punctuator", - "value": ";", - }, - ], - "type": "Program", -} -`; - -exports[`typescript fixtures/types/function-generic.src 1`] = ` -Object { - "body": Array [ - Object { - "declarations": Array [ - Object { - "id": Object { + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "params": Array [ + Object { + "elements": Array [ + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "name": "a", + "range": Array [ + 13, + 14, + ], + "type": "Identifier", + }, + ], "loc": Object { "end": Object { - "column": 21, + "column": 20, "line": 1, }, "start": Object { - "column": 4, + "column": 12, "line": 1, }, }, - "name": "f", "range": Array [ - 4, - 21, + 12, + 20, ], - "type": "Identifier", + "type": "ArrayPattern", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 21, + "column": 20, "line": 1, }, "start": Object { - "column": 5, + "column": 15, "line": 1, }, }, "range": Array [ - 5, - 21, + 15, + 20, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 21, + "column": 20, "line": 1, }, "start": Object { - "column": 7, + "column": 17, "line": 1, }, }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 15, - "line": 1, - }, - "start": Object { - "column": 11, - "line": 1, - }, - }, - "name": "a", - "range": Array [ - 11, - 15, - ], - "type": "Identifier", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 15, - "line": 1, - }, - "start": Object { - "column": 12, - "line": 1, - }, - }, - "range": Array [ - 12, - 15, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 15, - "line": 1, - }, - "start": Object { - "column": 14, - "line": 1, - }, - }, - "range": Array [ - 14, - 15, - ], - "type": "TSTypeReference", - "typeName": 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 [ - 7, - 21, + 17, + 20, ], - "returnType": Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 1, - }, - "start": Object { - "column": 17, - "line": 1, - }, - }, - "range": Array [ - 17, - 21, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 1, - }, - "start": Object { - "column": 20, - "line": 1, - }, - }, - "range": Array [ - 20, - 21, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 1, - }, - "start": Object { - "column": 20, - "line": 1, - }, - }, - "name": "T", - "range": Array [ - 20, - 21, - ], - "type": "Identifier", - }, - }, - }, - "type": "TSFunctionType", - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, - }, - }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 9, - "line": 1, - }, - "start": Object { - "column": 8, - "line": 1, - }, - }, - "name": Object { - "loc": Object { - "end": Object { - "column": 9, - "line": 1, - }, - "start": Object { - "column": 8, - "line": 1, - }, - }, - "name": "T", - "range": Array [ - 8, - 9, - ], - "type": "Identifier", - }, - "range": Array [ - 8, - 9, - ], - "type": "TSTypeParameter", - }, - ], - "range": Array [ - 7, - 10, - ], - "type": "TSTypeParameterDeclaration", - }, + "type": "TSAnyKeyword", }, }, }, - "init": null, + ], + "range": Array [ + 11, + 28, + ], + "returnType": Object { "loc": Object { "end": Object { - "column": 21, + "column": 28, "line": 1, }, "start": Object { - "column": 4, + "column": 22, "line": 1, }, }, "range": Array [ - 4, - 21, + 22, + 28, ], - "type": "VariableDeclarator", - }, - ], - "kind": "let", - "loc": Object { - "end": Object { - "column": 22, - "line": 1, - }, - "start": Object { - "column": 0, - "line": 1, - }, - }, - "range": Array [ - 0, - 22, - ], - "type": "VariableDeclaration", + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, + }, + "range": Array [ + 25, + 28, + ], + "type": "TSAnyKeyword", + }, + }, + "type": "TSFunctionType", + }, }, ], "comments": Array [], @@ -114881,14 +116662,14 @@ Object { }, "range": Array [ 0, - 23, + 29, ], "sourceType": "module", "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 3, + "column": 4, "line": 1, }, "start": Object { @@ -114898,33 +116679,15 @@ Object { }, "range": Array [ 0, - 3, - ], - "type": "Keyword", - "value": "let", - }, - Object { - "loc": Object { - "end": Object { - "column": 5, - "line": 1, - }, - "start": Object { - "column": 4, - "line": 1, - }, - }, - "range": Array [ 4, - 5, ], "type": "Identifier", - "value": "f", + "value": "type", }, Object { "loc": Object { "end": Object { - "column": 6, + "column": 8, "line": 1, }, "start": Object { @@ -114934,46 +116697,10 @@ Object { }, "range": Array [ 5, - 6, - ], - "type": "Punctuator", - "value": ":", - }, - Object { - "loc": Object { - "end": Object { - "column": 8, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, - }, - }, - "range": Array [ - 7, - 8, - ], - "type": "Punctuator", - "value": "<", - }, - Object { - "loc": Object { - "end": Object { - "column": 9, - "line": 1, - }, - "start": Object { - "column": 8, - "line": 1, - }, - }, - "range": Array [ 8, - 9, ], "type": "Identifier", - "value": "T", + "value": "foo", }, Object { "loc": Object { @@ -114991,22 +116718,22 @@ Object { 10, ], "type": "Punctuator", - "value": ">", + "value": "=", }, Object { "loc": Object { "end": Object { - "column": 11, + "column": 12, "line": 1, }, "start": Object { - "column": 10, + "column": 11, "line": 1, }, }, "range": Array [ - 10, 11, + 12, ], "type": "Punctuator", "value": "(", @@ -115014,38 +116741,38 @@ Object { Object { "loc": Object { "end": Object { - "column": 12, + "column": 13, "line": 1, }, "start": Object { - "column": 11, + "column": 12, "line": 1, }, }, "range": Array [ - 11, 12, + 13, ], - "type": "Identifier", - "value": "a", + "type": "Punctuator", + "value": "[", }, Object { "loc": Object { "end": Object { - "column": 13, + "column": 14, "line": 1, }, "start": Object { - "column": 12, + "column": 13, "line": 1, }, }, "range": Array [ - 12, 13, + 14, ], - "type": "Punctuator", - "value": ":", + "type": "Identifier", + "value": "a", }, Object { "loc": Object { @@ -115062,8 +116789,8 @@ Object { 14, 15, ], - "type": "Identifier", - "value": "T", + "type": "Punctuator", + "value": "]", }, Object { "loc": Object { @@ -115081,12 +116808,12 @@ Object { 16, ], "type": "Punctuator", - "value": ")", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 19, + "column": 20, "line": 1, }, "start": Object { @@ -115096,10 +116823,10 @@ Object { }, "range": Array [ 17, - 19, + 20, ], - "type": "Punctuator", - "value": "=>", + "type": "Identifier", + "value": "any", }, Object { "loc": Object { @@ -115116,213 +116843,250 @@ Object { 20, 21, ], - "type": "Identifier", - "value": "T", + "type": "Punctuator", + "value": ")", }, Object { "loc": Object { "end": Object { - "column": 22, + "column": 24, "line": 1, }, "start": Object { - "column": 21, + "column": 22, "line": 1, }, }, "range": Array [ - 21, 22, + 24, ], "type": "Punctuator", - "value": ";", + "value": "=>", + }, + Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, + }, + "range": Array [ + 25, + 28, + ], + "type": "Identifier", + "value": "any", }, ], "type": "Program", } `; -exports[`typescript fixtures/types/function-in-generic.src 1`] = ` +exports[`typescript fixtures/types/function-with-object-destruction.src 1`] = ` Object { "body": Array [ Object { - "declarations": Array [ - Object { - "id": Object { + "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": 28, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 28, + ], + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "params": Array [ + Object { "loc": Object { "end": Object { - "column": 24, + "column": 20, "line": 1, }, "start": Object { - "column": 4, + "column": 12, "line": 1, }, }, - "name": "x", - "range": Array [ - 4, - 24, - ], - "type": "Identifier", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 24, - "line": 1, - }, - "start": Object { - "column": 5, - "line": 1, + "properties": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "name": "a", + "range": Array [ + 13, + 14, + ], + "type": "Identifier", }, - }, - "range": Array [ - 5, - 24, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { + "kind": "init", "loc": Object { "end": Object { - "column": 24, + "column": 14, "line": 1, }, "start": Object { - "column": 7, + "column": 13, "line": 1, }, }, + "method": false, "range": Array [ - 7, - 24, + 13, + 14, ], - "type": "TSTypeReference", - "typeName": Object { + "shorthand": true, + "type": "Property", + "value": Object { "loc": Object { "end": Object { - "column": 12, + "column": 14, "line": 1, }, "start": Object { - "column": 7, + "column": 13, "line": 1, }, }, - "name": "Array", + "name": "a", "range": Array [ - 7, - 12, + 13, + 14, ], "type": "Identifier", }, - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 24, - "line": 1, - }, - "start": Object { - "column": 12, - "line": 1, - }, + }, + ], + "range": Array [ + 12, + 20, + ], + "type": "ObjectPattern", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 20, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 1, - }, - "start": Object { - "column": 13, - "line": 1, - }, - }, - "params": Array [], - "range": Array [ - 13, - 23, - ], - "returnType": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 1, - }, - "start": Object { - "column": 16, - "line": 1, - }, - }, - "range": Array [ - 16, - 23, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 1, - }, - "start": Object { - "column": 19, - "line": 1, - }, - }, - "range": Array [ - 19, - 23, - ], - "type": "TSVoidKeyword", - }, - }, - "type": "TSFunctionType", - }, - ], - "range": Array [ - 12, - 24, - ], - "type": "TSTypeParameterInstantiation", }, + "range": Array [ + 17, + 20, + ], + "type": "TSAnyKeyword", }, }, }, - "init": null, + ], + "range": Array [ + 11, + 28, + ], + "returnType": Object { "loc": Object { "end": Object { - "column": 24, + "column": 28, "line": 1, }, "start": Object { - "column": 4, + "column": 22, "line": 1, }, }, "range": Array [ - 4, - 24, + 22, + 28, ], - "type": "VariableDeclarator", - }, - ], - "kind": "let", - "loc": Object { - "end": Object { - "column": 25, - "line": 1, - }, - "start": Object { - "column": 0, - "line": 1, + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, + }, + "range": Array [ + 25, + 28, + ], + "type": "TSAnyKeyword", + }, }, + "type": "TSFunctionType", }, - "range": Array [ - 0, - 25, - ], - "type": "VariableDeclaration", }, ], "comments": Array [], @@ -115338,14 +117102,14 @@ Object { }, "range": Array [ 0, - 26, + 29, ], "sourceType": "module", "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 3, + "column": 4, "line": 1, }, "start": Object { @@ -115355,46 +117119,46 @@ Object { }, "range": Array [ 0, - 3, + 4, ], - "type": "Keyword", - "value": "let", + "type": "Identifier", + "value": "type", }, Object { "loc": Object { "end": Object { - "column": 5, + "column": 8, "line": 1, }, "start": Object { - "column": 4, + "column": 5, "line": 1, }, }, "range": Array [ - 4, 5, + 8, ], "type": "Identifier", - "value": "x", + "value": "foo", }, Object { "loc": Object { "end": Object { - "column": 6, + "column": 10, "line": 1, }, "start": Object { - "column": 5, + "column": 9, "line": 1, }, }, "range": Array [ - 5, - 6, + 9, + 10, ], "type": "Punctuator", - "value": ":", + "value": "=", }, Object { "loc": Object { @@ -115403,16 +117167,16 @@ Object { "line": 1, }, "start": Object { - "column": 7, + "column": 11, "line": 1, }, }, "range": Array [ - 7, + 11, 12, ], - "type": "Identifier", - "value": "Array", + "type": "Punctuator", + "value": "(", }, Object { "loc": Object { @@ -115430,7 +117194,7 @@ Object { 13, ], "type": "Punctuator", - "value": "<", + "value": "{", }, Object { "loc": Object { @@ -115447,8 +117211,8 @@ Object { 13, 14, ], - "type": "Punctuator", - "value": "(", + "type": "Identifier", + "value": "a", }, Object { "loc": Object { @@ -115466,43 +117230,61 @@ Object { 15, ], "type": "Punctuator", - "value": ")", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 18, + "column": 16, "line": 1, }, "start": Object { - "column": 16, + "column": 15, "line": 1, }, }, "range": Array [ + 15, 16, - 18, ], "type": "Punctuator", - "value": "=>", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 23, + "column": 20, "line": 1, }, "start": Object { - "column": 19, + "column": 17, "line": 1, }, }, "range": Array [ - 19, - 23, + 17, + 20, ], - "type": "Keyword", - "value": "void", + "type": "Identifier", + "value": "any", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Punctuator", + "value": ")", }, Object { "loc": Object { @@ -115511,34 +117293,34 @@ Object { "line": 1, }, "start": Object { - "column": 23, + "column": 22, "line": 1, }, }, "range": Array [ - 23, + 22, 24, ], "type": "Punctuator", - "value": ">", + "value": "=>", }, Object { "loc": Object { "end": Object { - "column": 25, + "column": 28, "line": 1, }, "start": Object { - "column": 24, + "column": 25, "line": 1, }, }, "range": Array [ - 24, 25, + 28, ], - "type": "Punctuator", - "value": ";", + "type": "Identifier", + "value": "any", }, ], "type": "Program", diff --git a/packages/shared-fixtures/fixtures/typescript/basics/function-anonymus-with-type-parameters.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/function-anonymus-with-type-parameters.src.ts new file mode 100644 index 000000000000..44c7468b366d --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/basics/function-anonymus-with-type-parameters.src.ts @@ -0,0 +1,3 @@ +var obj = function (a: string) { + return a; +}; diff --git a/packages/shared-fixtures/fixtures/typescript/basics/function-anynomus-with-return-type.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/function-anynomus-with-return-type.src.ts new file mode 100644 index 000000000000..a5d4544e0b12 --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/basics/function-anynomus-with-return-type.src.ts @@ -0,0 +1,2 @@ +var obj = function (): void { +}; diff --git a/packages/shared-fixtures/fixtures/typescript/types/function-with-array-destruction.src.ts b/packages/shared-fixtures/fixtures/typescript/types/function-with-array-destruction.src.ts new file mode 100644 index 000000000000..2517be450da2 --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/types/function-with-array-destruction.src.ts @@ -0,0 +1 @@ +type foo = ([a]: any) => any diff --git a/packages/shared-fixtures/fixtures/typescript/types/function-with-object-destruction.src.ts b/packages/shared-fixtures/fixtures/typescript/types/function-with-object-destruction.src.ts new file mode 100644 index 000000000000..fdb44b90178c --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/types/function-with-object-destruction.src.ts @@ -0,0 +1 @@ +type foo = ({a}: any) => any diff --git a/packages/typescript-estree/src/semantic-errors.ts b/packages/typescript-estree/src/semantic-errors.ts index 169031947d3f..f563e404464d 100644 --- a/packages/typescript-estree/src/semantic-errors.ts +++ b/packages/typescript-estree/src/semantic-errors.ts @@ -66,6 +66,8 @@ function whitelistSupportedDiagnostics( case 1090: // ts 3.2 "'{0}' modifier cannot appear on a parameter." case 1096: // ts 3.2 "An index signature must have exactly one parameter." case 1097: // ts 3.2 "'{0}' list cannot be empty." + case 1098: // ts 3.3 "Type parameter list cannot be empty." + case 1099: // ts 3.3 "Type argument list cannot be empty." case 1117: // ts 3.2 "An object literal cannot have multiple properties with the same name in strict mode." case 1121: // ts 3.2 "Octal literals are not allowed in strict mode." case 1123: // ts 3.2: "Variable declaration list cannot be empty." diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts index 564a5ab6a1ab..8fc5d6acd68c 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -383,8 +383,8 @@ tester.addFixturePatternConfig('typescript/basics', { */ 'type-assertion-arrow-function', /** - * Babel does not include optional keyword into range parameter in arrow function - * https://github.com/babel/babel/issues/9461 + * PR for optional parameters in arrow function has been merged into Babel: https://github.com/babel/babel/pull/9463 + * TODO: remove me in next babel > 7.3.2 */ 'arrow-function-with-optional-parameter' ], @@ -434,7 +434,23 @@ tester.addFixturePatternConfig('typescript/expressions', { }); tester.addFixturePatternConfig('typescript/errorRecovery', { - fileType: 'ts' + fileType: 'ts', + ignore: [ + /** + * Expected error on empty type arguments and type parameters + * TypeScript report diagnostics correctly but babel not + * https://github.com/babel/babel/issues/9462 + */ + 'empty-type-arguments', + 'empty-type-arguments-in-call-expression', + 'empty-type-arguments-in-new-expression', + 'empty-type-parameters', + 'empty-type-parameters-in-arrow-function', + 'empty-type-parameters-in-constructor', + 'empty-type-parameters-in-function-expression', + 'empty-type-parameters-in-method', + 'empty-type-parameters-in-method-signature' + ] }); tester.addFixturePatternConfig('typescript/types', { @@ -443,7 +459,11 @@ tester.addFixturePatternConfig('typescript/types', { /** * AST difference */ - 'literal-number-negative' + 'literal-number-negative', + /** + * Babel parse error: https://github.com/babel/babel/pull/9431 + */ + 'function-with-array-destruction' ] }); diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap index 45c5544625ef..bfbda1148412 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap @@ -1798,6 +1798,10 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/export-type-function-declaration.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/function-anonymus-with-type-parameters.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/function-anynomus-with-return-type.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/function-overloads.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/function-with-await.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; @@ -2073,23 +2077,86 @@ Object { } `; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-arguments.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-arguments.src 1`] = ` +Object { + "column": 14, + "index": 14, + "lineNumber": 1, + "message": "Type argument list cannot be empty.", +} +`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-arguments-in-call-expression.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-arguments-in-call-expression.src 1`] = ` +Object { + "column": 3, + "index": 3, + "lineNumber": 1, + "message": "Type argument list cannot be empty.", +} +`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-arguments-in-new-expression.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-arguments-in-new-expression.src 1`] = ` +Object { + "column": 7, + "index": 7, + "lineNumber": 1, + "message": "Type argument list cannot be empty.", +} +`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters.src 1`] = ` +Object { + "column": 11, + "index": 11, + "lineNumber": 1, + "message": "Type parameter list cannot be empty.", +} +`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-arrow-function.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-arrow-function.src 1`] = ` +Object { + "column": 11, + "index": 11, + "lineNumber": 1, + "message": "Type parameter list cannot be empty.", +} +`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-constructor.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-constructor.src 1`] = ` +Object { + "column": 13, + "index": 25, + "lineNumber": 2, + "message": "Type parameter list cannot be empty.", +} +`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-function-expression.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-function-expression.src 1`] = ` +Object { + "column": 20, + "index": 20, + "lineNumber": 1, + "message": "Type parameter list cannot be empty.", +} +`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-method.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-method.src 1`] = ` +Object { + "column": 6, + "index": 18, + "lineNumber": 2, + "message": "Type parameter list cannot be empty.", +} +`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-method-signature.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-method-signature.src 1`] = ` +Object { + "column": 6, + "index": 22, + "lineNumber": 2, + "message": "Type parameter list cannot be empty.", +} +`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/enum-with-keywords.src 1`] = ` Object { @@ -2360,6 +2427,10 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/function-in-generic.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/function-with-array-destruction.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/function-with-object-destruction.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/function-with-rest.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/types/function-with-this.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index 9c0094cff37b..b9e876c45955 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -39177,139 +39177,268 @@ Object { } `; -exports[`typescript fixtures/basics/function-overloads.src 1`] = ` +exports[`typescript fixtures/basics/function-anonymus-with-type-parameters.src 1`] = ` Object { "body": Array [ Object { - "declaration": Object { - "async": false, - "expression": false, - "generator": false, - "id": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 1, - }, - "start": Object { - "column": 16, - "line": 1, - }, - }, - "name": "f", - "range": Array [ - 16, - 17, - ], - "type": "Identifier", - }, - "loc": Object { - "end": Object { - "column": 37, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, - }, - }, - "params": Array [ - Object { + "declarations": Array [ + Object { + "id": Object { "loc": Object { "end": Object { - "column": 27, + "column": 7, "line": 1, }, "start": Object { - "column": 18, + "column": 4, "line": 1, }, }, - "name": "x", + "name": "obj", "range": Array [ - 18, - 27, + 4, + 7, ], "type": "Identifier", - "typeAnnotation": Object { + }, + "init": Object { + "async": false, + "body": Object { + "body": Array [ + Object { + "argument": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "name": "a", + "range": Array [ + 45, + 46, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 38, + 47, + ], + "type": "ReturnStatement", + }, + ], "loc": Object { "end": Object { - "column": 27, - "line": 1, + "column": 1, + "line": 3, }, "start": Object { - "column": 19, + "column": 34, "line": 1, }, }, "range": Array [ - 19, - 27, + 34, + 49, ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "params": Array [ + Object { "loc": Object { "end": Object { - "column": 27, + "column": 32, "line": 1, }, "start": Object { - "column": 21, + "column": 23, "line": 1, }, }, + "name": "a", "range": Array [ - 21, - 27, + 23, + 32, ], - "type": "TSNumberKeyword", + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 32, + "line": 1, + }, + "start": Object { + "column": 24, + "line": 1, + }, + }, + "range": Array [ + 24, + 32, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 32, + "line": 1, + }, + "start": Object { + "column": 26, + "line": 1, + }, + }, + "range": Array [ + 26, + 32, + ], + "type": "TSStringKeyword", + }, + }, + }, + ], + "range": Array [ + 10, + 49, + ], + "type": "FunctionExpression", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 1, + }, + "start": Object { + "column": 19, + "line": 1, + }, }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 20, + 21, + ], + "type": "Identifier", + }, + "range": Array [ + 20, + 21, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 19, + 22, + ], + "type": "TSTypeParameterDeclaration", }, }, - ], - "range": Array [ - 7, - 37, - ], - "returnType": Object { "loc": Object { "end": Object { - "column": 36, - "line": 1, + "column": 1, + "line": 3, }, "start": Object { - "column": 28, + "column": 4, "line": 1, }, }, "range": Array [ - 28, - 36, + 4, + 49, ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 1, - }, - "start": Object { - "column": 30, - "line": 1, - }, - }, - "range": Array [ - 30, - 36, - ], - "type": "TSNumberKeyword", - }, + "type": "VariableDeclarator", + }, + ], + "kind": "var", + "loc": Object { + "end": Object { + "column": 2, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, }, - "type": "TSDeclareFunction", }, + "range": Array [ + 0, + 50, + ], + "type": "VariableDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 51, + ], + "sourceType": "script", + "tokens": Array [ + Object { "loc": Object { "end": Object { - "column": 37, + "column": 3, "line": 1, }, "start": Object { @@ -39319,513 +39448,133 @@ Object { }, "range": Array [ 0, - 37, + 3, ], - "source": null, - "specifiers": Array [], - "type": "ExportNamedDeclaration", + "type": "Keyword", + "value": "var", }, Object { - "declaration": Object { - "async": false, - "expression": false, - "generator": false, - "id": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 2, - }, - "start": Object { - "column": 16, - "line": 2, - }, - }, - "name": "f", - "range": Array [ - 54, - 55, - ], - "type": "Identifier", + "loc": Object { + "end": Object { + "column": 7, + "line": 1, }, - "loc": Object { - "end": Object { - "column": 37, - "line": 2, - }, - "start": Object { - "column": 7, - "line": 2, - }, + "start": Object { + "column": 4, + "line": 1, }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 2, - }, - "start": Object { - "column": 18, - "line": 2, - }, - }, - "name": "x", - "range": Array [ - 56, - 65, - ], - "type": "Identifier", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 2, - }, - "start": Object { - "column": 19, - "line": 2, - }, - }, - "range": Array [ - 57, - 65, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 2, - }, - "start": Object { - "column": 21, - "line": 2, - }, - }, - "range": Array [ - 59, - 65, - ], - "type": "TSStringKeyword", - }, - }, - }, - ], - "range": Array [ - 45, - 75, - ], - "returnType": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 2, - }, - "start": Object { - "column": 28, - "line": 2, - }, - }, - "range": Array [ - 66, - 74, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 2, - }, - "start": Object { - "column": 30, - "line": 2, - }, - }, - "range": Array [ - 68, - 74, - ], - "type": "TSStringKeyword", - }, + }, + "range": Array [ + 4, + 7, + ], + "type": "Identifier", + "value": "obj", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, }, - "type": "TSDeclareFunction", }, + "range": Array [ + 8, + 9, + ], + "type": "Punctuator", + "value": "=", + }, + Object { "loc": Object { "end": Object { - "column": 37, - "line": 2, + "column": 18, + "line": 1, }, "start": Object { - "column": 0, - "line": 2, + "column": 10, + "line": 1, }, }, "range": Array [ - 38, - 75, + 10, + 18, ], - "source": null, - "specifiers": Array [], - "type": "ExportNamedDeclaration", + "type": "Keyword", + "value": "function", }, - Object { - "declaration": Object { - "async": false, - "body": Object { - "body": Array [ - Object { - "argument": Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 4, - }, - "start": Object { - "column": 9, - "line": 4, - }, - }, - "name": "x", - "range": Array [ - 142, - 143, - ], - "type": "Identifier", - }, - "loc": Object { - "end": Object { - "column": 11, - "line": 4, - }, - "start": Object { - "column": 2, - "line": 4, - }, - }, - "range": Array [ - 135, - 144, - ], - "type": "ReturnStatement", - }, - ], - "loc": Object { - "end": Object { - "column": 1, - "line": 5, - }, - "start": Object { - "column": 55, - "line": 3, - }, - }, - "range": Array [ - 131, - 146, - ], - "type": "BlockStatement", - }, - "expression": false, - "generator": false, - "id": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 3, - }, - "start": Object { - "column": 16, - "line": 3, - }, - }, - "name": "f", - "range": Array [ - 92, - 93, - ], - "type": "Identifier", - }, - "loc": Object { - "end": Object { - "column": 1, - "line": 5, - }, - "start": Object { - "column": 7, - "line": 3, - }, - }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 18, - "line": 3, - }, - }, - "name": "x", - "range": Array [ - 94, - 112, - ], - "type": "Identifier", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 19, - "line": 3, - }, - }, - "range": Array [ - 95, - 112, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 21, - "line": 3, - }, - }, - "range": Array [ - 97, - 112, - ], - "type": "TSUnionType", - "types": Array [ - Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 3, - }, - "start": Object { - "column": 21, - "line": 3, - }, - }, - "range": Array [ - 97, - 103, - ], - "type": "TSStringKeyword", - }, - Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 30, - "line": 3, - }, - }, - "range": Array [ - 106, - 112, - ], - "type": "TSNumberKeyword", - }, - ], - }, - }, - }, - ], - "range": Array [ - 83, - 146, - ], - "returnType": Object { - "loc": Object { - "end": Object { - "column": 54, - "line": 3, - }, - "start": Object { - "column": 37, - "line": 3, - }, - }, - "range": Array [ - 113, - 130, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 54, - "line": 3, - }, - "start": Object { - "column": 39, - "line": 3, - }, - }, - "range": Array [ - 115, - 130, - ], - "type": "TSUnionType", - "types": Array [ - Object { - "loc": Object { - "end": Object { - "column": 45, - "line": 3, - }, - "start": Object { - "column": 39, - "line": 3, - }, - }, - "range": Array [ - 115, - 121, - ], - "type": "TSStringKeyword", - }, - Object { - "loc": Object { - "end": Object { - "column": 54, - "line": 3, - }, - "start": Object { - "column": 48, - "line": 3, - }, - }, - "range": Array [ - 124, - 130, - ], - "type": "TSNumberKeyword", - }, - ], - }, - }, - "type": "FunctionDeclaration", - }, - "loc": Object { - "end": Object { - "column": 1, - "line": 5, - }, - "start": Object { - "column": 0, - "line": 3, - }, - }, - "range": Array [ - 76, - 146, - ], - "source": null, - "specifiers": Array [], - "type": "ExportNamedDeclaration", - }, - ], - "loc": Object { - "end": Object { - "column": 0, - "line": 6, - }, - "start": Object { - "column": 0, - "line": 1, - }, - }, - "range": Array [ - 0, - 147, - ], - "sourceType": "module", - "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 6, + "column": 20, "line": 1, }, "start": Object { - "column": 0, + "column": 19, "line": 1, }, }, "range": Array [ - 0, - 6, + 19, + 20, ], - "type": "Keyword", - "value": "export", + "type": "Punctuator", + "value": "<", }, Object { "loc": Object { "end": Object { - "column": 15, + "column": 21, "line": 1, }, "start": Object { - "column": 7, + "column": 20, "line": 1, }, }, "range": Array [ - 7, - 15, + 20, + 21, ], - "type": "Keyword", - "value": "function", + "type": "Identifier", + "value": "T", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 22, "line": 1, }, "start": Object { - "column": 16, + "column": 21, "line": 1, }, }, "range": Array [ - 16, - 17, + 21, + 22, ], - "type": "Identifier", - "value": "f", + "type": "Punctuator", + "value": ">", }, Object { "loc": Object { "end": Object { - "column": 18, + "column": 23, "line": 1, }, "start": Object { - "column": 17, + "column": 22, "line": 1, }, }, "range": Array [ - 17, - 18, + 22, + 23, ], "type": "Punctuator", "value": "(", @@ -39833,35 +39582,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 19, + "column": 24, "line": 1, }, "start": Object { - "column": 18, + "column": 23, "line": 1, }, }, "range": Array [ - 18, - 19, + 23, + 24, ], "type": "Identifier", - "value": "x", + "value": "a", }, Object { "loc": Object { "end": Object { - "column": 20, + "column": 25, "line": 1, }, "start": Object { - "column": 19, + "column": 24, "line": 1, }, }, "range": Array [ - 19, - 20, + 24, + 25, ], "type": "Punctuator", "value": ":", @@ -39869,35 +39618,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 27, + "column": 32, "line": 1, }, "start": Object { - "column": 21, + "column": 26, "line": 1, }, }, "range": Array [ - 21, - 27, + 26, + 32, ], "type": "Identifier", - "value": "number", + "value": "string", }, Object { "loc": Object { "end": Object { - "column": 28, + "column": 33, "line": 1, }, "start": Object { - "column": 27, + "column": 32, "line": 1, }, }, "range": Array [ - 27, - 28, + 32, + 33, ], "type": "Punctuator", "value": ")", @@ -39905,65 +39654,29 @@ Object { Object { "loc": Object { "end": Object { - "column": 29, - "line": 1, - }, - "start": Object { - "column": 28, - "line": 1, - }, - }, - "range": Array [ - 28, - 29, - ], - "type": "Punctuator", - "value": ":", - }, - Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 1, - }, - "start": Object { - "column": 30, - "line": 1, - }, - }, - "range": Array [ - 30, - 36, - ], - "type": "Identifier", - "value": "number", - }, - Object { - "loc": Object { - "end": Object { - "column": 37, + "column": 35, "line": 1, }, "start": Object { - "column": 36, + "column": 34, "line": 1, }, }, "range": Array [ - 36, - 37, + 34, + 35, ], "type": "Punctuator", - "value": ";", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 6, + "column": 8, "line": 2, }, "start": Object { - "column": 0, + "column": 2, "line": 2, }, }, @@ -39972,364 +39685,338 @@ Object { 44, ], "type": "Keyword", - "value": "export", + "value": "return", }, Object { "loc": Object { "end": Object { - "column": 15, + "column": 10, "line": 2, }, "start": Object { - "column": 7, + "column": 9, "line": 2, }, }, "range": Array [ 45, - 53, - ], - "type": "Keyword", - "value": "function", - }, - Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 2, - }, - "start": Object { - "column": 16, - "line": 2, - }, - }, - "range": Array [ - 54, - 55, - ], - "type": "Identifier", - "value": "f", - }, - Object { - "loc": Object { - "end": Object { - "column": 18, - "line": 2, - }, - "start": Object { - "column": 17, - "line": 2, - }, - }, - "range": Array [ - 55, - 56, - ], - "type": "Punctuator", - "value": "(", - }, - Object { - "loc": Object { - "end": Object { - "column": 19, - "line": 2, - }, - "start": Object { - "column": 18, - "line": 2, - }, - }, - "range": Array [ - 56, - 57, + 46, ], "type": "Identifier", - "value": "x", + "value": "a", }, Object { "loc": Object { "end": Object { - "column": 20, + "column": 11, "line": 2, }, "start": Object { - "column": 19, + "column": 10, "line": 2, }, }, "range": Array [ - 57, - 58, + 46, + 47, ], "type": "Punctuator", - "value": ":", - }, - Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 2, - }, - "start": Object { - "column": 21, - "line": 2, - }, - }, - "range": Array [ - 59, - 65, - ], - "type": "Identifier", - "value": "string", + "value": ";", }, Object { "loc": Object { "end": Object { - "column": 28, - "line": 2, + "column": 1, + "line": 3, }, "start": Object { - "column": 27, - "line": 2, + "column": 0, + "line": 3, }, }, "range": Array [ - 65, - 66, + 48, + 49, ], "type": "Punctuator", - "value": ")", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 29, - "line": 2, + "column": 2, + "line": 3, }, "start": Object { - "column": 28, - "line": 2, + "column": 1, + "line": 3, }, }, "range": Array [ - 66, - 67, + 49, + 50, ], "type": "Punctuator", - "value": ":", + "value": ";", }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/basics/function-anynomus-with-return-type.src 1`] = ` +Object { + "body": Array [ Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 2, - }, - "start": Object { - "column": 30, - "line": 2, + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "name": "obj", + "range": Array [ + 4, + 7, + ], + "type": "Identifier", + }, + "init": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 1, + "line": 2, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, + "range": Array [ + 28, + 31, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 1, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "params": Array [], + "range": Array [ + 10, + 31, + ], + "returnType": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 27, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "range": Array [ + 23, + 27, + ], + "type": "TSVoidKeyword", + }, + }, + "type": "FunctionExpression", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 31, + ], + "type": "VariableDeclarator", }, - }, - "range": Array [ - 68, - 74, ], - "type": "Identifier", - "value": "string", - }, - Object { + "kind": "var", "loc": Object { "end": Object { - "column": 37, + "column": 2, "line": 2, }, "start": Object { - "column": 36, - "line": 2, + "column": 0, + "line": 1, }, }, "range": Array [ - 74, - 75, + 0, + 32, ], - "type": "Punctuator", - "value": ";", + "type": "VariableDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, }, + }, + "range": Array [ + 0, + 33, + ], + "sourceType": "script", + "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 6, - "line": 3, + "column": 3, + "line": 1, }, "start": Object { "column": 0, - "line": 3, + "line": 1, }, }, "range": Array [ - 76, - 82, + 0, + 3, ], "type": "Keyword", - "value": "export", + "value": "var", }, Object { "loc": Object { "end": Object { - "column": 15, - "line": 3, - }, - "start": Object { "column": 7, - "line": 3, - }, - }, - "range": Array [ - 83, - 91, - ], - "type": "Keyword", - "value": "function", - }, - Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 3, + "line": 1, }, "start": Object { - "column": 16, - "line": 3, + "column": 4, + "line": 1, }, }, "range": Array [ - 92, - 93, + 4, + 7, ], "type": "Identifier", - "value": "f", + "value": "obj", }, Object { "loc": Object { "end": Object { - "column": 18, - "line": 3, + "column": 9, + "line": 1, }, "start": Object { - "column": 17, - "line": 3, + "column": 8, + "line": 1, }, }, "range": Array [ - 93, - 94, + 8, + 9, ], "type": "Punctuator", - "value": "(", + "value": "=", }, Object { "loc": Object { "end": Object { - "column": 19, - "line": 3, + "column": 18, + "line": 1, }, "start": Object { - "column": 18, - "line": 3, + "column": 10, + "line": 1, }, }, "range": Array [ - 94, - 95, + 10, + 18, ], - "type": "Identifier", - "value": "x", + "type": "Keyword", + "value": "function", }, Object { "loc": Object { "end": Object { "column": 20, - "line": 3, + "line": 1, }, "start": Object { "column": 19, - "line": 3, + "line": 1, }, }, "range": Array [ - 95, - 96, + 19, + 20, ], "type": "Punctuator", - "value": ":", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 27, - "line": 3, - }, - "start": Object { "column": 21, - "line": 3, - }, - }, - "range": Array [ - 97, - 103, - ], - "type": "Identifier", - "value": "string", - }, - Object { - "loc": Object { - "end": Object { - "column": 29, - "line": 3, - }, - "start": Object { - "column": 28, - "line": 3, - }, - }, - "range": Array [ - 104, - 105, - ], - "type": "Punctuator", - "value": "|", - }, - Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 3, - }, - "start": Object { - "column": 30, - "line": 3, - }, - }, - "range": Array [ - 106, - 112, - ], - "type": "Identifier", - "value": "number", - }, - Object { - "loc": Object { - "end": Object { - "column": 37, - "line": 3, + "line": 1, }, "start": Object { - "column": 36, - "line": 3, + "column": 20, + "line": 1, }, }, "range": Array [ - 112, - 113, + 20, + 21, ], "type": "Punctuator", "value": ")", @@ -40337,17 +40024,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 38, - "line": 3, + "column": 22, + "line": 1, }, "start": Object { - "column": 37, - "line": 3, + "column": 21, + "line": 1, }, }, "range": Array [ - 113, - 114, + 21, + 22, ], "type": "Punctuator", "value": ":", @@ -40355,216 +40042,1468 @@ Object { Object { "loc": Object { "end": Object { - "column": 45, - "line": 3, + "column": 27, + "line": 1, }, "start": Object { - "column": 39, - "line": 3, + "column": 23, + "line": 1, }, }, "range": Array [ - 115, - 121, + 23, + 27, ], - "type": "Identifier", - "value": "string", + "type": "Keyword", + "value": "void", }, Object { "loc": Object { "end": Object { - "column": 47, - "line": 3, + "column": 29, + "line": 1, }, "start": Object { - "column": 46, - "line": 3, + "column": 28, + "line": 1, }, }, "range": Array [ - 122, - 123, + 28, + 29, ], "type": "Punctuator", - "value": "|", - }, - Object { - "loc": Object { - "end": Object { - "column": 54, - "line": 3, - }, - "start": Object { - "column": 48, - "line": 3, - }, - }, - "range": Array [ - 124, - 130, - ], - "type": "Identifier", - "value": "number", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 56, - "line": 3, + "column": 1, + "line": 2, }, "start": Object { - "column": 55, - "line": 3, + "column": 0, + "line": 2, }, }, "range": Array [ - 131, - 132, + 30, + 31, ], "type": "Punctuator", - "value": "{", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 8, - "line": 4, - }, - "start": Object { "column": 2, - "line": 4, - }, - }, - "range": Array [ - 135, - 141, - ], - "type": "Keyword", - "value": "return", - }, - Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 4, - }, - "start": Object { - "column": 9, - "line": 4, - }, - }, - "range": Array [ - 142, - 143, - ], - "type": "Identifier", - "value": "x", - }, - Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 4, + "line": 2, }, "start": Object { - "column": 10, - "line": 4, - }, - }, - "range": Array [ - 143, - 144, - ], - "type": "Punctuator", - "value": ";", - }, - Object { - "loc": Object { - "end": Object { "column": 1, - "line": 5, - }, - "start": Object { - "column": 0, - "line": 5, + "line": 2, }, }, "range": Array [ - 145, - 146, + 31, + 32, ], "type": "Punctuator", - "value": "}", + "value": ";", }, ], "type": "Program", } `; -exports[`typescript fixtures/basics/function-with-await.src 1`] = ` +exports[`typescript fixtures/basics/function-overloads.src 1`] = ` Object { "body": Array [ Object { - "async": true, - "body": Object { - "body": Array [ - Object { - "expression": Object { - "argument": Object { - "loc": Object { - "end": Object { - "column": 16, - "line": 2, - }, - "start": Object { - "column": 10, - "line": 2, - }, - }, - "name": "future", - "range": Array [ - 40, - 46, - ], - "type": "Identifier", - }, - "loc": Object { - "end": Object { - "column": 16, - "line": 2, - }, - "start": Object { - "column": 4, - "line": 2, - }, - }, - "range": Array [ - 34, - 46, - ], - "type": "AwaitExpression", + "declaration": Object { + "async": false, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, }, - "loc": Object { - "end": Object { - "column": 17, - "line": 2, - }, - "start": Object { - "column": 4, - "line": 2, - }, + "start": Object { + "column": 16, + "line": 1, }, - "range": Array [ - 34, - 47, - ], - "type": "ExpressionStatement", }, - ], + "name": "f", + "range": Array [ + 16, + 17, + ], + "type": "Identifier", + }, "loc": Object { "end": Object { - "column": 1, - "line": 3, + "column": 37, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "name": "x", + "range": Array [ + 18, + 27, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 19, + "line": 1, + }, + }, + "range": Array [ + 19, + 27, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 27, + ], + "type": "TSNumberKeyword", + }, + }, + }, + ], + "range": Array [ + 7, + 37, + ], + "returnType": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 1, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, + "range": Array [ + 28, + 36, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 1, + }, + "start": Object { + "column": 30, + "line": 1, + }, + }, + "range": Array [ + 30, + 36, + ], + "type": "TSNumberKeyword", + }, + }, + "type": "TSDeclareFunction", + }, + "loc": Object { + "end": Object { + "column": 37, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 37, + ], + "source": null, + "specifiers": Array [], + "type": "ExportNamedDeclaration", + }, + Object { + "declaration": Object { + "async": false, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "name": "f", + "range": Array [ + 54, + 55, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 37, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "name": "x", + "range": Array [ + 56, + 65, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 19, + "line": 2, + }, + }, + "range": Array [ + 57, + 65, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 21, + "line": 2, + }, + }, + "range": Array [ + 59, + 65, + ], + "type": "TSStringKeyword", + }, + }, + }, + ], + "range": Array [ + 45, + 75, + ], + "returnType": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 2, + }, + "start": Object { + "column": 28, + "line": 2, + }, + }, + "range": Array [ + 66, + 74, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 2, + }, + "start": Object { + "column": 30, + "line": 2, + }, + }, + "range": Array [ + 68, + 74, + ], + "type": "TSStringKeyword", + }, + }, + "type": "TSDeclareFunction", + }, + "loc": Object { + "end": Object { + "column": 37, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 38, + 75, + ], + "source": null, + "specifiers": Array [], + "type": "ExportNamedDeclaration", + }, + Object { + "declaration": Object { + "async": false, + "body": Object { + "body": Array [ + Object { + "argument": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 4, + }, + "start": Object { + "column": 9, + "line": 4, + }, + }, + "name": "x", + "range": Array [ + 142, + 143, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, + }, + }, + "range": Array [ + 135, + 144, + ], + "type": "ReturnStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 55, + "line": 3, + }, + }, + "range": Array [ + 131, + 146, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 3, + }, + "start": Object { + "column": 16, + "line": 3, + }, + }, + "name": "f", + "range": Array [ + 92, + 93, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 7, + "line": 3, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 18, + "line": 3, + }, + }, + "name": "x", + "range": Array [ + 94, + 112, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 19, + "line": 3, + }, + }, + "range": Array [ + 95, + 112, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 21, + "line": 3, + }, + }, + "range": Array [ + 97, + 112, + ], + "type": "TSUnionType", + "types": Array [ + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 3, + }, + "start": Object { + "column": 21, + "line": 3, + }, + }, + "range": Array [ + 97, + 103, + ], + "type": "TSStringKeyword", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 30, + "line": 3, + }, + }, + "range": Array [ + 106, + 112, + ], + "type": "TSNumberKeyword", + }, + ], + }, + }, + }, + ], + "range": Array [ + 83, + 146, + ], + "returnType": Object { + "loc": Object { + "end": Object { + "column": 54, + "line": 3, + }, + "start": Object { + "column": 37, + "line": 3, + }, + }, + "range": Array [ + 113, + 130, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 54, + "line": 3, + }, + "start": Object { + "column": 39, + "line": 3, + }, + }, + "range": Array [ + 115, + 130, + ], + "type": "TSUnionType", + "types": Array [ + Object { + "loc": Object { + "end": Object { + "column": 45, + "line": 3, + }, + "start": Object { + "column": 39, + "line": 3, + }, + }, + "range": Array [ + 115, + 121, + ], + "type": "TSStringKeyword", + }, + Object { + "loc": Object { + "end": Object { + "column": 54, + "line": 3, + }, + "start": Object { + "column": 48, + "line": 3, + }, + }, + "range": Array [ + 124, + 130, + ], + "type": "TSNumberKeyword", + }, + ], + }, + }, + "type": "FunctionDeclaration", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 76, + 146, + ], + "source": null, + "specifiers": Array [], + "type": "ExportNamedDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 6, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 147, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 15, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 17, + ], + "type": "Identifier", + "value": "f", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, + }, + }, + "range": Array [ + 17, + 18, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 19, + "line": 1, + }, + }, + "range": Array [ + 19, + 20, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 27, + ], + "type": "Identifier", + "value": "number", + }, + Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 27, + "line": 1, + }, + }, + "range": Array [ + 27, + 28, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 1, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, + "range": Array [ + 28, + 29, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 1, + }, + "start": Object { + "column": 30, + "line": 1, + }, + }, + "range": Array [ + 30, + 36, + ], + "type": "Identifier", + "value": "number", + }, + Object { + "loc": Object { + "end": Object { + "column": 37, + "line": 1, + }, + "start": Object { + "column": 36, + "line": 1, + }, + }, + "range": Array [ + 36, + 37, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 38, + 44, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "range": Array [ + 45, + 53, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 54, + 55, + ], + "type": "Identifier", + "value": "f", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 55, + 56, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "range": Array [ + 56, + 57, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 2, + }, + "start": Object { + "column": 19, + "line": 2, + }, + }, + "range": Array [ + 57, + 58, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 21, + "line": 2, + }, + }, + "range": Array [ + 59, + 65, + ], + "type": "Identifier", + "value": "string", + }, + Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 2, + }, + "start": Object { + "column": 27, + "line": 2, + }, + }, + "range": Array [ + 65, + 66, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 2, + }, + "start": Object { + "column": 28, + "line": 2, + }, + }, + "range": Array [ + 66, + 67, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 2, + }, + "start": Object { + "column": 30, + "line": 2, + }, + }, + "range": Array [ + 68, + 74, + ], + "type": "Identifier", + "value": "string", + }, + Object { + "loc": Object { + "end": Object { + "column": 37, + "line": 2, + }, + "start": Object { + "column": 36, + "line": 2, + }, + }, + "range": Array [ + 74, + 75, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 76, + 82, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 7, + "line": 3, + }, + }, + "range": Array [ + 83, + 91, + ], + "type": "Keyword", + "value": "function", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 3, + }, + "start": Object { + "column": 16, + "line": 3, + }, + }, + "range": Array [ + 92, + 93, + ], + "type": "Identifier", + "value": "f", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 17, + "line": 3, + }, + }, + "range": Array [ + 93, + 94, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 3, + }, + "start": Object { + "column": 18, + "line": 3, + }, + }, + "range": Array [ + 94, + 95, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 3, + }, + "start": Object { + "column": 19, + "line": 3, + }, + }, + "range": Array [ + 95, + 96, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 3, + }, + "start": Object { + "column": 21, + "line": 3, + }, + }, + "range": Array [ + 97, + 103, + ], + "type": "Identifier", + "value": "string", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 3, + }, + "start": Object { + "column": 28, + "line": 3, + }, + }, + "range": Array [ + 104, + 105, + ], + "type": "Punctuator", + "value": "|", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 3, + }, + "start": Object { + "column": 30, + "line": 3, + }, + }, + "range": Array [ + 106, + 112, + ], + "type": "Identifier", + "value": "number", + }, + Object { + "loc": Object { + "end": Object { + "column": 37, + "line": 3, + }, + "start": Object { + "column": 36, + "line": 3, + }, + }, + "range": Array [ + 112, + 113, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 3, + }, + "start": Object { + "column": 37, + "line": 3, + }, + }, + "range": Array [ + 113, + 114, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 45, + "line": 3, + }, + "start": Object { + "column": 39, + "line": 3, + }, + }, + "range": Array [ + 115, + 121, + ], + "type": "Identifier", + "value": "string", + }, + Object { + "loc": Object { + "end": Object { + "column": 47, + "line": 3, + }, + "start": Object { + "column": 46, + "line": 3, + }, + }, + "range": Array [ + 122, + 123, + ], + "type": "Punctuator", + "value": "|", + }, + Object { + "loc": Object { + "end": Object { + "column": 54, + "line": 3, + }, + "start": Object { + "column": 48, + "line": 3, + }, + }, + "range": Array [ + 124, + 130, + ], + "type": "Identifier", + "value": "number", + }, + Object { + "loc": Object { + "end": Object { + "column": 56, + "line": 3, + }, + "start": Object { + "column": 55, + "line": 3, + }, + }, + "range": Array [ + 131, + 132, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, + }, + }, + "range": Array [ + 135, + 141, + ], + "type": "Keyword", + "value": "return", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 4, + }, + "start": Object { + "column": 9, + "line": 4, + }, + }, + "range": Array [ + 142, + 143, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 4, + }, + "start": Object { + "column": 10, + "line": 4, + }, + }, + "range": Array [ + 143, + 144, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 5, + }, + }, + "range": Array [ + 145, + 146, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/basics/function-with-await.src 1`] = ` +Object { + "body": Array [ + Object { + "async": true, + "body": Object { + "body": Array [ + Object { + "expression": Object { + "argument": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "name": "future", + "range": Array [ + 40, + 46, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 34, + 46, + ], + "type": "AwaitExpression", + }, + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 34, + 47, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 3, }, "start": Object { "column": 28, @@ -106491,131 +107430,563 @@ Object { "line": 1, }, }, - "range": Array [ - 9, - 231, - ], - "type": "TSModuleBlock", + "range": Array [ + 9, + 231, + ], + "type": "TSModuleBlock", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "name": "A", + "range": Array [ + 7, + 8, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 12, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 231, + ], + "type": "TSModuleDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 12, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 231, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Identifier", + "value": "module", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 8, + ], + "type": "Identifier", + "value": "A", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 10, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "range": Array [ + 16, + 22, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 3, + }, + "start": Object { + "column": 11, + "line": 3, + }, + }, + "range": Array [ + 23, + 26, + ], + "type": "Keyword", + "value": "var", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "range": Array [ + 27, + 28, + ], + "type": "Identifier", + "value": "x", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 17, + "line": 3, + }, + }, + "range": Array [ + 29, + 30, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 32, + "line": 3, + }, + "start": Object { + "column": 19, + "line": 3, + }, + }, + "range": Array [ + 31, + 44, + ], + "type": "String", + "value": "'hello world'", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 4, + }, + "start": Object { + "column": 4, + "line": 4, + }, }, - "id": Object { - "loc": Object { - "end": Object { - "column": 8, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, - }, + "range": Array [ + 49, + 55, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 4, + }, + "start": Object { + "column": 11, + "line": 4, }, - "name": "A", - "range": Array [ - 7, - 8, - ], - "type": "Identifier", }, + "range": Array [ + 56, + 61, + ], + "type": "Keyword", + "value": "class", + }, + Object { "loc": Object { "end": Object { - "column": 1, - "line": 12, + "column": 22, + "line": 4, }, "start": Object { - "column": 0, - "line": 1, + "column": 17, + "line": 4, }, }, "range": Array [ - 0, - 231, + 62, + 67, ], - "type": "TSModuleDeclaration", + "type": "Identifier", + "value": "Point", }, - ], - "loc": Object { - "end": Object { - "column": 1, - "line": 12, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 4, + }, + "start": Object { + "column": 23, + "line": 4, + }, + }, + "range": Array [ + 68, + 69, + ], + "type": "Punctuator", + "value": "{", }, - "start": Object { - "column": 0, - "line": 1, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 5, + }, + "start": Object { + "column": 8, + "line": 5, + }, + }, + "range": Array [ + 78, + 89, + ], + "type": "Identifier", + "value": "constructor", }, - }, - "range": Array [ - 0, - 231, - ], - "sourceType": "script", - "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 6, - "line": 1, + "column": 20, + "line": 5, }, "start": Object { - "column": 0, - "line": 1, + "column": 19, + "line": 5, }, }, "range": Array [ - 0, - 6, + 89, + 90, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 5, + }, + "start": Object { + "column": 20, + "line": 5, + }, + }, + "range": Array [ + 90, + 96, + ], + "type": "Keyword", + "value": "public", + }, + Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 5, + }, + "start": Object { + "column": 27, + "line": 5, + }, + }, + "range": Array [ + 97, + 98, ], "type": "Identifier", - "value": "module", + "value": "x", }, Object { "loc": Object { "end": Object { - "column": 8, - "line": 1, + "column": 29, + "line": 5, }, "start": Object { - "column": 7, - "line": 1, + "column": 28, + "line": 5, }, }, "range": Array [ - 7, - 8, + 98, + 99, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 5, + }, + "start": Object { + "column": 30, + "line": 5, + }, + }, + "range": Array [ + 100, + 106, ], "type": "Identifier", - "value": "A", + "value": "number", }, Object { "loc": Object { "end": Object { - "column": 10, - "line": 1, + "column": 37, + "line": 5, }, "start": Object { - "column": 9, - "line": 1, + "column": 36, + "line": 5, }, }, "range": Array [ - 9, - 10, + 106, + 107, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 44, + "line": 5, + }, + "start": Object { + "column": 38, + "line": 5, + }, + }, + "range": Array [ + 108, + 114, + ], + "type": "Keyword", + "value": "public", + }, + Object { + "loc": Object { + "end": Object { + "column": 46, + "line": 5, + }, + "start": Object { + "column": 45, + "line": 5, + }, + }, + "range": Array [ + 115, + 116, + ], + "type": "Identifier", + "value": "y", + }, + Object { + "loc": Object { + "end": Object { + "column": 47, + "line": 5, + }, + "start": Object { + "column": 46, + "line": 5, + }, + }, + "range": Array [ + 116, + 117, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 54, + "line": 5, + }, + "start": Object { + "column": 48, + "line": 5, + }, + }, + "range": Array [ + 118, + 124, + ], + "type": "Identifier", + "value": "number", + }, + Object { + "loc": Object { + "end": Object { + "column": 55, + "line": 5, + }, + "start": Object { + "column": 54, + "line": 5, + }, + }, + "range": Array [ + 124, + 125, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 57, + "line": 5, + }, + "start": Object { + "column": 56, + "line": 5, + }, + }, + "range": Array [ + 126, + 127, ], "type": "Punctuator", "value": "{", }, + Object { + "loc": Object { + "end": Object { + "column": 59, + "line": 5, + }, + "start": Object { + "column": 58, + "line": 5, + }, + }, + "range": Array [ + 128, + 129, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "range": Array [ + 134, + 135, + ], + "type": "Punctuator", + "value": "}", + }, Object { "loc": Object { "end": Object { "column": 10, - "line": 3, + "line": 7, }, "start": Object { "column": 4, - "line": 3, + "line": 7, }, }, "range": Array [ - 16, - 22, + 140, + 146, ], "type": "Keyword", "value": "export", @@ -106623,593 +107994,932 @@ Object { Object { "loc": Object { "end": Object { - "column": 14, - "line": 3, + "column": 17, + "line": 7, }, "start": Object { "column": 11, - "line": 3, + "line": 7, }, }, "range": Array [ - 23, - 26, + 147, + 153, + ], + "type": "Identifier", + "value": "module", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 7, + }, + "start": Object { + "column": 18, + "line": 7, + }, + }, + "range": Array [ + 154, + 155, + ], + "type": "Identifier", + "value": "B", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 7, + }, + "start": Object { + "column": 20, + "line": 7, + }, + }, + "range": Array [ + 156, + 157, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 8, + }, + "start": Object { + "column": 8, + "line": 8, + }, + }, + "range": Array [ + 166, + 172, + ], + "type": "Keyword", + "value": "export", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 8, + }, + "start": Object { + "column": 15, + "line": 8, + }, + }, + "range": Array [ + 173, + 182, + ], + "type": "Keyword", + "value": "interface", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 8, + }, + "start": Object { + "column": 25, + "line": 8, + }, + }, + "range": Array [ + 183, + 185, + ], + "type": "Identifier", + "value": "Id", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 8, + }, + "start": Object { + "column": 28, + "line": 8, + }, + }, + "range": Array [ + 186, + 187, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 9, + }, + "start": Object { + "column": 12, + "line": 9, + }, + }, + "range": Array [ + 200, + 204, + ], + "type": "Identifier", + "value": "name", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 9, + }, + "start": Object { + "column": 16, + "line": 9, + }, + }, + "range": Array [ + 204, + 205, ], - "type": "Keyword", - "value": "var", + "type": "Punctuator", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 16, - "line": 3, + "column": 24, + "line": 9, }, "start": Object { - "column": 15, - "line": 3, + "column": 18, + "line": 9, }, }, "range": Array [ - 27, - 28, + 206, + 212, ], "type": "Identifier", - "value": "x", + "value": "string", }, Object { "loc": Object { "end": Object { - "column": 18, - "line": 3, + "column": 25, + "line": 9, }, "start": Object { - "column": 17, - "line": 3, + "column": 24, + "line": 9, }, }, "range": Array [ - 29, - 30, + 212, + 213, ], "type": "Punctuator", - "value": "=", + "value": ";", }, Object { "loc": Object { "end": Object { - "column": 32, - "line": 3, + "column": 9, + "line": 10, }, "start": Object { - "column": 19, - "line": 3, + "column": 8, + "line": 10, }, }, "range": Array [ - 31, - 44, + 222, + 223, ], - "type": "String", - "value": "'hello world'", + "type": "Punctuator", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 10, - "line": 4, + "column": 5, + "line": 11, }, "start": Object { "column": 4, - "line": 4, + "line": 11, }, }, "range": Array [ - 49, - 55, + 228, + 229, ], - "type": "Keyword", - "value": "export", + "type": "Punctuator", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 16, - "line": 4, + "column": 1, + "line": 12, }, "start": Object { - "column": 11, - "line": 4, + "column": 0, + "line": 12, }, }, "range": Array [ - 56, - 61, + 230, + 231, ], - "type": "Keyword", - "value": "class", + "type": "Punctuator", + "value": "}", }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/namespaces-and-modules/shorthand-ambient-module-declaration.src 1`] = ` +Object { + "body": Array [ Object { + "declare": true, + "id": Object { + "loc": Object { + "end": Object { + "column": 31, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 31, + ], + "raw": "\\"hot-new-module\\"", + "type": "Literal", + "value": "hot-new-module", + }, "loc": Object { "end": Object { - "column": 22, - "line": 4, + "column": 32, + "line": 1, }, "start": Object { - "column": 17, - "line": 4, + "column": 0, + "line": 1, }, }, "range": Array [ - 62, - 67, + 0, + 32, ], - "type": "Identifier", - "value": "Point", + "type": "TSModuleDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 33, + ], + "sourceType": "script", + "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 24, - "line": 4, + "column": 7, + "line": 1, }, "start": Object { - "column": 23, - "line": 4, + "column": 0, + "line": 1, }, }, "range": Array [ - 68, - 69, + 0, + 7, ], - "type": "Punctuator", - "value": "{", + "type": "Identifier", + "value": "declare", }, Object { "loc": Object { "end": Object { - "column": 19, - "line": 5, + "column": 14, + "line": 1, }, "start": Object { "column": 8, - "line": 5, + "line": 1, }, }, "range": Array [ - 78, - 89, + 8, + 14, ], "type": "Identifier", - "value": "constructor", + "value": "module", }, Object { "loc": Object { "end": Object { - "column": 20, - "line": 5, + "column": 31, + "line": 1, }, "start": Object { - "column": 19, - "line": 5, + "column": 15, + "line": 1, }, }, "range": Array [ - 89, - 90, + 15, + 31, ], - "type": "Punctuator", - "value": "(", + "type": "String", + "value": "\\"hot-new-module\\"", }, Object { "loc": Object { "end": Object { - "column": 26, - "line": 5, + "column": 32, + "line": 1, }, "start": Object { - "column": 20, - "line": 5, + "column": 31, + "line": 1, }, }, "range": Array [ - 90, - 96, + 31, + 32, ], - "type": "Keyword", - "value": "public", + "type": "Punctuator", + "value": ";", }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/types/array-type.src 1`] = ` +Object { + "body": Array [ Object { + "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": 28, - "line": 5, + "column": 19, + "line": 1, }, "start": Object { - "column": 27, - "line": 5, + "column": 0, + "line": 1, }, }, "range": Array [ - 97, - 98, + 0, + 19, ], - "type": "Identifier", - "value": "x", + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "elementType": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 17, + ], + "type": "TSStringKeyword", + }, + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 19, + ], + "type": "TSArrayType", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 20, + ], + "sourceType": "script", + "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 29, - "line": 5, + "column": 4, + "line": 1, }, "start": Object { - "column": 28, - "line": 5, + "column": 0, + "line": 1, }, }, "range": Array [ - 98, - 99, + 0, + 4, ], - "type": "Punctuator", - "value": ":", + "type": "Identifier", + "value": "type", }, Object { "loc": Object { "end": Object { - "column": 36, - "line": 5, + "column": 8, + "line": 1, }, "start": Object { - "column": 30, - "line": 5, + "column": 5, + "line": 1, }, }, "range": Array [ - 100, - 106, + 5, + 8, ], "type": "Identifier", - "value": "number", + "value": "Foo", }, Object { "loc": Object { "end": Object { - "column": 37, - "line": 5, + "column": 10, + "line": 1, }, "start": Object { - "column": 36, - "line": 5, + "column": 9, + "line": 1, }, }, "range": Array [ - 106, - 107, + 9, + 10, ], "type": "Punctuator", - "value": ",", + "value": "=", }, Object { "loc": Object { "end": Object { - "column": 44, - "line": 5, + "column": 17, + "line": 1, }, "start": Object { - "column": 38, - "line": 5, + "column": 11, + "line": 1, }, }, "range": Array [ - 108, - 114, + 11, + 17, ], - "type": "Keyword", - "value": "public", + "type": "Identifier", + "value": "string", }, Object { "loc": Object { "end": Object { - "column": 46, - "line": 5, + "column": 18, + "line": 1, }, "start": Object { - "column": 45, - "line": 5, + "column": 17, + "line": 1, }, }, "range": Array [ - 115, - 116, + 17, + 18, ], - "type": "Identifier", - "value": "y", + "type": "Punctuator", + "value": "[", }, Object { "loc": Object { "end": Object { - "column": 47, - "line": 5, + "column": 19, + "line": 1, }, "start": Object { - "column": 46, - "line": 5, + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Punctuator", + "value": "]", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/types/conditional.src 1`] = ` +Object { + "body": Array [ + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 47, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "name": "x", + "range": Array [ + 4, + 47, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 47, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 47, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "checkType": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 13, + ], + "type": "TSNumberKeyword", + }, + "extendsType": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "range": Array [ + 22, + 28, + ], + "type": "TSStringKeyword", + }, + "falseType": Object { + "loc": Object { + "end": Object { + "column": 47, + "line": 1, + }, + "start": Object { + "column": 41, + "line": 1, + }, + }, + "range": Array [ + 41, + 47, + ], + "type": "TSStringKeyword", + }, + "loc": Object { + "end": Object { + "column": 47, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 47, + ], + "trueType": Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 1, + }, + "start": Object { + "column": 31, + "line": 1, + }, + }, + "range": Array [ + 31, + 38, + ], + "type": "TSBooleanKeyword", + }, + "type": "TSConditionalType", + }, + }, + }, + "init": null, + "loc": Object { + "end": Object { + "column": 47, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 47, + ], + "type": "VariableDeclarator", }, - }, - "range": Array [ - 116, - 117, ], - "type": "Punctuator", - "value": ":", - }, - Object { + "kind": "let", "loc": Object { "end": Object { - "column": 54, - "line": 5, - }, - "start": Object { "column": 48, - "line": 5, - }, - }, - "range": Array [ - 118, - 124, - ], - "type": "Identifier", - "value": "number", - }, - Object { - "loc": Object { - "end": Object { - "column": 55, - "line": 5, + "line": 1, }, "start": Object { - "column": 54, - "line": 5, + "column": 0, + "line": 1, }, }, "range": Array [ - 124, - 125, + 0, + 48, ], - "type": "Punctuator", - "value": ")", + "type": "VariableDeclaration", }, - Object { - "loc": Object { - "end": Object { - "column": 57, - "line": 5, - }, - "start": Object { - "column": 56, - "line": 5, - }, - }, - "range": Array [ - 126, - 127, - ], - "type": "Punctuator", - "value": "{", + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, }, - Object { - "loc": Object { - "end": Object { - "column": 59, - "line": 5, - }, - "start": Object { - "column": 58, - "line": 5, - }, - }, - "range": Array [ - 128, - 129, - ], - "type": "Punctuator", - "value": "}", + "start": Object { + "column": 0, + "line": 1, }, + }, + "range": Array [ + 0, + 49, + ], + "sourceType": "script", + "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 5, - "line": 6, + "column": 3, + "line": 1, }, "start": Object { - "column": 4, - "line": 6, + "column": 0, + "line": 1, }, }, "range": Array [ - 134, - 135, + 0, + 3, ], - "type": "Punctuator", - "value": "}", + "type": "Keyword", + "value": "let", }, Object { "loc": Object { "end": Object { - "column": 10, - "line": 7, + "column": 5, + "line": 1, }, "start": Object { "column": 4, - "line": 7, + "line": 1, }, }, "range": Array [ - 140, - 146, + 4, + 5, ], - "type": "Keyword", - "value": "export", + "type": "Identifier", + "value": "x", }, Object { "loc": Object { "end": Object { - "column": 17, - "line": 7, + "column": 6, + "line": 1, }, "start": Object { - "column": 11, - "line": 7, + "column": 5, + "line": 1, }, }, "range": Array [ - 147, - 153, + 5, + 6, ], - "type": "Identifier", - "value": "module", + "type": "Punctuator", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 19, - "line": 7, + "column": 13, + "line": 1, }, "start": Object { - "column": 18, - "line": 7, + "column": 7, + "line": 1, }, }, "range": Array [ - 154, - 155, + 7, + 13, ], "type": "Identifier", - "value": "B", + "value": "number", }, Object { "loc": Object { "end": Object { "column": 21, - "line": 7, + "line": 1, }, "start": Object { - "column": 20, - "line": 7, - }, - }, - "range": Array [ - 156, - 157, - ], - "type": "Punctuator", - "value": "{", - }, - Object { - "loc": Object { - "end": Object { "column": 14, - "line": 8, - }, - "start": Object { - "column": 8, - "line": 8, - }, - }, - "range": Array [ - 166, - 172, - ], - "type": "Keyword", - "value": "export", - }, - Object { - "loc": Object { - "end": Object { - "column": 24, - "line": 8, - }, - "start": Object { - "column": 15, - "line": 8, + "line": 1, }, }, "range": Array [ - 173, - 182, + 14, + 21, ], "type": "Keyword", - "value": "interface", + "value": "extends", }, Object { "loc": Object { "end": Object { - "column": 27, - "line": 8, + "column": 28, + "line": 1, }, "start": Object { - "column": 25, - "line": 8, + "column": 22, + "line": 1, }, }, "range": Array [ - 183, - 185, + 22, + 28, ], "type": "Identifier", - "value": "Id", + "value": "string", }, Object { "loc": Object { "end": Object { - "column": 29, - "line": 8, + "column": 30, + "line": 1, }, "start": Object { - "column": 28, - "line": 8, + "column": 29, + "line": 1, }, }, "range": Array [ - 186, - 187, + 29, + 30, ], "type": "Punctuator", - "value": "{", + "value": "?", }, Object { "loc": Object { "end": Object { - "column": 16, - "line": 9, + "column": 38, + "line": 1, }, "start": Object { - "column": 12, - "line": 9, + "column": 31, + "line": 1, }, }, "range": Array [ - 200, - 204, + 31, + 38, ], "type": "Identifier", - "value": "name", + "value": "boolean", }, Object { "loc": Object { "end": Object { - "column": 17, - "line": 9, + "column": 40, + "line": 1, }, "start": Object { - "column": 16, - "line": 9, + "column": 39, + "line": 1, }, }, "range": Array [ - 204, - 205, + 39, + 40, ], "type": "Punctuator", "value": ":", @@ -107217,17 +108927,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 24, - "line": 9, + "column": 47, + "line": 1, }, "start": Object { - "column": 18, - "line": 9, + "column": 41, + "line": 1, }, }, "range": Array [ - 206, - 212, + 41, + 47, ], "type": "Identifier", "value": "string", @@ -107235,141 +108945,51 @@ Object { Object { "loc": Object { "end": Object { - "column": 25, - "line": 9, + "column": 48, + "line": 1, }, "start": Object { - "column": 24, - "line": 9, + "column": 47, + "line": 1, }, }, "range": Array [ - 212, - 213, + 47, + 48, ], "type": "Punctuator", "value": ";", }, - Object { - "loc": Object { - "end": Object { - "column": 9, - "line": 10, - }, - "start": Object { - "column": 8, - "line": 10, - }, - }, - "range": Array [ - 222, - 223, - ], - "type": "Punctuator", - "value": "}", - }, - Object { - "loc": Object { - "end": Object { - "column": 5, - "line": 11, - }, - "start": Object { - "column": 4, - "line": 11, - }, - }, - "range": Array [ - 228, - 229, - ], - "type": "Punctuator", - "value": "}", - }, - Object { - "loc": Object { - "end": Object { - "column": 1, - "line": 12, - }, - "start": Object { - "column": 0, - "line": 12, - }, - }, - "range": Array [ - 230, - 231, - ], - "type": "Punctuator", - "value": "}", - }, ], "type": "Program", } `; -exports[`typescript fixtures/namespaces-and-modules/shorthand-ambient-module-declaration.src 1`] = ` +exports[`typescript fixtures/types/conditional-infer.src 1`] = ` Object { "body": Array [ Object { - "declare": true, "id": Object { "loc": Object { "end": Object { - "column": 31, + "column": 12, "line": 1, }, "start": Object { - "column": 15, + "column": 5, "line": 1, }, }, + "name": "Element", "range": Array [ - 15, - 31, + 5, + 12, ], - "raw": "\\"hot-new-module\\"", - "type": "Literal", - "value": "hot-new-module", - }, - "loc": Object { - "end": Object { - "column": 32, - "line": 1, - }, - "start": Object { - "column": 0, - "line": 1, - }, + "type": "Identifier", }, - "range": Array [ - 0, - 32, - ], - "type": "TSModuleDeclaration", - }, - ], - "loc": Object { - "end": Object { - "column": 0, - "line": 2, - }, - "start": Object { - "column": 0, - "line": 1, - }, - }, - "range": Array [ - 0, - 33, - ], - "sourceType": "script", - "tokens": Array [ - Object { "loc": Object { "end": Object { - "column": 7, + "column": 48, "line": 1, }, "start": Object { @@ -107379,140 +108999,270 @@ Object { }, "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, + 48, ], - "type": "Identifier", - "value": "module", - }, - Object { - "loc": Object { - "end": Object { - "column": 31, - "line": 1, - }, - "start": Object { - "column": 15, - "line": 1, + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "checkType": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 18, + 19, + ], + "type": "Identifier", + }, }, - }, - "range": Array [ - 15, - 31, - ], - "type": "String", - "value": "\\"hot-new-module\\"", - }, - Object { - "loc": Object { - "end": Object { - "column": 32, - "line": 1, + "extendsType": Object { + "elementType": Object { + "loc": Object { + "end": Object { + "column": 37, + "line": 1, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, + "range": Array [ + 28, + 37, + ], + "type": "TSParenthesizedType", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 1, + }, + "start": Object { + "column": 29, + "line": 1, + }, + }, + "range": Array [ + 29, + 36, + ], + "type": "TSInferType", + "typeParameter": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 1, + }, + "start": Object { + "column": 35, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 1, + }, + "start": Object { + "column": 35, + "line": 1, + }, + }, + "name": "U", + "range": Array [ + 35, + 36, + ], + "type": "Identifier", + }, + "range": Array [ + 35, + 36, + ], + "type": "TSTypeParameter", + }, + }, + }, + "loc": Object { + "end": Object { + "column": 39, + "line": 1, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, + "range": Array [ + 28, + 39, + ], + "type": "TSArrayType", }, - "start": Object { - "column": 31, - "line": 1, + "falseType": Object { + "loc": Object { + "end": Object { + "column": 47, + "line": 1, + }, + "start": Object { + "column": 46, + "line": 1, + }, + }, + "range": Array [ + 46, + 47, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 47, + "line": 1, + }, + "start": Object { + "column": 46, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 46, + 47, + ], + "type": "Identifier", + }, }, - }, - "range": Array [ - 31, - 32, - ], - "type": "Punctuator", - "value": ";", - }, - ], - "type": "Program", -} -`; - -exports[`typescript fixtures/types/array-type.src 1`] = ` -Object { - "body": Array [ - Object { - "id": Object { "loc": Object { "end": Object { - "column": 8, + "column": 47, "line": 1, }, "start": Object { - "column": 5, + "column": 18, "line": 1, }, }, - "name": "Foo", "range": Array [ - 5, - 8, + 18, + 47, ], - "type": "Identifier", - }, - "loc": Object { - "end": Object { - "column": 19, - "line": 1, - }, - "start": Object { - "column": 0, - "line": 1, - }, - }, - "range": Array [ - 0, - 19, - ], - "type": "TSTypeAliasDeclaration", - "typeAnnotation": Object { - "elementType": Object { + "trueType": Object { "loc": Object { "end": Object { - "column": 17, + "column": 43, "line": 1, }, "start": Object { - "column": 11, + "column": 42, "line": 1, }, }, "range": Array [ - 11, - 17, + 42, + 43, ], - "type": "TSStringKeyword", + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 43, + "line": 1, + }, + "start": Object { + "column": 42, + "line": 1, + }, + }, + "name": "U", + "range": Array [ + 42, + 43, + ], + "type": "Identifier", + }, }, + "type": "TSConditionalType", + }, + "typeParameters": Object { "loc": Object { "end": Object { - "column": 19, + "column": 15, "line": 1, }, "start": Object { - "column": 11, + "column": 12, "line": 1, }, }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "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, + ], + "type": "TSTypeParameter", + }, + ], "range": Array [ - 11, - 19, + 12, + 15, ], - "type": "TSArrayType", + "type": "TSTypeParameterDeclaration", }, }, ], @@ -107528,7 +109278,7 @@ Object { }, "range": Array [ 0, - 20, + 49, ], "sourceType": "script", "tokens": Array [ @@ -107553,7 +109303,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 8, + "column": 12, "line": 1, }, "start": Object { @@ -107563,64 +109313,82 @@ Object { }, "range": Array [ 5, - 8, + 12, ], "type": "Identifier", - "value": "Foo", + "value": "Element", }, Object { "loc": Object { "end": Object { - "column": 10, + "column": 13, "line": 1, }, "start": Object { - "column": 9, + "column": 12, "line": 1, }, }, "range": Array [ - 9, - 10, + 12, + 13, ], "type": "Punctuator", - "value": "=", + "value": "<", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 14, "line": 1, }, "start": Object { - "column": 11, + "column": 13, "line": 1, }, }, "range": Array [ - 11, - 17, + 13, + 14, ], "type": "Identifier", - "value": "string", + "value": "T", }, Object { "loc": Object { "end": Object { - "column": 18, + "column": 15, "line": 1, }, "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { "column": 17, "line": 1, }, + "start": Object { + "column": 16, + "line": 1, + }, }, "range": Array [ + 16, 17, - 18, ], "type": "Punctuator", - "value": "[", + "value": "=", }, Object { "loc": Object { @@ -107637,314 +109405,149 @@ Object { 18, 19, ], - "type": "Punctuator", - "value": "]", + "type": "Identifier", + "value": "T", }, - ], - "type": "Program", -} -`; - -exports[`typescript fixtures/types/conditional.src 1`] = ` -Object { - "body": Array [ Object { - "declarations": Array [ - Object { - "id": Object { - "loc": Object { - "end": Object { - "column": 47, - "line": 1, - }, - "start": Object { - "column": 4, - "line": 1, - }, - }, - "name": "x", - "range": Array [ - 4, - 47, - ], - "type": "Identifier", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 47, - "line": 1, - }, - "start": Object { - "column": 5, - "line": 1, - }, - }, - "range": Array [ - 5, - 47, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "checkType": Object { - "loc": Object { - "end": Object { - "column": 13, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, - }, - }, - "range": Array [ - 7, - 13, - ], - "type": "TSNumberKeyword", - }, - "extendsType": Object { - "loc": Object { - "end": Object { - "column": 28, - "line": 1, - }, - "start": Object { - "column": 22, - "line": 1, - }, - }, - "range": Array [ - 22, - 28, - ], - "type": "TSStringKeyword", - }, - "falseType": Object { - "loc": Object { - "end": Object { - "column": 47, - "line": 1, - }, - "start": Object { - "column": 41, - "line": 1, - }, - }, - "range": Array [ - 41, - 47, - ], - "type": "TSStringKeyword", - }, - "loc": Object { - "end": Object { - "column": 47, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, - }, - }, - "range": Array [ - 7, - 47, - ], - "trueType": Object { - "loc": Object { - "end": Object { - "column": 38, - "line": 1, - }, - "start": Object { - "column": 31, - "line": 1, - }, - }, - "range": Array [ - 31, - 38, - ], - "type": "TSBooleanKeyword", - }, - "type": "TSConditionalType", - }, - }, - }, - "init": null, - "loc": Object { - "end": Object { - "column": 47, - "line": 1, - }, - "start": Object { - "column": 4, - "line": 1, - }, - }, - "range": Array [ - 4, - 47, - ], - "type": "VariableDeclarator", - }, - ], - "kind": "let", "loc": Object { "end": Object { - "column": 48, + "column": 27, "line": 1, }, "start": Object { - "column": 0, + "column": 20, "line": 1, }, }, "range": Array [ - 0, - 48, + 20, + 27, ], - "type": "VariableDeclaration", - }, - ], - "loc": Object { - "end": Object { - "column": 0, - "line": 2, - }, - "start": Object { - "column": 0, - "line": 1, + "type": "Keyword", + "value": "extends", }, - }, - "range": Array [ - 0, - 49, - ], - "sourceType": "script", - "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 3, + "column": 29, "line": 1, }, "start": Object { - "column": 0, + "column": 28, "line": 1, }, }, "range": Array [ - 0, - 3, + 28, + 29, ], - "type": "Keyword", - "value": "let", + "type": "Punctuator", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 5, + "column": 34, "line": 1, }, "start": Object { - "column": 4, + "column": 29, "line": 1, }, }, "range": Array [ - 4, - 5, + 29, + 34, ], "type": "Identifier", - "value": "x", + "value": "infer", }, Object { "loc": Object { "end": Object { - "column": 6, + "column": 36, "line": 1, }, "start": Object { - "column": 5, + "column": 35, "line": 1, }, }, "range": Array [ - 5, - 6, + 35, + 36, ], - "type": "Punctuator", - "value": ":", + "type": "Identifier", + "value": "U", }, Object { "loc": Object { "end": Object { - "column": 13, + "column": 37, "line": 1, }, "start": Object { - "column": 7, + "column": 36, "line": 1, }, }, "range": Array [ - 7, - 13, + 36, + 37, ], - "type": "Identifier", - "value": "number", + "type": "Punctuator", + "value": ")", }, Object { "loc": Object { "end": Object { - "column": 21, + "column": 38, "line": 1, }, "start": Object { - "column": 14, + "column": 37, "line": 1, }, }, "range": Array [ - 14, - 21, + 37, + 38, ], - "type": "Keyword", - "value": "extends", + "type": "Punctuator", + "value": "[", }, Object { "loc": Object { "end": Object { - "column": 28, + "column": 39, "line": 1, }, "start": Object { - "column": 22, + "column": 38, "line": 1, }, }, - "range": Array [ - 22, - 28, + "range": Array [ + 38, + 39, ], - "type": "Identifier", - "value": "string", + "type": "Punctuator", + "value": "]", }, Object { "loc": Object { "end": Object { - "column": 30, + "column": 41, "line": 1, }, "start": Object { - "column": 29, + "column": 40, "line": 1, }, }, "range": Array [ - 29, - 30, + 40, + 41, ], "type": "Punctuator", "value": "?", @@ -107952,35 +109555,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 38, + "column": 43, "line": 1, }, "start": Object { - "column": 31, + "column": 42, "line": 1, }, }, "range": Array [ - 31, - 38, + 42, + 43, ], "type": "Identifier", - "value": "boolean", + "value": "U", }, Object { "loc": Object { "end": Object { - "column": 40, + "column": 45, "line": 1, }, "start": Object { - "column": 39, + "column": 44, "line": 1, }, }, "range": Array [ - 39, - 40, + 44, + 45, ], "type": "Punctuator", "value": ":", @@ -107992,16 +109595,16 @@ Object { "line": 1, }, "start": Object { - "column": 41, + "column": 46, "line": 1, }, }, "range": Array [ - 41, + 46, 47, ], "type": "Identifier", - "value": "string", + "value": "T", }, Object { "loc": Object { @@ -108026,14 +109629,14 @@ Object { } `; -exports[`typescript fixtures/types/conditional-infer.src 1`] = ` +exports[`typescript fixtures/types/conditional-infer-nested.src 1`] = ` Object { "body": Array [ Object { "id": Object { "loc": Object { "end": Object { - "column": 12, + "column": 13, "line": 1, }, "start": Object { @@ -108041,17 +109644,17 @@ Object { "line": 1, }, }, - "name": "Element", + "name": "Unpacked", "range": Array [ 5, - 12, + 13, ], "type": "Identifier", }, "loc": Object { "end": Object { - "column": 48, - "line": 1, + "column": 10, + "line": 5, }, "start": Object { "column": 0, @@ -108060,41 +109663,41 @@ Object { }, "range": Array [ 0, - 48, + 126, ], "type": "TSTypeAliasDeclaration", "typeAnnotation": Object { "checkType": Object { "loc": Object { "end": Object { - "column": 19, - "line": 1, + "column": 3, + "line": 2, }, "start": Object { - "column": 18, - "line": 1, + "column": 2, + "line": 2, }, }, "range": Array [ - 18, - 19, + 21, + 22, ], "type": "TSTypeReference", "typeName": Object { "loc": Object { "end": Object { - "column": 19, - "line": 1, + "column": 3, + "line": 2, }, "start": Object { - "column": 18, - "line": 1, + "column": 2, + "line": 2, }, }, "name": "T", "range": Array [ - 18, - 19, + 21, + 22, ], "type": "Identifier", }, @@ -108103,67 +109706,67 @@ Object { "elementType": Object { "loc": Object { "end": Object { - "column": 37, - "line": 1, + "column": 21, + "line": 2, }, "start": Object { - "column": 28, - "line": 1, + "column": 12, + "line": 2, }, }, "range": Array [ - 28, - 37, + 31, + 40, ], "type": "TSParenthesizedType", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 36, - "line": 1, + "column": 20, + "line": 2, }, "start": Object { - "column": 29, - "line": 1, + "column": 13, + "line": 2, }, }, "range": Array [ - 29, - 36, + 32, + 39, ], "type": "TSInferType", "typeParameter": Object { "loc": Object { "end": Object { - "column": 36, - "line": 1, + "column": 20, + "line": 2, }, "start": Object { - "column": 35, - "line": 1, + "column": 19, + "line": 2, }, }, "name": Object { "loc": Object { "end": Object { - "column": 36, - "line": 1, + "column": 20, + "line": 2, }, "start": Object { - "column": 35, - "line": 1, + "column": 19, + "line": 2, }, }, "name": "U", "range": Array [ - 35, - 36, + 38, + 39, ], "type": "Identifier", }, "range": Array [ - 35, - 36, + 38, + 39, ], "type": "TSTypeParameter", }, @@ -108171,100 +109774,432 @@ Object { }, "loc": Object { "end": Object { - "column": 39, - "line": 1, + "column": 23, + "line": 2, }, "start": Object { - "column": 28, - "line": 1, + "column": 12, + "line": 2, }, }, "range": Array [ - 28, - 39, + 31, + 42, ], "type": "TSArrayType", }, "falseType": Object { + "checkType": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "range": Array [ + 53, + 54, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "name": "T", + "range": Array [ + 53, + 54, + ], + "type": "Identifier", + }, + }, + "extendsType": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 3, + }, + "start": Object { + "column": 14, + "line": 3, + }, + }, + "range": Array [ + 63, + 70, + ], + "type": "TSInferType", + "typeParameter": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 3, + }, + "start": Object { + "column": 20, + "line": 3, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 3, + }, + "start": Object { + "column": 20, + "line": 3, + }, + }, + "name": "U", + "range": Array [ + 69, + 70, + ], + "type": "Identifier", + }, + "range": Array [ + 69, + 70, + ], + "type": "TSTypeParameter", + }, + }, + "falseType": Object { + "checkType": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 4, + }, + "start": Object { + "column": 6, + "line": 4, + }, + }, + "range": Array [ + 83, + 84, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 4, + }, + "start": Object { + "column": 6, + "line": 4, + }, + }, + "name": "T", + "range": Array [ + 83, + 84, + ], + "type": "Identifier", + }, + }, + "extendsType": Object { + "loc": Object { + "end": Object { + "column": 32, + "line": 4, + }, + "start": Object { + "column": 16, + "line": 4, + }, + }, + "range": Array [ + 93, + 109, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 4, + }, + "start": Object { + "column": 16, + "line": 4, + }, + }, + "name": "Promise", + "range": Array [ + 93, + 100, + ], + "type": "Identifier", + }, + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 32, + "line": 4, + }, + "start": Object { + "column": 23, + "line": 4, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 31, + "line": 4, + }, + "start": Object { + "column": 24, + "line": 4, + }, + }, + "range": Array [ + 101, + 108, + ], + "type": "TSInferType", + "typeParameter": Object { + "loc": Object { + "end": Object { + "column": 31, + "line": 4, + }, + "start": Object { + "column": 30, + "line": 4, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 31, + "line": 4, + }, + "start": Object { + "column": 30, + "line": 4, + }, + }, + "name": "U", + "range": Array [ + 107, + 108, + ], + "type": "Identifier", + }, + "range": Array [ + 107, + 108, + ], + "type": "TSTypeParameter", + }, + }, + ], + "range": Array [ + 100, + 109, + ], + "type": "TSTypeParameterInstantiation", + }, + }, + "falseType": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 5, + }, + "start": Object { + "column": 8, + "line": 5, + }, + }, + "range": Array [ + 124, + 125, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 5, + }, + "start": Object { + "column": 8, + "line": 5, + }, + }, + "name": "T", + "range": Array [ + 124, + 125, + ], + "type": "Identifier", + }, + }, + "loc": Object { + "end": Object { + "column": 9, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 4, + }, + }, + "range": Array [ + 83, + 125, + ], + "trueType": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 4, + }, + "start": Object { + "column": 35, + "line": 4, + }, + }, + "range": Array [ + 112, + 113, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 4, + }, + "start": Object { + "column": 35, + "line": 4, + }, + }, + "name": "U", + "range": Array [ + 112, + 113, + ], + "type": "Identifier", + }, + }, + "type": "TSConditionalType", + }, "loc": Object { "end": Object { - "column": 47, - "line": 1, + "column": 9, + "line": 5, }, "start": Object { - "column": 46, - "line": 1, + "column": 4, + "line": 3, }, }, "range": Array [ - 46, - 47, + 53, + 125, ], - "type": "TSTypeReference", - "typeName": Object { + "trueType": Object { "loc": Object { "end": Object { - "column": 47, - "line": 1, + "column": 25, + "line": 3, }, "start": Object { - "column": 46, - "line": 1, + "column": 24, + "line": 3, }, }, - "name": "T", "range": Array [ - 46, - 47, + 73, + 74, ], - "type": "Identifier", + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 3, + }, + "start": Object { + "column": 24, + "line": 3, + }, + }, + "name": "U", + "range": Array [ + 73, + 74, + ], + "type": "Identifier", + }, }, + "type": "TSConditionalType", }, "loc": Object { "end": Object { - "column": 47, - "line": 1, + "column": 9, + "line": 5, }, "start": Object { - "column": 18, - "line": 1, + "column": 2, + "line": 2, }, }, - "range": Array [ - 18, - 47, + "range": Array [ + 21, + 125, ], "trueType": Object { "loc": Object { "end": Object { - "column": 43, - "line": 1, + "column": 27, + "line": 2, }, "start": Object { - "column": 42, - "line": 1, + "column": 26, + "line": 2, }, }, "range": Array [ - 42, - 43, + 45, + 46, ], "type": "TSTypeReference", "typeName": Object { "loc": Object { "end": Object { - "column": 43, - "line": 1, + "column": 27, + "line": 2, }, "start": Object { - "column": 42, - "line": 1, + "column": 26, + "line": 2, }, }, "name": "U", "range": Array [ - 42, - 43, + 45, + 46, ], "type": "Identifier", }, @@ -108274,11 +110209,11 @@ Object { "typeParameters": Object { "loc": Object { "end": Object { - "column": 15, + "column": 16, "line": 1, }, "start": Object { - "column": 12, + "column": 13, "line": 1, }, }, @@ -108286,42 +110221,42 @@ Object { Object { "loc": Object { "end": Object { - "column": 14, + "column": 15, "line": 1, }, "start": Object { - "column": 13, + "column": 14, "line": 1, }, }, "name": Object { "loc": Object { "end": Object { - "column": 14, + "column": 15, "line": 1, }, "start": Object { - "column": 13, + "column": 14, "line": 1, }, }, "name": "T", "range": Array [ - 13, 14, + 15, ], "type": "Identifier", }, "range": Array [ - 13, 14, + 15, ], "type": "TSTypeParameter", }, ], "range": Array [ - 12, - 15, + 13, + 16, ], "type": "TSTypeParameterDeclaration", }, @@ -108330,7 +110265,7 @@ Object { "loc": Object { "end": Object { "column": 0, - "line": 2, + "line": 6, }, "start": Object { "column": 0, @@ -108339,7 +110274,7 @@ Object { }, "range": Array [ 0, - 49, + 127, ], "sourceType": "script", "tokens": Array [ @@ -108364,7 +110299,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 12, + "column": 13, "line": 1, }, "start": Object { @@ -108374,25 +110309,25 @@ Object { }, "range": Array [ 5, - 12, + 13, ], "type": "Identifier", - "value": "Element", + "value": "Unpacked", }, Object { "loc": Object { "end": Object { - "column": 13, + "column": 14, "line": 1, }, "start": Object { - "column": 12, + "column": 13, "line": 1, }, }, "range": Array [ - 12, 13, + 14, ], "type": "Punctuator", "value": "<", @@ -108400,17 +110335,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 14, + "column": 15, "line": 1, }, "start": Object { - "column": 13, + "column": 14, "line": 1, }, }, "range": Array [ - 13, 14, + 15, ], "type": "Identifier", "value": "T", @@ -108418,17 +110353,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 15, + "column": 16, "line": 1, }, "start": Object { - "column": 14, + "column": 15, "line": 1, }, }, "range": Array [ - 14, 15, + 16, ], "type": "Punctuator", "value": ">", @@ -108436,17 +110371,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 17, + "column": 18, "line": 1, }, "start": Object { - "column": 16, + "column": 17, "line": 1, }, }, "range": Array [ - 16, 17, + 18, ], "type": "Punctuator", "value": "=", @@ -108454,17 +110389,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 19, - "line": 1, + "column": 3, + "line": 2, }, "start": Object { - "column": 18, - "line": 1, + "column": 2, + "line": 2, }, }, "range": Array [ - 18, - 19, + 21, + 22, ], "type": "Identifier", "value": "T", @@ -108472,17 +110407,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 27, - "line": 1, + "column": 11, + "line": 2, }, "start": Object { - "column": 20, - "line": 1, + "column": 4, + "line": 2, }, }, "range": Array [ - 20, - 27, + 23, + 30, ], "type": "Keyword", "value": "extends", @@ -108490,17 +110425,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 29, - "line": 1, + "column": 13, + "line": 2, }, "start": Object { - "column": 28, - "line": 1, + "column": 12, + "line": 2, }, }, "range": Array [ - 28, - 29, + 31, + 32, ], "type": "Punctuator", "value": "(", @@ -108508,17 +110443,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 34, - "line": 1, + "column": 18, + "line": 2, }, "start": Object { - "column": 29, - "line": 1, + "column": 13, + "line": 2, }, }, "range": Array [ - 29, - 34, + 32, + 37, ], "type": "Identifier", "value": "infer", @@ -108526,17 +110461,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 36, - "line": 1, + "column": 20, + "line": 2, }, "start": Object { - "column": 35, - "line": 1, + "column": 19, + "line": 2, }, }, "range": Array [ - 35, - 36, + 38, + 39, ], "type": "Identifier", "value": "U", @@ -108544,17 +110479,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 37, - "line": 1, + "column": 21, + "line": 2, }, "start": Object { - "column": 36, - "line": 1, + "column": 20, + "line": 2, }, }, "range": Array [ - 36, - 37, + 39, + 40, ], "type": "Punctuator", "value": ")", @@ -108562,17 +110497,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 38, - "line": 1, + "column": 22, + "line": 2, }, "start": Object { - "column": 37, - "line": 1, + "column": 21, + "line": 2, }, }, "range": Array [ - 37, - 38, + 40, + 41, ], "type": "Punctuator", "value": "[", @@ -108580,17 +110515,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 39, - "line": 1, + "column": 23, + "line": 2, }, "start": Object { - "column": 38, - "line": 1, + "column": 22, + "line": 2, }, }, "range": Array [ - 38, - 39, + 41, + 42, ], "type": "Punctuator", "value": "]", @@ -108598,17 +110533,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 41, - "line": 1, + "column": 25, + "line": 2, }, "start": Object { - "column": 40, - "line": 1, + "column": 24, + "line": 2, }, }, "range": Array [ - 40, - 41, + 43, + 44, ], "type": "Punctuator", "value": "?", @@ -108616,17 +110551,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 43, - "line": 1, + "column": 27, + "line": 2, }, "start": Object { - "column": 42, - "line": 1, + "column": 26, + "line": 2, }, }, "range": Array [ - 42, - 43, + 45, + 46, ], "type": "Identifier", "value": "U", @@ -108634,17 +110569,323 @@ Object { Object { "loc": Object { "end": Object { - "column": 45, - "line": 1, + "column": 29, + "line": 2, }, "start": Object { - "column": 44, - "line": 1, + "column": 28, + "line": 2, + }, + }, + "range": Array [ + 47, + 48, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "range": Array [ + 53, + 54, + ], + "type": "Identifier", + "value": "T", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 6, + "line": 3, + }, + }, + "range": Array [ + 55, + 62, + ], + "type": "Keyword", + "value": "extends", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 3, + }, + "start": Object { + "column": 14, + "line": 3, + }, + }, + "range": Array [ + 63, + 68, + ], + "type": "Identifier", + "value": "infer", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 3, + }, + "start": Object { + "column": 20, + "line": 3, + }, + }, + "range": Array [ + 69, + 70, + ], + "type": "Identifier", + "value": "U", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 22, + "line": 3, + }, + }, + "range": Array [ + 71, + 72, + ], + "type": "Punctuator", + "value": "?", + }, + Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 3, + }, + "start": Object { + "column": 24, + "line": 3, + }, + }, + "range": Array [ + 73, + 74, + ], + "type": "Identifier", + "value": "U", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 3, + }, + "start": Object { + "column": 26, + "line": 3, + }, + }, + "range": Array [ + 75, + 76, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 4, + }, + "start": Object { + "column": 6, + "line": 4, + }, + }, + "range": Array [ + 83, + 84, + ], + "type": "Identifier", + "value": "T", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 4, + }, + "start": Object { + "column": 8, + "line": 4, + }, + }, + "range": Array [ + 85, + 92, + ], + "type": "Keyword", + "value": "extends", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 4, + }, + "start": Object { + "column": 16, + "line": 4, + }, + }, + "range": Array [ + 93, + 100, + ], + "type": "Identifier", + "value": "Promise", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 4, + }, + "start": Object { + "column": 23, + "line": 4, + }, + }, + "range": Array [ + 100, + 101, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 4, + }, + "start": Object { + "column": 24, + "line": 4, + }, + }, + "range": Array [ + 101, + 106, + ], + "type": "Identifier", + "value": "infer", + }, + Object { + "loc": Object { + "end": Object { + "column": 31, + "line": 4, + }, + "start": Object { + "column": 30, + "line": 4, + }, + }, + "range": Array [ + 107, + 108, + ], + "type": "Identifier", + "value": "U", + }, + Object { + "loc": Object { + "end": Object { + "column": 32, + "line": 4, + }, + "start": Object { + "column": 31, + "line": 4, + }, + }, + "range": Array [ + 108, + 109, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 34, + "line": 4, + }, + "start": Object { + "column": 33, + "line": 4, + }, + }, + "range": Array [ + 110, + 111, + ], + "type": "Punctuator", + "value": "?", + }, + Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 4, + }, + "start": Object { + "column": 35, + "line": 4, + }, + }, + "range": Array [ + 112, + 113, + ], + "type": "Identifier", + "value": "U", + }, + Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 4, + }, + "start": Object { + "column": 37, + "line": 4, }, }, "range": Array [ - 44, - 45, + 114, + 115, ], "type": "Punctuator", "value": ":", @@ -108652,17 +110893,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 47, - "line": 1, + "column": 9, + "line": 5, }, "start": Object { - "column": 46, - "line": 1, + "column": 8, + "line": 5, }, }, "range": Array [ - 46, - 47, + 124, + 125, ], "type": "Identifier", "value": "T", @@ -108670,17 +110911,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 48, - "line": 1, + "column": 10, + "line": 5, }, "start": Object { - "column": 47, - "line": 1, + "column": 9, + "line": 5, }, }, "range": Array [ - 47, - 48, + 125, + 126, ], "type": "Punctuator", "value": ";", @@ -108690,14 +110931,14 @@ Object { } `; -exports[`typescript fixtures/types/conditional-infer-nested.src 1`] = ` +exports[`typescript fixtures/types/conditional-infer-simple.src 1`] = ` Object { "body": Array [ Object { "id": Object { "loc": Object { "end": Object { - "column": 13, + "column": 8, "line": 1, }, "start": Object { @@ -108705,17 +110946,17 @@ Object { "line": 1, }, }, - "name": "Unpacked", + "name": "Foo", "range": Array [ 5, - 13, + 8, ], "type": "Identifier", }, "loc": Object { "end": Object { - "column": 10, - "line": 5, + "column": 63, + "line": 1, }, "start": Object { "column": 0, @@ -108724,543 +110965,336 @@ Object { }, "range": Array [ 0, - 126, + 63, ], "type": "TSTypeAliasDeclaration", "typeAnnotation": Object { "checkType": Object { "loc": Object { "end": Object { - "column": 3, - "line": 2, + "column": 15, + "line": 1, }, "start": Object { - "column": 2, - "line": 2, + "column": 14, + "line": 1, }, }, "range": Array [ - 21, - 22, + 14, + 15, ], "type": "TSTypeReference", "typeName": Object { "loc": Object { "end": Object { - "column": 3, - "line": 2, + "column": 15, + "line": 1, }, "start": Object { - "column": 2, - "line": 2, + "column": 14, + "line": 1, }, }, "name": "T", "range": Array [ - 21, - 22, + 14, + 15, ], "type": "Identifier", }, }, "extendsType": Object { - "elementType": Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 2, - }, - "start": Object { - "column": 12, - "line": 2, - }, - }, - "range": Array [ - 31, - 40, - ], - "type": "TSParenthesizedType", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 20, - "line": 2, - }, - "start": Object { - "column": 13, - "line": 2, - }, - }, - "range": Array [ - 32, - 39, - ], - "type": "TSInferType", - "typeParameter": Object { - "loc": Object { - "end": Object { - "column": 20, - "line": 2, - }, - "start": Object { - "column": 19, - "line": 2, - }, - }, - "name": Object { - "loc": Object { - "end": Object { - "column": 20, - "line": 2, - }, - "start": Object { - "column": 19, - "line": 2, - }, - }, - "name": "U", - "range": Array [ - 38, - 39, - ], - "type": "Identifier", - }, - "range": Array [ - 38, - 39, - ], - "type": "TSTypeParameter", - }, - }, - }, "loc": Object { "end": Object { - "column": 23, - "line": 2, + "column": 50, + "line": 1, }, "start": Object { - "column": 12, - "line": 2, - }, - }, - "range": Array [ - 31, - 42, - ], - "type": "TSArrayType", - }, - "falseType": Object { - "checkType": Object { - "loc": Object { - "end": Object { - "column": 5, - "line": 3, - }, - "start": Object { - "column": 4, - "line": 3, - }, - }, - "range": Array [ - 53, - 54, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 5, - "line": 3, - }, - "start": Object { - "column": 4, - "line": 3, - }, - }, - "name": "T", - "range": Array [ - 53, - 54, - ], - "type": "Identifier", - }, - }, - "extendsType": Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 3, - }, - "start": Object { - "column": 14, - "line": 3, - }, - }, - "range": Array [ - 63, - 70, - ], - "type": "TSInferType", - "typeParameter": Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 3, - }, - "start": Object { - "column": 20, - "line": 3, - }, - }, - "name": Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 3, - }, - "start": Object { - "column": 20, - "line": 3, - }, - }, - "name": "U", - "range": Array [ - 69, - 70, - ], - "type": "Identifier", - }, - "range": Array [ - 69, - 70, - ], - "type": "TSTypeParameter", + "column": 24, + "line": 1, }, }, - "falseType": Object { - "checkType": Object { - "loc": Object { - "end": Object { - "column": 7, - "line": 4, - }, - "start": Object { - "column": 6, - "line": 4, - }, - }, - "range": Array [ - 83, - 84, - ], - "type": "TSTypeReference", - "typeName": Object { + "members": Array [ + Object { + "computed": false, + "key": Object { "loc": Object { "end": Object { - "column": 7, - "line": 4, + "column": 27, + "line": 1, }, "start": Object { - "column": 6, - "line": 4, + "column": 26, + "line": 1, }, }, - "name": "T", + "name": "a", "range": Array [ - 83, - 84, + 26, + 27, ], "type": "Identifier", }, - }, - "extendsType": Object { "loc": Object { "end": Object { - "column": 32, - "line": 4, + "column": 37, + "line": 1, }, "start": Object { - "column": 16, - "line": 4, + "column": 26, + "line": 1, }, }, "range": Array [ - 93, - 109, + 26, + 37, ], - "type": "TSTypeReference", - "typeName": Object { + "type": "TSPropertySignature", + "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 23, - "line": 4, + "column": 36, + "line": 1, }, "start": Object { - "column": 16, - "line": 4, + "column": 27, + "line": 1, }, }, - "name": "Promise", "range": Array [ - 93, - 100, + 27, + 36, ], - "type": "Identifier", - }, - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 32, - "line": 4, - }, - "start": Object { - "column": 23, - "line": 4, + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 36, + "line": 1, + }, + "start": Object { + "column": 29, + "line": 1, + }, }, - }, - "params": Array [ - Object { + "range": Array [ + 29, + 36, + ], + "type": "TSInferType", + "typeParameter": Object { "loc": Object { "end": Object { - "column": 31, - "line": 4, + "column": 36, + "line": 1, }, "start": Object { - "column": 24, - "line": 4, + "column": 35, + "line": 1, }, }, - "range": Array [ - 101, - 108, - ], - "type": "TSInferType", - "typeParameter": Object { + "name": Object { "loc": Object { "end": Object { - "column": 31, - "line": 4, + "column": 36, + "line": 1, }, "start": Object { - "column": 30, - "line": 4, - }, - }, - "name": Object { - "loc": Object { - "end": Object { - "column": 31, - "line": 4, - }, - "start": Object { - "column": 30, - "line": 4, - }, + "column": 35, + "line": 1, }, - "name": "U", - "range": Array [ - 107, - 108, - ], - "type": "Identifier", }, + "name": "U", "range": Array [ - 107, - 108, + 35, + 36, ], - "type": "TSTypeParameter", + "type": "Identifier", }, + "range": Array [ + 35, + 36, + ], + "type": "TSTypeParameter", }, - ], - "range": Array [ - 100, - 109, - ], - "type": "TSTypeParameterInstantiation", - }, - }, - "falseType": Object { - "loc": Object { - "end": Object { - "column": 9, - "line": 5, - }, - "start": Object { - "column": 8, - "line": 5, }, }, - "range": Array [ - 124, - 125, - ], - "type": "TSTypeReference", - "typeName": Object { + }, + Object { + "computed": false, + "key": Object { "loc": Object { "end": Object { - "column": 9, - "line": 5, + "column": 39, + "line": 1, }, "start": Object { - "column": 8, - "line": 5, + "column": 38, + "line": 1, }, }, - "name": "T", + "name": "b", "range": Array [ - 124, - 125, + 38, + 39, ], "type": "Identifier", }, - }, - "loc": Object { - "end": Object { - "column": 9, - "line": 5, - }, - "start": Object { - "column": 6, - "line": 4, - }, - }, - "range": Array [ - 83, - 125, - ], - "trueType": Object { "loc": Object { "end": Object { - "column": 36, - "line": 4, + "column": 48, + "line": 1, }, "start": Object { - "column": 35, - "line": 4, + "column": 38, + "line": 1, }, }, "range": Array [ - 112, - 113, + 38, + 48, ], - "type": "TSTypeReference", - "typeName": Object { + "type": "TSPropertySignature", + "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 36, - "line": 4, + "column": 48, + "line": 1, }, "start": Object { - "column": 35, - "line": 4, + "column": 39, + "line": 1, + }, + }, + "range": Array [ + 39, + 48, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 48, + "line": 1, + }, + "start": Object { + "column": 41, + "line": 1, + }, + }, + "range": Array [ + 41, + 48, + ], + "type": "TSInferType", + "typeParameter": Object { + "loc": Object { + "end": Object { + "column": 48, + "line": 1, + }, + "start": Object { + "column": 47, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 48, + "line": 1, + }, + "start": Object { + "column": 47, + "line": 1, + }, + }, + "name": "U", + "range": Array [ + 47, + 48, + ], + "type": "Identifier", + }, + "range": Array [ + 47, + 48, + ], + "type": "TSTypeParameter", }, }, - "name": "U", - "range": Array [ - 112, - 113, - ], - "type": "Identifier", }, }, - "type": "TSConditionalType", - }, + ], + "range": Array [ + 24, + 50, + ], + "type": "TSTypeLiteral", + }, + "falseType": Object { "loc": Object { "end": Object { - "column": 9, - "line": 5, + "column": 62, + "line": 1, }, "start": Object { - "column": 4, - "line": 3, + "column": 57, + "line": 1, }, }, "range": Array [ - 53, - 125, + 57, + 62, ], - "trueType": Object { - "loc": Object { - "end": Object { - "column": 25, - "line": 3, - }, - "start": Object { - "column": 24, - "line": 3, - }, - }, - "range": Array [ - 73, - 74, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 25, - "line": 3, - }, - "start": Object { - "column": 24, - "line": 3, - }, - }, - "name": "U", - "range": Array [ - 73, - 74, - ], - "type": "Identifier", - }, - }, - "type": "TSConditionalType", + "type": "TSNeverKeyword", }, "loc": Object { "end": Object { - "column": 9, - "line": 5, + "column": 62, + "line": 1, }, "start": Object { - "column": 2, - "line": 2, + "column": 14, + "line": 1, }, }, "range": Array [ - 21, - 125, + 14, + 62, ], "trueType": Object { "loc": Object { "end": Object { - "column": 27, - "line": 2, + "column": 54, + "line": 1, }, "start": Object { - "column": 26, - "line": 2, + "column": 53, + "line": 1, }, }, "range": Array [ - 45, - 46, + 53, + 54, ], "type": "TSTypeReference", "typeName": Object { "loc": Object { "end": Object { - "column": 27, - "line": 2, + "column": 54, + "line": 1, }, "start": Object { - "column": 26, - "line": 2, + "column": 53, + "line": 1, }, }, "name": "U", "range": Array [ - 45, - 46, + 53, + 54, ], "type": "Identifier", }, @@ -109270,11 +111304,11 @@ Object { "typeParameters": Object { "loc": Object { "end": Object { - "column": 16, + "column": 11, "line": 1, }, "start": Object { - "column": 13, + "column": 8, "line": 1, }, }, @@ -109282,42 +111316,42 @@ Object { Object { "loc": Object { "end": Object { - "column": 15, + "column": 10, "line": 1, }, "start": Object { - "column": 14, + "column": 9, "line": 1, }, }, "name": Object { "loc": Object { "end": Object { - "column": 15, + "column": 10, "line": 1, }, "start": Object { - "column": 14, + "column": 9, "line": 1, }, }, "name": "T", "range": Array [ - 14, - 15, + 9, + 10, ], "type": "Identifier", }, "range": Array [ - 14, - 15, + 9, + 10, ], "type": "TSTypeParameter", }, ], "range": Array [ - 13, - 16, + 8, + 11, ], "type": "TSTypeParameterDeclaration", }, @@ -109326,7 +111360,7 @@ Object { "loc": Object { "end": Object { "column": 0, - "line": 6, + "line": 2, }, "start": Object { "column": 0, @@ -109335,7 +111369,7 @@ Object { }, "range": Array [ 0, - 127, + 64, ], "sourceType": "script", "tokens": Array [ @@ -109360,7 +111394,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 13, + "column": 8, "line": 1, }, "start": Object { @@ -109370,25 +111404,25 @@ Object { }, "range": Array [ 5, - 13, + 8, ], "type": "Identifier", - "value": "Unpacked", + "value": "Foo", }, Object { "loc": Object { "end": Object { - "column": 14, + "column": 9, "line": 1, }, "start": Object { - "column": 13, + "column": 8, "line": 1, }, }, "range": Array [ - 13, - 14, + 8, + 9, ], "type": "Punctuator", "value": "<", @@ -109396,17 +111430,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 15, + "column": 10, "line": 1, }, "start": Object { - "column": 14, + "column": 9, "line": 1, }, }, "range": Array [ - 14, - 15, + 9, + 10, ], "type": "Identifier", "value": "T", @@ -109414,17 +111448,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 16, + "column": 11, "line": 1, }, "start": Object { - "column": 15, + "column": 10, "line": 1, }, }, "range": Array [ - 15, - 16, + 10, + 11, ], "type": "Punctuator", "value": ">", @@ -109432,17 +111466,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 18, + "column": 13, "line": 1, }, "start": Object { - "column": 17, + "column": 12, "line": 1, }, }, "range": Array [ - 17, - 18, + 12, + 13, ], "type": "Punctuator", "value": "=", @@ -109450,17 +111484,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 3, - "line": 2, + "column": 15, + "line": 1, }, "start": Object { - "column": 2, - "line": 2, + "column": 14, + "line": 1, }, }, "range": Array [ - 21, - 22, + 14, + 15, ], "type": "Identifier", "value": "T", @@ -109468,179 +111502,71 @@ Object { Object { "loc": Object { "end": Object { - "column": 11, - "line": 2, + "column": 23, + "line": 1, }, "start": Object { - "column": 4, - "line": 2, + "column": 16, + "line": 1, }, }, "range": Array [ + 16, 23, - 30, ], "type": "Keyword", "value": "extends", }, - Object { - "loc": Object { - "end": Object { - "column": 13, - "line": 2, - }, - "start": Object { - "column": 12, - "line": 2, - }, - }, - "range": Array [ - 31, - 32, - ], - "type": "Punctuator", - "value": "(", - }, - Object { - "loc": Object { - "end": Object { - "column": 18, - "line": 2, - }, - "start": Object { - "column": 13, - "line": 2, - }, - }, - "range": Array [ - 32, - 37, - ], - "type": "Identifier", - "value": "infer", - }, - Object { - "loc": Object { - "end": Object { - "column": 20, - "line": 2, - }, - "start": Object { - "column": 19, - "line": 2, - }, - }, - "range": Array [ - 38, - 39, - ], - "type": "Identifier", - "value": "U", - }, - Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 2, - }, - "start": Object { - "column": 20, - "line": 2, - }, - }, - "range": Array [ - 39, - 40, - ], - "type": "Punctuator", - "value": ")", - }, - Object { - "loc": Object { - "end": Object { - "column": 22, - "line": 2, - }, - "start": Object { - "column": 21, - "line": 2, - }, - }, - "range": Array [ - 40, - 41, - ], - "type": "Punctuator", - "value": "[", - }, - Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 2, - }, - "start": Object { - "column": 22, - "line": 2, - }, - }, - "range": Array [ - 41, - 42, - ], - "type": "Punctuator", - "value": "]", - }, Object { "loc": Object { "end": Object { "column": 25, - "line": 2, + "line": 1, }, "start": Object { "column": 24, - "line": 2, + "line": 1, }, }, "range": Array [ - 43, - 44, + 24, + 25, ], "type": "Punctuator", - "value": "?", + "value": "{", }, Object { "loc": Object { "end": Object { "column": 27, - "line": 2, + "line": 1, }, "start": Object { "column": 26, - "line": 2, + "line": 1, }, }, "range": Array [ - 45, - 46, + 26, + 27, ], "type": "Identifier", - "value": "U", + "value": "a", }, Object { "loc": Object { "end": Object { - "column": 29, - "line": 2, + "column": 28, + "line": 1, }, "start": Object { - "column": 28, - "line": 2, + "column": 27, + "line": 1, }, }, "range": Array [ - 47, - 48, + 27, + 28, ], "type": "Punctuator", "value": ":", @@ -109648,53 +111574,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 5, - "line": 3, - }, - "start": Object { - "column": 4, - "line": 3, - }, - }, - "range": Array [ - 53, - 54, - ], - "type": "Identifier", - "value": "T", - }, - Object { - "loc": Object { - "end": Object { - "column": 13, - "line": 3, - }, - "start": Object { - "column": 6, - "line": 3, - }, - }, - "range": Array [ - 55, - 62, - ], - "type": "Keyword", - "value": "extends", - }, - Object { - "loc": Object { - "end": Object { - "column": 19, - "line": 3, + "column": 34, + "line": 1, }, "start": Object { - "column": 14, - "line": 3, + "column": 29, + "line": 1, }, }, "range": Array [ - 63, - 68, + 29, + 34, ], "type": "Identifier", "value": "infer", @@ -109702,53 +111592,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 21, - "line": 3, - }, - "start": Object { - "column": 20, - "line": 3, - }, - }, - "range": Array [ - 69, - 70, - ], - "type": "Identifier", - "value": "U", - }, - Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 3, - }, - "start": Object { - "column": 22, - "line": 3, - }, - }, - "range": Array [ - 71, - 72, - ], - "type": "Punctuator", - "value": "?", - }, - Object { - "loc": Object { - "end": Object { - "column": 25, - "line": 3, + "column": 36, + "line": 1, }, "start": Object { - "column": 24, - "line": 3, + "column": 35, + "line": 1, }, }, "range": Array [ - 73, - 74, + 35, + 36, ], "type": "Identifier", "value": "U", @@ -109756,107 +111610,71 @@ Object { Object { "loc": Object { "end": Object { - "column": 27, - "line": 3, + "column": 37, + "line": 1, }, "start": Object { - "column": 26, - "line": 3, + "column": 36, + "line": 1, }, }, "range": Array [ - 75, - 76, + 36, + 37, ], "type": "Punctuator", - "value": ":", - }, - Object { - "loc": Object { - "end": Object { - "column": 7, - "line": 4, - }, - "start": Object { - "column": 6, - "line": 4, - }, - }, - "range": Array [ - 83, - 84, - ], - "type": "Identifier", - "value": "T", - }, - Object { - "loc": Object { - "end": Object { - "column": 15, - "line": 4, - }, - "start": Object { - "column": 8, - "line": 4, - }, - }, - "range": Array [ - 85, - 92, - ], - "type": "Keyword", - "value": "extends", + "value": ",", }, Object { "loc": Object { "end": Object { - "column": 23, - "line": 4, + "column": 39, + "line": 1, }, "start": Object { - "column": 16, - "line": 4, + "column": 38, + "line": 1, }, }, "range": Array [ - 93, - 100, + 38, + 39, ], "type": "Identifier", - "value": "Promise", + "value": "b", }, Object { "loc": Object { "end": Object { - "column": 24, - "line": 4, + "column": 40, + "line": 1, }, "start": Object { - "column": 23, - "line": 4, + "column": 39, + "line": 1, }, }, "range": Array [ - 100, - 101, + 39, + 40, ], "type": "Punctuator", - "value": "<", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 29, - "line": 4, + "column": 46, + "line": 1, }, "start": Object { - "column": 24, - "line": 4, + "column": 41, + "line": 1, }, }, "range": Array [ - 101, - 106, + 41, + 46, ], "type": "Identifier", "value": "infer", @@ -109864,17 +111682,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 31, - "line": 4, + "column": 48, + "line": 1, }, "start": Object { - "column": 30, - "line": 4, + "column": 47, + "line": 1, }, }, "range": Array [ - 107, - 108, + 47, + 48, ], "type": "Identifier", "value": "U", @@ -109882,35 +111700,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 32, - "line": 4, + "column": 50, + "line": 1, }, "start": Object { - "column": 31, - "line": 4, + "column": 49, + "line": 1, }, }, "range": Array [ - 108, - 109, + 49, + 50, ], "type": "Punctuator", - "value": ">", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 34, - "line": 4, + "column": 52, + "line": 1, }, "start": Object { - "column": 33, - "line": 4, + "column": 51, + "line": 1, }, }, "range": Array [ - 110, - 111, + 51, + 52, ], "type": "Punctuator", "value": "?", @@ -109918,17 +111736,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 36, - "line": 4, + "column": 54, + "line": 1, }, "start": Object { - "column": 35, - "line": 4, + "column": 53, + "line": 1, }, }, "range": Array [ - 112, - 113, + 53, + 54, ], "type": "Identifier", "value": "U", @@ -109936,17 +111754,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 38, - "line": 4, + "column": 56, + "line": 1, }, "start": Object { - "column": 37, - "line": 4, + "column": 55, + "line": 1, }, }, "range": Array [ - 114, - 115, + 55, + 56, ], "type": "Punctuator", "value": ":", @@ -109954,35 +111772,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 9, - "line": 5, + "column": 62, + "line": 1, }, "start": Object { - "column": 8, - "line": 5, + "column": 57, + "line": 1, }, }, "range": Array [ - 124, - 125, + 57, + 62, ], "type": "Identifier", - "value": "T", + "value": "never", }, Object { "loc": Object { "end": Object { - "column": 10, - "line": 5, + "column": 63, + "line": 1, }, "start": Object { - "column": 9, - "line": 5, + "column": 62, + "line": 1, }, }, "range": Array [ - 125, - 126, + 62, + 63, ], "type": "Punctuator", "value": ";", @@ -109992,430 +111810,166 @@ Object { } `; -exports[`typescript fixtures/types/conditional-infer-simple.src 1`] = ` +exports[`typescript fixtures/types/conditional-with-null.src 1`] = ` Object { "body": Array [ Object { - "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": 63, - "line": 1, - }, - "start": Object { - "column": 0, - "line": 1, - }, - }, - "range": Array [ - 0, - 63, - ], - "type": "TSTypeAliasDeclaration", - "typeAnnotation": Object { - "checkType": Object { - "loc": Object { - "end": Object { - "column": 15, - "line": 1, - }, - "start": Object { - "column": 14, - "line": 1, - }, - }, - "range": Array [ - 14, - 15, - ], - "type": "TSTypeReference", - "typeName": Object { + "declarations": Array [ + Object { + "id": Object { "loc": Object { "end": Object { - "column": 15, + "column": 45, "line": 1, }, "start": Object { - "column": 14, + "column": 4, "line": 1, }, }, - "name": "T", + "name": "x", "range": Array [ - 14, - 15, + 4, + 45, ], "type": "Identifier", - }, - }, - "extendsType": Object { - "loc": Object { - "end": Object { - "column": 50, - "line": 1, - }, - "start": Object { - "column": 24, - "line": 1, - }, - }, - "members": Array [ - Object { - "computed": false, - "key": Object { - "loc": Object { - "end": Object { - "column": 27, - "line": 1, - }, - "start": Object { - "column": 26, - "line": 1, - }, - }, - "name": "a", - "range": Array [ - 26, - 27, - ], - "type": "Identifier", - }, + "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 37, + "column": 45, "line": 1, }, "start": Object { - "column": 26, + "column": 5, "line": 1, }, }, "range": Array [ - 26, - 37, + 5, + 45, ], - "type": "TSPropertySignature", + "type": "TSTypeAnnotation", "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 1, - }, - "start": Object { - "column": 27, - "line": 1, - }, - }, - "range": Array [ - 27, - 36, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { + "checkType": Object { "loc": Object { "end": Object { - "column": 36, + "column": 13, "line": 1, }, "start": Object { - "column": 29, + "column": 7, "line": 1, }, }, "range": Array [ - 29, - 36, + 7, + 13, ], - "type": "TSInferType", - "typeParameter": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 1, - }, - "start": Object { - "column": 35, - "line": 1, - }, + "type": "TSNumberKeyword", + }, + "extendsType": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, }, - "name": Object { - "loc": Object { - "end": Object { - "column": 36, - "line": 1, - }, - "start": Object { - "column": 35, - "line": 1, - }, - }, - "name": "U", - "range": Array [ - 35, - 36, - ], - "type": "Identifier", + "start": Object { + "column": 22, + "line": 1, }, - "range": Array [ - 35, - 36, - ], - "type": "TSTypeParameter", }, + "range": Array [ + 22, + 28, + ], + "type": "TSStringKeyword", }, - }, - }, - Object { - "computed": false, - "key": Object { - "loc": Object { - "end": Object { - "column": 39, - "line": 1, - }, - "start": Object { - "column": 38, - "line": 1, + "falseType": Object { + "loc": Object { + "end": Object { + "column": 45, + "line": 1, + }, + "start": Object { + "column": 41, + "line": 1, + }, }, + "range": Array [ + 41, + 45, + ], + "type": "TSNullKeyword", }, - "name": "b", - "range": Array [ - 38, - 39, - ], - "type": "Identifier", - }, - "loc": Object { - "end": Object { - "column": 48, - "line": 1, - }, - "start": Object { - "column": 38, - "line": 1, - }, - }, - "range": Array [ - 38, - 48, - ], - "type": "TSPropertySignature", - "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 48, + "column": 45, "line": 1, }, "start": Object { - "column": 39, + "column": 7, "line": 1, }, }, "range": Array [ - 39, - 48, + 7, + 45, ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { + "trueType": Object { "loc": Object { "end": Object { - "column": 48, - "line": 1, - }, - "start": Object { - "column": 41, + "column": 38, "line": 1, - }, - }, - "range": Array [ - 41, - 48, - ], - "type": "TSInferType", - "typeParameter": Object { - "loc": Object { - "end": Object { - "column": 48, - "line": 1, - }, - "start": Object { - "column": 47, - "line": 1, - }, - }, - "name": Object { - "loc": Object { - "end": Object { - "column": 48, - "line": 1, - }, - "start": Object { - "column": 47, - "line": 1, - }, - }, - "name": "U", - "range": Array [ - 47, - 48, - ], - "type": "Identifier", - }, - "range": Array [ - 47, - 48, - ], - "type": "TSTypeParameter", - }, - }, - }, - }, - ], - "range": Array [ - 24, - 50, - ], - "type": "TSTypeLiteral", - }, - "falseType": Object { - "loc": Object { - "end": Object { - "column": 62, - "line": 1, - }, - "start": Object { - "column": 57, - "line": 1, - }, - }, - "range": Array [ - 57, - 62, - ], - "type": "TSNeverKeyword", - }, - "loc": Object { - "end": Object { - "column": 62, - "line": 1, - }, - "start": Object { - "column": 14, - "line": 1, - }, - }, - "range": Array [ - 14, - 62, - ], - "trueType": Object { - "loc": Object { - "end": Object { - "column": 54, - "line": 1, - }, - "start": Object { - "column": 53, - "line": 1, - }, - }, - "range": Array [ - 53, - 54, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 54, - "line": 1, - }, - "start": Object { - "column": 53, - "line": 1, - }, - }, - "name": "U", - "range": Array [ - 53, - 54, - ], - "type": "Identifier", - }, - }, - "type": "TSConditionalType", - }, - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 11, - "line": 1, - }, - "start": Object { - "column": 8, - "line": 1, - }, - }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 1, - }, - "start": Object { - "column": 9, - "line": 1, - }, - }, - "name": Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 1, - }, - "start": Object { - "column": 9, - "line": 1, + }, + "start": Object { + "column": 31, + "line": 1, + }, + }, + "range": Array [ + 31, + 38, + ], + "type": "TSBooleanKeyword", }, + "type": "TSConditionalType", }, - "name": "T", - "range": Array [ - 9, - 10, - ], - "type": "Identifier", }, - "range": Array [ - 9, - 10, - ], - "type": "TSTypeParameter", }, - ], - "range": Array [ - 8, - 11, - ], - "type": "TSTypeParameterDeclaration", + "init": null, + "loc": Object { + "end": Object { + "column": 45, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 45, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "let", + "loc": Object { + "end": Object { + "column": 46, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, }, + "range": Array [ + 0, + 46, + ], + "type": "VariableDeclaration", }, ], "loc": Object { @@ -110430,14 +111984,14 @@ Object { }, "range": Array [ 0, - 64, + 47, ], "sourceType": "script", "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 4, + "column": 3, "line": 1, }, "start": Object { @@ -110447,15 +112001,33 @@ Object { }, "range": Array [ 0, + 3, + ], + "type": "Keyword", + "value": "let", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ 4, + 5, ], "type": "Identifier", - "value": "type", + "value": "x", }, Object { "loc": Object { "end": Object { - "column": 8, + "column": 6, "line": 1, }, "start": Object { @@ -110465,169 +112037,461 @@ Object { }, "range": Array [ 5, - 8, + 6, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "range": Array [ + 7, + 13, ], "type": "Identifier", - "value": "Foo", + "value": "number", }, Object { "loc": Object { "end": Object { - "column": 9, + "column": 21, "line": 1, }, "start": Object { - "column": 8, + "column": 14, "line": 1, }, }, "range": Array [ - 8, - 9, + 14, + 21, ], - "type": "Punctuator", - "value": "<", + "type": "Keyword", + "value": "extends", }, Object { "loc": Object { "end": Object { - "column": 10, + "column": 28, "line": 1, }, "start": Object { - "column": 9, + "column": 22, "line": 1, }, }, "range": Array [ - 9, - 10, + 22, + 28, ], "type": "Identifier", - "value": "T", + "value": "string", }, Object { "loc": Object { "end": Object { - "column": 11, + "column": 30, "line": 1, }, "start": Object { - "column": 10, + "column": 29, "line": 1, }, }, "range": Array [ - 10, - 11, + 29, + 30, ], "type": "Punctuator", - "value": ">", + "value": "?", }, Object { "loc": Object { "end": Object { - "column": 13, + "column": 38, "line": 1, }, "start": Object { - "column": 12, + "column": 31, "line": 1, }, }, "range": Array [ - 12, - 13, + 31, + 38, ], - "type": "Punctuator", - "value": "=", + "type": "Identifier", + "value": "boolean", }, Object { "loc": Object { "end": Object { - "column": 15, + "column": 40, "line": 1, }, "start": Object { - "column": 14, + "column": 39, "line": 1, }, }, "range": Array [ - 14, - 15, + 39, + 40, ], - "type": "Identifier", - "value": "T", + "type": "Punctuator", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 23, + "column": 45, "line": 1, }, "start": Object { - "column": 16, + "column": 41, "line": 1, }, }, "range": Array [ - 16, - 23, + 41, + 45, ], "type": "Keyword", - "value": "extends", + "value": "null", }, Object { "loc": Object { "end": Object { - "column": 25, + "column": 46, "line": 1, }, "start": Object { - "column": 24, + "column": 45, "line": 1, }, }, "range": Array [ - 24, - 25, + 45, + 46, ], "type": "Punctuator", - "value": "{", + "value": ";", + }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/types/constructor.src 1`] = ` +Object { + "body": Array [ + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "name": "f", + "range": Array [ + 4, + 42, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 42, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "name": "a", + "range": Array [ + 12, + 21, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 21, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 21, + ], + "type": "TSNumberKeyword", + }, + }, + }, + Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 1, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "name": "b", + "optional": true, + "range": Array [ + 23, + 33, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, + }, + "range": Array [ + 25, + 33, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 1, + }, + "start": Object { + "column": 27, + "line": 1, + }, + }, + "range": Array [ + 27, + 33, + ], + "type": "TSNumberKeyword", + }, + }, + }, + ], + "range": Array [ + 7, + 42, + ], + "returnType": Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 1, + }, + "start": Object { + "column": 35, + "line": 1, + }, + }, + "range": Array [ + 35, + 42, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 42, + "line": 1, + }, + "start": Object { + "column": 38, + "line": 1, + }, + }, + "range": Array [ + 38, + 42, + ], + "type": "TSVoidKeyword", + }, + }, + "type": "TSConstructorType", + }, + }, + }, + "init": null, + "loc": Object { + "end": Object { + "column": 42, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 42, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "let", + "loc": Object { + "end": Object { + "column": 43, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 43, + ], + "type": "VariableDeclaration", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, }, + }, + "range": Array [ + 0, + 44, + ], + "sourceType": "script", + "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 27, + "column": 3, "line": 1, }, "start": Object { - "column": 26, + "column": 0, "line": 1, }, }, "range": Array [ - 26, - 27, + 0, + 3, + ], + "type": "Keyword", + "value": "let", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 5, ], "type": "Identifier", - "value": "a", + "value": "f", }, Object { "loc": Object { "end": Object { - "column": 28, + "column": 6, "line": 1, }, "start": Object { - "column": 27, + "column": 5, "line": 1, }, }, "range": Array [ - 27, - 28, + 5, + 6, ], "type": "Punctuator", "value": ":", @@ -110635,233 +112499,251 @@ Object { Object { "loc": Object { "end": Object { - "column": 34, + "column": 10, "line": 1, }, "start": Object { - "column": 29, + "column": 7, "line": 1, }, }, "range": Array [ - 29, - 34, + 7, + 10, ], - "type": "Identifier", - "value": "infer", + "type": "Keyword", + "value": "new", }, Object { "loc": Object { "end": Object { - "column": 36, + "column": 12, "line": 1, }, "start": Object { - "column": 35, + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 12, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 12, "line": 1, }, }, "range": Array [ - 35, - 36, + 12, + 13, ], "type": "Identifier", - "value": "U", + "value": "a", }, Object { "loc": Object { "end": Object { - "column": 37, + "column": 14, "line": 1, }, "start": Object { - "column": 36, + "column": 13, "line": 1, }, }, "range": Array [ - 36, - 37, + 13, + 14, ], "type": "Punctuator", - "value": ",", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 39, + "column": 21, "line": 1, }, "start": Object { - "column": 38, + "column": 15, "line": 1, }, }, "range": Array [ - 38, - 39, + 15, + 21, ], "type": "Identifier", - "value": "b", + "value": "number", }, Object { "loc": Object { "end": Object { - "column": 40, + "column": 22, "line": 1, }, "start": Object { - "column": 39, + "column": 21, "line": 1, }, }, "range": Array [ - 39, - 40, + 21, + 22, ], "type": "Punctuator", - "value": ":", + "value": ",", }, Object { "loc": Object { "end": Object { - "column": 46, + "column": 24, "line": 1, }, "start": Object { - "column": 41, + "column": 23, "line": 1, }, }, "range": Array [ - 41, - 46, + 23, + 24, ], "type": "Identifier", - "value": "infer", + "value": "b", }, Object { "loc": Object { "end": Object { - "column": 48, + "column": 25, "line": 1, }, "start": Object { - "column": 47, + "column": 24, "line": 1, }, }, "range": Array [ - 47, - 48, + 24, + 25, ], - "type": "Identifier", - "value": "U", + "type": "Punctuator", + "value": "?", }, Object { "loc": Object { "end": Object { - "column": 50, + "column": 26, "line": 1, }, "start": Object { - "column": 49, + "column": 25, "line": 1, }, }, "range": Array [ - 49, - 50, + 25, + 26, ], "type": "Punctuator", - "value": "}", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 52, + "column": 33, "line": 1, }, "start": Object { - "column": 51, + "column": 27, "line": 1, }, }, "range": Array [ - 51, - 52, + 27, + 33, ], - "type": "Punctuator", - "value": "?", + "type": "Identifier", + "value": "number", }, Object { "loc": Object { "end": Object { - "column": 54, + "column": 34, "line": 1, }, "start": Object { - "column": 53, + "column": 33, "line": 1, }, }, "range": Array [ - 53, - 54, + 33, + 34, ], - "type": "Identifier", - "value": "U", + "type": "Punctuator", + "value": ")", }, Object { "loc": Object { "end": Object { - "column": 56, + "column": 37, "line": 1, }, "start": Object { - "column": 55, + "column": 35, "line": 1, }, }, "range": Array [ - 55, - 56, + 35, + 37, ], "type": "Punctuator", - "value": ":", + "value": "=>", }, Object { "loc": Object { "end": Object { - "column": 62, + "column": 42, "line": 1, }, "start": Object { - "column": 57, + "column": 38, "line": 1, }, }, "range": Array [ - 57, - 62, + 38, + 42, ], - "type": "Identifier", - "value": "never", + "type": "Keyword", + "value": "void", }, Object { "loc": Object { "end": Object { - "column": 63, + "column": 43, "line": 1, }, "start": Object { - "column": 62, + "column": 42, "line": 1, }, }, "range": Array [ - 62, - 63, + 42, + 43, ], "type": "Punctuator", "value": ";", @@ -110871,7 +112753,7 @@ Object { } `; -exports[`typescript fixtures/types/conditional-with-null.src 1`] = ` +exports[`typescript fixtures/types/constructor-generic.src 1`] = ` Object { "body": Array [ Object { @@ -110880,7 +112762,7 @@ Object { "id": Object { "loc": Object { "end": Object { - "column": 45, + "column": 25, "line": 1, }, "start": Object { @@ -110888,16 +112770,16 @@ Object { "line": 1, }, }, - "name": "x", + "name": "f", "range": Array [ 4, - 45, + 25, ], "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 45, + "column": 25, "line": 1, }, "start": Object { @@ -110907,100 +112789,210 @@ Object { }, "range": Array [ 5, - 45, + 25, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { - "checkType": Object { - "loc": Object { - "end": Object { - "column": 13, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, - }, + "loc": Object { + "end": Object { + "column": 25, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, }, - "range": Array [ - 7, - 13, - ], - "type": "TSNumberKeyword", }, - "extendsType": Object { - "loc": Object { - "end": Object { - "column": 28, - "line": 1, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, }, - "start": Object { - "column": 22, - "line": 1, + "name": "a", + "range": Array [ + 15, + 19, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 16, + "line": 1, + }, + }, + "range": Array [ + 16, + 19, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 18, + 19, + ], + "type": "Identifier", + }, + }, }, }, - "range": Array [ - 22, - 28, - ], - "type": "TSStringKeyword", - }, - "falseType": Object { + ], + "range": Array [ + 7, + 25, + ], + "returnType": Object { "loc": Object { "end": Object { - "column": 45, + "column": 25, "line": 1, }, "start": Object { - "column": 41, + "column": 21, "line": 1, }, }, "range": Array [ - 41, - 45, + 21, + 25, ], - "type": "TSNullKeyword", - }, - "loc": Object { - "end": Object { - "column": 45, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 1, + }, + "start": Object { + "column": 24, + "line": 1, + }, + }, + "range": Array [ + 24, + 25, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 1, + }, + "start": Object { + "column": 24, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 24, + 25, + ], + "type": "Identifier", + }, }, }, - "range": Array [ - 7, - 45, - ], - "trueType": Object { + "type": "TSConstructorType", + "typeParameters": Object { "loc": Object { "end": Object { - "column": 38, + "column": 14, "line": 1, }, "start": Object { - "column": 31, + "column": 11, "line": 1, }, }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "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, + ], + "type": "TSTypeParameter", + }, + ], "range": Array [ - 31, - 38, + 11, + 14, ], - "type": "TSBooleanKeyword", + "type": "TSTypeParameterDeclaration", }, - "type": "TSConditionalType", }, }, }, "init": null, "loc": Object { "end": Object { - "column": 45, + "column": 25, "line": 1, }, "start": Object { @@ -111010,7 +113002,7 @@ Object { }, "range": Array [ 4, - 45, + 25, ], "type": "VariableDeclarator", }, @@ -111018,7 +113010,7 @@ Object { "kind": "let", "loc": Object { "end": Object { - "column": 46, + "column": 26, "line": 1, }, "start": Object { @@ -111028,7 +113020,7 @@ Object { }, "range": Array [ 0, - 46, + 26, ], "type": "VariableDeclaration", }, @@ -111045,7 +113037,7 @@ Object { }, "range": Array [ 0, - 47, + 27, ], "sourceType": "script", "tokens": Array [ @@ -111083,7 +113075,7 @@ Object { 5, ], "type": "Identifier", - "value": "x", + "value": "f", }, Object { "loc": Object { @@ -111106,7 +113098,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 13, + "column": 10, "line": 1, }, "start": Object { @@ -111116,15 +113108,69 @@ Object { }, "range": Array [ 7, + 10, + ], + "type": "Keyword", + "value": "new", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 12, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "range": Array [ + 12, 13, ], "type": "Identifier", - "value": "number", + "value": "T", }, Object { "loc": Object { "end": Object { - "column": 21, + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, "line": 1, }, "start": Object { @@ -111134,115 +113180,133 @@ Object { }, "range": Array [ 14, - 21, + 15, ], - "type": "Keyword", - "value": "extends", + "type": "Punctuator", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 28, + "column": 16, "line": 1, }, "start": Object { - "column": 22, + "column": 15, "line": 1, }, }, "range": Array [ - 22, - 28, + 15, + 16, ], "type": "Identifier", - "value": "string", + "value": "a", }, Object { "loc": Object { "end": Object { - "column": 30, + "column": 17, "line": 1, }, "start": Object { - "column": 29, + "column": 16, "line": 1, }, }, "range": Array [ - 29, - 30, + 16, + 17, ], "type": "Punctuator", - "value": "?", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 38, + "column": 19, "line": 1, }, "start": Object { - "column": 31, + "column": 18, "line": 1, }, }, "range": Array [ - 31, - 38, + 18, + 19, ], "type": "Identifier", - "value": "boolean", + "value": "T", }, Object { "loc": Object { "end": Object { - "column": 40, + "column": 20, "line": 1, }, "start": Object { - "column": 39, + "column": 19, "line": 1, }, }, "range": Array [ - 39, - 40, + 19, + 20, ], "type": "Punctuator", - "value": ":", + "value": ")", }, Object { "loc": Object { "end": Object { - "column": 45, + "column": 23, "line": 1, }, "start": Object { - "column": 41, + "column": 21, "line": 1, }, }, "range": Array [ - 41, - 45, + 21, + 23, ], - "type": "Keyword", - "value": "null", + "type": "Punctuator", + "value": "=>", }, Object { "loc": Object { "end": Object { - "column": 46, + "column": 25, "line": 1, }, "start": Object { - "column": 45, + "column": 24, "line": 1, }, }, "range": Array [ - 45, - 46, + 24, + 25, + ], + "type": "Identifier", + "value": "T", + }, + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, + }, + "range": Array [ + 25, + 26, ], "type": "Punctuator", "value": ";", @@ -111252,7 +113316,7 @@ Object { } `; -exports[`typescript fixtures/types/constructor.src 1`] = ` +exports[`typescript fixtures/types/constructor-in-generic.src 1`] = ` Object { "body": Array [ Object { @@ -111261,7 +113325,7 @@ Object { "id": Object { "loc": Object { "end": Object { - "column": 42, + "column": 30, "line": 1, }, "start": Object { @@ -111269,16 +113333,16 @@ Object { "line": 1, }, }, - "name": "f", + "name": "x", "range": Array [ 4, - 42, + 30, ], "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 42, + "column": 30, "line": 1, }, "start": Object { @@ -111288,13 +113352,13 @@ Object { }, "range": Array [ 5, - 42, + 30, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 42, + "column": 30, "line": 1, }, "start": Object { @@ -111302,28 +113366,45 @@ Object { "line": 1, }, }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 1, - }, - "start": Object { - "column": 12, - "line": 1, - }, + "range": Array [ + 7, + 30, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, }, - "name": "a", - "range": Array [ - 12, - 21, - ], - "type": "Identifier", - "typeAnnotation": Object { + "start": Object { + "column": 7, + "line": 1, + }, + }, + "name": "Array", + "range": Array [ + 7, + 12, + ], + "type": "Identifier", + }, + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 30, + "line": 1, + }, + "start": Object { + "column": 12, + "line": 1, + }, + }, + "params": Array [ + Object { "loc": Object { "end": Object { - "column": 21, + "column": 29, "line": 1, }, "start": Object { @@ -111331,130 +113412,61 @@ Object { "line": 1, }, }, + "params": Array [], "range": Array [ 13, - 21, + 29, ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { - "column": 21, + "column": 29, "line": 1, }, "start": Object { - "column": 15, + "column": 20, "line": 1, }, }, "range": Array [ - 15, - 21, + 20, + 29, ], - "type": "TSNumberKeyword", - }, - }, - }, - Object { - "loc": Object { - "end": Object { - "column": 33, - "line": 1, - }, - "start": Object { - "column": 23, - "line": 1, - }, - }, - "name": "b", - "optional": true, - "range": Array [ - 23, - 33, - ], - "type": "Identifier", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 33, - "line": 1, - }, - "start": Object { - "column": 25, - "line": 1, - }, - }, - "range": Array [ - 25, - 33, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 33, - "line": 1, - }, - "start": Object { - "column": 27, - "line": 1, + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 1, + }, + "start": Object { + "column": 23, + "line": 1, + }, }, + "range": Array [ + 23, + 29, + ], + "type": "TSStringKeyword", }, - "range": Array [ - 27, - 33, - ], - "type": "TSNumberKeyword", }, + "type": "TSConstructorType", }, - }, - ], - "range": Array [ - 7, - 42, - ], - "returnType": Object { - "loc": Object { - "end": Object { - "column": 42, - "line": 1, - }, - "start": Object { - "column": 35, - "line": 1, - }, - }, + ], "range": Array [ - 35, - 42, + 12, + 30, ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 42, - "line": 1, - }, - "start": Object { - "column": 38, - "line": 1, - }, - }, - "range": Array [ - 38, - 42, - ], - "type": "TSVoidKeyword", - }, + "type": "TSTypeParameterInstantiation", }, - "type": "TSConstructorType", }, }, }, "init": null, "loc": Object { "end": Object { - "column": 42, + "column": 30, "line": 1, }, "start": Object { @@ -111464,7 +113476,7 @@ Object { }, "range": Array [ 4, - 42, + 30, ], "type": "VariableDeclarator", }, @@ -111472,7 +113484,7 @@ Object { "kind": "let", "loc": Object { "end": Object { - "column": 43, + "column": 31, "line": 1, }, "start": Object { @@ -111482,7 +113494,7 @@ Object { }, "range": Array [ 0, - 43, + 31, ], "type": "VariableDeclaration", }, @@ -111499,7 +113511,7 @@ Object { }, "range": Array [ 0, - 44, + 32, ], "sourceType": "script", "tokens": Array [ @@ -111537,7 +113549,7 @@ Object { 5, ], "type": "Identifier", - "value": "f", + "value": "x", }, Object { "loc": Object { @@ -111560,7 +113572,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 10, + "column": 12, "line": 1, }, "start": Object { @@ -111570,28 +113582,10 @@ Object { }, "range": Array [ 7, - 10, - ], - "type": "Keyword", - "value": "new", - }, - Object { - "loc": Object { - "end": Object { - "column": 12, - "line": 1, - }, - "start": Object { - "column": 11, - "line": 1, - }, - }, - "range": Array [ - 11, 12, ], - "type": "Punctuator", - "value": "(", + "type": "Identifier", + "value": "Array", }, Object { "loc": Object { @@ -111608,13 +113602,13 @@ Object { 12, 13, ], - "type": "Identifier", - "value": "a", + "type": "Punctuator", + "value": "<", }, Object { "loc": Object { "end": Object { - "column": 14, + "column": 16, "line": 1, }, "start": Object { @@ -111624,187 +113618,115 @@ Object { }, "range": Array [ 13, - 14, - ], - "type": "Punctuator", - "value": ":", - }, - Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 1, - }, - "start": Object { - "column": 15, - "line": 1, - }, - }, - "range": Array [ - 15, - 21, + 16, ], - "type": "Identifier", - "value": "number", + "type": "Keyword", + "value": "new", }, Object { "loc": Object { "end": Object { - "column": 22, + "column": 18, "line": 1, }, "start": Object { - "column": 21, + "column": 17, "line": 1, }, }, "range": Array [ - 21, - 22, + 17, + 18, ], "type": "Punctuator", - "value": ",", - }, - Object { - "loc": Object { - "end": Object { - "column": 24, - "line": 1, - }, - "start": Object { - "column": 23, - "line": 1, - }, - }, - "range": Array [ - 23, - 24, - ], - "type": "Identifier", - "value": "b", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 25, + "column": 19, "line": 1, }, "start": Object { - "column": 24, + "column": 18, "line": 1, }, }, "range": Array [ - 24, - 25, + 18, + 19, ], "type": "Punctuator", - "value": "?", + "value": ")", }, Object { "loc": Object { "end": Object { - "column": 26, + "column": 22, "line": 1, }, "start": Object { - "column": 25, + "column": 20, "line": 1, }, }, "range": Array [ - 25, - 26, + 20, + 22, ], "type": "Punctuator", - "value": ":", + "value": "=>", }, Object { "loc": Object { "end": Object { - "column": 33, + "column": 29, "line": 1, }, "start": Object { - "column": 27, + "column": 23, "line": 1, }, }, "range": Array [ - 27, - 33, + 23, + 29, ], "type": "Identifier", - "value": "number", - }, - Object { - "loc": Object { - "end": Object { - "column": 34, - "line": 1, - }, - "start": Object { - "column": 33, - "line": 1, - }, - }, - "range": Array [ - 33, - 34, - ], - "type": "Punctuator", - "value": ")", + "value": "string", }, Object { "loc": Object { "end": Object { - "column": 37, + "column": 30, "line": 1, }, "start": Object { - "column": 35, + "column": 29, "line": 1, }, }, "range": Array [ - 35, - 37, + 29, + 30, ], "type": "Punctuator", - "value": "=>", - }, - Object { - "loc": Object { - "end": Object { - "column": 42, - "line": 1, - }, - "start": Object { - "column": 38, - "line": 1, - }, - }, - "range": Array [ - 38, - 42, - ], - "type": "Keyword", - "value": "void", + "value": ">", }, Object { "loc": Object { "end": Object { - "column": 43, + "column": 31, "line": 1, }, "start": Object { - "column": 42, + "column": 30, "line": 1, }, }, "range": Array [ - 42, - 43, + 30, + 31, ], "type": "Punctuator", "value": ";", @@ -111814,7 +113736,7 @@ Object { } `; -exports[`typescript fixtures/types/constructor-generic.src 1`] = ` +exports[`typescript fixtures/types/constructor-with-rest.src 1`] = ` Object { "body": Array [ Object { @@ -111823,7 +113745,7 @@ Object { "id": Object { "loc": Object { "end": Object { - "column": 25, + "column": 35, "line": 1, }, "start": Object { @@ -111834,13 +113756,13 @@ Object { "name": "f", "range": Array [ 4, - 25, + 35, ], "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 25, + "column": 35, "line": 1, }, "start": Object { @@ -111850,13 +113772,13 @@ Object { }, "range": Array [ 5, - 25, + 35, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 25, + "column": 35, "line": 1, }, "start": Object { @@ -111866,194 +113788,138 @@ Object { }, "params": Array [ Object { - "loc": Object { - "end": Object { - "column": 19, - "line": 1, - }, - "start": Object { - "column": 15, - "line": 1, - }, - }, - "name": "a", - "range": Array [ - 15, - 19, - ], - "type": "Identifier", - "typeAnnotation": Object { + "argument": Object { "loc": Object { "end": Object { - "column": 19, + "column": 16, "line": 1, }, "start": Object { - "column": 16, + "column": 15, "line": 1, }, }, + "name": "a", "range": Array [ + 15, 16, - 19, ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 19, - "line": 1, - }, - "start": Object { - "column": 18, - "line": 1, - }, - }, - "range": Array [ - 18, - 19, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 19, - "line": 1, - }, - "start": Object { - "column": 18, - "line": 1, - }, - }, - "name": "T", - "range": Array [ - 18, - 19, - ], - "type": "Identifier", - }, - }, - }, - }, - ], - "range": Array [ - 7, - 25, - ], - "returnType": Object { - "loc": Object { - "end": Object { - "column": 25, - "line": 1, - }, - "start": Object { - "column": 21, - "line": 1, + "type": "Identifier", }, - }, - "range": Array [ - 21, - 25, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 25, + "column": 26, "line": 1, }, "start": Object { - "column": 24, + "column": 12, "line": 1, }, }, "range": Array [ - 24, - 25, + 12, + 26, ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 25, - "line": 1, - }, - "start": Object { - "column": 24, - "line": 1, - }, - }, - "name": "T", - "range": Array [ - 24, - 25, - ], - "type": "Identifier", - }, - }, - }, - "type": "TSConstructorType", - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 14, - "line": 1, - }, - "start": Object { - "column": 11, - "line": 1, - }, - }, - "params": Array [ - Object { + "type": "RestElement", + "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 13, + "column": 26, "line": 1, }, "start": Object { - "column": 12, + "column": 16, "line": 1, }, }, - "name": Object { + "range": Array [ + 16, + 26, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "elementType": Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 18, + "line": 1, + }, + }, + "range": Array [ + 18, + 24, + ], + "type": "TSNumberKeyword", + }, "loc": Object { "end": Object { - "column": 13, + "column": 26, "line": 1, }, "start": Object { - "column": 12, + "column": 18, "line": 1, }, }, - "name": "T", "range": Array [ - 12, - 13, + 18, + 26, ], - "type": "Identifier", + "type": "TSArrayType", }, - "range": Array [ - 12, - 13, - ], - "type": "TSTypeParameter", }, - ], + }, + ], + "range": Array [ + 7, + 35, + ], + "returnType": Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 1, + }, + "start": Object { + "column": 28, + "line": 1, + }, + }, "range": Array [ - 11, - 14, + 28, + 35, ], - "type": "TSTypeParameterDeclaration", + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 35, + "line": 1, + }, + "start": Object { + "column": 31, + "line": 1, + }, + }, + "range": Array [ + 31, + 35, + ], + "type": "TSVoidKeyword", + }, }, + "type": "TSConstructorType", }, }, }, "init": null, "loc": Object { "end": Object { - "column": 25, + "column": 35, "line": 1, }, "start": Object { @@ -112063,7 +113929,7 @@ Object { }, "range": Array [ 4, - 25, + 35, ], "type": "VariableDeclarator", }, @@ -112071,7 +113937,7 @@ Object { "kind": "let", "loc": Object { "end": Object { - "column": 26, + "column": 36, "line": 1, }, "start": Object { @@ -112081,7 +113947,7 @@ Object { }, "range": Array [ 0, - 26, + 36, ], "type": "VariableDeclaration", }, @@ -112098,7 +113964,7 @@ Object { }, "range": Array [ 0, - 27, + 37, ], "sourceType": "script", "tokens": Array [ @@ -112190,12 +114056,12 @@ Object { 12, ], "type": "Punctuator", - "value": "<", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 13, + "column": 15, "line": 1, }, "start": Object { @@ -112205,115 +114071,115 @@ Object { }, "range": Array [ 12, - 13, + 15, ], - "type": "Identifier", - "value": "T", + "type": "Punctuator", + "value": "...", }, Object { "loc": Object { "end": Object { - "column": 14, + "column": 16, "line": 1, }, "start": Object { - "column": 13, + "column": 15, "line": 1, }, }, "range": Array [ - 13, - 14, + 15, + 16, ], - "type": "Punctuator", - "value": ">", + "type": "Identifier", + "value": "a", }, Object { "loc": Object { "end": Object { - "column": 15, + "column": 17, "line": 1, }, "start": Object { - "column": 14, + "column": 16, "line": 1, }, }, "range": Array [ - 14, - 15, + 16, + 17, ], "type": "Punctuator", - "value": "(", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 16, + "column": 24, "line": 1, }, "start": Object { - "column": 15, + "column": 18, "line": 1, }, }, "range": Array [ - 15, - 16, + 18, + 24, ], "type": "Identifier", - "value": "a", + "value": "number", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 25, "line": 1, }, "start": Object { - "column": 16, + "column": 24, "line": 1, }, }, "range": Array [ - 16, - 17, + 24, + 25, ], "type": "Punctuator", - "value": ":", + "value": "[", }, Object { "loc": Object { "end": Object { - "column": 19, + "column": 26, "line": 1, }, "start": Object { - "column": 18, + "column": 25, "line": 1, }, }, "range": Array [ - 18, - 19, + 25, + 26, ], - "type": "Identifier", - "value": "T", + "type": "Punctuator", + "value": "]", }, Object { "loc": Object { "end": Object { - "column": 20, + "column": 27, "line": 1, }, "start": Object { - "column": 19, + "column": 26, "line": 1, }, }, "range": Array [ - 19, - 20, + 26, + 27, ], "type": "Punctuator", "value": ")", @@ -112321,17 +114187,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 23, + "column": 30, "line": 1, }, "start": Object { - "column": 21, + "column": 28, "line": 1, }, }, "range": Array [ - 21, - 23, + 28, + 30, ], "type": "Punctuator", "value": "=>", @@ -112339,35 +114205,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 25, + "column": 35, "line": 1, }, "start": Object { - "column": 24, + "column": 31, "line": 1, }, }, "range": Array [ - 24, - 25, + 31, + 35, ], - "type": "Identifier", - "value": "T", + "type": "Keyword", + "value": "void", }, Object { "loc": Object { "end": Object { - "column": 26, + "column": 36, "line": 1, }, "start": Object { - "column": 25, + "column": 35, "line": 1, }, }, "range": Array [ - 25, - 26, + 35, + 36, ], "type": "Punctuator", "value": ";", @@ -112377,7 +114243,7 @@ Object { } `; -exports[`typescript fixtures/types/constructor-in-generic.src 1`] = ` +exports[`typescript fixtures/types/function.src 1`] = ` Object { "body": Array [ Object { @@ -112386,7 +114252,7 @@ Object { "id": Object { "loc": Object { "end": Object { - "column": 30, + "column": 38, "line": 1, }, "start": Object { @@ -112394,16 +114260,16 @@ Object { "line": 1, }, }, - "name": "x", + "name": "f", "range": Array [ 4, - 30, + 38, ], "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 30, + "column": 38, "line": 1, }, "start": Object { @@ -112413,13 +114279,13 @@ Object { }, "range": Array [ 5, - 30, + 38, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 30, + "column": 38, "line": 1, }, "start": Object { @@ -112427,107 +114293,159 @@ Object { "line": 1, }, }, - "range": Array [ - 7, - 30, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 12, - "line": 1, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, }, - "start": Object { - "column": 7, - "line": 1, + "name": "a", + "range": Array [ + 8, + 17, + ], + "type": "Identifier", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 9, + "line": 1, + }, + }, + "range": Array [ + 9, + 17, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "range": Array [ + 11, + 17, + ], + "type": "TSNumberKeyword", + }, }, }, - "name": "Array", - "range": Array [ - 7, - 12, - ], - "type": "Identifier", - }, - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 30, - "line": 1, - }, - "start": Object { - "column": 12, - "line": 1, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 1, + }, + "start": Object { + "column": 19, + "line": 1, + }, }, - }, - "params": Array [ - Object { + "name": "b", + "optional": true, + "range": Array [ + 19, + 29, + ], + "type": "Identifier", + "typeAnnotation": Object { "loc": Object { "end": Object { "column": 29, "line": 1, }, "start": Object { - "column": 13, + "column": 21, "line": 1, }, }, - "params": Array [], "range": Array [ - 13, + 21, 29, ], - "returnType": Object { + "type": "TSTypeAnnotation", + "typeAnnotation": Object { "loc": Object { "end": Object { "column": 29, "line": 1, }, "start": Object { - "column": 20, + "column": 23, "line": 1, }, }, "range": Array [ - 20, + 23, 29, ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 29, - "line": 1, - }, - "start": Object { - "column": 23, - "line": 1, - }, - }, - "range": Array [ - 23, - 29, - ], - "type": "TSStringKeyword", - }, + "type": "TSNumberKeyword", }, - "type": "TSConstructorType", }, - ], + }, + ], + "range": Array [ + 7, + 38, + ], + "returnType": Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 1, + }, + "start": Object { + "column": 31, + "line": 1, + }, + }, "range": Array [ - 12, - 30, + 31, + 38, ], - "type": "TSTypeParameterInstantiation", + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 1, + }, + "start": Object { + "column": 34, + "line": 1, + }, + }, + "range": Array [ + 34, + 38, + ], + "type": "TSVoidKeyword", + }, }, + "type": "TSFunctionType", }, }, }, "init": null, "loc": Object { "end": Object { - "column": 30, + "column": 38, "line": 1, }, "start": Object { @@ -112537,7 +114455,7 @@ Object { }, "range": Array [ 4, - 30, + 38, ], "type": "VariableDeclarator", }, @@ -112545,7 +114463,7 @@ Object { "kind": "let", "loc": Object { "end": Object { - "column": 31, + "column": 39, "line": 1, }, "start": Object { @@ -112555,7 +114473,7 @@ Object { }, "range": Array [ 0, - 31, + 39, ], "type": "VariableDeclaration", }, @@ -112572,7 +114490,7 @@ Object { }, "range": Array [ 0, - 32, + 40, ], "sourceType": "script", "tokens": Array [ @@ -112610,7 +114528,7 @@ Object { 5, ], "type": "Identifier", - "value": "x", + "value": "f", }, Object { "loc": Object { @@ -112633,7 +114551,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 12, + "column": 8, "line": 1, }, "start": Object { @@ -112643,46 +114561,64 @@ Object { }, "range": Array [ 7, - 12, + 8, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "range": Array [ + 8, + 9, ], "type": "Identifier", - "value": "Array", + "value": "a", }, Object { "loc": Object { "end": Object { - "column": 13, + "column": 10, "line": 1, }, "start": Object { - "column": 12, + "column": 9, "line": 1, }, }, "range": Array [ - 12, - 13, + 9, + 10, ], "type": "Punctuator", - "value": "<", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 16, + "column": 17, "line": 1, }, "start": Object { - "column": 13, + "column": 11, "line": 1, }, }, "range": Array [ - 13, - 16, + 11, + 17, ], - "type": "Keyword", - "value": "new", + "type": "Identifier", + "value": "number", }, Object { "loc": Object { @@ -112700,30 +114636,30 @@ Object { 18, ], "type": "Punctuator", - "value": "(", + "value": ",", }, Object { "loc": Object { "end": Object { - "column": 19, + "column": 20, "line": 1, }, "start": Object { - "column": 18, + "column": 19, "line": 1, }, }, "range": Array [ - 18, 19, + 20, ], - "type": "Punctuator", - "value": ")", + "type": "Identifier", + "value": "b", }, Object { "loc": Object { "end": Object { - "column": 22, + "column": 21, "line": 1, }, "start": Object { @@ -112733,10 +114669,28 @@ Object { }, "range": Array [ 20, + 21, + ], + "type": "Punctuator", + "value": "?", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, 22, ], "type": "Punctuator", - "value": "=>", + "value": ":", }, Object { "loc": Object { @@ -112754,7 +114708,7 @@ Object { 29, ], "type": "Identifier", - "value": "string", + "value": "number", }, Object { "loc": Object { @@ -112771,23 +114725,59 @@ Object { 29, 30, ], - "type": "Punctuator", - "value": ">", + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 1, + }, + "start": Object { + "column": 31, + "line": 1, + }, + }, + "range": Array [ + 31, + 33, + ], + "type": "Punctuator", + "value": "=>", + }, + Object { + "loc": Object { + "end": Object { + "column": 38, + "line": 1, + }, + "start": Object { + "column": 34, + "line": 1, + }, + }, + "range": Array [ + 34, + 38, + ], + "type": "Keyword", + "value": "void", }, Object { "loc": Object { "end": Object { - "column": 31, + "column": 39, "line": 1, }, "start": Object { - "column": 30, + "column": 38, "line": 1, }, }, "range": Array [ - 30, - 31, + 38, + 39, ], "type": "Punctuator", "value": ";", @@ -112797,7 +114787,7 @@ Object { } `; -exports[`typescript fixtures/types/constructor-with-rest.src 1`] = ` +exports[`typescript fixtures/types/function-generic.src 1`] = ` Object { "body": Array [ Object { @@ -112806,7 +114796,7 @@ Object { "id": Object { "loc": Object { "end": Object { - "column": 35, + "column": 21, "line": 1, }, "start": Object { @@ -112817,13 +114807,13 @@ Object { "name": "f", "range": Array [ 4, - 35, + 21, ], "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 35, + "column": 21, "line": 1, }, "start": Object { @@ -112833,13 +114823,13 @@ Object { }, "range": Array [ 5, - 35, + 21, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 35, + "column": 21, "line": 1, }, "start": Object { @@ -112849,138 +114839,194 @@ Object { }, "params": Array [ Object { - "argument": Object { - "loc": Object { - "end": Object { - "column": 16, - "line": 1, - }, - "start": Object { - "column": 15, - "line": 1, - }, - }, - "name": "a", - "range": Array [ - 15, - 16, - ], - "type": "Identifier", - }, "loc": Object { "end": Object { - "column": 26, + "column": 15, "line": 1, }, "start": Object { - "column": 12, + "column": 11, "line": 1, }, }, + "name": "a", "range": Array [ - 12, - 26, + 11, + 15, ], - "type": "RestElement", + "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 26, + "column": 15, "line": 1, }, "start": Object { - "column": 16, + "column": 12, "line": 1, }, }, "range": Array [ - 16, - 26, + 12, + 15, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { - "elementType": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "TSTypeReference", + "typeName": Object { "loc": Object { "end": Object { - "column": 24, + "column": 15, "line": 1, }, "start": Object { - "column": 18, + "column": 14, "line": 1, }, }, + "name": "T", "range": Array [ - 18, - 24, + 14, + 15, ], - "type": "TSNumberKeyword", - }, - "loc": Object { - "end": Object { - "column": 26, - "line": 1, - }, - "start": Object { - "column": 18, - "line": 1, - }, + "type": "Identifier", }, - "range": Array [ - 18, - 26, - ], - "type": "TSArrayType", }, }, }, ], "range": Array [ 7, - 35, + 21, ], "returnType": Object { "loc": Object { "end": Object { - "column": 35, + "column": 21, "line": 1, }, "start": Object { - "column": 28, + "column": 17, "line": 1, }, }, "range": Array [ - 28, - 35, + 17, + 21, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 35, + "column": 21, "line": 1, }, "start": Object { - "column": 31, + "column": 20, "line": 1, }, }, "range": Array [ - 31, - 35, + 20, + 21, ], - "type": "TSVoidKeyword", + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 20, + 21, + ], + "type": "Identifier", + }, }, }, - "type": "TSConstructorType", + "type": "TSFunctionType", + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 1, + }, + "start": Object { + "column": 7, + "line": 1, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "name": "T", + "range": Array [ + 8, + 9, + ], + "type": "Identifier", + }, + "range": Array [ + 8, + 9, + ], + "type": "TSTypeParameter", + }, + ], + "range": Array [ + 7, + 10, + ], + "type": "TSTypeParameterDeclaration", + }, }, }, }, "init": null, "loc": Object { "end": Object { - "column": 35, + "column": 21, "line": 1, }, "start": Object { @@ -112990,7 +115036,7 @@ Object { }, "range": Array [ 4, - 35, + 21, ], "type": "VariableDeclarator", }, @@ -112998,7 +115044,7 @@ Object { "kind": "let", "loc": Object { "end": Object { - "column": 36, + "column": 22, "line": 1, }, "start": Object { @@ -113008,7 +115054,7 @@ Object { }, "range": Array [ 0, - 36, + 22, ], "type": "VariableDeclaration", }, @@ -113025,7 +115071,7 @@ Object { }, "range": Array [ 0, - 37, + 23, ], "sourceType": "script", "tokens": Array [ @@ -113086,7 +115132,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 10, + "column": 8, "line": 1, }, "start": Object { @@ -113096,151 +115142,133 @@ Object { }, "range": Array [ 7, - 10, - ], - "type": "Keyword", - "value": "new", - }, - Object { - "loc": Object { - "end": Object { - "column": 12, - "line": 1, - }, - "start": Object { - "column": 11, - "line": 1, - }, - }, - "range": Array [ - 11, - 12, + 8, ], "type": "Punctuator", - "value": "(", + "value": "<", }, Object { "loc": Object { "end": Object { - "column": 15, + "column": 9, "line": 1, }, "start": Object { - "column": 12, + "column": 8, "line": 1, }, }, "range": Array [ - 12, - 15, + 8, + 9, ], - "type": "Punctuator", - "value": "...", + "type": "Identifier", + "value": "T", }, Object { "loc": Object { "end": Object { - "column": 16, + "column": 10, "line": 1, }, "start": Object { - "column": 15, + "column": 9, "line": 1, }, }, "range": Array [ - 15, - 16, + 9, + 10, ], - "type": "Identifier", - "value": "a", + "type": "Punctuator", + "value": ">", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 11, "line": 1, }, "start": Object { - "column": 16, + "column": 10, "line": 1, }, }, "range": Array [ - 16, - 17, + 10, + 11, ], "type": "Punctuator", - "value": ":", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 24, + "column": 12, "line": 1, }, "start": Object { - "column": 18, + "column": 11, "line": 1, }, }, "range": Array [ - 18, - 24, + 11, + 12, ], "type": "Identifier", - "value": "number", + "value": "a", }, Object { "loc": Object { "end": Object { - "column": 25, + "column": 13, "line": 1, }, "start": Object { - "column": 24, + "column": 12, "line": 1, }, }, "range": Array [ - 24, - 25, + 12, + 13, ], "type": "Punctuator", - "value": "[", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 26, + "column": 15, "line": 1, }, "start": Object { - "column": 25, + "column": 14, "line": 1, }, }, "range": Array [ - 25, - 26, + 14, + 15, ], - "type": "Punctuator", - "value": "]", + "type": "Identifier", + "value": "T", }, Object { "loc": Object { "end": Object { - "column": 27, + "column": 16, "line": 1, }, "start": Object { - "column": 26, + "column": 15, "line": 1, }, }, "range": Array [ - 26, - 27, + 15, + 16, ], "type": "Punctuator", "value": ")", @@ -113248,17 +115276,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 30, + "column": 19, "line": 1, }, "start": Object { - "column": 28, + "column": 17, "line": 1, }, }, "range": Array [ - 28, - 30, + 17, + 19, ], "type": "Punctuator", "value": "=>", @@ -113266,35 +115294,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 35, + "column": 21, "line": 1, }, "start": Object { - "column": 31, + "column": 20, "line": 1, }, }, "range": Array [ - 31, - 35, + 20, + 21, ], - "type": "Keyword", - "value": "void", + "type": "Identifier", + "value": "T", }, Object { "loc": Object { "end": Object { - "column": 36, + "column": 22, "line": 1, }, "start": Object { - "column": 35, + "column": 21, "line": 1, }, }, "range": Array [ - 35, - 36, + 21, + 22, ], "type": "Punctuator", "value": ";", @@ -113304,7 +115332,7 @@ Object { } `; -exports[`typescript fixtures/types/function.src 1`] = ` +exports[`typescript fixtures/types/function-in-generic.src 1`] = ` Object { "body": Array [ Object { @@ -113313,7 +115341,7 @@ Object { "id": Object { "loc": Object { "end": Object { - "column": 38, + "column": 24, "line": 1, }, "start": Object { @@ -113321,16 +115349,16 @@ Object { "line": 1, }, }, - "name": "f", + "name": "x", "range": Array [ 4, - 38, + 24, ], "type": "Identifier", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 38, + "column": 24, "line": 1, }, "start": Object { @@ -113340,13 +115368,13 @@ Object { }, "range": Array [ 5, - 38, + 24, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 38, + "column": 24, "line": 1, }, "start": Object { @@ -113354,159 +115382,107 @@ Object { "line": 1, }, }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 1, - }, - "start": Object { - "column": 8, - "line": 1, - }, + "range": Array [ + 7, + 24, + ], + "type": "TSTypeReference", + "typeName": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, }, - "name": "a", - "range": Array [ - 8, - 17, - ], - "type": "Identifier", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 1, - }, - "start": Object { - "column": 9, - "line": 1, - }, - }, - "range": Array [ - 9, - 17, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 17, - "line": 1, - }, - "start": Object { - "column": 11, - "line": 1, - }, - }, - "range": Array [ - 11, - 17, - ], - "type": "TSNumberKeyword", - }, + "start": Object { + "column": 7, + "line": 1, }, }, - Object { - "loc": Object { - "end": Object { - "column": 29, - "line": 1, - }, - "start": Object { - "column": 19, - "line": 1, - }, + "name": "Array", + "range": Array [ + 7, + 12, + ], + "type": "Identifier", + }, + "typeParameters": Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 1, }, - "name": "b", - "optional": true, - "range": Array [ - 19, - 29, - ], - "type": "Identifier", - "typeAnnotation": Object { + "start": Object { + "column": 12, + "line": 1, + }, + }, + "params": Array [ + Object { "loc": Object { "end": Object { - "column": 29, + "column": 23, "line": 1, }, "start": Object { - "column": 21, + "column": 13, "line": 1, }, }, + "params": Array [], "range": Array [ - 21, - 29, + 13, + 23, ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { + "returnType": Object { "loc": Object { "end": Object { - "column": 29, + "column": 23, "line": 1, }, "start": Object { - "column": 23, + "column": 16, "line": 1, }, }, "range": Array [ + 16, 23, - 29, ], - "type": "TSNumberKeyword", - }, - }, - }, - ], - "range": Array [ - 7, - 38, - ], - "returnType": Object { - "loc": Object { - "end": Object { - "column": 38, - "line": 1, - }, - "start": Object { - "column": 31, - "line": 1, - }, - }, - "range": Array [ - 31, - 38, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 38, - "line": 1, - }, - "start": Object { - "column": 34, - "line": 1, + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 19, + "line": 1, + }, + }, + "range": Array [ + 19, + 23, + ], + "type": "TSVoidKeyword", + }, }, + "type": "TSFunctionType", }, - "range": Array [ - 34, - 38, - ], - "type": "TSVoidKeyword", - }, + ], + "range": Array [ + 12, + 24, + ], + "type": "TSTypeParameterInstantiation", }, - "type": "TSFunctionType", }, }, }, "init": null, "loc": Object { "end": Object { - "column": 38, + "column": 24, "line": 1, }, "start": Object { @@ -113516,7 +115492,7 @@ Object { }, "range": Array [ 4, - 38, + 24, ], "type": "VariableDeclarator", }, @@ -113524,7 +115500,7 @@ Object { "kind": "let", "loc": Object { "end": Object { - "column": 39, + "column": 25, "line": 1, }, "start": Object { @@ -113534,7 +115510,7 @@ Object { }, "range": Array [ 0, - 39, + 25, ], "type": "VariableDeclaration", }, @@ -113551,7 +115527,7 @@ Object { }, "range": Array [ 0, - 40, + 26, ], "sourceType": "script", "tokens": Array [ @@ -113589,7 +115565,7 @@ Object { 5, ], "type": "Identifier", - "value": "f", + "value": "x", }, Object { "loc": Object { @@ -113612,7 +115588,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 8, + "column": 12, "line": 1, }, "start": Object { @@ -113622,64 +115598,64 @@ Object { }, "range": Array [ 7, - 8, + 12, ], - "type": "Punctuator", - "value": "(", + "type": "Identifier", + "value": "Array", }, Object { "loc": Object { "end": Object { - "column": 9, + "column": 13, "line": 1, }, "start": Object { - "column": 8, + "column": 12, "line": 1, }, }, "range": Array [ - 8, - 9, + 12, + 13, ], - "type": "Identifier", - "value": "a", + "type": "Punctuator", + "value": "<", }, Object { "loc": Object { "end": Object { - "column": 10, + "column": 14, "line": 1, }, "start": Object { - "column": 9, + "column": 13, "line": 1, }, }, "range": Array [ - 9, - 10, + 13, + 14, ], "type": "Punctuator", - "value": ":", + "value": "(", }, Object { "loc": Object { "end": Object { - "column": 17, + "column": 15, "line": 1, }, "start": Object { - "column": 11, + "column": 14, "line": 1, }, }, "range": Array [ - 11, - 17, + 14, + 15, ], - "type": "Identifier", - "value": "number", + "type": "Punctuator", + "value": ")", }, Object { "loc": Object { @@ -113688,21 +115664,21 @@ Object { "line": 1, }, "start": Object { - "column": 17, + "column": 16, "line": 1, }, }, "range": Array [ - 17, + 16, 18, ], "type": "Punctuator", - "value": ",", + "value": "=>", }, Object { "loc": Object { "end": Object { - "column": 20, + "column": 23, "line": 1, }, "start": Object { @@ -113712,51 +115688,15 @@ Object { }, "range": Array [ 19, - 20, - ], - "type": "Identifier", - "value": "b", - }, - Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 1, - }, - "start": Object { - "column": 20, - "line": 1, - }, - }, - "range": Array [ - 20, - 21, - ], - "type": "Punctuator", - "value": "?", - }, - Object { - "loc": Object { - "end": Object { - "column": 22, - "line": 1, - }, - "start": Object { - "column": 21, - "line": 1, - }, - }, - "range": Array [ - 21, - 22, + 23, ], - "type": "Punctuator", - "value": ":", + "type": "Keyword", + "value": "void", }, Object { "loc": Object { "end": Object { - "column": 29, + "column": 24, "line": 1, }, "start": Object { @@ -113766,358 +115706,195 @@ Object { }, "range": Array [ 23, - 29, - ], - "type": "Identifier", - "value": "number", - }, - Object { - "loc": Object { - "end": Object { - "column": 30, - "line": 1, - }, - "start": Object { - "column": 29, - "line": 1, - }, - }, - "range": Array [ - 29, - 30, + 24, ], "type": "Punctuator", - "value": ")", + "value": ">", }, Object { "loc": Object { "end": Object { - "column": 33, + "column": 25, "line": 1, }, "start": Object { - "column": 31, + "column": 24, "line": 1, }, }, "range": Array [ - 31, - 33, + 24, + 25, ], "type": "Punctuator", - "value": "=>", + "value": ";", }, + ], + "type": "Program", +} +`; + +exports[`typescript fixtures/types/function-with-array-destruction.src 1`] = ` +Object { + "body": Array [ Object { - "loc": Object { - "end": Object { - "column": 38, - "line": 1, - }, - "start": Object { - "column": 34, - "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", }, - "range": Array [ - 34, - 38, - ], - "type": "Keyword", - "value": "void", - }, - Object { "loc": Object { "end": Object { - "column": 39, + "column": 28, "line": 1, }, "start": Object { - "column": 38, + "column": 0, "line": 1, }, }, "range": Array [ - 38, - 39, + 0, + 28, ], - "type": "Punctuator", - "value": ";", - }, - ], - "type": "Program", -} -`; - -exports[`typescript fixtures/types/function-generic.src 1`] = ` -Object { - "body": Array [ - Object { - "declarations": Array [ - Object { - "id": Object { + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "params": Array [ + Object { + "elements": Array [ + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "name": "a", + "range": Array [ + 13, + 14, + ], + "type": "Identifier", + }, + ], "loc": Object { "end": Object { - "column": 21, + "column": 20, "line": 1, }, "start": Object { - "column": 4, + "column": 12, "line": 1, }, }, - "name": "f", "range": Array [ - 4, - 21, + 12, + 20, ], - "type": "Identifier", + "type": "ArrayPattern", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 21, + "column": 20, "line": 1, }, "start": Object { - "column": 5, + "column": 15, "line": 1, }, }, "range": Array [ - 5, - 21, + 15, + 20, ], "type": "TSTypeAnnotation", "typeAnnotation": Object { "loc": Object { "end": Object { - "column": 21, + "column": 20, "line": 1, }, "start": Object { - "column": 7, + "column": 17, "line": 1, }, }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 15, - "line": 1, - }, - "start": Object { - "column": 11, - "line": 1, - }, - }, - "name": "a", - "range": Array [ - 11, - 15, - ], - "type": "Identifier", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 15, - "line": 1, - }, - "start": Object { - "column": 12, - "line": 1, - }, - }, - "range": Array [ - 12, - 15, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 15, - "line": 1, - }, - "start": Object { - "column": 14, - "line": 1, - }, - }, - "range": Array [ - 14, - 15, - ], - "type": "TSTypeReference", - "typeName": 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 [ - 7, - 21, + 17, + 20, ], - "returnType": Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 1, - }, - "start": Object { - "column": 17, - "line": 1, - }, - }, - "range": Array [ - 17, - 21, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 1, - }, - "start": Object { - "column": 20, - "line": 1, - }, - }, - "range": Array [ - 20, - 21, - ], - "type": "TSTypeReference", - "typeName": Object { - "loc": Object { - "end": Object { - "column": 21, - "line": 1, - }, - "start": Object { - "column": 20, - "line": 1, - }, - }, - "name": "T", - "range": Array [ - 20, - 21, - ], - "type": "Identifier", - }, - }, - }, - "type": "TSFunctionType", - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 10, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, - }, - }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 9, - "line": 1, - }, - "start": Object { - "column": 8, - "line": 1, - }, - }, - "name": Object { - "loc": Object { - "end": Object { - "column": 9, - "line": 1, - }, - "start": Object { - "column": 8, - "line": 1, - }, - }, - "name": "T", - "range": Array [ - 8, - 9, - ], - "type": "Identifier", - }, - "range": Array [ - 8, - 9, - ], - "type": "TSTypeParameter", - }, - ], - "range": Array [ - 7, - 10, - ], - "type": "TSTypeParameterDeclaration", - }, + "type": "TSAnyKeyword", }, }, }, - "init": null, + ], + "range": Array [ + 11, + 28, + ], + "returnType": Object { "loc": Object { "end": Object { - "column": 21, + "column": 28, "line": 1, }, "start": Object { - "column": 4, + "column": 22, "line": 1, }, }, "range": Array [ - 4, - 21, + 22, + 28, ], - "type": "VariableDeclarator", - }, - ], - "kind": "let", - "loc": Object { - "end": Object { - "column": 22, - "line": 1, - }, - "start": Object { - "column": 0, - "line": 1, - }, - }, - "range": Array [ - 0, - 22, - ], - "type": "VariableDeclaration", + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, + }, + "range": Array [ + 25, + 28, + ], + "type": "TSAnyKeyword", + }, + }, + "type": "TSFunctionType", + }, }, ], "loc": Object { @@ -114132,14 +115909,14 @@ Object { }, "range": Array [ 0, - 23, + 29, ], "sourceType": "script", "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 3, + "column": 4, "line": 1, }, "start": Object { @@ -114149,33 +115926,15 @@ Object { }, "range": Array [ 0, - 3, - ], - "type": "Keyword", - "value": "let", - }, - Object { - "loc": Object { - "end": Object { - "column": 5, - "line": 1, - }, - "start": Object { - "column": 4, - "line": 1, - }, - }, - "range": Array [ 4, - 5, ], "type": "Identifier", - "value": "f", + "value": "type", }, Object { "loc": Object { "end": Object { - "column": 6, + "column": 8, "line": 1, }, "start": Object { @@ -114185,46 +115944,10 @@ Object { }, "range": Array [ 5, - 6, - ], - "type": "Punctuator", - "value": ":", - }, - Object { - "loc": Object { - "end": Object { - "column": 8, - "line": 1, - }, - "start": Object { - "column": 7, - "line": 1, - }, - }, - "range": Array [ - 7, - 8, - ], - "type": "Punctuator", - "value": "<", - }, - Object { - "loc": Object { - "end": Object { - "column": 9, - "line": 1, - }, - "start": Object { - "column": 8, - "line": 1, - }, - }, - "range": Array [ 8, - 9, ], "type": "Identifier", - "value": "T", + "value": "foo", }, Object { "loc": Object { @@ -114242,22 +115965,22 @@ Object { 10, ], "type": "Punctuator", - "value": ">", + "value": "=", }, Object { "loc": Object { "end": Object { - "column": 11, + "column": 12, "line": 1, }, "start": Object { - "column": 10, + "column": 11, "line": 1, }, }, "range": Array [ - 10, 11, + 12, ], "type": "Punctuator", "value": "(", @@ -114265,38 +115988,38 @@ Object { Object { "loc": Object { "end": Object { - "column": 12, + "column": 13, "line": 1, }, "start": Object { - "column": 11, + "column": 12, "line": 1, }, }, "range": Array [ - 11, 12, + 13, ], - "type": "Identifier", - "value": "a", + "type": "Punctuator", + "value": "[", }, Object { "loc": Object { "end": Object { - "column": 13, + "column": 14, "line": 1, }, "start": Object { - "column": 12, + "column": 13, "line": 1, }, }, "range": Array [ - 12, 13, + 14, ], - "type": "Punctuator", - "value": ":", + "type": "Identifier", + "value": "a", }, Object { "loc": Object { @@ -114313,8 +116036,8 @@ Object { 14, 15, ], - "type": "Identifier", - "value": "T", + "type": "Punctuator", + "value": "]", }, Object { "loc": Object { @@ -114332,12 +116055,12 @@ Object { 16, ], "type": "Punctuator", - "value": ")", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 19, + "column": 20, "line": 1, }, "start": Object { @@ -114347,10 +116070,10 @@ Object { }, "range": Array [ 17, - 19, + 20, ], - "type": "Punctuator", - "value": "=>", + "type": "Identifier", + "value": "any", }, Object { "loc": Object { @@ -114367,213 +116090,250 @@ Object { 20, 21, ], - "type": "Identifier", - "value": "T", + "type": "Punctuator", + "value": ")", }, Object { "loc": Object { "end": Object { - "column": 22, + "column": 24, "line": 1, }, "start": Object { - "column": 21, + "column": 22, "line": 1, }, }, "range": Array [ - 21, 22, + 24, ], "type": "Punctuator", - "value": ";", + "value": "=>", + }, + Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, + }, + "range": Array [ + 25, + 28, + ], + "type": "Identifier", + "value": "any", }, ], "type": "Program", } `; -exports[`typescript fixtures/types/function-in-generic.src 1`] = ` +exports[`typescript fixtures/types/function-with-object-destruction.src 1`] = ` Object { "body": Array [ Object { - "declarations": Array [ - Object { - "id": Object { + "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": 28, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 28, + ], + "type": "TSTypeAliasDeclaration", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 11, + "line": 1, + }, + }, + "params": Array [ + Object { "loc": Object { "end": Object { - "column": 24, + "column": 20, "line": 1, }, "start": Object { - "column": 4, + "column": 12, "line": 1, }, }, - "name": "x", - "range": Array [ - 4, - 24, - ], - "type": "Identifier", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 24, - "line": 1, - }, - "start": Object { - "column": 5, - "line": 1, + "properties": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "name": "a", + "range": Array [ + 13, + 14, + ], + "type": "Identifier", }, - }, - "range": Array [ - 5, - 24, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { + "kind": "init", "loc": Object { "end": Object { - "column": 24, + "column": 14, "line": 1, }, "start": Object { - "column": 7, + "column": 13, "line": 1, }, }, + "method": false, "range": Array [ - 7, - 24, + 13, + 14, ], - "type": "TSTypeReference", - "typeName": Object { + "shorthand": true, + "type": "Property", + "value": Object { "loc": Object { "end": Object { - "column": 12, + "column": 14, "line": 1, }, "start": Object { - "column": 7, + "column": 13, "line": 1, }, }, - "name": "Array", + "name": "a", "range": Array [ - 7, - 12, + 13, + 14, ], "type": "Identifier", }, - "typeParameters": Object { - "loc": Object { - "end": Object { - "column": 24, - "line": 1, - }, - "start": Object { - "column": 12, - "line": 1, - }, + }, + ], + "range": Array [ + 12, + 20, + ], + "type": "ObjectPattern", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 20, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 17, + "line": 1, }, - "params": Array [ - Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 1, - }, - "start": Object { - "column": 13, - "line": 1, - }, - }, - "params": Array [], - "range": Array [ - 13, - 23, - ], - "returnType": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 1, - }, - "start": Object { - "column": 16, - "line": 1, - }, - }, - "range": Array [ - 16, - 23, - ], - "type": "TSTypeAnnotation", - "typeAnnotation": Object { - "loc": Object { - "end": Object { - "column": 23, - "line": 1, - }, - "start": Object { - "column": 19, - "line": 1, - }, - }, - "range": Array [ - 19, - 23, - ], - "type": "TSVoidKeyword", - }, - }, - "type": "TSFunctionType", - }, - ], - "range": Array [ - 12, - 24, - ], - "type": "TSTypeParameterInstantiation", }, + "range": Array [ + 17, + 20, + ], + "type": "TSAnyKeyword", }, }, }, - "init": null, + ], + "range": Array [ + 11, + 28, + ], + "returnType": Object { "loc": Object { "end": Object { - "column": 24, + "column": 28, "line": 1, }, "start": Object { - "column": 4, + "column": 22, "line": 1, }, }, "range": Array [ - 4, - 24, + 22, + 28, ], - "type": "VariableDeclarator", - }, - ], - "kind": "let", - "loc": Object { - "end": Object { - "column": 25, - "line": 1, - }, - "start": Object { - "column": 0, - "line": 1, + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 28, + "line": 1, + }, + "start": Object { + "column": 25, + "line": 1, + }, + }, + "range": Array [ + 25, + 28, + ], + "type": "TSAnyKeyword", + }, }, + "type": "TSFunctionType", }, - "range": Array [ - 0, - 25, - ], - "type": "VariableDeclaration", }, ], "loc": Object { @@ -114588,14 +116348,14 @@ Object { }, "range": Array [ 0, - 26, + 29, ], "sourceType": "script", "tokens": Array [ Object { "loc": Object { "end": Object { - "column": 3, + "column": 4, "line": 1, }, "start": Object { @@ -114605,46 +116365,46 @@ Object { }, "range": Array [ 0, - 3, + 4, ], - "type": "Keyword", - "value": "let", + "type": "Identifier", + "value": "type", }, Object { "loc": Object { "end": Object { - "column": 5, + "column": 8, "line": 1, }, "start": Object { - "column": 4, + "column": 5, "line": 1, }, }, "range": Array [ - 4, 5, + 8, ], "type": "Identifier", - "value": "x", + "value": "foo", }, Object { "loc": Object { "end": Object { - "column": 6, + "column": 10, "line": 1, }, "start": Object { - "column": 5, + "column": 9, "line": 1, }, }, "range": Array [ - 5, - 6, + 9, + 10, ], "type": "Punctuator", - "value": ":", + "value": "=", }, Object { "loc": Object { @@ -114653,16 +116413,16 @@ Object { "line": 1, }, "start": Object { - "column": 7, + "column": 11, "line": 1, }, }, "range": Array [ - 7, + 11, 12, ], - "type": "Identifier", - "value": "Array", + "type": "Punctuator", + "value": "(", }, Object { "loc": Object { @@ -114680,7 +116440,7 @@ Object { 13, ], "type": "Punctuator", - "value": "<", + "value": "{", }, Object { "loc": Object { @@ -114697,8 +116457,8 @@ Object { 13, 14, ], - "type": "Punctuator", - "value": "(", + "type": "Identifier", + "value": "a", }, Object { "loc": Object { @@ -114716,43 +116476,61 @@ Object { 15, ], "type": "Punctuator", - "value": ")", + "value": "}", }, Object { "loc": Object { "end": Object { - "column": 18, + "column": 16, "line": 1, }, "start": Object { - "column": 16, + "column": 15, "line": 1, }, }, "range": Array [ + 15, 16, - 18, ], "type": "Punctuator", - "value": "=>", + "value": ":", }, Object { "loc": Object { "end": Object { - "column": 23, + "column": 20, "line": 1, }, "start": Object { - "column": 19, + "column": 17, "line": 1, }, }, "range": Array [ - 19, - 23, + 17, + 20, ], - "type": "Keyword", - "value": "void", + "type": "Identifier", + "value": "any", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 1, + }, + "start": Object { + "column": 20, + "line": 1, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Punctuator", + "value": ")", }, Object { "loc": Object { @@ -114761,34 +116539,34 @@ Object { "line": 1, }, "start": Object { - "column": 23, + "column": 22, "line": 1, }, }, "range": Array [ - 23, + 22, 24, ], "type": "Punctuator", - "value": ">", + "value": "=>", }, Object { "loc": Object { "end": Object { - "column": 25, + "column": 28, "line": 1, }, "start": Object { - "column": 24, + "column": 25, "line": 1, }, }, "range": Array [ - 24, 25, + 28, ], - "type": "Punctuator", - "value": ";", + "type": "Identifier", + "value": "any", }, ], "type": "Program", From 5f3aec9f3397825dd8f61be111798964f864a343 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 7 Feb 2019 08:04:03 -0500 Subject: [PATCH 24/26] feat(eslint-plugin): added new rule promise-function-async (#194) --- packages/eslint-plugin/README.md | 1 + packages/eslint-plugin/ROADMAP.md | 2 +- .../docs/rules/promise-function-async.md | 65 +++++ .../lib/rules/promise-function-async.js | 125 ++++++++ packages/eslint-plugin/lib/utils/types.js | 38 +++ .../tests/lib/rules/promise-function-async.js | 275 ++++++++++++++++++ 6 files changed, 505 insertions(+), 1 deletion(-) create mode 100644 packages/eslint-plugin/docs/rules/promise-function-async.md create mode 100644 packages/eslint-plugin/lib/rules/promise-function-async.js create mode 100644 packages/eslint-plugin/lib/utils/types.js create mode 100644 packages/eslint-plugin/tests/lib/rules/promise-function-async.js diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md index 3807877a073e..90da943b887c 100644 --- a/packages/eslint-plugin/README.md +++ b/packages/eslint-plugin/README.md @@ -145,6 +145,7 @@ Then you should add `airbnb` (or `airbnb-base`) to your `extends` section of `.e | [`@typescript-eslint/no-var-requires`](./docs/rules/no-var-requires.md) | Disallows the use of require statements except in import statements (`no-var-requires` from TSLint) | :heavy_check_mark: | | | [`@typescript-eslint/prefer-interface`](./docs/rules/prefer-interface.md) | Prefer an interface declaration over a type literal (type T = { ... }) (`interface-over-type-literal` from TSLint) | :heavy_check_mark: | :wrench: | | [`@typescript-eslint/prefer-namespace-keyword`](./docs/rules/prefer-namespace-keyword.md) | Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules. (`no-internal-module` from TSLint) | :heavy_check_mark: | :wrench: | +| [`@typescript-eslint/promise-function-async`](./docs/rules/promise-function-async.md) | Requires any function or method that returns a Promise to be marked async. (`promise-function-async` from TSLint) | :heavy_check_mark: | | | [`@typescript-eslint/restrict-plus-operands`](./docs/rules/restrict-plus-operands.md) | When adding two variables, operands must both be of type number or of type string. (`restrict-plus-operands` from TSLint) | | | | [`@typescript-eslint/type-annotation-spacing`](./docs/rules/type-annotation-spacing.md) | Require consistent spacing around type annotations (`typedef-whitespace` from TSLint) | :heavy_check_mark: | :wrench: | diff --git a/packages/eslint-plugin/ROADMAP.md b/packages/eslint-plugin/ROADMAP.md index 48ccaa900b63..444700439669 100644 --- a/packages/eslint-plugin/ROADMAP.md +++ b/packages/eslint-plugin/ROADMAP.md @@ -30,7 +30,7 @@ | [`no-var-requires`] | ✅ | [`@typescript-eslint/no-var-requires`] | | [`only-arrow-functions`] | 🔌 | [`prefer-arrow/prefer-arrow-functions`] | | [`prefer-for-of`] | 🛑 | N/A | -| [`promise-function-async`] | 🛑 | N/A ([relevant plugin][plugin:promise]) | +| [`promise-function-async`] | ✅ | [`@typescript-eslint/promise-function-async`] | | [`typedef`] | 🛑 | N/A | | [`typedef-whitespace`] | ✅ | [`@typescript-eslint/type-annotation-spacing`] | | [`unified-signatures`] | 🛑 | N/A | diff --git a/packages/eslint-plugin/docs/rules/promise-function-async.md b/packages/eslint-plugin/docs/rules/promise-function-async.md new file mode 100644 index 000000000000..c64c25c11b5a --- /dev/null +++ b/packages/eslint-plugin/docs/rules/promise-function-async.md @@ -0,0 +1,65 @@ +# Functions that return promises must be async (promise-function-async) + +Requires any function or method that returns a Promise to be marked async. +Ensures that each function is only capable of: + +- returning a rejected promise, or +- throwing an Error object. + +In contrast, non-`async` `Promise`-returning functions are technically capable of either. +Code that handles the results of those functions will often need to handle both cases, which can get complex. +This rule's practice removes a requirement for creating code to handle both cases. + +## Rule Details + +Examples of **incorrect** code for this rule + +```ts +const arrowFunctionReturnsPromise = () => Promise.resolve('value'); + +function functionDeturnsPromise() { + return Math.random() > 0.5 ? Promise.resolve('value') : false; +} +``` + +Examples of **correct** code for this rule + +```ts +const arrowFunctionReturnsPromise = async () => 'value'; + +async function functionDeturnsPromise() { + return Math.random() > 0.5 ? 'value' : false; +} +``` + +## Options + +Options may be provided as an object with: + +- `allowedPromiseNames` to indicate any extra names of classes or interfaces to be considered Promises when returned. + +In addition, each of the following properties may be provided, and default to `true`: + +- `checkArrowFunctions` +- `checkFunctionDeclarations` +- `checkFunctionExpressions` +- `checkMethodDeclarations` + +```json +{ + "@typescript-eslint/promise-function-async": [ + "error", + { + "allowedPromiseNames": ["Thenable"], + "checkArrowFunctions": true, + "checkFunctionDeclarations": true, + "checkFunctionExpressions": true, + "checkMethodDeclarations": true + } + ] +} +``` + +## Related To + +- TSLint: [promise-function-async](https://palantir.github.io/tslint/rules/promise-function-async) diff --git a/packages/eslint-plugin/lib/rules/promise-function-async.js b/packages/eslint-plugin/lib/rules/promise-function-async.js new file mode 100644 index 000000000000..febbbc2a012b --- /dev/null +++ b/packages/eslint-plugin/lib/rules/promise-function-async.js @@ -0,0 +1,125 @@ +/** + * @fileoverview Requires any function or method that returns a Promise to be marked async + * @author Josh Goldberg + */ +'use strict'; + +const util = require('../util'); +const types = require('../utils/types'); + +//------------------------------------------------------------------------------ +// Rule Definition +//------------------------------------------------------------------------------ + +const defaultOptions = [ + { + allowedPromiseNames: [], + checkArrowFunctions: true, + checkFunctionDeclarations: true, + checkFunctionExpressions: true, + checkMethodDeclarations: true + } +]; + +/** + * @type {import("eslint").Rule.RuleModule} + */ +module.exports = { + meta: { + type: 'suggestion', + docs: { + description: + 'Requires any function or method that returns a Promise to be marked async.', + extraDescription: [util.tslintRule('promise-function-async')], + category: 'TypeScript', + url: util.metaDocsUrl('promise-function-async'), + recommended: 'error' + }, + fixable: null, + messages: { + missingAsync: 'Functions that return promises must be async.' + }, + schema: [ + { + type: 'object', + properties: { + allowedPromiseNames: { + type: 'array', + items: { + type: 'string' + } + }, + checkArrowFunctions: { + type: 'boolean' + }, + checkFunctionDeclarations: { + type: 'boolean' + }, + checkFunctionExpressions: { + type: 'boolean' + }, + checkMethodDeclarations: { + type: 'boolean' + } + }, + additionalProperties: false + } + ] + }, + + create(context) { + const { + allowedPromiseNames, + checkArrowFunctions, + checkFunctionDeclarations, + checkFunctionExpressions, + checkMethodDeclarations + } = util.applyDefault(defaultOptions, context.options)[0]; + + const allAllowedPromiseNames = new Set(['Promise', ...allowedPromiseNames]); + const parserServices = util.getParserServices(context); + const checker = parserServices.program.getTypeChecker(); + + /** + * @param {import("estree").Function} node + */ + function validateNode(node) { + const originalNode = parserServices.esTreeNodeToTSNodeMap.get(node); + const [callSignature] = checker + .getTypeAtLocation(originalNode) + .getCallSignatures(); + const returnType = checker.getReturnTypeOfSignature(callSignature); + + if (!types.containsTypeByName(returnType, allAllowedPromiseNames)) { + return; + } + + context.report({ + messageId: 'missingAsync', + node + }); + } + + return { + ArrowFunctionExpression(node) { + if (checkArrowFunctions && !node.async) { + validateNode(node); + } + }, + FunctionDeclaration(node) { + if (checkFunctionDeclarations && !node.async) { + validateNode(node); + } + }, + FunctionExpression(node) { + if (!!node.parent && node.parent.kind === 'method') { + if (checkMethodDeclarations && !node.async) { + validateNode(node.parent); + } + } else if (checkFunctionExpressions && !node.async) { + validateNode(node); + } + } + }; + } +}; diff --git a/packages/eslint-plugin/lib/utils/types.js b/packages/eslint-plugin/lib/utils/types.js new file mode 100644 index 000000000000..adfb402b72ae --- /dev/null +++ b/packages/eslint-plugin/lib/utils/types.js @@ -0,0 +1,38 @@ +'use strict'; + +const tsutils = require('tsutils'); +const ts = require('typescript'); + +/** + * @param {string} type Type being checked by name. + * @param {Set} allowedNames Symbol names checking on the type. + * @returns {boolean} Whether the type is, extends, or contains any of the allowed names. + */ +function containsTypeByName(type, allowedNames) { + if (tsutils.isTypeFlagSet(type, ts.TypeFlags.Any | ts.TypeFlags.Unknown)) { + return true; + } + + if (tsutils.isTypeReference(type)) { + type = type.target; + } + + if ( + typeof type.symbol !== 'undefined' && + allowedNames.has(type.symbol.name) + ) { + return true; + } + + if (tsutils.isUnionOrIntersectionType(type)) { + return type.types.some(t => containsTypeByName(t, allowedNames)); + } + + const bases = type.getBaseTypes(); + return ( + typeof bases !== 'undefined' && + bases.some(t => containsTypeByName(t, allowedNames)) + ); +} + +exports.containsTypeByName = containsTypeByName; diff --git a/packages/eslint-plugin/tests/lib/rules/promise-function-async.js b/packages/eslint-plugin/tests/lib/rules/promise-function-async.js new file mode 100644 index 000000000000..dddb26046435 --- /dev/null +++ b/packages/eslint-plugin/tests/lib/rules/promise-function-async.js @@ -0,0 +1,275 @@ +/** + * @fileoverview Requires any function or method that returns a Promise to be marked async + * @author Josh Goldberg + */ +'use strict'; + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +const rule = require('../../../lib/rules/promise-function-async'), + RuleTester = require('eslint').RuleTester, + path = require('path'); + +//------------------------------------------------------------------------------ +// Tests +//------------------------------------------------------------------------------ + +const rootDir = path.join(process.cwd(), 'tests/fixtures/'); +const parserOptions = { + ecmaVersion: 2018, + tsconfigRootDir: rootDir, + project: './tsconfig.json' +}; + +const messageId = 'missingAsync'; + +const ruleTester = new RuleTester({ + parserOptions, + parser: '@typescript-eslint/parser' +}); + +ruleTester.run('promise-function-async', rule, { + valid: [ + ` +const nonAsyncNonPromiseArrowFunction = (n: number) => n; + +function nonAsyncNonPromiseFunctionDeclaration(n: number) { return n; } + +const asyncPromiseFunctionExpressionA = async function(p: Promise) { return p; }; +const asyncPromiseFunctionExpressionB = async function() { return new Promise(); }; + +class Test { + public nonAsyncNonPromiseArrowFunction = (n: number) => n; + + public nonAsyncNonPromiseMethod() { + return 0; + } + + public async asyncPromiseMethodA(p: Promise) { + return p; + } + + public async asyncPromiseMethodB() { + return new Promise(); + } +} +` + ], + invalid: [ + { + code: ` +const nonAsyncPromiseFunctionExpressionA = function(p: Promise) { return p; }; + +const nonAsyncPromiseFunctionExpressionB = function() { return new Promise(); }; + +function nonAsyncPromiseFunctionDeclarationA(p: Promise) { return p; } + +function nonAsyncPromiseFunctionDeclarationB() { return new Promise(); } + +const nonAsyncPromiseArrowFunctionA = (p: Promise) => p; + +const nonAsyncPromiseArrowFunctionB = () => new Promise(); + +class Test { + public nonAsyncPromiseMethodA(p: Promise) { + return p; + } + + public nonAsyncPromiseMethodB() { + return new Promise(); + } +} +`, + errors: [ + { + line: 2, + messageId + }, + { + line: 4, + messageId + }, + { + line: 6, + messageId + }, + { + line: 8, + messageId + }, + { + line: 10, + messageId + }, + { + line: 12, + messageId + }, + { + line: 15, + messageId + }, + { + line: 19, + messageId + } + ] + }, + { + code: ` +const nonAsyncPromiseFunctionExpression = function(p: Promise) { return p; }; + +function nonAsyncPromiseFunctionDeclaration(p: Promise) { return p; } + +const nonAsyncPromiseArrowFunction = (p: Promise) => p; + +class Test { + public nonAsyncPromiseMethod(p: Promise) { + return p; + } +} +`, + options: [ + { + checkArrowFunctions: false + } + ], + errors: [ + { + line: 2, + messageId + }, + { + line: 4, + messageId + }, + { + line: 9, + messageId + } + ] + }, + { + code: ` +const nonAsyncPromiseFunctionExpression = function(p: Promise) { return p; }; + +function nonAsyncPromiseFunctionDeclaration(p: Promise) { return p; } + +const nonAsyncPromiseArrowFunction = (p: Promise) => p; + +class Test { + public nonAsyncPromiseMethod(p: Promise) { + return p; + } +} +`, + options: [ + { + checkFunctionDeclarations: false + } + ], + errors: [ + { + line: 2, + messageId + }, + { + line: 6, + messageId + }, + { + line: 9, + messageId + } + ] + }, + { + code: ` +const nonAsyncPromiseFunctionExpression = function(p: Promise) { return p; }; + +function nonAsyncPromiseFunctionDeclaration(p: Promise) { return p; } + +const nonAsyncPromiseArrowFunction = (p: Promise) => p; + +class Test { + public nonAsyncPromiseMethod(p: Promise) { + return p; + } +} +`, + options: [ + { + checkFunctionExpressions: false + } + ], + errors: [ + { + line: 4, + messageId + }, + { + line: 6, + messageId + }, + { + line: 9, + messageId + } + ] + }, + { + code: ` +const nonAsyncPromiseFunctionExpression = function(p: Promise) { return p; }; + +function nonAsyncPromiseFunctionDeclaration(p: Promise) { return p; } + +const nonAsyncPromiseArrowFunction = (p: Promise) => p; + +class Test { + public nonAsyncPromiseMethod(p: Promise) { + return p; + } +} +`, + options: [ + { + checkMethodDeclarations: false + } + ], + errors: [ + { + line: 2, + messageId + }, + { + line: 4, + messageId + }, + { + line: 6, + messageId + } + ] + }, + { + code: ` +class PromiseType { } + +const returnAllowedType = () => new PromiseType(); +`, + options: [ + { + allowedPromiseNames: ['PromiseType'] + } + ], + errors: [ + { + line: 4, + messageId + } + ] + } + ] +}); From 683e5bcf38682cf66c52ba41980f52fa2d0c3bc6 Mon Sep 17 00:00:00 2001 From: Kanitkorn Sujautra Date: Thu, 7 Feb 2019 22:11:15 +0900 Subject: [PATCH 25/26] feat(eslint-plugin): add new rule no-require-imports (#199) --- packages/eslint-plugin/README.md | 1 + packages/eslint-plugin/ROADMAP.md | 3 +- .../docs/rules/no-require-imports.md | 34 ++++++++ .../lib/rules/no-require-imports.js | 50 ++++++++++++ .../tests/lib/rules/no-require-imports.js | 81 +++++++++++++++++++ 5 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 packages/eslint-plugin/docs/rules/no-require-imports.md create mode 100644 packages/eslint-plugin/lib/rules/no-require-imports.js create mode 100644 packages/eslint-plugin/tests/lib/rules/no-require-imports.js diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md index 90da943b887c..5030ca291751 100644 --- a/packages/eslint-plugin/README.md +++ b/packages/eslint-plugin/README.md @@ -135,6 +135,7 @@ Then you should add `airbnb` (or `airbnb-base`) to your `extends` section of `.e | [`@typescript-eslint/no-non-null-assertion`](./docs/rules/no-non-null-assertion.md) | Disallows non-null assertions using the `!` postfix operator (`no-non-null-assertion` from TSLint) | :heavy_check_mark: | | | [`@typescript-eslint/no-object-literal-type-assertion`](./docs/rules/no-object-literal-type-assertion.md) | Forbids an object literal to appear in a type assertion expression (`no-object-literal-type-assertion` from TSLint) | :heavy_check_mark: | | | [`@typescript-eslint/no-parameter-properties`](./docs/rules/no-parameter-properties.md) | Disallow the use of parameter properties in class constructors. (`no-parameter-properties` from TSLint) | :heavy_check_mark: | | +| [`@typescript-eslint/no-require-imports`](./docs/rules/no-require-imports.md) | Disallows invocation of `require()` (`no-require-imports` from TSLint) | :heavy_check_mark: | | | [`@typescript-eslint/no-this-alias`](./docs/rules/no-this-alias.md) | Disallow aliasing `this` (`no-this-assignment` from TSLint) | | | | [`@typescript-eslint/no-triple-slash-reference`](./docs/rules/no-triple-slash-reference.md) | Disallow `/// ` comments (`no-reference` from TSLint) | :heavy_check_mark: | | | [`@typescript-eslint/no-type-alias`](./docs/rules/no-type-alias.md) | Disallow the use of type aliases (`interface-over-type-literal` from TSLint) | | | diff --git a/packages/eslint-plugin/ROADMAP.md b/packages/eslint-plugin/ROADMAP.md index 444700439669..86f0224f0af5 100644 --- a/packages/eslint-plugin/ROADMAP.md +++ b/packages/eslint-plugin/ROADMAP.md @@ -114,7 +114,7 @@ | [`no-default-export`] | 🔌 | [`import/no-default-export`] | | [`no-duplicate-imports`] | 🔌 | [`import/no-duplicates`] | | [`no-mergeable-namespace`] | 🛑 | N/A | -| [`no-require-imports`] | 🛑 | N/A | +| [`no-require-imports`] | ✅ | [`@typescript-eslint/no-require-imports`] | | [`object-literal-sort-keys`] | 🌓 | [`sort-keys`][sort-keys] [2] | | [`prefer-const`] | 🌟 | [`prefer-const`][prefer-const] | | [`prefer-readonly`] | 🛑 | N/A | @@ -578,6 +578,7 @@ Relevant plugins: [`chai-expect-keywords`](https://github.com/gavinaiken/eslint- [`@typescript-eslint/no-use-before-define`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-use-before-define.md [`@typescript-eslint/restrict-plus-operands`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/restrict-plus-operands.md [`@typescript-eslint/indent`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/indent.md +[`@typescript-eslint/no-require-imports`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-require-imports.md [`@typescript-eslint/array-type`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md [`@typescript-eslint/class-name-casing`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/class-name-casing.md [`@typescript-eslint/interface-name-prefix`]: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/interface-name-prefix.md diff --git a/packages/eslint-plugin/docs/rules/no-require-imports.md b/packages/eslint-plugin/docs/rules/no-require-imports.md new file mode 100644 index 000000000000..0d2b831a1acd --- /dev/null +++ b/packages/eslint-plugin/docs/rules/no-require-imports.md @@ -0,0 +1,34 @@ +# Disallows invocation of `require()` (no-require-imports) + +Prefer the newer ES6-style imports over `require()`. + +## Rule Details + +Examples of **incorrect** code for this rule: + +```ts +var lib = require('lib'); +let lib2 = require('lib2'); +var lib5 = require('lib5'), + lib6 = require('lib6'); +import lib8 = require('lib8'); +``` + +Examples of **correct** code for this rule: + +```ts +import { l } from 'lib'; +var lib3 = load('not_an_import'); +var lib4 = lib2.subImport; +var lib7 = 700; +import lib9 = lib2.anotherSubImport; +import lib10 from 'lib10'; +``` + +## When Not To Use It + +If you don't care about TypeScript module syntax, then you will not need this rule. + +## Compatibility + +- TSLint: [no-require-imports](https://palantir.github.io/tslint/rules/no-require-imports/) diff --git a/packages/eslint-plugin/lib/rules/no-require-imports.js b/packages/eslint-plugin/lib/rules/no-require-imports.js new file mode 100644 index 000000000000..82537a4dcdaa --- /dev/null +++ b/packages/eslint-plugin/lib/rules/no-require-imports.js @@ -0,0 +1,50 @@ +/** + * @fileoverview Disallows invocation of `require()`. + * @author Kanitkorn Sujautra + */ +'use strict'; + +const util = require('../util'); + +//------------------------------------------------------------------------------ +// Rule Definition +//------------------------------------------------------------------------------ + +module.exports = { + meta: { + type: 'problem', + docs: { + description: 'Disallows invocation of `require()`.', + extraDescription: [util.tslintRule('no-require-imports')], + category: 'TypeScript', + url: util.metaDocsUrl('no-require-imports'), + recommended: 'error' + }, + schema: [], + messages: { + noRequireImports: 'A `require()` style import is forbidden.' + } + }, + create(context) { + //---------------------------------------------------------------------- + // Public + //---------------------------------------------------------------------- + + return { + CallExpression(node) { + if (node.callee.name === 'require') { + context.report({ + node, + messageId: 'noRequireImports' + }); + } + }, + TSExternalModuleReference(node) { + context.report({ + node, + messageId: 'noRequireImports' + }); + } + }; + } +}; diff --git a/packages/eslint-plugin/tests/lib/rules/no-require-imports.js b/packages/eslint-plugin/tests/lib/rules/no-require-imports.js new file mode 100644 index 000000000000..1eb40a59c34e --- /dev/null +++ b/packages/eslint-plugin/tests/lib/rules/no-require-imports.js @@ -0,0 +1,81 @@ +/** + * @fileoverview Disallows invocation of `require()`. + * @author Kanitkorn Sujautra + */ +'use strict'; + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +const rule = require('../../../lib/rules/no-require-imports'), + RuleTester = require('eslint').RuleTester; + +//------------------------------------------------------------------------------ +// Tests +//------------------------------------------------------------------------------ + +const ruleTester = new RuleTester({ + parserOptions: { + sourceType: 'module' + }, + parser: '@typescript-eslint/parser' +}); + +ruleTester.run('no-require-imports', rule, { + valid: [ + "import {l} from 'lib'", + "var lib3 = load('not_an_import')", + 'var lib4 = lib2.subImport', + 'var lib7 = 700', + 'import lib9 = lib2.anotherSubImport', + "import lib10 from 'lib10'" + ], + invalid: [ + { + code: "var lib = require('lib')", + errors: [ + { + message: 'A `require()` style import is forbidden.', + line: 1, + column: 11 + } + ] + }, + { + code: "let lib2 = require('lib2')", + errors: [ + { + message: 'A `require()` style import is forbidden.', + line: 1, + column: 12 + } + ] + }, + { + code: "var lib5 = require('lib5'), lib6 = require('lib6')", + errors: [ + { + message: 'A `require()` style import is forbidden.', + line: 1, + column: 12 + }, + { + message: 'A `require()` style import is forbidden.', + line: 1, + column: 36 + } + ] + }, + { + code: "import lib8 = require('lib8')", + errors: [ + { + message: 'A `require()` style import is forbidden.', + line: 1, + column: 15 + } + ] + } + ] +}); From d1784992902a41ffc76e917c6b2227e487c76671 Mon Sep 17 00:00:00 2001 From: James Henry Date: Thu, 7 Feb 2019 08:11:57 -0500 Subject: [PATCH 26/26] chore: publish v1.3.0 --- CHANGELOG.md | 17 +++++++++++++++++ lerna.json | 2 +- packages/eslint-plugin-tslint/CHANGELOG.md | 4 ++++ packages/eslint-plugin-tslint/package.json | 4 ++-- packages/eslint-plugin/CHANGELOG.md | 13 +++++++++++++ packages/eslint-plugin/package.json | 4 ++-- packages/parser/CHANGELOG.md | 13 +++++++++++++ packages/parser/package.json | 6 +++--- packages/shared-fixtures/CHANGELOG.md | 16 ++++++++++++++++ packages/shared-fixtures/package.json | 2 +- packages/typescript-estree/CHANGELOG.md | 13 +++++++++++++ packages/typescript-estree/package.json | 4 ++-- 12 files changed, 87 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbde088c3966..ee67cc587fb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,23 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [1.3.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.2.0...v1.3.0) (2019-02-07) + +### Bug Fixes + +- **eslint-plugin:** fix false positive from adjacent-overload-signatures ([#206](https://github.com/typescript-eslint/typescript-eslint/issues/206)) ([07e950e](https://github.com/typescript-eslint/typescript-eslint/commit/07e950e)) +- **ts-estree:** align typeArguments and typeParameters across nodes ([#223](https://github.com/typescript-eslint/typescript-eslint/issues/223)) ([3306198](https://github.com/typescript-eslint/typescript-eslint/commit/3306198)) +- **ts-estree:** convert decorators on var and fn decs ([#211](https://github.com/typescript-eslint/typescript-eslint/issues/211)) ([0a1777f](https://github.com/typescript-eslint/typescript-eslint/commit/0a1777f)) +- **ts-estree:** fix issues with typeParams in FunctionExpression ([#208](https://github.com/typescript-eslint/typescript-eslint/issues/208)) ([d4dfa3b](https://github.com/typescript-eslint/typescript-eslint/commit/d4dfa3b)) + +### Features + +- change TypeScript version range to >=3.2.1 <3.4.0 ([#184](https://github.com/typescript-eslint/typescript-eslint/issues/184)) ([f513a14](https://github.com/typescript-eslint/typescript-eslint/commit/f513a14)) +- **eslint-plugin:** add new rule no-for-in-array ([#155](https://github.com/typescript-eslint/typescript-eslint/issues/155)) ([84162ba](https://github.com/typescript-eslint/typescript-eslint/commit/84162ba)) +- **eslint-plugin:** add new rule no-require-imports ([#199](https://github.com/typescript-eslint/typescript-eslint/issues/199)) ([683e5bc](https://github.com/typescript-eslint/typescript-eslint/commit/683e5bc)) +- **eslint-plugin:** added new rule promise-function-async ([#194](https://github.com/typescript-eslint/typescript-eslint/issues/194)) ([5f3aec9](https://github.com/typescript-eslint/typescript-eslint/commit/5f3aec9)) +- **ts-estree:** enable errors 1098 and 1099 ([#219](https://github.com/typescript-eslint/typescript-eslint/issues/219)) ([fc50167](https://github.com/typescript-eslint/typescript-eslint/commit/fc50167)) + # [1.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.1...v1.2.0) (2019-02-01) ### Bug Fixes diff --git a/lerna.json b/lerna.json index 77a95bb3fb2c..ba8df5d99378 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "1.2.0", + "version": "1.3.0", "npmClient": "yarn", "useWorkspaces": true, "stream": true diff --git a/packages/eslint-plugin-tslint/CHANGELOG.md b/packages/eslint-plugin-tslint/CHANGELOG.md index ca4b53781cd3..20c017da22b5 100644 --- a/packages/eslint-plugin-tslint/CHANGELOG.md +++ b/packages/eslint-plugin-tslint/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [1.3.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.2.0...v1.3.0) (2019-02-07) + +**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint + # [1.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.1...v1.2.0) (2019-02-01) **Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint diff --git a/packages/eslint-plugin-tslint/package.json b/packages/eslint-plugin-tslint/package.json index 59b66dd7b153..c69652e9c659 100644 --- a/packages/eslint-plugin-tslint/package.json +++ b/packages/eslint-plugin-tslint/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/eslint-plugin-tslint", - "version": "1.2.0", + "version": "1.3.0", "main": "dist/index.js", "typings": "src/index.ts", "description": "TSLint wrapper plugin for ESLint", @@ -34,6 +34,6 @@ "devDependencies": { "@types/eslint": "^4.16.3", "@types/lodash.memoize": "^4.1.4", - "@typescript-eslint/parser": "1.2.0" + "@typescript-eslint/parser": "1.3.0" } } diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md index 6f10e09e6f08..1cecaf46e024 100644 --- a/packages/eslint-plugin/CHANGELOG.md +++ b/packages/eslint-plugin/CHANGELOG.md @@ -3,6 +3,19 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [1.3.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.2.0...v1.3.0) (2019-02-07) + +### Bug Fixes + +- **eslint-plugin:** fix false positive from adjacent-overload-signatures ([#206](https://github.com/typescript-eslint/typescript-eslint/issues/206)) ([07e950e](https://github.com/typescript-eslint/typescript-eslint/commit/07e950e)) + +### Features + +- change TypeScript version range to >=3.2.1 <3.4.0 ([#184](https://github.com/typescript-eslint/typescript-eslint/issues/184)) ([f513a14](https://github.com/typescript-eslint/typescript-eslint/commit/f513a14)) +- **eslint-plugin:** add new rule no-for-in-array ([#155](https://github.com/typescript-eslint/typescript-eslint/issues/155)) ([84162ba](https://github.com/typescript-eslint/typescript-eslint/commit/84162ba)) +- **eslint-plugin:** add new rule no-require-imports ([#199](https://github.com/typescript-eslint/typescript-eslint/issues/199)) ([683e5bc](https://github.com/typescript-eslint/typescript-eslint/commit/683e5bc)) +- **eslint-plugin:** added new rule promise-function-async ([#194](https://github.com/typescript-eslint/typescript-eslint/issues/194)) ([5f3aec9](https://github.com/typescript-eslint/typescript-eslint/commit/5f3aec9)) + # [1.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.1...v1.2.0) (2019-02-01) ### Bug Fixes diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index e710176c4250..7b1c3d4bc204 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/eslint-plugin", - "version": "1.2.0", + "version": "1.3.0", "description": "TypeScript plugin for ESLint", "keywords": [ "eslint", @@ -24,7 +24,7 @@ "recommended:update": "node tools/update-recommended.js" }, "dependencies": { - "@typescript-eslint/parser": "1.2.0", + "@typescript-eslint/parser": "1.3.0", "requireindex": "^1.2.0", "tsutils": "^3.7.0" }, diff --git a/packages/parser/CHANGELOG.md b/packages/parser/CHANGELOG.md index 5e618787d914..7df65d7a587a 100644 --- a/packages/parser/CHANGELOG.md +++ b/packages/parser/CHANGELOG.md @@ -3,6 +3,19 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [1.3.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.2.0...v1.3.0) (2019-02-07) + +### Bug Fixes + +- **ts-estree:** align typeArguments and typeParameters across nodes ([#223](https://github.com/typescript-eslint/typescript-eslint/issues/223)) ([3306198](https://github.com/typescript-eslint/typescript-eslint/commit/3306198)) +- **ts-estree:** convert decorators on var and fn decs ([#211](https://github.com/typescript-eslint/typescript-eslint/issues/211)) ([0a1777f](https://github.com/typescript-eslint/typescript-eslint/commit/0a1777f)) +- **ts-estree:** fix issues with typeParams in FunctionExpression ([#208](https://github.com/typescript-eslint/typescript-eslint/issues/208)) ([d4dfa3b](https://github.com/typescript-eslint/typescript-eslint/commit/d4dfa3b)) + +### Features + +- change TypeScript version range to >=3.2.1 <3.4.0 ([#184](https://github.com/typescript-eslint/typescript-eslint/issues/184)) ([f513a14](https://github.com/typescript-eslint/typescript-eslint/commit/f513a14)) +- **ts-estree:** enable errors 1098 and 1099 ([#219](https://github.com/typescript-eslint/typescript-eslint/issues/219)) ([fc50167](https://github.com/typescript-eslint/typescript-eslint/commit/fc50167)) + # [1.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.1...v1.2.0) (2019-02-01) ### Bug Fixes diff --git a/packages/parser/package.json b/packages/parser/package.json index 8cadc1c74159..5b89a50f1eff 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/parser", - "version": "1.2.0", + "version": "1.3.0", "description": "An ESLint custom parser which leverages TypeScript ESTree", "main": "dist/parser.js", "files": [ @@ -36,13 +36,13 @@ "typescript": "*" }, "dependencies": { - "@typescript-eslint/typescript-estree": "1.2.0", + "@typescript-eslint/typescript-estree": "1.3.0", "eslint-scope": "^4.0.0", "eslint-visitor-keys": "^1.0.0" }, "devDependencies": { "@types/eslint": "^4.16.5", "@types/eslint-visitor-keys": "^1.0.0", - "@typescript-eslint/shared-fixtures": "1.2.0" + "@typescript-eslint/shared-fixtures": "1.3.0" } } diff --git a/packages/shared-fixtures/CHANGELOG.md b/packages/shared-fixtures/CHANGELOG.md index 6ac765de90a1..d6a58a75e6c3 100644 --- a/packages/shared-fixtures/CHANGELOG.md +++ b/packages/shared-fixtures/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [1.3.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.2.0...v1.3.0) (2019-02-07) + + +### Bug Fixes + +* **ts-estree:** align typeArguments and typeParameters across nodes ([#223](https://github.com/typescript-eslint/typescript-eslint/issues/223)) ([3306198](https://github.com/typescript-eslint/typescript-eslint/commit/3306198)) + + +### Features + +* **ts-estree:** enable errors 1098 and 1099 ([#219](https://github.com/typescript-eslint/typescript-eslint/issues/219)) ([fc50167](https://github.com/typescript-eslint/typescript-eslint/commit/fc50167)) + + + + + # [1.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.1...v1.2.0) (2019-02-01) **Note:** Version bump only for package @typescript-eslint/shared-fixtures diff --git a/packages/shared-fixtures/package.json b/packages/shared-fixtures/package.json index 99e0091de873..30339b84cab3 100644 --- a/packages/shared-fixtures/package.json +++ b/packages/shared-fixtures/package.json @@ -1,5 +1,5 @@ { "name": "@typescript-eslint/shared-fixtures", - "version": "1.2.0", + "version": "1.3.0", "private": true } diff --git a/packages/typescript-estree/CHANGELOG.md b/packages/typescript-estree/CHANGELOG.md index a1fc5f4167ef..53d7a048eabe 100644 --- a/packages/typescript-estree/CHANGELOG.md +++ b/packages/typescript-estree/CHANGELOG.md @@ -3,6 +3,19 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [1.3.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.2.0...v1.3.0) (2019-02-07) + +### Bug Fixes + +- **ts-estree:** align typeArguments and typeParameters across nodes ([#223](https://github.com/typescript-eslint/typescript-eslint/issues/223)) ([3306198](https://github.com/typescript-eslint/typescript-eslint/commit/3306198)) +- **ts-estree:** convert decorators on var and fn decs ([#211](https://github.com/typescript-eslint/typescript-eslint/issues/211)) ([0a1777f](https://github.com/typescript-eslint/typescript-eslint/commit/0a1777f)) +- **ts-estree:** fix issues with typeParams in FunctionExpression ([#208](https://github.com/typescript-eslint/typescript-eslint/issues/208)) ([d4dfa3b](https://github.com/typescript-eslint/typescript-eslint/commit/d4dfa3b)) + +### Features + +- change TypeScript version range to >=3.2.1 <3.4.0 ([#184](https://github.com/typescript-eslint/typescript-eslint/issues/184)) ([f513a14](https://github.com/typescript-eslint/typescript-eslint/commit/f513a14)) +- **ts-estree:** enable errors 1098 and 1099 ([#219](https://github.com/typescript-eslint/typescript-eslint/issues/219)) ([fc50167](https://github.com/typescript-eslint/typescript-eslint/commit/fc50167)) + # [1.2.0](https://github.com/typescript-eslint/typescript-eslint/compare/v1.1.1...v1.2.0) (2019-02-01) **Note:** Version bump only for package @typescript-eslint/typescript-estree diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index 50432ba4d214..18b452e4be5d 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/typescript-estree", - "version": "1.2.0", + "version": "1.3.0", "description": "A parser that converts TypeScript source code into an ESTree compatible form", "main": "dist/parser.js", "types": "dist/parser.d.ts", @@ -42,6 +42,6 @@ "typescript": "*" }, "devDependencies": { - "@typescript-eslint/shared-fixtures": "1.2.0" + "@typescript-eslint/shared-fixtures": "1.3.0" } }