Skip to content

Commit 592e231

Browse files
Simplify typewriter code.
1 parent 96995e7 commit 592e231

File tree

1,553 files changed

+9116
-335
lines changed

Some content is hidden

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

1,553 files changed

+9116
-335
lines changed

src/harness/typeWriter.ts

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -29,68 +29,13 @@ class TypeWriterWalker {
2929
}
3030

3131
private visitNode(node: ts.Node): void {
32-
switch (node.kind) {
33-
// Should always log expressions that are not tokens
34-
// Also, always log the "this" keyword
35-
// TODO: Ideally we should log all expressions, but to compare to the
36-
// old typeWriter baselines, suppress tokens
37-
case ts.SyntaxKind.ThisKeyword:
38-
case ts.SyntaxKind.SuperKeyword:
39-
case ts.SyntaxKind.ArrayLiteralExpression:
40-
case ts.SyntaxKind.ObjectLiteralExpression:
41-
case ts.SyntaxKind.ElementAccessExpression:
42-
case ts.SyntaxKind.CallExpression:
43-
case ts.SyntaxKind.NewExpression:
44-
case ts.SyntaxKind.TypeAssertionExpression:
45-
case ts.SyntaxKind.ParenthesizedExpression:
46-
case ts.SyntaxKind.FunctionExpression:
47-
case ts.SyntaxKind.ArrowFunction:
48-
case ts.SyntaxKind.TypeOfExpression:
49-
case ts.SyntaxKind.VoidExpression:
50-
case ts.SyntaxKind.DeleteExpression:
51-
case ts.SyntaxKind.PrefixUnaryExpression:
52-
case ts.SyntaxKind.PostfixUnaryExpression:
53-
case ts.SyntaxKind.BinaryExpression:
54-
case ts.SyntaxKind.ConditionalExpression:
55-
case ts.SyntaxKind.SpreadElementExpression:
56-
this.log(node, this.getTypeOfNode(node));
57-
break;
58-
59-
case ts.SyntaxKind.PropertyAccessExpression:
60-
for (var current = node; current.kind === ts.SyntaxKind.PropertyAccessExpression; current = current.parent) {
61-
}
62-
if (current.kind !== ts.SyntaxKind.HeritageClauseElement) {
63-
this.log(node, this.getTypeOfNode(node));
64-
}
65-
break;
66-
67-
// Should not change expression status (maybe expressions)
68-
// TODO: Again, ideally should log number and string literals too,
69-
// but to be consistent with the old typeWriter, just log identifiers
70-
case ts.SyntaxKind.Identifier:
71-
var identifier = <ts.Identifier>node;
72-
if (!this.isLabel(identifier)) {
73-
var type = this.getTypeOfNode(identifier);
74-
this.log(node, type);
75-
}
76-
break;
32+
if (ts.isExpression(node) || node.kind === ts.SyntaxKind.Identifier) {
33+
this.log(node, this.getTypeOfNode(node));
7734
}
7835

7936
ts.forEachChild(node, child => this.visitNode(child));
8037
}
8138

82-
private isLabel(identifier: ts.Identifier): boolean {
83-
var parent = identifier.parent;
84-
switch (parent.kind) {
85-
case ts.SyntaxKind.ContinueStatement:
86-
case ts.SyntaxKind.BreakStatement:
87-
return (<ts.BreakOrContinueStatement>parent).label === identifier;
88-
case ts.SyntaxKind.LabeledStatement:
89-
return (<ts.LabeledStatement>parent).label === identifier;
90-
}
91-
return false;
92-
}
93-
9439
private log(node: ts.Node, type: ts.Type): void {
9540
var actualPos = ts.skipTrivia(this.currentSourceFile.text, node.pos);
9641
var lineAndCharacter = this.currentSourceFile.getLineAndCharacterOfPosition(actualPos);

tests/baselines/reference/APISample_compile.types

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,25 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void
8585
>diagnostic.messageText : string | ts.DiagnosticMessageChain
8686
>diagnostic : ts.Diagnostic
8787
>messageText : string | ts.DiagnosticMessageChain
88+
>'\n' : string
8889

8990
console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
9091
>console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`) : any
9192
>console.log : any
9293
>console : any
9394
>log : any
95+
>`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}` : string
9496
>diagnostic.file.fileName : string
9597
>diagnostic.file : ts.SourceFile
9698
>diagnostic : ts.Diagnostic
9799
>file : ts.SourceFile
98100
>fileName : string
99101
>line + 1 : number
100102
>line : number
103+
>1 : number
101104
>character + 1 : number
102105
>character : number
106+
>1 : number
103107
>message : string
104108

105109
});
@@ -110,12 +114,15 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void
110114
>emitResult.emitSkipped : boolean
111115
>emitResult : ts.EmitResult
112116
>emitSkipped : boolean
117+
>1 : number
118+
>0 : number
113119

114120
console.log(`Process exiting with code '${exitCode}'.`);
115121
>console.log(`Process exiting with code '${exitCode}'.`) : any
116122
>console.log : any
117123
>console : any
118124
>log : any
125+
>`Process exiting with code '${exitCode}'.` : string
119126
>exitCode : number
120127

121128
process.exit(exitCode);
@@ -135,11 +142,14 @@ compile(process.argv.slice(2), {
135142
>process : any
136143
>argv : any
137144
>slice : any
145+
>2 : number
138146
>{ noEmitOnError: true, noImplicitAny: true, target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS} : { [x: string]: boolean | ts.ScriptTarget | ts.ModuleKind; noEmitOnError: boolean; noImplicitAny: boolean; target: ts.ScriptTarget; module: ts.ModuleKind; }
139147

140148
noEmitOnError: true, noImplicitAny: true,
141149
>noEmitOnError : boolean
150+
>true : boolean
142151
>noImplicitAny : boolean
152+
>true : boolean
143153

144154
target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS
145155
>target : ts.ScriptTarget

tests/baselines/reference/APISample_linter.types

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export function delint(sourceFile: ts.SourceFile) {
8989
>report(node, "A looping statement's contents should be wrapped in a block body.") : void
9090
>report : (node: ts.Node, message: string) => void
9191
>node : ts.Node
92+
>"A looping statement's contents should be wrapped in a block body." : string
9293
}
9394
break;
9495

@@ -126,6 +127,7 @@ export function delint(sourceFile: ts.SourceFile) {
126127
>ifStatement.thenStatement : ts.Statement
127128
>ifStatement : ts.IfStatement
128129
>thenStatement : ts.Statement
130+
>"An if statement's contents should be wrapped in a block body." : string
129131
}
130132
if (ifStatement.elseStatement &&
131133
>ifStatement.elseStatement && ifStatement.elseStatement.kind !== ts.SyntaxKind.Block && ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement : boolean
@@ -166,6 +168,7 @@ export function delint(sourceFile: ts.SourceFile) {
166168
>ifStatement.elseStatement : ts.Statement
167169
>ifStatement : ts.IfStatement
168170
>elseStatement : ts.Statement
171+
>"An else statement's contents should be wrapped in a block body." : string
169172
}
170173
break;
171174

@@ -209,6 +212,7 @@ export function delint(sourceFile: ts.SourceFile) {
209212
>report(node, "Use '===' and '!=='.") : void
210213
>report : (node: ts.Node, message: string) => void
211214
>node : ts.Node
215+
>"Use '===' and '!=='." : string
212216
}
213217
break;
214218
}
@@ -246,13 +250,16 @@ export function delint(sourceFile: ts.SourceFile) {
246250
>console.log : any
247251
>console : any
248252
>log : any
253+
>`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}` : string
249254
>sourceFile.fileName : string
250255
>sourceFile : ts.SourceFile
251256
>fileName : string
252257
>line + 1 : number
253258
>line : number
259+
>1 : number
254260
>character + 1 : number
255261
>character : number
262+
>1 : number
256263
>message : string
257264
}
258265
}
@@ -265,6 +272,7 @@ const fileNames = process.argv.slice(2);
265272
>process : any
266273
>argv : any
267274
>slice : any
275+
>2 : number
268276

269277
fileNames.forEach(fileName => {
270278
>fileNames.forEach(fileName => { // Parse a file let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true); // delint it delint(sourceFile);}) : any
@@ -293,6 +301,7 @@ fileNames.forEach(fileName => {
293301
>ts : typeof ts
294302
>ScriptTarget : typeof ts.ScriptTarget
295303
>ES6 : ts.ScriptTarget
304+
>true : boolean
296305

297306
// delint it
298307
delint(sourceFile);

tests/baselines/reference/APISample_transform.types

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as ts from "typescript";
1414

1515
const source = "let x: string = 'string'";
1616
>source : string
17+
>"let x: string = 'string'" : string
1718

1819
let result = ts.transpile(source, { module: ts.ModuleKind.CommonJS });
1920
>result : string

tests/baselines/reference/APISample_watcher.types

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
5151
>fileName : string
5252
>{ version: 0 } : { version: number; }
5353
>version : number
54+
>0 : number
5455

5556
});
5657

@@ -181,7 +182,9 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
181182
{ persistent: true, interval: 250 },
182183
>{ persistent: true, interval: 250 } : { persistent: boolean; interval: number; }
183184
>persistent : boolean
185+
>true : boolean
184186
>interval : number
187+
>250 : number
185188

186189
(curr, prev) => {
187190
>(curr, prev) => { // Check timestamp if (+curr.mtime <= +prev.mtime) { return; } // Update the version to signal a change in the file files[fileName].version++; // write the changes to disk emitFile(fileName); } : (curr: any, prev: any) => void
@@ -244,6 +247,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
244247
>console.log : any
245248
>console : any
246249
>log : any
250+
>`Emitting ${fileName}` : string
247251
>fileName : string
248252
}
249253
else {
@@ -252,6 +256,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
252256
>console.log : any
253257
>console : any
254258
>log : any
259+
>`Emitting ${fileName} failed` : string
255260
>fileName : string
256261

257262
logErrors(fileName);
@@ -281,6 +286,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
281286
>o.text : string
282287
>o : ts.OutputFile
283288
>text : string
289+
>"utf8" : string
284290

285291
});
286292
}
@@ -333,6 +339,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
333339
>diagnostic.messageText : string | ts.DiagnosticMessageChain
334340
>diagnostic : ts.Diagnostic
335341
>messageText : string | ts.DiagnosticMessageChain
342+
>"\n" : string
336343

337344
if (diagnostic.file) {
338345
>diagnostic.file : ts.SourceFile
@@ -357,15 +364,18 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
357364
>console.log : any
358365
>console : any
359366
>log : any
367+
>` Error ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}` : string
360368
>diagnostic.file.fileName : string
361369
>diagnostic.file : ts.SourceFile
362370
>diagnostic : ts.Diagnostic
363371
>file : ts.SourceFile
364372
>fileName : string
365373
>line + 1 : number
366374
>line : number
375+
>1 : number
367376
>character + 1 : number
368377
>character : number
378+
>1 : number
369379
>message : string
370380
}
371381
else {
@@ -374,6 +384,7 @@ function watch(rootFileNames: string[], options: ts.CompilerOptions) {
374384
>console.log : any
375385
>console : any
376386
>log : any
387+
>` Error: ${message}` : string
377388
>message : string
378389
}
379390
});
@@ -403,6 +414,7 @@ const currentDirectoryFiles = fs.readdirSync(process.cwd()).
403414
>fileName.length : any
404415
>fileName : any
405416
>length : any
417+
>3 : number
406418
>fileName.substr(fileName.length - 3, 3) === ".ts" : boolean
407419
>fileName.substr(fileName.length - 3, 3) : any
408420
>fileName.substr : any
@@ -412,6 +424,9 @@ const currentDirectoryFiles = fs.readdirSync(process.cwd()).
412424
>fileName.length : any
413425
>fileName : any
414426
>length : any
427+
>3 : number
428+
>3 : number
429+
>".ts" : string
415430

416431
// Start the watcher
417432
watch(currentDirectoryFiles, { module: ts.ModuleKind.CommonJS });

tests/baselines/reference/AmbientModuleAndAmbientWithSameNameAndCommonRoot.types

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,6 @@ var p = new A.Point(0, 0); // unexpected error here, bug 840000
5656
>A.Point : typeof A.Point
5757
>A : typeof A
5858
>Point : typeof A.Point
59+
>0 : number
60+
>0 : number
5961

tests/baselines/reference/AmbientModuleAndNonAmbientClassWithSameNameAndCommonRoot.types

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,6 @@ var p = new A.Point(0, 0); // unexpected error here, bug 840000
5050
>A.Point : typeof A.Point
5151
>A : typeof A
5252
>Point : typeof A.Point
53+
>0 : number
54+
>0 : number
5355

tests/baselines/reference/AmbientModuleAndNonAmbientFunctionWithTheSameNameAndCommonRoot.types

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ function Point() {
1515
return { x: 0, y: 0 };
1616
>{ x: 0, y: 0 } : { x: number; y: number; }
1717
>x : number
18+
>0 : number
1819
>y : number
20+
>0 : number
1921
}
2022

2123
=== tests/cases/conformance/internalModules/DeclarationMerging/test.ts ===

tests/baselines/reference/ClassAndModuleThatMergeWithStaticFunctionAndNonExportedFunctionThatShareAName.types

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ class Point {
1111
>Point : Point
1212
>{ x: 0, y: 0 } : { x: number; y: number; }
1313
>x : number
14+
>0 : number
1415
>y : number
16+
>0 : number
1517
}
1618

1719
module Point {
1820
>Point : typeof Point
1921

2022
function Origin() { return ""; }// not an error, since not exported
2123
>Origin : () => string
24+
>"" : string
2225
}
2326

2427

@@ -37,13 +40,16 @@ module A {
3740
>Point : Point
3841
>{ x: 0, y: 0 } : { x: number; y: number; }
3942
>x : number
43+
>0 : number
4044
>y : number
45+
>0 : number
4146
}
4247

4348
export module Point {
4449
>Point : typeof Point
4550

4651
function Origin() { return ""; }// not an error since not exported
4752
>Origin : () => string
53+
>"" : string
4854
}
4955
}

tests/baselines/reference/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName.types

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ class Point {
1111
>Point : Point
1212
>{ x: 0, y: 0 } : { x: number; y: number; }
1313
>x : number
14+
>0 : number
1415
>y : number
16+
>0 : number
1517
}
1618

1719
module Point {
1820
>Point : typeof Point
1921

2022
var Origin = ""; // not an error, since not exported
2123
>Origin : string
24+
>"" : string
2225
}
2326

2427

@@ -37,13 +40,16 @@ module A {
3740
>Point : Point
3841
>{ x: 0, y: 0 } : { x: number; y: number; }
3942
>x : number
43+
>0 : number
4044
>y : number
45+
>0 : number
4146
}
4247

4348
export module Point {
4449
>Point : typeof Point
4550

4651
var Origin = ""; // not an error since not exported
4752
>Origin : string
53+
>"" : string
4854
}
4955
}

0 commit comments

Comments
 (0)