1namespace ts { 2 describe("unittests:: services:: extract:: Symbol Walker", () => { 3 function test(description: string, source: string, verifier: (file: SourceFile, checker: TypeChecker) => void) { 4 it(description, () => { 5 const result = Harness.Compiler.compileFiles([{ 6 unitName: "main.ts", 7 content: source 8 }], [], {}, {}, "/"); 9 const file = result.program!.getSourceFile("main.ts")!; 10 const checker = result.program!.getTypeChecker(); 11 verifier(file, checker); 12 }); 13 } 14 15 test("can be created", ` 16interface Bar { 17 x: number; 18 y: number; 19 history: Bar[]; 20} 21export default function foo(a: number, b: Bar): void {}`, (file, checker) => { 22 let foundCount = 0; 23 let stdLibRefSymbols = 0; 24 const expectedSymbols = ["default", "a", "b", "Bar", "x", "y", "history"]; 25 const walker = checker.getSymbolWalker(symbol => { 26 const isStdLibSymbol = forEach(symbol.declarations, d => { 27 return getSourceFileOfNode(d).hasNoDefaultLib; 28 }); 29 if (isStdLibSymbol) { 30 stdLibRefSymbols++; 31 return false; // Don't traverse into the stdlib. That's unnecessary for this test. 32 } 33 assert.equal(symbol.name, expectedSymbols[foundCount]); 34 foundCount++; 35 return true; 36 }); 37 const symbols = checker.getExportsOfModule(file.symbol); 38 for (const symbol of symbols) { 39 walker.walkSymbol(symbol); 40 } 41 assert.equal(foundCount, expectedSymbols.length); 42 assert.equal(stdLibRefSymbols, 1); // Expect 1 stdlib entry symbol - the implicit Array referenced by Bar.history 43 }); 44 }); 45} 46