Skip to content

Commit a2efe47

Browse files
Split symbol baselines from type baselines.
1 parent 05480e3 commit a2efe47

File tree

4,929 files changed

+243430
-87849
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,929 files changed

+243430
-87849
lines changed

src/harness/compilerRunner.ts

+43-17
Original file line numberDiff line numberDiff line change
@@ -270,29 +270,53 @@ class CompilerBaselineRunner extends RunnerBase {
270270
// These types are equivalent, but depend on what order the compiler observed
271271
// certain parts of the program.
272272

273-
var fullWalker = new TypeWriterWalker(program, /*fullTypeCheck:*/ true);
274-
var pullWalker = new TypeWriterWalker(program, /*fullTypeCheck:*/ false);
273+
let allFiles = toBeCompiled.concat(otherFiles).filter(file => !!program.getSourceFile(file.unitName));
275274

276-
var fullTypes = generateTypes(fullWalker);
277-
var pullTypes = generateTypes(pullWalker);
275+
let fullWalker = new TypeWriterWalker(program, /*fullTypeCheck:*/ true);
276+
let pullWalker = new TypeWriterWalker(program, /*fullTypeCheck:*/ false);
278277

279-
if (fullTypes !== pullTypes) {
280-
Harness.Baseline.runBaseline('Correct full expression types for ' + fileName, justName.replace(/\.ts/, '.types'), () => fullTypes);
281-
Harness.Baseline.runBaseline('Correct pull expression types for ' + fileName, justName.replace(/\.ts/, '.types.pull'), () => pullTypes);
278+
let fullResults: ts.Map<TypeWriterResult[]> = {};
279+
let pullResults: ts.Map<TypeWriterResult[]> = {};
280+
281+
for (let sourceFile of allFiles) {
282+
fullResults[sourceFile.unitName] = fullWalker.getTypeAndSymbols(sourceFile.unitName);
283+
pullResults[sourceFile.unitName] = fullWalker.getTypeAndSymbols(sourceFile.unitName);
282284
}
283-
else {
284-
Harness.Baseline.runBaseline('Correct expression types for ' + fileName, justName.replace(/\.ts/, '.types'), () => fullTypes);
285+
286+
// Produce baselines. The first gives the types for all expressions.
287+
// The second gives symbols for all identifiers.
288+
checkBaseLines(/*isSymbolBaseLine:*/ false);
289+
checkBaseLines(/*isSymbolBaseLine:*/ true);
290+
291+
function checkBaseLines(isSymbolBaseLine: boolean) {
292+
let fullBaseLine = generateBaseLine(fullResults, isSymbolBaseLine);
293+
let pullBaseLine = generateBaseLine(pullResults, isSymbolBaseLine);
294+
295+
let fullExtension = isSymbolBaseLine ? '.symbols' : '.types';
296+
let pullExtension = isSymbolBaseLine ? '.symbols.pull' : '.types.pull';
297+
298+
if (fullBaseLine !== pullBaseLine) {
299+
Harness.Baseline.runBaseline('Correct full information for ' + fileName, justName.replace(/\.ts/, fullExtension), () => fullBaseLine);
300+
Harness.Baseline.runBaseline('Correct pull information for ' + fileName, justName.replace(/\.ts/, pullExtension), () => pullBaseLine);
301+
}
302+
else {
303+
Harness.Baseline.runBaseline('Correct information for ' + fileName, justName.replace(/\.ts/, fullExtension), () => fullBaseLine);
304+
}
285305
}
286306

287-
function generateTypes(walker: TypeWriterWalker): string {
288-
var allFiles = toBeCompiled.concat(otherFiles).filter(file => !!program.getSourceFile(file.unitName));
289-
var typeLines: string[] = [];
290-
var typeMap: { [fileName: string]: { [lineNum: number]: string[]; } } = {};
307+
function generateBaseLine(typeWriterResults: ts.Map<TypeWriterResult[]>, isSymbolBaseline: boolean): string {
308+
let typeLines: string[] = [];
309+
let typeMap: { [fileName: string]: { [lineNum: number]: string[]; } } = {};
291310

292311
allFiles.forEach(file => {
293312
var codeLines = file.content.split('\n');
294-
walker.getTypes(file.unitName).forEach(result => {
295-
var formattedLine = result.sourceText.replace(/\r?\n/g, "") + " : " + result.type;
313+
typeWriterResults[file.unitName].forEach(result => {
314+
if (isSymbolBaseline && !result.symbol) {
315+
return;
316+
}
317+
318+
var typeOrSymbolString = isSymbolBaseline ? result.symbol : result.type;
319+
var formattedLine = result.sourceText.replace(/\r?\n/g, "") + " : " + typeOrSymbolString;
296320
if (!typeMap[file.unitName]) {
297321
typeMap[file.unitName] = {};
298322
}
@@ -316,11 +340,13 @@ class CompilerBaselineRunner extends RunnerBase {
316340
typeLines.push('>' + ty + '\r\n');
317341
});
318342
if (i + 1 < codeLines.length && (codeLines[i + 1].match(/^\s*[{|}]\s*$/) || codeLines[i + 1].trim() === '')) {
319-
} else {
343+
}
344+
else {
320345
typeLines.push('\r\n');
321346
}
322347
}
323-
} else {
348+
}
349+
else {
324350
typeLines.push('No type information for this code.');
325351
}
326352
}

src/harness/typeWriter.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ interface TypeWriterResult {
33
syntaxKind: number;
44
sourceText: string;
55
type: string;
6+
symbol: string;
67
}
78

89
class TypeWriterWalker {
@@ -19,7 +20,7 @@ class TypeWriterWalker {
1920
: program.getTypeChecker();
2021
}
2122

22-
public getTypes(fileName: string): TypeWriterResult[] {
23+
public getTypeAndSymbols(fileName: string): TypeWriterResult[] {
2324
var sourceFile = this.program.getSourceFile(fileName);
2425
this.currentSourceFile = sourceFile;
2526
this.results = [];
@@ -45,8 +46,9 @@ class TypeWriterWalker {
4546
var symbol = this.checker.getSymbolAtLocation(node);
4647

4748
var typeString = this.checker.typeToString(type, node.parent, ts.TypeFormatFlags.NoTruncation);
49+
var symbolString: string;
4850
if (symbol) {
49-
var symbolString = "Symbol(" + this.checker.symbolToString(symbol, node.parent);
51+
symbolString = "Symbol(" + this.checker.symbolToString(symbol, node.parent);
5052
if (symbol.declarations) {
5153
for (let declaration of symbol.declarations) {
5254
symbolString += ", ";
@@ -56,15 +58,14 @@ class TypeWriterWalker {
5658
}
5759
}
5860
symbolString += ")";
59-
60-
typeString += ", " + symbolString;
6161
}
6262

6363
this.results.push({
6464
line: lineAndCharacter.line,
6565
syntaxKind: node.kind,
6666
sourceText: sourceText,
67-
type: typeString
67+
type: typeString,
68+
symbol: symbolString
6869
});
6970
}
7071
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
=== tests/cases/compiler/2dArrays.ts ===
2+
class Cell {
3+
>Cell : Symbol(Cell, Decl(2dArrays.ts, 0, 0))
4+
}
5+
6+
class Ship {
7+
>Ship : Symbol(Ship, Decl(2dArrays.ts, 1, 1))
8+
9+
isSunk: boolean;
10+
>isSunk : Symbol(isSunk, Decl(2dArrays.ts, 3, 12))
11+
}
12+
13+
class Board {
14+
>Board : Symbol(Board, Decl(2dArrays.ts, 5, 1))
15+
16+
ships: Ship[];
17+
>ships : Symbol(ships, Decl(2dArrays.ts, 7, 13))
18+
>Ship : Symbol(Ship, Decl(2dArrays.ts, 1, 1))
19+
20+
cells: Cell[];
21+
>cells : Symbol(cells, Decl(2dArrays.ts, 8, 18))
22+
>Cell : Symbol(Cell, Decl(2dArrays.ts, 0, 0))
23+
24+
private allShipsSunk() {
25+
>allShipsSunk : Symbol(allShipsSunk, Decl(2dArrays.ts, 9, 18))
26+
27+
return this.ships.every(function (val) { return val.isSunk; });
28+
>this.ships.every : Symbol(Array.every, Decl(lib.d.ts, 1094, 62))
29+
>this.ships : Symbol(ships, Decl(2dArrays.ts, 7, 13))
30+
>this : Symbol(Board, Decl(2dArrays.ts, 5, 1))
31+
>ships : Symbol(ships, Decl(2dArrays.ts, 7, 13))
32+
>every : Symbol(Array.every, Decl(lib.d.ts, 1094, 62))
33+
>val : Symbol(val, Decl(2dArrays.ts, 12, 42))
34+
>val.isSunk : Symbol(Ship.isSunk, Decl(2dArrays.ts, 3, 12))
35+
>val : Symbol(val, Decl(2dArrays.ts, 12, 42))
36+
>isSunk : Symbol(Ship.isSunk, Decl(2dArrays.ts, 3, 12))
37+
}
38+
}
+18-18
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
=== tests/cases/compiler/2dArrays.ts ===
22
class Cell {
3-
>Cell : Cell, Symbol(Cell, Decl(2dArrays.ts, 0, 0))
3+
>Cell : Cell
44
}
55

66
class Ship {
7-
>Ship : Ship, Symbol(Ship, Decl(2dArrays.ts, 1, 1))
7+
>Ship : Ship
88

99
isSunk: boolean;
10-
>isSunk : boolean, Symbol(isSunk, Decl(2dArrays.ts, 3, 12))
10+
>isSunk : boolean
1111
}
1212

1313
class Board {
14-
>Board : Board, Symbol(Board, Decl(2dArrays.ts, 5, 1))
14+
>Board : Board
1515

1616
ships: Ship[];
17-
>ships : Ship[], Symbol(ships, Decl(2dArrays.ts, 7, 13))
18-
>Ship : Ship, Symbol(Ship, Decl(2dArrays.ts, 1, 1))
17+
>ships : Ship[]
18+
>Ship : Ship
1919

2020
cells: Cell[];
21-
>cells : Cell[], Symbol(cells, Decl(2dArrays.ts, 8, 18))
22-
>Cell : Cell, Symbol(Cell, Decl(2dArrays.ts, 0, 0))
21+
>cells : Cell[]
22+
>Cell : Cell
2323

2424
private allShipsSunk() {
25-
>allShipsSunk : () => boolean, Symbol(allShipsSunk, Decl(2dArrays.ts, 9, 18))
25+
>allShipsSunk : () => boolean
2626

2727
return this.ships.every(function (val) { return val.isSunk; });
2828
>this.ships.every(function (val) { return val.isSunk; }) : boolean
29-
>this.ships.every : (callbackfn: (value: Ship, index: number, array: Ship[]) => boolean, thisArg?: any) => boolean, Symbol(Array.every, Decl(lib.d.ts, 1094, 62))
30-
>this.ships : Ship[], Symbol(ships, Decl(2dArrays.ts, 7, 13))
31-
>this : Board, Symbol(Board, Decl(2dArrays.ts, 5, 1))
32-
>ships : Ship[], Symbol(ships, Decl(2dArrays.ts, 7, 13))
33-
>every : (callbackfn: (value: Ship, index: number, array: Ship[]) => boolean, thisArg?: any) => boolean, Symbol(Array.every, Decl(lib.d.ts, 1094, 62))
29+
>this.ships.every : (callbackfn: (value: Ship, index: number, array: Ship[]) => boolean, thisArg?: any) => boolean
30+
>this.ships : Ship[]
31+
>this : Board
32+
>ships : Ship[]
33+
>every : (callbackfn: (value: Ship, index: number, array: Ship[]) => boolean, thisArg?: any) => boolean
3434
>function (val) { return val.isSunk; } : (val: Ship) => boolean
35-
>val : Ship, Symbol(val, Decl(2dArrays.ts, 12, 42))
36-
>val.isSunk : boolean, Symbol(Ship.isSunk, Decl(2dArrays.ts, 3, 12))
37-
>val : Ship, Symbol(val, Decl(2dArrays.ts, 12, 42))
38-
>isSunk : boolean, Symbol(Ship.isSunk, Decl(2dArrays.ts, 3, 12))
35+
>val : Ship
36+
>val.isSunk : boolean
37+
>val : Ship
38+
>isSunk : boolean
3939
}
4040
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
=== tests/cases/compiler/APISample_compile.ts ===
2+
3+
/*
4+
* Note: This test is a public API sample. The sample sources can be found
5+
at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#a-minimal-compiler
6+
* Please log a "breaking change" issue for any API breaking change affecting this issue
7+
*/
8+
9+
declare var process: any;
10+
>process : Symbol(process, Decl(APISample_compile.ts, 7, 11))
11+
12+
declare var console: any;
13+
>console : Symbol(console, Decl(APISample_compile.ts, 8, 11))
14+
15+
declare var os: any;
16+
>os : Symbol(os, Decl(APISample_compile.ts, 9, 11))
17+
18+
import ts = require("typescript");
19+
>ts : Symbol(ts, Decl(APISample_compile.ts, 9, 20))
20+
21+
export function compile(fileNames: string[], options: ts.CompilerOptions): void {
22+
>compile : Symbol(compile, Decl(APISample_compile.ts, 11, 34))
23+
>fileNames : Symbol(fileNames, Decl(APISample_compile.ts, 13, 24))
24+
>options : Symbol(options, Decl(APISample_compile.ts, 13, 44))
25+
>ts : Symbol(ts, Decl(APISample_compile.ts, 9, 20))
26+
>CompilerOptions : Symbol(ts.CompilerOptions, Decl(typescript.d.ts, 1074, 5))
27+
28+
var program = ts.createProgram(fileNames, options);
29+
>program : Symbol(program, Decl(APISample_compile.ts, 14, 7))
30+
>ts.createProgram : Symbol(ts.createProgram, Decl(typescript.d.ts, 1229, 113))
31+
>ts : Symbol(ts, Decl(APISample_compile.ts, 9, 20))
32+
>createProgram : Symbol(ts.createProgram, Decl(typescript.d.ts, 1229, 113))
33+
>fileNames : Symbol(fileNames, Decl(APISample_compile.ts, 13, 24))
34+
>options : Symbol(options, Decl(APISample_compile.ts, 13, 44))
35+
36+
var emitResult = program.emit();
37+
>emitResult : Symbol(emitResult, Decl(APISample_compile.ts, 15, 7))
38+
>program.emit : Symbol(ts.Program.emit, Decl(typescript.d.ts, 767, 39))
39+
>program : Symbol(program, Decl(APISample_compile.ts, 14, 7))
40+
>emit : Symbol(ts.Program.emit, Decl(typescript.d.ts, 767, 39))
41+
42+
var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
43+
>allDiagnostics : Symbol(allDiagnostics, Decl(APISample_compile.ts, 17, 7))
44+
>ts.getPreEmitDiagnostics(program).concat : Symbol(Array.concat, Decl(lib.d.ts, 1025, 13), Decl(lib.d.ts, 1030, 46))
45+
>ts.getPreEmitDiagnostics : Symbol(ts.getPreEmitDiagnostics, Decl(typescript.d.ts, 1227, 98))
46+
>ts : Symbol(ts, Decl(APISample_compile.ts, 9, 20))
47+
>getPreEmitDiagnostics : Symbol(ts.getPreEmitDiagnostics, Decl(typescript.d.ts, 1227, 98))
48+
>program : Symbol(program, Decl(APISample_compile.ts, 14, 7))
49+
>concat : Symbol(Array.concat, Decl(lib.d.ts, 1025, 13), Decl(lib.d.ts, 1030, 46))
50+
>emitResult.diagnostics : Symbol(ts.EmitResult.diagnostics, Decl(typescript.d.ts, 820, 29))
51+
>emitResult : Symbol(emitResult, Decl(APISample_compile.ts, 15, 7))
52+
>diagnostics : Symbol(ts.EmitResult.diagnostics, Decl(typescript.d.ts, 820, 29))
53+
54+
allDiagnostics.forEach(diagnostic => {
55+
>allDiagnostics.forEach : Symbol(Array.forEach, Decl(lib.d.ts, 1108, 95))
56+
>allDiagnostics : Symbol(allDiagnostics, Decl(APISample_compile.ts, 17, 7))
57+
>forEach : Symbol(Array.forEach, Decl(lib.d.ts, 1108, 95))
58+
>diagnostic : Symbol(diagnostic, Decl(APISample_compile.ts, 19, 27))
59+
60+
var { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
61+
>line : Symbol(line, Decl(APISample_compile.ts, 20, 13))
62+
>character : Symbol(character, Decl(APISample_compile.ts, 20, 19))
63+
>diagnostic.file.getLineAndCharacterOfPosition : Symbol(ts.SourceFile.getLineAndCharacterOfPosition, Decl(typescript.d.ts, 1290, 26))
64+
>diagnostic.file : Symbol(ts.Diagnostic.file, Decl(typescript.d.ts, 1062, 26))
65+
>diagnostic : Symbol(diagnostic, Decl(APISample_compile.ts, 19, 27))
66+
>file : Symbol(ts.Diagnostic.file, Decl(typescript.d.ts, 1062, 26))
67+
>getLineAndCharacterOfPosition : Symbol(ts.SourceFile.getLineAndCharacterOfPosition, Decl(typescript.d.ts, 1290, 26))
68+
>diagnostic.start : Symbol(ts.Diagnostic.start, Decl(typescript.d.ts, 1063, 25))
69+
>diagnostic : Symbol(diagnostic, Decl(APISample_compile.ts, 19, 27))
70+
>start : Symbol(ts.Diagnostic.start, Decl(typescript.d.ts, 1063, 25))
71+
72+
var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
73+
>message : Symbol(message, Decl(APISample_compile.ts, 21, 11))
74+
>ts.flattenDiagnosticMessageText : Symbol(ts.flattenDiagnosticMessageText, Decl(typescript.d.ts, 1228, 67))
75+
>ts : Symbol(ts, Decl(APISample_compile.ts, 9, 20))
76+
>flattenDiagnosticMessageText : Symbol(ts.flattenDiagnosticMessageText, Decl(typescript.d.ts, 1228, 67))
77+
>diagnostic.messageText : Symbol(ts.Diagnostic.messageText, Decl(typescript.d.ts, 1065, 23))
78+
>diagnostic : Symbol(diagnostic, Decl(APISample_compile.ts, 19, 27))
79+
>messageText : Symbol(ts.Diagnostic.messageText, Decl(typescript.d.ts, 1065, 23))
80+
81+
console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
82+
>console : Symbol(console, Decl(APISample_compile.ts, 8, 11))
83+
>diagnostic.file.fileName : Symbol(ts.SourceFile.fileName, Decl(typescript.d.ts, 743, 29))
84+
>diagnostic.file : Symbol(ts.Diagnostic.file, Decl(typescript.d.ts, 1062, 26))
85+
>diagnostic : Symbol(diagnostic, Decl(APISample_compile.ts, 19, 27))
86+
>file : Symbol(ts.Diagnostic.file, Decl(typescript.d.ts, 1062, 26))
87+
>fileName : Symbol(ts.SourceFile.fileName, Decl(typescript.d.ts, 743, 29))
88+
>line : Symbol(line, Decl(APISample_compile.ts, 20, 13))
89+
>character : Symbol(character, Decl(APISample_compile.ts, 20, 19))
90+
>message : Symbol(message, Decl(APISample_compile.ts, 21, 11))
91+
92+
});
93+
94+
var exitCode = emitResult.emitSkipped ? 1 : 0;
95+
>exitCode : Symbol(exitCode, Decl(APISample_compile.ts, 25, 7))
96+
>emitResult.emitSkipped : Symbol(ts.EmitResult.emitSkipped, Decl(typescript.d.ts, 819, 26))
97+
>emitResult : Symbol(emitResult, Decl(APISample_compile.ts, 15, 7))
98+
>emitSkipped : Symbol(ts.EmitResult.emitSkipped, Decl(typescript.d.ts, 819, 26))
99+
100+
console.log(`Process exiting with code '${exitCode}'.`);
101+
>console : Symbol(console, Decl(APISample_compile.ts, 8, 11))
102+
>exitCode : Symbol(exitCode, Decl(APISample_compile.ts, 25, 7))
103+
104+
process.exit(exitCode);
105+
>process : Symbol(process, Decl(APISample_compile.ts, 7, 11))
106+
>exitCode : Symbol(exitCode, Decl(APISample_compile.ts, 25, 7))
107+
}
108+
109+
compile(process.argv.slice(2), {
110+
>compile : Symbol(compile, Decl(APISample_compile.ts, 11, 34))
111+
>process : Symbol(process, Decl(APISample_compile.ts, 7, 11))
112+
113+
noEmitOnError: true, noImplicitAny: true,
114+
>noEmitOnError : Symbol(noEmitOnError, Decl(APISample_compile.ts, 30, 32))
115+
>noImplicitAny : Symbol(noImplicitAny, Decl(APISample_compile.ts, 31, 24))
116+
117+
target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS
118+
>target : Symbol(target, Decl(APISample_compile.ts, 31, 45))
119+
>ts.ScriptTarget.ES5 : Symbol(ts.ScriptTarget.ES5, Decl(typescript.d.ts, 1117, 16))
120+
>ts.ScriptTarget : Symbol(ts.ScriptTarget, Decl(typescript.d.ts, 1115, 5))
121+
>ts : Symbol(ts, Decl(APISample_compile.ts, 9, 20))
122+
>ScriptTarget : Symbol(ts.ScriptTarget, Decl(typescript.d.ts, 1115, 5))
123+
>ES5 : Symbol(ts.ScriptTarget.ES5, Decl(typescript.d.ts, 1117, 16))
124+
>module : Symbol(module, Decl(APISample_compile.ts, 32, 32))
125+
>ts.ModuleKind.CommonJS : Symbol(ts.ModuleKind.CommonJS, Decl(typescript.d.ts, 1108, 17))
126+
>ts.ModuleKind : Symbol(ts.ModuleKind, Decl(typescript.d.ts, 1106, 5))
127+
>ts : Symbol(ts, Decl(APISample_compile.ts, 9, 20))
128+
>ModuleKind : Symbol(ts.ModuleKind, Decl(typescript.d.ts, 1106, 5))
129+
>CommonJS : Symbol(ts.ModuleKind.CommonJS, Decl(typescript.d.ts, 1108, 17))
130+
131+
});

0 commit comments

Comments
 (0)