@@ -256,125 +256,128 @@ class CompilerBaselineRunner extends RunnerBase {
256256 }
257257
258258 // NEWTODO: Type baselines
259- if ( result . errors . length === 0 ) {
260- // The full walker simulates the types that you would get from doing a full
261- // compile. The pull walker simulates the types you get when you just do
262- // a type query for a random node (like how the LS would do it). Most of the
263- // time, these will be the same. However, occasionally, they can be different.
264- // Specifically, when the compiler internally depends on symbol IDs to order
265- // things, then we may see different results because symbols can be created in a
266- // different order with 'pull' operations, and thus can produce slightly differing
267- // output.
268- //
269- // For example, with a full type check, we may see a type displayed as: number | string
270- // But with a pull type check, we may see it as: string | number
271- //
272- // These types are equivalent, but depend on what order the compiler observed
273- // certain parts of the program.
274-
275- const program = result . program ;
276- const allFiles = toBeCompiled . concat ( otherFiles ) . filter ( file => ! ! program . getSourceFile ( file . unitName ) ) ;
277-
278- const fullWalker = new TypeWriterWalker ( program , /*fullTypeCheck*/ true ) ;
279-
280- const fullResults : ts . Map < TypeWriterResult [ ] > = { } ;
281- const pullResults : ts . Map < TypeWriterResult [ ] > = { } ;
282-
283- for ( const sourceFile of allFiles ) {
284- fullResults [ sourceFile . unitName ] = fullWalker . getTypeAndSymbols ( sourceFile . unitName ) ;
285- pullResults [ sourceFile . unitName ] = fullWalker . getTypeAndSymbols ( sourceFile . unitName ) ;
286- }
259+ if ( result . errors . length !== 0 ) {
260+ return ;
261+ }
287262
288- // Produce baselines. The first gives the types for all expressions.
289- // The second gives symbols for all identifiers.
290- let e1 : Error , e2 : Error ;
291- try {
292- checkBaseLines ( /*isSymbolBaseLine*/ false ) ;
293- }
294- catch ( e ) {
295- e1 = e ;
296- }
263+ // The full walker simulates the types that you would get from doing a full
264+ // compile. The pull walker simulates the types you get when you just do
265+ // a type query for a random node (like how the LS would do it). Most of the
266+ // time, these will be the same. However, occasionally, they can be different.
267+ // Specifically, when the compiler internally depends on symbol IDs to order
268+ // things, then we may see different results because symbols can be created in a
269+ // different order with 'pull' operations, and thus can produce slightly differing
270+ // output.
271+ //
272+ // For example, with a full type check, we may see a type displayed as: number | string
273+ // But with a pull type check, we may see it as: string | number
274+ //
275+ // These types are equivalent, but depend on what order the compiler observed
276+ // certain parts of the program.
277+
278+ const program = result . program ;
279+ const allFiles = toBeCompiled . concat ( otherFiles ) . filter ( file => ! ! program . getSourceFile ( file . unitName ) ) ;
280+
281+ const fullWalker = new TypeWriterWalker ( program , /*fullTypeCheck*/ true ) ;
282+
283+ const fullResults : ts . Map < TypeWriterResult [ ] > = { } ;
284+ const pullResults : ts . Map < TypeWriterResult [ ] > = { } ;
285+
286+ for ( const sourceFile of allFiles ) {
287+ fullResults [ sourceFile . unitName ] = fullWalker . getTypeAndSymbols ( sourceFile . unitName ) ;
288+ pullResults [ sourceFile . unitName ] = fullWalker . getTypeAndSymbols ( sourceFile . unitName ) ;
289+ }
297290
298- try {
299- checkBaseLines ( /*isSymbolBaseLine*/ true ) ;
300- }
301- catch ( e ) {
302- e2 = e ;
303- }
291+ // Produce baselines. The first gives the types for all expressions.
292+ // The second gives symbols for all identifiers.
293+ let e1 : Error , e2 : Error ;
294+ try {
295+ checkBaseLines ( /*isSymbolBaseLine*/ false ) ;
296+ }
297+ catch ( e ) {
298+ e1 = e ;
299+ }
304300
305- if ( e1 || e2 ) {
306- throw e1 || e2 ;
307- }
301+ try {
302+ checkBaseLines ( /*isSymbolBaseLine*/ true ) ;
303+ }
304+ catch ( e ) {
305+ e2 = e ;
306+ }
308307
309- return ;
308+ if ( e1 || e2 ) {
309+ throw e1 || e2 ;
310+ }
310311
311- function checkBaseLines ( isSymbolBaseLine : boolean ) {
312- const fullBaseLine = generateBaseLine ( fullResults , isSymbolBaseLine ) ;
313- const pullBaseLine = generateBaseLine ( pullResults , isSymbolBaseLine ) ;
312+ return ;
314313
315- const fullExtension = isSymbolBaseLine ? ".symbols" : ".types" ;
316- const pullExtension = isSymbolBaseLine ? ".symbols.pull" : ".types.pull" ;
314+ function checkBaseLines ( isSymbolBaseLine : boolean ) {
315+ const fullBaseLine = generateBaseLine ( fullResults , isSymbolBaseLine ) ;
316+ const pullBaseLine = generateBaseLine ( pullResults , isSymbolBaseLine ) ;
317317
318- if ( fullBaseLine !== pullBaseLine ) {
319- Harness . Baseline . runBaseline ( "Correct full information for " + fileName , justName . replace ( / \. t s x ? / , fullExtension ) , ( ) => fullBaseLine ) ;
320- Harness . Baseline . runBaseline ( "Correct pull information for " + fileName , justName . replace ( / \. t s x ? / , pullExtension ) , ( ) => pullBaseLine ) ;
321- }
322- else {
323- Harness . Baseline . runBaseline ( "Correct information for " + fileName , justName . replace ( / \. t s x ? / , fullExtension ) , ( ) => fullBaseLine ) ;
324- }
318+ const fullExtension = isSymbolBaseLine ? ".symbols" : ".types" ;
319+ const pullExtension = isSymbolBaseLine ? ".symbols.pull" : ".types.pull" ;
320+
321+ if ( fullBaseLine !== pullBaseLine ) {
322+ Harness . Baseline . runBaseline ( "Correct full information for " + fileName , justName . replace ( / \. t s x ? / , fullExtension ) , ( ) => fullBaseLine ) ;
323+ Harness . Baseline . runBaseline ( "Correct pull information for " + fileName , justName . replace ( / \. t s x ? / , pullExtension ) , ( ) => pullBaseLine ) ;
325324 }
325+ else {
326+ Harness . Baseline . runBaseline ( "Correct information for " + fileName , justName . replace ( / \. t s x ? / , fullExtension ) , ( ) => fullBaseLine ) ;
327+ }
328+ }
326329
327- function generateBaseLine ( typeWriterResults : ts . Map < TypeWriterResult [ ] > , isSymbolBaseline : boolean ) : string {
328- const typeLines : string [ ] = [ ] ;
329- const typeMap : { [ fileName : string ] : { [ lineNum : number ] : string [ ] ; } } = { } ;
330+ function generateBaseLine ( typeWriterResults : ts . Map < TypeWriterResult [ ] > , isSymbolBaseline : boolean ) : string {
331+ const typeLines : string [ ] = [ ] ;
332+ const typeMap : { [ fileName : string ] : { [ lineNum : number ] : string [ ] ; } } = { } ;
330333
331- allFiles . forEach ( file => {
332- const codeLines = file . content . split ( "\n" ) ;
333- typeWriterResults [ file . unitName ] . forEach ( result => {
334- if ( isSymbolBaseline && ! result . symbol ) {
335- return ;
336- }
334+ allFiles . forEach ( file => {
335+ const codeLines = file . content . split ( "\n" ) ;
336+ typeWriterResults [ file . unitName ] . forEach ( result => {
337+ if ( isSymbolBaseline && ! result . symbol ) {
338+ return ;
339+ }
337340
338- const typeOrSymbolString = isSymbolBaseline ? result . symbol : result . type ;
339- const formattedLine = result . sourceText . replace ( / \r ? \n / g, "" ) + " : " + typeOrSymbolString ;
340- if ( ! typeMap [ file . unitName ] ) {
341- typeMap [ file . unitName ] = { } ;
342- }
341+ const typeOrSymbolString = isSymbolBaseline ? result . symbol : result . type ;
342+ const formattedLine = result . sourceText . replace ( / \r ? \n / g, "" ) + " : " + typeOrSymbolString ;
343+ if ( ! typeMap [ file . unitName ] ) {
344+ typeMap [ file . unitName ] = { } ;
345+ }
343346
344- let typeInfo = [ formattedLine ] ;
345- const existingTypeInfo = typeMap [ file . unitName ] [ result . line ] ;
346- if ( existingTypeInfo ) {
347- typeInfo = existingTypeInfo . concat ( typeInfo ) ;
348- }
349- typeMap [ file . unitName ] [ result . line ] = typeInfo ;
350- } ) ;
351-
352- typeLines . push ( "=== " + file . unitName + " ===\r\n" ) ;
353- for ( let i = 0 ; i < codeLines . length ; i ++ ) {
354- const currentCodeLine = codeLines [ i ] ;
355- typeLines . push ( currentCodeLine + "\r\n" ) ;
356- if ( typeMap [ file . unitName ] ) {
357- const typeInfo = typeMap [ file . unitName ] [ i ] ;
358- if ( typeInfo ) {
359- typeInfo . forEach ( ty => {
360- typeLines . push ( ">" + ty + "\r\n" ) ;
361- } ) ;
362- if ( i + 1 < codeLines . length && ( codeLines [ i + 1 ] . match ( / ^ \s * [ { | } ] \s * $ / ) || codeLines [ i + 1 ] . trim ( ) === "" ) ) {
363- }
364- else {
365- typeLines . push ( "\r\n" ) ;
366- }
347+ let typeInfo = [ formattedLine ] ;
348+ const existingTypeInfo = typeMap [ file . unitName ] [ result . line ] ;
349+ if ( existingTypeInfo ) {
350+ typeInfo = existingTypeInfo . concat ( typeInfo ) ;
351+ }
352+ typeMap [ file . unitName ] [ result . line ] = typeInfo ;
353+ } ) ;
354+
355+ typeLines . push ( "=== " + file . unitName + " ===\r\n" ) ;
356+ for ( let i = 0 ; i < codeLines . length ; i ++ ) {
357+ const currentCodeLine = codeLines [ i ] ;
358+ typeLines . push ( currentCodeLine + "\r\n" ) ;
359+ if ( typeMap [ file . unitName ] ) {
360+ const typeInfo = typeMap [ file . unitName ] [ i ] ;
361+ if ( typeInfo ) {
362+ typeInfo . forEach ( ty => {
363+ typeLines . push ( ">" + ty + "\r\n" ) ;
364+ } ) ;
365+ if ( i + 1 < codeLines . length && ( codeLines [ i + 1 ] . match ( / ^ \s * [ { | } ] \s * $ / ) || codeLines [ i + 1 ] . trim ( ) === "" ) ) {
366+ }
367+ else {
368+ typeLines . push ( "\r\n" ) ;
367369 }
368- }
369- else {
370- typeLines . push ( "No type information for this code." ) ;
371370 }
372371 }
373- } ) ;
372+ else {
373+ typeLines . push ( "No type information for this code." ) ;
374+ }
375+ }
376+ } ) ;
374377
375- return typeLines . join ( "" ) ;
376- }
378+ return typeLines . join ( "" ) ;
377379 }
380+
378381 } ) ;
379382 } ) ;
380383 }
0 commit comments