From e5675a8495c1a3c25f00802ffc14746a59fd0fba Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 23 Aug 2016 12:02:03 -0700 Subject: [PATCH 1/5] Always output something at the end of walkSymbol --- src/compiler/checker.ts | 49 ++++++++++--------- .../reference/augmentExportEquals3.symbols | 4 +- .../reference/augmentExportEquals3.types | 4 +- .../reference/augmentExportEquals3_1.symbols | 4 +- .../reference/augmentExportEquals3_1.types | 4 +- .../reference/augmentExportEquals4.symbols | 4 +- .../reference/augmentExportEquals4.types | 4 +- .../reference/augmentExportEquals4_1.symbols | 4 +- .../reference/augmentExportEquals4_1.types | 4 +- .../reference/augmentExportEquals5.symbols | 4 +- .../reference/augmentExportEquals5.types | 4 +- .../reference/augmentExportEquals6.symbols | 4 +- .../reference/augmentExportEquals6.types | 4 +- .../reference/augmentExportEquals6_1.symbols | 4 +- .../reference/augmentExportEquals6_1.types | 4 +- .../moduleAugmentationGlobal1.symbols | 2 +- .../moduleAugmentationGlobal2.symbols | 2 +- .../moduleAugmentationGlobal3.symbols | 2 +- .../moduleAugmentationGlobal4.symbols | 4 +- .../moduleAugmentationGlobal5.symbols | 4 +- ...moduleAugmentationInAmbientModule5.symbols | 2 +- ...module_augmentUninstantiatedModule.symbols | 4 +- .../baselines/reference/systemModule15.types | 4 +- tests/cases/fourslash/jsRequireQuickInfo.ts | 11 +++++ 24 files changed, 76 insertions(+), 64 deletions(-) create mode 100644 tests/cases/fourslash/jsRequireQuickInfo.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3d74190b14..00801fce0c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2058,7 +2058,7 @@ namespace ts { parentSymbol = symbol; } - // const the writer know we just wrote out a symbol. The declaration emitter writer uses + // Let the writer know we just wrote out a symbol. The declaration emitter writer uses // this to determine if an import it has previously seen (and not written out) needs // to be written to the file once the walk of the tree is complete. // @@ -2067,37 +2067,38 @@ namespace ts { // and we could then access that data during declaration emit. writer.trackSymbol(symbol, enclosingDeclaration, meaning); function walkSymbol(symbol: Symbol, meaning: SymbolFlags): void { - if (symbol) { - const accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing)); + function recur(symbol: Symbol, meaning: SymbolFlags, endOfChain?: boolean): void { + if (symbol) { + const accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing)); - if (!accessibleSymbolChain || - needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { + if (!accessibleSymbolChain || + needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { - // Go up and add our parent. - walkSymbol( - getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol), - getQualifiedLeftMeaning(meaning)); - } - - if (accessibleSymbolChain) { - for (const accessibleSymbol of accessibleSymbolChain) { - appendParentTypeArgumentsAndSymbolName(accessibleSymbol); - } - } - else { - // If we didn't find accessible symbol chain for this symbol, break if this is external module - if (!parentSymbol && ts.forEach(symbol.declarations, hasExternalModuleSymbol)) { - return; + // Go up and add our parent. + recur( + getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol), + getQualifiedLeftMeaning(meaning)); } - // if this is anonymous type break - if (symbol.flags & SymbolFlags.TypeLiteral || symbol.flags & SymbolFlags.ObjectLiteral) { - return; + if (accessibleSymbolChain) { + for (const accessibleSymbol of accessibleSymbolChain) { + appendParentTypeArgumentsAndSymbolName(accessibleSymbol); + } } + else if ( + // If this is the last part of outputting the symbol, always output. The cases apply only to parent symbols. + endOfChain || + // If a parent symbol is an external module, don't write it. (We prefer just `x` vs `"foo/bar".x`.) + !(!parentSymbol && ts.forEach(symbol.declarations, hasExternalModuleSymbol)) && + // If a parent symbol is an anonymous type, don't write it. + !(symbol.flags & (SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral))) { - appendParentTypeArgumentsAndSymbolName(symbol); + appendParentTypeArgumentsAndSymbolName(symbol); + } } } + + recur(symbol, meaning, /*endOfChain*/ true); } // Get qualified name if the symbol is not a type parameter diff --git a/tests/baselines/reference/augmentExportEquals3.symbols b/tests/baselines/reference/augmentExportEquals3.symbols index c733886702..485f977321 100644 --- a/tests/baselines/reference/augmentExportEquals3.symbols +++ b/tests/baselines/reference/augmentExportEquals3.symbols @@ -1,10 +1,10 @@ === tests/cases/compiler/file1.ts === function foo() {} ->foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 17), Decl(file2.ts, 1, 8)) +>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 17), Decl(file2.ts, 1, 8)) namespace foo { ->foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 17), Decl(file2.ts, 1, 8)) +>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 17), Decl(file2.ts, 1, 8)) export var v = 1; >v : Symbol(v, Decl(file1.ts, 3, 14)) diff --git a/tests/baselines/reference/augmentExportEquals3.types b/tests/baselines/reference/augmentExportEquals3.types index 4df7bbc60f..47c92ab343 100644 --- a/tests/baselines/reference/augmentExportEquals3.types +++ b/tests/baselines/reference/augmentExportEquals3.types @@ -1,10 +1,10 @@ === tests/cases/compiler/file1.ts === function foo() {} ->foo : typeof +>foo : typeof foo namespace foo { ->foo : typeof +>foo : typeof foo export var v = 1; >v : number diff --git a/tests/baselines/reference/augmentExportEquals3_1.symbols b/tests/baselines/reference/augmentExportEquals3_1.symbols index 09827aaa09..ad3505c283 100644 --- a/tests/baselines/reference/augmentExportEquals3_1.symbols +++ b/tests/baselines/reference/augmentExportEquals3_1.symbols @@ -1,10 +1,10 @@ === tests/cases/compiler/file1.d.ts === declare module "file1" { function foo(): void; ->foo : Symbol(, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25), Decl(file2.ts, 2, 8)) +>foo : Symbol(foo, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25), Decl(file2.ts, 2, 8)) namespace foo { ->foo : Symbol(, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25), Decl(file2.ts, 2, 8)) +>foo : Symbol(foo, Decl(file1.d.ts, 0, 24), Decl(file1.d.ts, 1, 25), Decl(file2.ts, 2, 8)) export var v: number; >v : Symbol(v, Decl(file1.d.ts, 3, 18)) diff --git a/tests/baselines/reference/augmentExportEquals3_1.types b/tests/baselines/reference/augmentExportEquals3_1.types index 8a70a6ec0a..48aa478167 100644 --- a/tests/baselines/reference/augmentExportEquals3_1.types +++ b/tests/baselines/reference/augmentExportEquals3_1.types @@ -1,10 +1,10 @@ === tests/cases/compiler/file1.d.ts === declare module "file1" { function foo(): void; ->foo : typeof +>foo : typeof foo namespace foo { ->foo : typeof +>foo : typeof foo export var v: number; >v : number diff --git a/tests/baselines/reference/augmentExportEquals4.symbols b/tests/baselines/reference/augmentExportEquals4.symbols index 94941693ba..7394e8c6b2 100644 --- a/tests/baselines/reference/augmentExportEquals4.symbols +++ b/tests/baselines/reference/augmentExportEquals4.symbols @@ -1,10 +1,10 @@ === tests/cases/compiler/file1.ts === class foo {} ->foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 8)) +>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 8)) namespace foo { ->foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 8)) +>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 8)) export var v = 1; >v : Symbol(v, Decl(file1.ts, 3, 14)) diff --git a/tests/baselines/reference/augmentExportEquals4.types b/tests/baselines/reference/augmentExportEquals4.types index 3d25ae2dec..8d3b6ecc89 100644 --- a/tests/baselines/reference/augmentExportEquals4.types +++ b/tests/baselines/reference/augmentExportEquals4.types @@ -1,10 +1,10 @@ === tests/cases/compiler/file1.ts === class foo {} ->foo : +>foo : foo namespace foo { ->foo : typeof +>foo : typeof foo export var v = 1; >v : number diff --git a/tests/baselines/reference/augmentExportEquals4_1.symbols b/tests/baselines/reference/augmentExportEquals4_1.symbols index 5c4aadbdf8..9954f71bfb 100644 --- a/tests/baselines/reference/augmentExportEquals4_1.symbols +++ b/tests/baselines/reference/augmentExportEquals4_1.symbols @@ -2,10 +2,10 @@ declare module "file1" { class foo {} ->foo : Symbol(, Decl(file1.d.ts, 1, 24), Decl(file1.d.ts, 2, 16), Decl(file2.ts, 2, 8)) +>foo : Symbol(foo, Decl(file1.d.ts, 1, 24), Decl(file1.d.ts, 2, 16), Decl(file2.ts, 2, 8)) namespace foo { ->foo : Symbol(, Decl(file1.d.ts, 1, 24), Decl(file1.d.ts, 2, 16), Decl(file2.ts, 2, 8)) +>foo : Symbol(foo, Decl(file1.d.ts, 1, 24), Decl(file1.d.ts, 2, 16), Decl(file2.ts, 2, 8)) export var v: number; >v : Symbol(v, Decl(file1.d.ts, 4, 18)) diff --git a/tests/baselines/reference/augmentExportEquals4_1.types b/tests/baselines/reference/augmentExportEquals4_1.types index 9f21928600..a16efb29ce 100644 --- a/tests/baselines/reference/augmentExportEquals4_1.types +++ b/tests/baselines/reference/augmentExportEquals4_1.types @@ -2,10 +2,10 @@ declare module "file1" { class foo {} ->foo : +>foo : foo namespace foo { ->foo : typeof +>foo : typeof foo export var v: number; >v : number diff --git a/tests/baselines/reference/augmentExportEquals5.symbols b/tests/baselines/reference/augmentExportEquals5.symbols index 37fa00bd8c..09da5f32d7 100644 --- a/tests/baselines/reference/augmentExportEquals5.symbols +++ b/tests/baselines/reference/augmentExportEquals5.symbols @@ -16,12 +16,12 @@ declare module Express { declare module "express" { function e(): e.Express; ->e : Symbol(, Decl(express.d.ts, 8, 26), Decl(express.d.ts, 9, 28), Decl(augmentation.ts, 1, 29)) +>e : Symbol(e, Decl(express.d.ts, 8, 26), Decl(express.d.ts, 9, 28), Decl(augmentation.ts, 1, 29)) >e : Symbol(e, Decl(express.d.ts, 8, 26), Decl(express.d.ts, 9, 28)) >Express : Symbol(Express, Decl(express.d.ts, 54, 9)) namespace e { ->e : Symbol(, Decl(express.d.ts, 8, 26), Decl(express.d.ts, 9, 28), Decl(augmentation.ts, 1, 29)) +>e : Symbol(e, Decl(express.d.ts, 8, 26), Decl(express.d.ts, 9, 28), Decl(augmentation.ts, 1, 29)) interface IRoute { >IRoute : Symbol(IRoute, Decl(express.d.ts, 10, 17)) diff --git a/tests/baselines/reference/augmentExportEquals5.types b/tests/baselines/reference/augmentExportEquals5.types index 42b79674df..7d4d765e5e 100644 --- a/tests/baselines/reference/augmentExportEquals5.types +++ b/tests/baselines/reference/augmentExportEquals5.types @@ -16,12 +16,12 @@ declare module Express { declare module "express" { function e(): e.Express; ->e : typeof +>e : typeof e >e : any >Express : Express namespace e { ->e : typeof +>e : typeof e interface IRoute { >IRoute : IRoute diff --git a/tests/baselines/reference/augmentExportEquals6.symbols b/tests/baselines/reference/augmentExportEquals6.symbols index 4af820f24d..9ccf8685af 100644 --- a/tests/baselines/reference/augmentExportEquals6.symbols +++ b/tests/baselines/reference/augmentExportEquals6.symbols @@ -1,10 +1,10 @@ === tests/cases/compiler/file1.ts === class foo {} ->foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 10)) +>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 10)) namespace foo { ->foo : Symbol(, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 10)) +>foo : Symbol(foo, Decl(file1.ts, 0, 0), Decl(file1.ts, 1, 12), Decl(file2.ts, 1, 10)) export class A {} >A : Symbol(A, Decl(file1.ts, 2, 15), Decl(file2.ts, 4, 26)) diff --git a/tests/baselines/reference/augmentExportEquals6.types b/tests/baselines/reference/augmentExportEquals6.types index 1a2b2b22cc..4cb7f3e2b6 100644 --- a/tests/baselines/reference/augmentExportEquals6.types +++ b/tests/baselines/reference/augmentExportEquals6.types @@ -1,10 +1,10 @@ === tests/cases/compiler/file1.ts === class foo {} ->foo : +>foo : foo namespace foo { ->foo : typeof +>foo : typeof foo export class A {} >A : A diff --git a/tests/baselines/reference/augmentExportEquals6_1.symbols b/tests/baselines/reference/augmentExportEquals6_1.symbols index 3db6702448..c66f01e2d1 100644 --- a/tests/baselines/reference/augmentExportEquals6_1.symbols +++ b/tests/baselines/reference/augmentExportEquals6_1.symbols @@ -2,10 +2,10 @@ declare module "file1" { class foo {} ->foo : Symbol(, Decl(file1.d.ts, 1, 24), Decl(file1.d.ts, 2, 16), Decl(file2.ts, 1, 28)) +>foo : Symbol(foo, Decl(file1.d.ts, 1, 24), Decl(file1.d.ts, 2, 16), Decl(file2.ts, 1, 28)) namespace foo { ->foo : Symbol(, Decl(file1.d.ts, 1, 24), Decl(file1.d.ts, 2, 16), Decl(file2.ts, 1, 28)) +>foo : Symbol(foo, Decl(file1.d.ts, 1, 24), Decl(file1.d.ts, 2, 16), Decl(file2.ts, 1, 28)) class A {} >A : Symbol(A, Decl(file1.d.ts, 3, 19), Decl(file2.ts, 4, 24)) diff --git a/tests/baselines/reference/augmentExportEquals6_1.types b/tests/baselines/reference/augmentExportEquals6_1.types index a9cc78056c..9d6042ee65 100644 --- a/tests/baselines/reference/augmentExportEquals6_1.types +++ b/tests/baselines/reference/augmentExportEquals6_1.types @@ -2,10 +2,10 @@ declare module "file1" { class foo {} ->foo : +>foo : foo namespace foo { ->foo : typeof +>foo : typeof foo class A {} >A : A diff --git a/tests/baselines/reference/moduleAugmentationGlobal1.symbols b/tests/baselines/reference/moduleAugmentationGlobal1.symbols index 4115379b0f..53cc4500e0 100644 --- a/tests/baselines/reference/moduleAugmentationGlobal1.symbols +++ b/tests/baselines/reference/moduleAugmentationGlobal1.symbols @@ -10,7 +10,7 @@ import {A} from "./f1"; // change the shape of Array declare global { ->global : Symbol(, Decl(f2.ts, 0, 23)) +>global : Symbol(global, Decl(f2.ts, 0, 23)) interface Array { >Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(f2.ts, 3, 16)) diff --git a/tests/baselines/reference/moduleAugmentationGlobal2.symbols b/tests/baselines/reference/moduleAugmentationGlobal2.symbols index 48fe93353f..0e6d8a6024 100644 --- a/tests/baselines/reference/moduleAugmentationGlobal2.symbols +++ b/tests/baselines/reference/moduleAugmentationGlobal2.symbols @@ -10,7 +10,7 @@ import {A} from "./f1"; >A : Symbol(A, Decl(f2.ts, 2, 8)) declare global { ->global : Symbol(, Decl(f2.ts, 2, 23)) +>global : Symbol(global, Decl(f2.ts, 2, 23)) interface Array { >Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(f2.ts, 4, 16)) diff --git a/tests/baselines/reference/moduleAugmentationGlobal3.symbols b/tests/baselines/reference/moduleAugmentationGlobal3.symbols index 41c7f25b81..1521fbb6e3 100644 --- a/tests/baselines/reference/moduleAugmentationGlobal3.symbols +++ b/tests/baselines/reference/moduleAugmentationGlobal3.symbols @@ -10,7 +10,7 @@ import {A} from "./f1"; >A : Symbol(A, Decl(f2.ts, 2, 8)) declare global { ->global : Symbol(, Decl(f2.ts, 2, 23)) +>global : Symbol(global, Decl(f2.ts, 2, 23)) interface Array { >Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(f2.ts, 4, 16)) diff --git a/tests/baselines/reference/moduleAugmentationGlobal4.symbols b/tests/baselines/reference/moduleAugmentationGlobal4.symbols index f9cdac3fc2..6aaa587234 100644 --- a/tests/baselines/reference/moduleAugmentationGlobal4.symbols +++ b/tests/baselines/reference/moduleAugmentationGlobal4.symbols @@ -1,7 +1,7 @@ === tests/cases/compiler/f1.ts === declare global { ->global : Symbol(, Decl(f1.ts, 0, 0)) +>global : Symbol(global, Decl(f1.ts, 0, 0)) interface Something {x} >Something : Symbol(Something, Decl(f1.ts, 1, 16), Decl(f2.ts, 1, 16)) @@ -11,7 +11,7 @@ export {}; === tests/cases/compiler/f2.ts === declare global { ->global : Symbol(, Decl(f2.ts, 0, 0)) +>global : Symbol(global, Decl(f2.ts, 0, 0)) interface Something {y} >Something : Symbol(Something, Decl(f1.ts, 1, 16), Decl(f2.ts, 1, 16)) diff --git a/tests/baselines/reference/moduleAugmentationGlobal5.symbols b/tests/baselines/reference/moduleAugmentationGlobal5.symbols index 27548b05ef..4c4693601e 100644 --- a/tests/baselines/reference/moduleAugmentationGlobal5.symbols +++ b/tests/baselines/reference/moduleAugmentationGlobal5.symbols @@ -9,7 +9,7 @@ No type information for this code.=== tests/cases/compiler/f1.d.ts === declare module "A" { global { ->global : Symbol(, Decl(f1.d.ts, 1, 20)) +>global : Symbol(global, Decl(f1.d.ts, 1, 20)) interface Something {x} >Something : Symbol(Something, Decl(f1.d.ts, 2, 12), Decl(f2.d.ts, 1, 12)) @@ -19,7 +19,7 @@ declare module "A" { === tests/cases/compiler/f2.d.ts === declare module "B" { global { ->global : Symbol(, Decl(f2.d.ts, 0, 20)) +>global : Symbol(global, Decl(f2.d.ts, 0, 20)) interface Something {y} >Something : Symbol(Something, Decl(f1.d.ts, 2, 12), Decl(f2.d.ts, 1, 12)) diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule5.symbols b/tests/baselines/reference/moduleAugmentationInAmbientModule5.symbols index 76b135307d..a8cc1a3412 100644 --- a/tests/baselines/reference/moduleAugmentationInAmbientModule5.symbols +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule5.symbols @@ -26,7 +26,7 @@ declare module "array" { >A : Symbol(A, Decl(array.d.ts, 6, 12)) global { ->global : Symbol(, Decl(array.d.ts, 6, 24)) +>global : Symbol(global, Decl(array.d.ts, 6, 24)) interface Array { >Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(array.d.ts, 7, 12)) diff --git a/tests/baselines/reference/module_augmentUninstantiatedModule.symbols b/tests/baselines/reference/module_augmentUninstantiatedModule.symbols index d405f9549e..4ea073b025 100644 --- a/tests/baselines/reference/module_augmentUninstantiatedModule.symbols +++ b/tests/baselines/reference/module_augmentUninstantiatedModule.symbols @@ -1,10 +1,10 @@ === tests/cases/compiler/module_augmentUninstantiatedModule.ts === declare module "foo" { namespace M {} ->M : Symbol(, Decl(module_augmentUninstantiatedModule.ts, 0, 22), Decl(module_augmentUninstantiatedModule.ts, 2, 6), Decl(module_augmentUninstantiatedModule.ts, 6, 22)) +>M : Symbol(M, Decl(module_augmentUninstantiatedModule.ts, 0, 22), Decl(module_augmentUninstantiatedModule.ts, 2, 6), Decl(module_augmentUninstantiatedModule.ts, 6, 22)) var M; ->M : Symbol(, Decl(module_augmentUninstantiatedModule.ts, 0, 22), Decl(module_augmentUninstantiatedModule.ts, 2, 6), Decl(module_augmentUninstantiatedModule.ts, 6, 22)) +>M : Symbol(M, Decl(module_augmentUninstantiatedModule.ts, 0, 22), Decl(module_augmentUninstantiatedModule.ts, 2, 6), Decl(module_augmentUninstantiatedModule.ts, 6, 22)) export = M; >M : Symbol(M, Decl(module_augmentUninstantiatedModule.ts, 0, 22), Decl(module_augmentUninstantiatedModule.ts, 2, 6)) diff --git a/tests/baselines/reference/systemModule15.types b/tests/baselines/reference/systemModule15.types index 502638dab9..fa16cc3ce1 100644 --- a/tests/baselines/reference/systemModule15.types +++ b/tests/baselines/reference/systemModule15.types @@ -25,9 +25,9 @@ use(moduleB.moduleC); use(moduleB.moduleCStar); >use(moduleB.moduleCStar) : void >use : (v: any) => void ->moduleB.moduleCStar : typeof +>moduleB.moduleCStar : typeof "tests/cases/compiler/file3" >moduleB : typeof moduleB ->moduleCStar : typeof +>moduleCStar : typeof "tests/cases/compiler/file3" === tests/cases/compiler/file2.ts === diff --git a/tests/cases/fourslash/jsRequireQuickInfo.ts b/tests/cases/fourslash/jsRequireQuickInfo.ts new file mode 100644 index 0000000000..1bf0a3f7f3 --- /dev/null +++ b/tests/cases/fourslash/jsRequireQuickInfo.ts @@ -0,0 +1,11 @@ +/// + +// @allowJs: true +// @Filename: a.js +////const /**/x = require("./b"); + +// @Filename: b.js +////exports.x = 0; + +goTo.marker(); +verify.quickInfoIs('const x: typeof "tests/cases/fourslash/b"'); From d44385577f7f79dbba95703ad6f5eb126710b433 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 24 Aug 2016 06:47:15 -0700 Subject: [PATCH 2/5] Rename function and clean up code --- src/compiler/checker.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 00801fce0c..3e566f1b77 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2067,7 +2067,7 @@ namespace ts { // and we could then access that data during declaration emit. writer.trackSymbol(symbol, enclosingDeclaration, meaning); function walkSymbol(symbol: Symbol, meaning: SymbolFlags): void { - function recur(symbol: Symbol, meaning: SymbolFlags, endOfChain?: boolean): void { + function climbSymbol(symbol: Symbol, meaning: SymbolFlags, endOfChain?: boolean): void { if (symbol) { const accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing)); @@ -2075,7 +2075,7 @@ namespace ts { needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { // Go up and add our parent. - recur( + climbSymbol( getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol), getQualifiedLeftMeaning(meaning)); } @@ -2098,7 +2098,7 @@ namespace ts { } } - recur(symbol, meaning, /*endOfChain*/ true); + climbSymbol(symbol, meaning, /*endOfChain*/ true); } // Get qualified name if the symbol is not a type parameter @@ -2108,10 +2108,10 @@ namespace ts { const typeFormatFlag = TypeFormatFlags.UseFullyQualifiedType & typeFlags; if (!isTypeParameter && (enclosingDeclaration || typeFormatFlag)) { walkSymbol(symbol, meaning); - return; } - - return appendParentTypeArgumentsAndSymbolName(symbol); + else { + appendParentTypeArgumentsAndSymbolName(symbol); + } } function buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, symbolStack?: Symbol[]) { From a9602facdb54f8b2c5d5ec3dcdbcfd60f302bae0 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 25 Aug 2016 06:18:50 -0700 Subject: [PATCH 3/5] Reduce nesting --- src/compiler/checker.ts | 53 +++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3e566f1b77..5020fd4835 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2066,39 +2066,34 @@ namespace ts { // up front (for example, during checking) could determine if we need to emit the imports // and we could then access that data during declaration emit. writer.trackSymbol(symbol, enclosingDeclaration, meaning); - function walkSymbol(symbol: Symbol, meaning: SymbolFlags): void { - function climbSymbol(symbol: Symbol, meaning: SymbolFlags, endOfChain?: boolean): void { - if (symbol) { - const accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing)); + function walkSymbol(symbol: Symbol, meaning: SymbolFlags, endOfChain: boolean): void { + const accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing)); - if (!accessibleSymbolChain || - needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { + if (!accessibleSymbolChain || + needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { - // Go up and add our parent. - climbSymbol( - getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol), - getQualifiedLeftMeaning(meaning)); - } - - if (accessibleSymbolChain) { - for (const accessibleSymbol of accessibleSymbolChain) { - appendParentTypeArgumentsAndSymbolName(accessibleSymbol); - } - } - else if ( - // If this is the last part of outputting the symbol, always output. The cases apply only to parent symbols. - endOfChain || - // If a parent symbol is an external module, don't write it. (We prefer just `x` vs `"foo/bar".x`.) - !(!parentSymbol && ts.forEach(symbol.declarations, hasExternalModuleSymbol)) && - // If a parent symbol is an anonymous type, don't write it. - !(symbol.flags & (SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral))) { - - appendParentTypeArgumentsAndSymbolName(symbol); - } + // Go up and add our parent. + const parent = getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol); + if (parent) { + walkSymbol(parent, getQualifiedLeftMeaning(meaning), /*endOfChain*/ false); } } - climbSymbol(symbol, meaning, /*endOfChain*/ true); + if (accessibleSymbolChain) { + for (const accessibleSymbol of accessibleSymbolChain) { + appendParentTypeArgumentsAndSymbolName(accessibleSymbol); + } + } + else if ( + // If this is the last part of outputting the symbol, always output. The cases apply only to parent symbols. + endOfChain || + // If a parent symbol is an external module, don't write it. (We prefer just `x` vs `"foo/bar".x`.) + !(!parentSymbol && ts.forEach(symbol.declarations, hasExternalModuleSymbol)) && + // If a parent symbol is an anonymous type, don't write it. + !(symbol.flags & (SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral))) { + + appendParentTypeArgumentsAndSymbolName(symbol); + } } // Get qualified name if the symbol is not a type parameter @@ -2107,7 +2102,7 @@ namespace ts { const isTypeParameter = symbol.flags & SymbolFlags.TypeParameter; const typeFormatFlag = TypeFormatFlags.UseFullyQualifiedType & typeFlags; if (!isTypeParameter && (enclosingDeclaration || typeFormatFlag)) { - walkSymbol(symbol, meaning); + walkSymbol(symbol, meaning, /*endOfChain*/ true); } else { appendParentTypeArgumentsAndSymbolName(symbol); From b2db2295eeef1e0721920ca7b2bed2071f72bdcd Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Fri, 9 Sep 2016 12:45:21 -0700 Subject: [PATCH 4/5] Document `endOfChain` --- src/compiler/checker.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5020fd4835..5a5d7ee786 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2066,6 +2066,7 @@ namespace ts { // up front (for example, during checking) could determine if we need to emit the imports // and we could then access that data during declaration emit. writer.trackSymbol(symbol, enclosingDeclaration, meaning); + /** @param endOfChain Set to false for recursive calls; non-recursive calls should always output something. */ function walkSymbol(symbol: Symbol, meaning: SymbolFlags, endOfChain: boolean): void { const accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing)); From 739ec8e54414f0a7ae79f63173426e36bd730a51 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 12 Sep 2016 06:25:54 -0700 Subject: [PATCH 5/5] Update tests --- tests/baselines/reference/umdGlobalConflict.types | 2 +- tests/cases/fourslash/jsRequireQuickInfo.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/umdGlobalConflict.types b/tests/baselines/reference/umdGlobalConflict.types index fa74e26874..d23d42e702 100644 --- a/tests/baselines/reference/umdGlobalConflict.types +++ b/tests/baselines/reference/umdGlobalConflict.types @@ -7,7 +7,7 @@ export var x: string; === tests/cases/compiler/v2/index.d.ts === export as namespace Alpha; ->Alpha : typeof +>Alpha : typeof "tests/cases/compiler/v2/index" export var y: number; >y : number diff --git a/tests/cases/fourslash/jsRequireQuickInfo.ts b/tests/cases/fourslash/jsRequireQuickInfo.ts index 1bf0a3f7f3..3de49830a2 100644 --- a/tests/cases/fourslash/jsRequireQuickInfo.ts +++ b/tests/cases/fourslash/jsRequireQuickInfo.ts @@ -8,4 +8,4 @@ ////exports.x = 0; goTo.marker(); -verify.quickInfoIs('const x: typeof "tests/cases/fourslash/b"'); +verify.quickInfoIs('const x: typeof "/tests/cases/fourslash/b"');