From fdac435e5cd53e4addc69619caa800be59c2ea0d Mon Sep 17 00:00:00 2001 From: Armano Date: Wed, 6 Feb 2019 02:45:52 +0100 Subject: [PATCH 01/10] 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 ca3d27db77e..bad5cdd6fd5 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 05a20300876..3049a51ae47 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 ee2a44f7b7c..6fb1077a471 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 2f8463cc0a2..60aee02b1a0 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 02/10] 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 db01c0bf521..301ec05cfdf 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 e8dcf0aca78..ddda926b320 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 51d8518fb37..00804abee1f 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 03/10] 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 ddda926b320..564a5ab6a1a 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 dde844c7e15..cfc83e85d3c 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 1d02e2fa671..63b53ce9047 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 8231b96185d..2cd5555bce7 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 21dbbd57efe..c9409877b84 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 9740c4570e7..2ccd8cb9786 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 c2d57246ca0..d06d229a36e 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 04/10] 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 6f4ae3ff203..ef757ac0453 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 00000000000..8370eae3584 --- /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 00000000000..58900f001ee --- /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 00000000000..1dbabedb798 --- /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 00000000000..1c24174dfb9 --- /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 00000000000..97b3b1bd5b9 --- /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 00000000000..266c7827325 --- /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 00000000000..5544096856d --- /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 00000000000..1dbabedb798 --- /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 eb2e69a60ec..da34cb8e7d8 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 f00b7d9ad16..3b9cdfd087c 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 cfc83e85d3c..45c5544625e 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 d1040b3b295..38bc1e93b18 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 05/10] 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 78e946af629..f2ae0e55efd 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 26de602491a..8cadc1c7415 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 2e8ae2e0a3c..f3a6b5f78ac 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 08f92526c82..28de7f8c759 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 be3c3e7506e..78d71197e9f 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 59a2326122c..1efff92648d 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 da34cb8e7d8..3686ba91915 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 aa5a10418c7..4ab71cf5e9a 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 a838db4af13..6ec07b902cd 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 bad5cdd6fd5..bb77a186171 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 00000000000..846392c5443 --- /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 a9a100e6462..af8d17e0157 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 a164288ceb0..531ab1a34d5 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 00804abee1f..95f575e0097 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 06/10] 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 d8eb7950955..0c53769c0e8 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 161ffd4035e..fe42efd1015 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 07/10] 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 cacb6666fdd..3807877a073 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 bd0480101cf..5abf9e26d4e 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 00000000000..3a1cf2bdd37 --- /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 00000000000..23a19732ac4 --- /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 dac41fe21bb..6714e600ee6 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 00000000000..91984453000 --- /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 08/10] 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 ef757ac0453..ac457ec0ca3 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 3686ba91915..bf121fa01bb 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 38bc1e93b18..9c0094cff37 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 09/10] 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 5abf9e26d4e..48ccaa900b6 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 10/10] 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 ac457ec0ca3..876c8b3b43b 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 00000000000..44c7468b366 --- /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 00000000000..a5d4544e0b1 --- /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 00000000000..2517be450da --- /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 00000000000..fdb44b90178 --- /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 169031947d3..f563e404464 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 564a5ab6a1a..8fc5d6acd68 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 45c5544625e..bfbda114841 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 9c0094cff37..b9e876c4595 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",