@@ -163,10 +163,14 @@ namespace ts {
163163
164164 let filesByName = createFileMap < SourceFile > ( fileName => host . getCanonicalFileName ( fileName ) ) ;
165165
166- // if old program was provided by has different target module kind - assume that it cannot be reused
167- // different module kind can lead to different way of resolving modules
168- if ( oldProgram && oldProgram . getCompilerOptions ( ) . module !== options . module ) {
169- oldProgram = undefined ;
166+ if ( oldProgram ) {
167+ let oldOptions = oldProgram . getCompilerOptions ( ) ;
168+ if ( ( oldOptions . module !== options . module ) ||
169+ ( oldOptions . noResolve !== options . noResolve ) ||
170+ ( oldOptions . target !== options . target ) ||
171+ ( oldOptions . noLib !== options . noLib ) ) {
172+ oldProgram = undefined ;
173+ }
170174 }
171175
172176 if ( ! tryReuseStructureFromOldProgram ( ) ) {
@@ -222,10 +226,6 @@ namespace ts {
222226 }
223227
224228 function tryReuseStructureFromOldProgram ( ) : boolean {
225- if ( ! host . hasChanges ) {
226- // host does not support method 'hasChanges'
227- return false ;
228- }
229229 if ( ! oldProgram ) {
230230 return false ;
231231 }
@@ -234,28 +234,19 @@ namespace ts {
234234
235235 // there is an old program, check if we can reuse its structure
236236 let oldRootNames = oldProgram . getRootFileNames ( ) ;
237- if ( rootNames . length !== oldRootNames . length ) {
238- // different amount of root names - structure cannot be reused
237+ if ( ! arrayIsEqualTo ( oldRootNames , rootNames ) ) {
239238 return false ;
240239 }
241240
242- for ( let i = 0 ; i < rootNames . length ; i ++ ) {
243- if ( oldRootNames [ i ] !== rootNames [ i ] ) {
244- // different order of root names - structure cannot be reused
245- return false ;
246- }
247- }
248-
249241 // check if program source files has changed in the way that can affect structure of the program
250242 let newSourceFiles : SourceFile [ ] = [ ] ;
251243 for ( let oldSourceFile of oldProgram . getSourceFiles ( ) ) {
252- let newSourceFile : SourceFile ;
253- if ( host . hasChanges ( oldSourceFile ) ) {
254- newSourceFile = host . getSourceFile ( oldSourceFile . fileName , options . target ) ;
255- if ( ! newSourceFile ) {
256- return false ;
257- }
258-
244+ let newSourceFile = host . getSourceFile ( oldSourceFile . fileName , options . target ) ;
245+ if ( ! newSourceFile ) {
246+ return false ;
247+ }
248+
249+ if ( oldSourceFile !== newSourceFile ) {
259250 // check tripleslash references
260251 if ( ! arrayIsEqualTo ( oldSourceFile . referencedFiles , newSourceFile . referencedFiles , fileReferenceIsEqualTo ) ) {
261252 // tripleslash references has changed
@@ -420,7 +411,7 @@ namespace ts {
420411 }
421412
422413 function moduleNameIsEqualTo ( a : LiteralExpression , b : LiteralExpression ) : boolean {
423- return a . text === b . text ;
414+ return a . text === b . text ;
424415 }
425416
426417 function collectExternalModuleReferences ( file : SourceFile ) : void {
@@ -603,7 +594,7 @@ namespace ts {
603594 checkImports: {
604595 if ( file . resolvedModules ) {
605596 for ( let moduleName of file . imports ) {
606- if ( ! hasResolvedModuleName ( file , moduleName ) ) {
597+ if ( ! hasResolvedModuleName ( file , moduleName . text ) ) {
607598 break checkImports;
608599 }
609600 }
@@ -640,7 +631,7 @@ namespace ts {
640631 if ( existingResolutions && hasProperty ( existingResolutions , moduleNameExpr . text ) ) {
641632 let fileName = existingResolutions [ moduleNameExpr . text ] ;
642633 // use existing resolution
643- setResolvedModuleName ( file , moduleNameExpr , fileName ) ;
634+ setResolvedModuleName ( file , moduleNameExpr . text , fileName ) ;
644635 if ( fileName ) {
645636 findModuleSourceFile ( fileName , moduleNameExpr ) ;
646637 }
@@ -651,7 +642,7 @@ namespace ts {
651642 searchName = normalizePath ( combinePaths ( searchPath , moduleNameExpr . text ) ) ;
652643 let referencedSourceFile = forEach ( supportedExtensions , extension => findModuleSourceFile ( searchName + extension , moduleNameExpr ) ) ;
653644 if ( referencedSourceFile ) {
654- setResolvedModuleName ( file , moduleNameExpr , referencedSourceFile . fileName ) ;
645+ setResolvedModuleName ( file , moduleNameExpr . text , referencedSourceFile . fileName ) ;
655646 return ;
656647 }
657648
@@ -662,7 +653,7 @@ namespace ts {
662653 searchPath = parentPath ;
663654 }
664655 // mark reference as non-resolved
665- setResolvedModuleName ( file , moduleNameExpr , undefined ) ;
656+ setResolvedModuleName ( file , moduleNameExpr . text , undefined ) ;
666657 }
667658 }
668659
0 commit comments