@@ -39,8 +39,9 @@ class CompilerBaselineRunner extends RunnerBase {
3939
4040 public checkTestCodeOutput ( fileName : string ) {
4141 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.
4445 var content = Harness . IO . readFile ( fileName ) ;
4546 var testCaseContent = Harness . TestCaseParser . makeUnitsFromTest ( content , fileName ) ;
4647
@@ -52,6 +53,7 @@ class CompilerBaselineRunner extends RunnerBase {
5253 var rootDir = lastUnit . originalFilePath . indexOf ( 'conformance' ) === - 1 ? 'tests/cases/compiler/' : lastUnit . originalFilePath . substring ( 0 , lastUnit . originalFilePath . lastIndexOf ( '/' ) ) + '/' ;
5354
5455 var result : Harness . Compiler . CompilerResult ;
56+ var checker : ts . TypeChecker ;
5557 var options : ts . CompilerOptions ;
5658 // equivalent to the files that will be passed on the command line
5759 var toBeCompiled : { unitName : string ; content : string } [ ] ;
@@ -85,8 +87,10 @@ class CompilerBaselineRunner extends RunnerBase {
8587 } ) ;
8688 }
8789
88- options = harnessCompiler . compileFiles ( toBeCompiled , otherFiles , function ( compileResult ) {
90+ options = harnessCompiler . compileFiles ( toBeCompiled , otherFiles , function ( compileResult , _checker ) {
8991 result = compileResult ;
92+ // The checker will be used by typeWriter
93+ checker = _checker ;
9094 } , function ( settings ) {
9195 harnessCompiler . setCompilerSettings ( tcSettings ) ;
9296 } ) ;
@@ -97,6 +101,7 @@ class CompilerBaselineRunner extends RunnerBase {
97101 a fresh compiler instance for themselves and then create a fresh one for the next test. Would be nice to get dev fixes
98102 eventually to remove this limitation. */
99103 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
100105 if ( ! createNewInstance && ( tcSettings [ i ] . flag == "noimplicitany" || tcSettings [ i ] . flag === 'target' ) ) {
101106 harnessCompiler = Harness . Compiler . getCompiler ( {
102107 useExistingInstance : false ,
@@ -118,6 +123,27 @@ class CompilerBaselineRunner extends RunnerBase {
118123 }
119124 } ) ;
120125
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+
121147 function getByteOrderMarkText ( file : Harness . Compiler . GeneratedFile ) : string {
122148 return file . writeByteOrderMark ? "\u00EF\u00BB\u00BF" : "" ;
123149 }
@@ -251,32 +277,15 @@ class CompilerBaselineRunner extends RunnerBase {
251277
252278 it ( 'Correct type baselines for ' + fileName , ( ) => {
253279 // NEWTODO: Type baselines
254- if ( /* ! */ false && /* ! */ result . errors . length === 0 ) {
280+ if ( result . errors . length === 0 ) {
255281 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 ) ) ;
273283 var typeLines : string [ ] = [ ] ;
274284 var typeMap : { [ fileName : string ] : { [ lineNum : number ] : string [ ] ; } } = { } ;
285+ var walker = new TypeWriterWalker ( checker ) ;
275286 allFiles . forEach ( file => {
276287 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 => {
280289 var formattedLine = result . identifierName + " : " + result . type ;
281290 if ( ! typeMap [ file . unitName ] ) {
282291 typeMap [ file . unitName ] = { } ;
@@ -290,23 +299,6 @@ class CompilerBaselineRunner extends RunnerBase {
290299 typeMap [ file . unitName ] [ result . line ] = typeInfo ;
291300 } ) ;
292301
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-
310302 typeLines . push ( '=== ' + file . unitName + ' ===\r\n' ) ;
311303 for ( var i = 0 ; i < codeLines . length ; i ++ ) {
312304 var currentCodeLine = codeLines [ i ] ;
0 commit comments