@@ -499,8 +499,49 @@ namespace ts {
499499
500500 const options : CompilerOptions = { target : ScriptTarget . ES2015 , traceResolution : true , moduleResolution : ModuleResolutionKind . Classic } ;
501501 const program_1 = newProgram ( files , files . map ( f => f . name ) , options ) ;
502- assert . deepEqual ( program_1 . host . getTrace ( ) ,
503- [
502+ let expectedErrors = 0 ;
503+ {
504+ assert . deepEqual ( program_1 . host . getTrace ( ) ,
505+ [
506+ "======== Resolving type reference directive 'typerefs1', containing file 'f1.ts', root directory 'node_modules/@types'. ========" ,
507+ "Resolving with primary search path 'node_modules/@types'." ,
508+ "File 'node_modules/@types/typerefs1/package.json' does not exist." ,
509+ "File 'node_modules/@types/typerefs1/index.d.ts' exist - use it as a name resolution result." ,
510+ "======== Type reference directive 'typerefs1' was successfully resolved to 'node_modules/@types/typerefs1/index.d.ts', primary: true. ========" ,
511+ "======== Resolving module './b1' from 'f1.ts'. ========" ,
512+ "Explicitly specified module resolution kind: 'Classic'." ,
513+ "File 'b1.ts' exist - use it as a name resolution result." ,
514+ "======== Module name './b1' was successfully resolved to 'b1.ts'. ========" ,
515+ "======== Resolving type reference directive 'typerefs2', containing file 'f2.ts', root directory 'node_modules/@types'. ========" ,
516+ "Resolving with primary search path 'node_modules/@types'." ,
517+ "File 'node_modules/@types/typerefs2/package.json' does not exist." ,
518+ "File 'node_modules/@types/typerefs2/index.d.ts' exist - use it as a name resolution result." ,
519+ "======== Type reference directive 'typerefs2' was successfully resolved to 'node_modules/@types/typerefs2/index.d.ts', primary: true. ========" ,
520+ "======== Resolving module './b2' from 'f2.ts'. ========" ,
521+ "Explicitly specified module resolution kind: 'Classic'." ,
522+ "File 'b2.ts' exist - use it as a name resolution result." ,
523+ "======== Module name './b2' was successfully resolved to 'b2.ts'. ========" ,
524+ "======== Resolving module './f1' from 'f2.ts'. ========" ,
525+ "Explicitly specified module resolution kind: 'Classic'." ,
526+ "File 'f1.ts' exist - use it as a name resolution result." ,
527+ "======== Module name './f1' was successfully resolved to 'f1.ts'. ========"
528+ ] ,
529+ "program_1: execute module reoslution normally." ) ;
530+
531+ const program_1Diagnostics = program_1 . getSemanticDiagnostics ( program_1 . getSourceFile ( "f2.ts" ) ) ;
532+ assert ( program_1Diagnostics . length === expectedErrors , `initial program should be well-formed` ) ;
533+ }
534+ const indexOfF1 = 6 ;
535+ const program_2 = updateProgram ( program_1 , program_1 . getRootFileNames ( ) , options , f => {
536+ const newSourceText = f [ indexOfF1 ] . text . updateReferences ( `/// <reference path="a1.ts"/>${ newLine } /// <reference types="typerefs1"/>` ) ;
537+ f [ indexOfF1 ] = { name : "f1.ts" , text : newSourceText } ;
538+ } ) ;
539+
540+ {
541+ const program_2Diagnostics = program_2 . getSemanticDiagnostics ( program_2 . getSourceFile ( "f2.ts" ) ) ;
542+ assert ( program_2Diagnostics . length === expectedErrors , `removing no-default-lib shouldn't affect any types used.` ) ;
543+
544+ assert . deepEqual ( program_2 . host . getTrace ( ) , [
504545 "======== Resolving type reference directive 'typerefs1', containing file 'f1.ts', root directory 'node_modules/@types'. ========" ,
505546 "Resolving with primary search path 'node_modules/@types'." ,
506547 "File 'node_modules/@types/typerefs1/package.json' does not exist." ,
@@ -515,41 +556,120 @@ namespace ts {
515556 "File 'node_modules/@types/typerefs2/package.json' does not exist." ,
516557 "File 'node_modules/@types/typerefs2/index.d.ts' exist - use it as a name resolution result." ,
517558 "======== Type reference directive 'typerefs2' was successfully resolved to 'node_modules/@types/typerefs2/index.d.ts', primary: true. ========" ,
518- "======== Resolving module './b2' from 'f2.ts'. ========" ,
559+ "Reusing resolution of module './b2' to file 'f2.ts' from old program." ,
560+ "Reusing resolution of module './f1' to file 'f2.ts' from old program."
561+ ] , "program_2: reuse module resolutions in f2 since it is unchanged" ) ;
562+ }
563+
564+ const program_3 = updateProgram ( program_2 , program_2 . getRootFileNames ( ) , options , f => {
565+ const newSourceText = f [ indexOfF1 ] . text . updateReferences ( `/// <reference path="a1.ts"/>` ) ;
566+ f [ indexOfF1 ] = { name : "f1.ts" , text : newSourceText } ;
567+ } ) ;
568+
569+ {
570+ const program_3Diagnostics = program_3 . getSemanticDiagnostics ( program_3 . getSourceFile ( "f2.ts" ) ) ;
571+ assert ( program_3Diagnostics . length === expectedErrors , `typerefs2 was unused, so diagnostics should be unaffected.` ) ;
572+
573+ assert . deepEqual ( program_3 . host . getTrace ( ) , [
574+ "======== Resolving module './b1' from 'f1.ts'. ========" ,
519575 "Explicitly specified module resolution kind: 'Classic'." ,
520- "File 'b2.ts' exist - use it as a name resolution result." ,
521- "======== Module name './b2' was successfully resolved to 'b2.ts'. ========" ,
522- "======== Resolving module './f1' from 'f2.ts'. ========" ,
576+ "File 'b1.ts' exist - use it as a name resolution result." ,
577+ "======== Module name './b1' was successfully resolved to 'b1.ts'. ========" ,
578+ "======== Resolving type reference directive 'typerefs2', containing file 'f2.ts', root directory 'node_modules/@types'. ========" ,
579+ "Resolving with primary search path 'node_modules/@types'." ,
580+ "File 'node_modules/@types/typerefs2/package.json' does not exist." ,
581+ "File 'node_modules/@types/typerefs2/index.d.ts' exist - use it as a name resolution result." ,
582+ "======== Type reference directive 'typerefs2' was successfully resolved to 'node_modules/@types/typerefs2/index.d.ts', primary: true. ========" ,
583+ "Reusing resolution of module './b2' to file 'f2.ts' from old program." ,
584+ "Reusing resolution of module './f1' to file 'f2.ts' from old program."
585+ ] , "program_3: reuse module resolutions in f2 since it is unchanged" ) ;
586+ }
587+
588+
589+ const program_4 = updateProgram ( program_3 , program_3 . getRootFileNames ( ) , options , f => {
590+ const newSourceText = f [ indexOfF1 ] . text . updateReferences ( "" ) ;
591+ f [ indexOfF1 ] = { name : "f1.ts" , text : newSourceText } ;
592+ } ) ;
593+
594+ {
595+ const program_4Diagnostics = program_4 . getSemanticDiagnostics ( program_4 . getSourceFile ( "f2.ts" ) ) ;
596+ assert ( program_4Diagnostics . length === expectedErrors , `a1.ts was unused, so diagnostics should be unaffected.` ) ;
597+
598+ assert . deepEqual ( program_4 . host . getTrace ( ) , [
599+ "======== Resolving module './b1' from 'f1.ts'. ========" ,
523600 "Explicitly specified module resolution kind: 'Classic'." ,
524- "File 'f1.ts' exist - use it as a name resolution result." ,
525- "======== Module name './f1' was successfully resolved to 'f1.ts'. ========"
526- ] ,
527- "First program should execute module reoslution normally." ) ;
601+ "File 'b1.ts' exist - use it as a name resolution result." ,
602+ "======== Module name './b1' was successfully resolved to 'b1.ts'. ========" ,
603+ "======== Resolving type reference directive 'typerefs2', containing file 'f2.ts', root directory 'node_modules/@types'. ========" ,
604+ "Resolving with primary search path 'node_modules/@types'." ,
605+ "File 'node_modules/@types/typerefs2/package.json' does not exist." ,
606+ "File 'node_modules/@types/typerefs2/index.d.ts' exist - use it as a name resolution result." ,
607+ "======== Type reference directive 'typerefs2' was successfully resolved to 'node_modules/@types/typerefs2/index.d.ts', primary: true. ========" ,
608+ "Reusing resolution of module './b2' to file 'f2.ts' from old program." ,
609+ "Reusing resolution of module './f1' to file 'f2.ts' from old program."
610+ ] , "program_4: reuse module resolutions in f2 since it is unchanged" ) ;
611+ }
612+
613+ const program_5 = updateProgram ( program_4 , program_4 . getRootFileNames ( ) , options , f => {
614+ const newSourceText = f [ indexOfF1 ] . text . updateImportsAndExports ( `import { B } from './b1';` ) ;
615+ f [ indexOfF1 ] = { name : "f1.ts" , text : newSourceText } ;
616+ } ) ;
528617
529- const program_1Diagnostics = program_1 . getSemanticDiagnostics ( program_1 . getSourceFile ( "f2.ts" ) ) ;
530- assert ( program_1Diagnostics . length === 0 , `initial program should be well-formed` ) ;
618+ {
619+ const program_5Diagnostics = program_5 . getSemanticDiagnostics ( program_5 . getSourceFile ( "f2.ts" ) ) ;
620+ assert ( program_5Diagnostics . length === ++ expectedErrors , `import of BB in f1 fails. BB is of type any. Add one error` ) ;
531621
532- const indexOfF1 = 6 ;
533- const program_2 = updateProgram ( program_1 , program_1 . getRootFileNames ( ) , options , f => {
534- let newSourceText = f [ indexOfF1 ] . text . updateProgram ( "" ) ;
535- newSourceText = newSourceText . updateImportsAndExports ( "" ) ;
536- newSourceText = newSourceText . updateReferences ( "" ) ;
622+ assert . deepEqual ( program_5 . host . getTrace ( ) , [
623+ "======== Resolving module './b1' from 'f1.ts'. ========" ,
624+ "Explicitly specified module resolution kind: 'Classic'." ,
625+ "File 'b1.ts' exist - use it as a name resolution result." ,
626+ "======== Module name './b1' was successfully resolved to 'b1.ts'. ========"
627+ ] , "program_5: exports do not affect program structure, so f2's reoslutions are silently reused." ) ;
628+ }
629+
630+ const program_6 = updateProgram ( program_5 , program_5 . getRootFileNames ( ) , options , f => {
631+ const newSourceText = f [ indexOfF1 ] . text . updateProgram ( "" ) ;
537632 f [ indexOfF1 ] = { name : "f1.ts" , text : newSourceText } ;
538633 } ) ;
539634
635+ {
636+ const program_6Diagnostics = program_6 . getSemanticDiagnostics ( program_6 . getSourceFile ( "f2.ts" ) ) ;
637+ assert ( program_6Diagnostics . length === expectedErrors , `import of BB in f1 fails.` ) ;
638+
639+ assert . deepEqual ( program_6 . host . getTrace ( ) , [
640+ "======== Resolving module './b1' from 'f1.ts'. ========" ,
641+ "Explicitly specified module resolution kind: 'Classic'." ,
642+ "File 'b1.ts' exist - use it as a name resolution result." ,
643+ "======== Module name './b1' was successfully resolved to 'b1.ts'. ========" ,
644+ "======== Resolving type reference directive 'typerefs2', containing file 'f2.ts', root directory 'node_modules/@types'. ========" ,
645+ "Resolving with primary search path 'node_modules/@types'." ,
646+ "File 'node_modules/@types/typerefs2/package.json' does not exist." ,
647+ "File 'node_modules/@types/typerefs2/index.d.ts' exist - use it as a name resolution result." ,
648+ "======== Type reference directive 'typerefs2' was successfully resolved to 'node_modules/@types/typerefs2/index.d.ts', primary: true. ========" ,
649+ "Reusing resolution of module './b2' to file 'f2.ts' from old program." ,
650+ "Reusing resolution of module './f1' to file 'f2.ts' from old program."
651+ ] , "program_6: reuse module resolutions in f2 since it is unchanged" ) ;
652+ }
653+
654+ const program_7 = updateProgram ( program_6 , program_6 . getRootFileNames ( ) , options , f => {
655+ const newSourceText = f [ indexOfF1 ] . text . updateImportsAndExports ( "" ) ;
656+ f [ indexOfF1 ] = { name : "f1.ts" , text : newSourceText } ;
657+ } ) ;
540658
541- const program_2Diagnostics = program_2 . getSemanticDiagnostics ( program_2 . getSourceFile ( "f2.ts" ) ) ;
542- assert ( program_2Diagnostics . length === 1 , `f1 no longer augments BB, should get one error.` ) ;
659+ {
660+ const program_7Diagnostics = program_7 . getSemanticDiagnostics ( program_7 . getSourceFile ( "f2.ts" ) ) ;
661+ assert ( program_7Diagnostics . length === expectedErrors , `removing import is noop with respect to program, so no change in diangostics.` ) ;
543662
544- assert . deepEqual ( program_2 . host . getTrace ( ) , [
545- "======== Resolving type reference directive 'typerefs2', containing file 'f2.ts', root directory 'node_modules/@types'. ========" ,
546- "Resolving with primary search path 'node_modules/@types'." ,
547- "File 'node_modules/@types/typerefs2/package.json' does not exist." ,
548- "File 'node_modules/@types/typerefs2/index.d.ts' exist - use it as a name resolution result." ,
549- "======== Type reference directive 'typerefs2' was successfully resolved to 'node_modules/@types/typerefs2/index.d.ts', primary: true. ========" ,
550- "Reusing resolution of module './b2' to file 'f2.ts' from old program." ,
551- "Reusing resolution of module './f1' to file 'f2.ts' from old program."
552- ] , "should reuse module resolutions in f2 since it is unchanged" ) ;
663+ assert . deepEqual ( program_7 . host . getTrace ( ) , [
664+ "======== Resolving type reference directive 'typerefs2', containing file 'f2.ts', root directory 'node_modules/@types'. ========" ,
665+ "Resolving with primary search path 'node_modules/@types'." ,
666+ "File 'node_modules/@types/typerefs2/package.json' does not exist." ,
667+ "File 'node_modules/@types/typerefs2/index.d.ts' exist - use it as a name resolution result." ,
668+ "======== Type reference directive 'typerefs2' was successfully resolved to 'node_modules/@types/typerefs2/index.d.ts', primary: true. ========" ,
669+ "Reusing resolution of module './b2' to file 'f2.ts' from old program." ,
670+ "Reusing resolution of module './f1' to file 'f2.ts' from old program."
671+ ] , "program_7 should reuse module resolutions in f2 since it is unchanged" ) ;
672+ }
553673 } ) ;
554674 } ) ;
555675
0 commit comments