@@ -256,11 +256,40 @@ class CompilerBaselineRunner extends RunnerBase {
256256 it ( 'Correct type baselines for ' + fileName , ( ) => {
257257 // NEWTODO: Type baselines
258258 if ( result . errors . length === 0 ) {
259- Harness . Baseline . runBaseline ( 'Correct expression types for ' + fileName , justName . replace ( / \. t s / , '.types' ) , ( ) => {
259+ // The full walker simulates the types that you would get from doing a full
260+ // compile. The pull walker simulates the types you get when you just do
261+ // a type query for a random node (like how the LS would do it). Most of the
262+ // time, these will be the same. However, occasionally, they can be different.
263+ // Specifically, when the compiler internally depends on symbol IDs to order
264+ // things, then we may see different results because symbols can be created in a
265+ // different order with 'pull' operations, and thus can produce slightly differing
266+ // output.
267+ //
268+ // For example, with a full type check, we may see a type outputed as: number | string
269+ // But with a pull type check, we may see it as: string | number
270+ //
271+ // These types are equivalent, but depend on what order the compiler observed
272+ // certain parts of the program.
273+
274+ var fullWalker = new TypeWriterWalker ( program , /*fullTypeCheck:*/ true ) ;
275+ var pullWalker = new TypeWriterWalker ( program , /*fullTypeCheck:*/ false ) ;
276+
277+ var fullTypes = generateTypes ( fullWalker ) ;
278+ var pullTypes = generateTypes ( pullWalker ) ;
279+
280+ if ( fullTypes !== pullTypes ) {
281+ Harness . Baseline . runBaseline ( 'Correct full expression types for ' + fileName , justName . replace ( / \. t s / , '.types' ) , ( ) => fullTypes ) ;
282+ Harness . Baseline . runBaseline ( 'Correct pull expression types for ' + fileName , justName . replace ( / \. t s / , '.types.pull' ) , ( ) => pullTypes ) ;
283+ }
284+ else {
285+ Harness . Baseline . runBaseline ( 'Correct expression types for ' + fileName , justName . replace ( / \. t s / , '.types' ) , ( ) => fullTypes ) ;
286+ }
287+
288+ function generateTypes ( walker : TypeWriterWalker ) : string {
260289 var allFiles = toBeCompiled . concat ( otherFiles ) . filter ( file => ! ! program . getSourceFile ( file . unitName ) ) ;
261290 var typeLines : string [ ] = [ ] ;
262291 var typeMap : { [ fileName : string ] : { [ lineNum : number ] : string [ ] ; } } = { } ;
263- var walker = new TypeWriterWalker ( program ) ;
292+
264293 allFiles . forEach ( file => {
265294 var codeLines = file . content . split ( '\n' ) ;
266295 walker . getTypes ( file . unitName ) . forEach ( result => {
@@ -299,7 +328,7 @@ class CompilerBaselineRunner extends RunnerBase {
299328 } ) ;
300329
301330 return typeLines . join ( '' ) ;
302- } ) ;
331+ }
303332 }
304333 } ) ;
305334 } ) ;
0 commit comments