@@ -39,8 +39,9 @@ class CompilerBaselineRunner extends RunnerBase {
39
39
40
40
public checkTestCodeOutput ( fileName : string ) {
41
41
describe ( 'compiler tests for ' + fileName , ( ) => {
42
- // strips the fileName from the path.
43
- var justName = fileName . replace ( / ^ .* [ \\ \/ ] / , '' ) ;
42
+ // Mocha holds onto the closure environment of the describe callback even after the test is done.
43
+ // Everything declared here should be cleared out in the "after" callback.
44
+ var justName = fileName . replace ( / ^ .* [ \\ \/ ] / , '' ) ; // strips the fileName from the path.
44
45
var content = Harness . IO . readFile ( fileName ) ;
45
46
var testCaseContent = Harness . TestCaseParser . makeUnitsFromTest ( content , fileName ) ;
46
47
@@ -52,6 +53,7 @@ class CompilerBaselineRunner extends RunnerBase {
52
53
var rootDir = lastUnit . originalFilePath . indexOf ( 'conformance' ) === - 1 ? 'tests/cases/compiler/' : lastUnit . originalFilePath . substring ( 0 , lastUnit . originalFilePath . lastIndexOf ( '/' ) ) + '/' ;
53
54
54
55
var result : Harness . Compiler . CompilerResult ;
56
+ var checker : ts . TypeChecker ;
55
57
var options : ts . CompilerOptions ;
56
58
// equivalent to the files that will be passed on the command line
57
59
var toBeCompiled : { unitName : string ; content : string } [ ] ;
@@ -85,8 +87,10 @@ class CompilerBaselineRunner extends RunnerBase {
85
87
} ) ;
86
88
}
87
89
88
- options = harnessCompiler . compileFiles ( toBeCompiled , otherFiles , function ( compileResult ) {
90
+ options = harnessCompiler . compileFiles ( toBeCompiled , otherFiles , function ( compileResult , _checker ) {
89
91
result = compileResult ;
92
+ // The checker will be used by typeWriter
93
+ checker = _checker ;
90
94
} , function ( settings ) {
91
95
harnessCompiler . setCompilerSettings ( tcSettings ) ;
92
96
} ) ;
@@ -97,6 +101,7 @@ class CompilerBaselineRunner extends RunnerBase {
97
101
a fresh compiler instance for themselves and then create a fresh one for the next test. Would be nice to get dev fixes
98
102
eventually to remove this limitation. */
99
103
for ( var i = 0 ; i < tcSettings . length ; ++ i ) {
104
+ // noImplicitAny is passed to getCompiler, but target is just passed in the settings blob to setCompilerSettings
100
105
if ( ! createNewInstance && ( tcSettings [ i ] . flag == "noimplicitany" || tcSettings [ i ] . flag === 'target' ) ) {
101
106
harnessCompiler = Harness . Compiler . getCompiler ( {
102
107
useExistingInstance : false ,
@@ -118,6 +123,27 @@ class CompilerBaselineRunner extends RunnerBase {
118
123
}
119
124
} ) ;
120
125
126
+ after ( ( ) => {
127
+ // Mocha holds onto the closure environment of the describe callback even after the test is done.
128
+ // Therefore we have to clean out large objects after the test is done.
129
+ justName = undefined ;
130
+ content = undefined ;
131
+ testCaseContent = undefined ;
132
+ units = undefined ;
133
+ tcSettings = undefined ;
134
+ lastUnit = undefined ;
135
+ rootDir = undefined ;
136
+ result = undefined ;
137
+ checker = undefined ;
138
+ options = undefined ;
139
+ toBeCompiled = undefined ;
140
+ otherFiles = undefined ;
141
+ harnessCompiler = undefined ;
142
+ declToBeCompiled = undefined ;
143
+ declOtherFiles = undefined ;
144
+ declResult = undefined ;
145
+ } ) ;
146
+
121
147
function getByteOrderMarkText ( file : Harness . Compiler . GeneratedFile ) : string {
122
148
return file . writeByteOrderMark ? "\u00EF\u00BB\u00BF" : "" ;
123
149
}
@@ -251,32 +277,15 @@ class CompilerBaselineRunner extends RunnerBase {
251
277
252
278
it ( 'Correct type baselines for ' + fileName , ( ) => {
253
279
// NEWTODO: Type baselines
254
- if ( /* ! */ false && /* ! */ result . errors . length === 0 ) {
280
+ if ( result . errors . length === 0 ) {
255
281
Harness . Baseline . runBaseline ( 'Correct expression types for ' + fileName , justName . replace ( / \. t s / , '.types' ) , ( ) => {
256
- // TODO: Rewrite this part
257
- //var compiler = new TypeScript.TypeScriptCompiler(
258
- // new TypeScript.NullLogger(), TypeScript.ImmutableCompilationSettings.defaultSettings());
259
-
260
- //compiler.addFile('lib.d.ts', TypeScript.ScriptSnapshot.fromString(Harness.Compiler.libTextMinimal),
261
- // TypeScript.ByteOrderMark.None, /*version:*/ "0", /*isOpen:*/ true);
262
-
263
- //var allFiles = toBeCompiled.concat(otherFiles);
264
- //allFiles.forEach(file => {
265
- // compiler.addFile(file.unitName, TypeScript.ScriptSnapshot.fromString(file.content),
266
- // TypeScript.ByteOrderMark.None, /*version:*/ "0", /*isOpen:*/ true);
267
- //});
268
-
269
- var allFiles : any [ ] = [ ] ;
270
- var compiler : any = undefined ;
271
-
272
- var typeBaselineText = '' ;
282
+ var allFiles = toBeCompiled . concat ( otherFiles ) . filter ( file => ! ! checker . getProgram ( ) . getSourceFile ( file . unitName ) ) ;
273
283
var typeLines : string [ ] = [ ] ;
274
284
var typeMap : { [ fileName : string ] : { [ lineNum : number ] : string [ ] ; } } = { } ;
285
+ var walker = new TypeWriterWalker ( checker ) ;
275
286
allFiles . forEach ( file => {
276
287
var codeLines = file . content . split ( '\n' ) ;
277
- var walker = new TypeWriterWalker ( file . unitName , compiler ) ;
278
- walker . run ( ) ;
279
- walker . results . forEach ( result => {
288
+ walker . getTypes ( file . unitName ) . forEach ( result => {
280
289
var formattedLine = result . identifierName + " : " + result . type ;
281
290
if ( ! typeMap [ file . unitName ] ) {
282
291
typeMap [ file . unitName ] = { } ;
@@ -290,23 +299,6 @@ class CompilerBaselineRunner extends RunnerBase {
290
299
typeMap [ file . unitName ] [ result . line ] = typeInfo ;
291
300
} ) ;
292
301
293
- var typeBaselineText = '' ;
294
- var typeLines : string [ ] = [ ] ;
295
- var typeMap : { [ fileName : string ] : { [ lineNum : number ] : string [ ] ; } } = { } ;
296
- allFiles . forEach ( file => {
297
- var codeLines = file . content . split ( '\n' ) ;
298
- var walker = new TypeWriterWalker ( file . unitName , compiler ) ;
299
- walker . run ( ) ;
300
- walker . results . forEach ( result => {
301
- var formattedLine = result . identifierName + " : " + result . type ;
302
- if ( ! typeMap [ file . unitName ] ) {
303
- typeMap [ file . unitName ] = { } ;
304
- } else {
305
- typeLines . push ( 'No type information for this code.' ) ;
306
- }
307
- } ) ;
308
- } ) ;
309
-
310
302
typeLines . push ( '=== ' + file . unitName + ' ===\r\n' ) ;
311
303
for ( var i = 0 ; i < codeLines . length ; i ++ ) {
312
304
var currentCodeLine = codeLines [ i ] ;
0 commit comments