Always output something at the end of walkSymbol

This commit is contained in:
Andy Hanson
2016-08-23 12:05:21 -07:00
parent ddb5a00410
commit e5675a8495
24 changed files with 76 additions and 64 deletions
+25 -24
View File
@@ -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
@@ -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))
@@ -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
@@ -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))
@@ -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
@@ -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))
@@ -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
@@ -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))
@@ -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
@@ -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))
@@ -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
@@ -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))
@@ -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
@@ -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))
@@ -2,10 +2,10 @@
declare module "file1" {
class foo {}
>foo :
>foo : foo
namespace foo {
>foo : typeof
>foo : typeof foo
class A {}
>A : A
@@ -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))
@@ -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))
@@ -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))
@@ -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))
@@ -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))
@@ -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))
@@ -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))
@@ -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 ===
@@ -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"');