Merge pull request #10507 from Microsoft/walk_symbol

Always output something at the end of walkSymbol
This commit is contained in:
Andy 2016-09-12 07:34:49 -07:00 committed by GitHub
commit 37d6ab3e13
25 changed files with 79 additions and 71 deletions

View file

@ -2068,7 +2068,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.
//
@ -2076,37 +2076,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 {
if (symbol) {
const accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing));
/** @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));
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));
// Go up and add our parent.
const parent = getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol);
if (parent) {
walkSymbol(parent, getQualifiedLeftMeaning(meaning), /*endOfChain*/ false);
}
}
if (accessibleSymbolChain) {
for (const accessibleSymbol of accessibleSymbolChain) {
appendParentTypeArgumentsAndSymbolName(accessibleSymbol);
}
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;
}
}
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))) {
// if this is anonymous type break
if (symbol.flags & SymbolFlags.TypeLiteral || symbol.flags & SymbolFlags.ObjectLiteral) {
return;
}
appendParentTypeArgumentsAndSymbolName(symbol);
}
appendParentTypeArgumentsAndSymbolName(symbol);
}
}
@ -2116,11 +2113,11 @@ namespace ts {
const isTypeParameter = symbol.flags & SymbolFlags.TypeParameter;
const typeFormatFlag = TypeFormatFlags.UseFullyQualifiedType & typeFlags;
if (!isTypeParameter && (enclosingDeclaration || typeFormatFlag)) {
walkSymbol(symbol, meaning);
return;
walkSymbol(symbol, meaning, /*endOfChain*/ true);
}
else {
appendParentTypeArgumentsAndSymbolName(symbol);
}
return appendParentTypeArgumentsAndSymbolName(symbol);
}
function buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, symbolStack?: Symbol[]) {

View file

@ -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))

View file

@ -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

View file

@ -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))

View file

@ -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

View file

@ -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))

View file

@ -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

View file

@ -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))

View file

@ -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

View file

@ -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))

View file

@ -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

View file

@ -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))

View file

@ -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

View file

@ -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))

View file

@ -2,10 +2,10 @@
declare module "file1" {
class foo {}
>foo :
>foo : foo
namespace foo {
>foo : typeof
>foo : typeof foo
class A {}
>A : A

View file

@ -10,7 +10,7 @@ import {A} from "./f1";
// change the shape of Array<T>
declare global {
>global : Symbol(, Decl(f2.ts, 0, 23))
>global : Symbol(global, Decl(f2.ts, 0, 23))
interface Array<T> {
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(f2.ts, 3, 16))

View file

@ -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<T> {
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(f2.ts, 4, 16))

View file

@ -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<T> {
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(f2.ts, 4, 16))

View file

@ -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))

View file

@ -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))

View file

@ -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<T> {
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(array.d.ts, 7, 12))

View file

@ -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))

View file

@ -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 ===

View file

@ -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

View file

@ -0,0 +1,11 @@
/// <reference path="fourslash.ts" />
// @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"');