@@ -107,6 +107,47 @@ describe('perform watch', () => {
107107 expect ( getSourceFileSpy ! ) . toHaveBeenCalledWith ( utilTsPath , ts . ScriptTarget . ES5 ) ;
108108 } ) ;
109109
110+ // https://github.com/angular/angular/pull/26036
111+ it ( 'should handle redirected source files' , ( ) => {
112+ const config = createConfig ( ) ;
113+ const host = new MockWatchHost ( config ) ;
114+ host . createCompilerHost = ( options : ng . CompilerOptions ) => {
115+ const ngHost = ng . createCompilerHost ( { options} ) ;
116+ return ngHost ;
117+ } ;
118+
119+ // This file structure has an identical version of "a" under the root node_modules and inside
120+ // of "b". Because their package.json file indicates it is the exact same version of "a",
121+ // TypeScript will transform the source file of "node_modules/b/node_modules/a/index.d.ts"
122+ // into a redirect to "node_modules/a/index.d.ts". During watch compilations, we must assure
123+ // not to reintroduce "node_modules/b/node_modules/a/index.d.ts" as its redirected source file,
124+ // but instead using its original file.
125+ testSupport . writeFiles ( {
126+ 'node_modules/a/index.js' : `export class ServiceA {}` ,
127+ 'node_modules/a/index.d.ts' : `export declare class ServiceA {}` ,
128+ 'node_modules/a/package.json' : `{"name": "a", "version": "1.0"}` ,
129+ 'node_modules/b/node_modules/a/index.js' : `export class ServiceA {}` ,
130+ 'node_modules/b/node_modules/a/index.d.ts' : `export declare class ServiceA {}` ,
131+ 'node_modules/b/node_modules/a/package.json' : `{"name": "a", "version": "1.0"}` ,
132+ 'node_modules/b/index.js' : `export {ServiceA as ServiceB} from 'a';` ,
133+ 'node_modules/b/index.d.ts' : `export {ServiceA as ServiceB} from 'a';` ,
134+ 'src/index.ts' : `
135+ import {ServiceA} from 'a';
136+ import {ServiceB} from 'b';
137+ ` ,
138+ } ) ;
139+
140+ const indexTsPath = path . posix . join ( testSupport . basePath , 'src' , 'index.ts' ) ;
141+
142+ performWatchCompilation ( host ) ;
143+
144+ // Trigger a file change. This recreates the program from the old program. If redirect sources
145+ // were introduced into the new program, this would fail due to an assertion failure in TS.
146+ host . triggerFileChange ( FileChangeEvent . Change , indexTsPath ) ;
147+ expectNoDiagnostics ( config . options , host . diagnostics ) ;
148+ } ) ;
149+
150+
110151 it ( 'should recover from static analysis errors' , ( ) => {
111152 const config = createConfig ( ) ;
112153 const host = new MockWatchHost ( config ) ;
0 commit comments