@@ -290,6 +290,64 @@ module Utils {
290290 return o ;
291291 }
292292 }
293+
294+ export function assertStructuralEquals ( node1 : ts . Node , node2 : ts . Node ) {
295+ if ( node1 === node2 ) {
296+ return ;
297+ }
298+
299+ assert ( node1 , "node1" ) ;
300+ assert ( node2 , "node2" ) ;
301+ assert . equal ( node1 . pos , node2 . pos , "node1.pos !== node2.pos" ) ;
302+ assert . equal ( node1 . end , node2 . end , "node1.end !== node2.end" ) ;
303+ assert . equal ( node1 . kind , node2 . kind , "node1.kind !== node2.kind" ) ;
304+ assert . equal ( node1 . flags , node2 . flags , "node1.flags !== node2.flags" ) ;
305+
306+ // call this on both nodes to ensure all propagated flags have been set (and thus can be
307+ // compared).
308+ assert . equal ( ts . containsParseError ( node1 ) , ts . containsParseError ( node2 ) ) ;
309+ assert . equal ( node1 . parserContextFlags , node2 . parserContextFlags , "node1.parserContextFlags !== node2.parserContextFlags" ) ;
310+
311+ ts . forEachChild ( node1 ,
312+ child1 => {
313+ var childName = findChildName ( node1 , child1 ) ;
314+ var child2 : ts . Node = ( < any > node2 ) [ childName ] ;
315+
316+ assertStructuralEquals ( child1 , child2 ) ;
317+ } ,
318+ ( array1 : ts . NodeArray < ts . Node > ) => {
319+ var childName = findChildName ( node1 , array1 ) ;
320+ var array2 : ts . NodeArray < ts . Node > = ( < any > node2 ) [ childName ] ;
321+
322+ assertArrayStructuralEquals ( array1 , array2 ) ;
323+ } ) ;
324+ }
325+
326+ function assertArrayStructuralEquals ( array1 : ts . NodeArray < ts . Node > , array2 : ts . NodeArray < ts . Node > ) {
327+ if ( array1 === array2 ) {
328+ return ;
329+ }
330+
331+ assert ( array1 , "array1" ) ;
332+ assert ( array2 , "array2" ) ;
333+ assert . equal ( array1 . pos , array2 . pos , "array1.pos !== array2.pos" ) ;
334+ assert . equal ( array1 . end , array2 . end , "array1.end !== array2.end" ) ;
335+ assert . equal ( array1 . length , array2 . length , "array1.length !== array2.length" ) ;
336+
337+ for ( var i = 0 , n = array1 . length ; i < n ; i ++ ) {
338+ assertStructuralEquals ( array1 [ i ] , array2 [ i ] ) ;
339+ }
340+ }
341+
342+ function findChildName ( parent : any , child : any ) {
343+ for ( var name in parent ) {
344+ if ( parent . hasOwnProperty ( name ) && parent [ name ] === child ) {
345+ return name ;
346+ }
347+ }
348+
349+ throw new Error ( "Could not find child in parent" ) ;
350+ }
293351}
294352
295353module Harness . Path {
@@ -772,7 +830,7 @@ module Harness {
772830 writeFile,
773831 getCanonicalFileName,
774832 useCaseSensitiveFileNames : ( ) => useCaseSensitiveFileNames ,
775- getNewLine : ( ) => ts . sys . newLine
833+ getNewLine : ( ) => ts . sys . newLine
776834 } ;
777835 }
778836
@@ -814,7 +872,7 @@ module Harness {
814872 }
815873
816874 public emitAll ( ioHost ?: IEmitterIOHost ) {
817- this . compileFiles ( this . inputFiles , [ ] , ( result ) => {
875+ this . compileFiles ( this . inputFiles , [ ] , ( result ) => {
818876 result . files . forEach ( file => {
819877 ioHost . writeFile ( file . fileName , file . code , false ) ;
820878 } ) ;
@@ -824,7 +882,7 @@ module Harness {
824882 result . sourceMaps . forEach ( file => {
825883 ioHost . writeFile ( file . fileName , file . code , false ) ;
826884 } ) ;
827- } , ( ) => { } , this . compileOptions ) ;
885+ } , ( ) => { } , this . compileOptions ) ;
828886 }
829887
830888 public compileFiles ( inputFiles : { unitName : string ; content : string } [ ] ,
@@ -962,7 +1020,7 @@ module Harness {
9621020 break ;
9631021
9641022 case 'includebuiltfile' :
965- inputFiles . push ( { unitName : setting . value , content : IO . readFile ( libFolder + setting . value ) } ) ;
1023+ inputFiles . push ( { unitName : setting . value , content : IO . readFile ( libFolder + setting . value ) } ) ;
9661024 break ;
9671025
9681026 default :
@@ -1071,7 +1129,7 @@ module Harness {
10711129 return ts . removeFileExtension ( sourceFileName ) + ".d.ts" ;
10721130 }
10731131 } ) ;
1074-
1132+
10751133 return ts . forEach ( result . declFilesCode , declFile => declFile . fileName === dTsFileName ? declFile : undefined ) ;
10761134 }
10771135
@@ -1584,4 +1642,4 @@ module Harness {
15841642}
15851643
15861644// TODO: not sure why Utils.evalFile isn't working with this, eventually will concat it like old compiler instead of eval
1587- eval ( Harness . tcServicesFile ) ;
1645+ eval ( Harness . tcServicesFile ) ;
0 commit comments