fix(compiler): don’t store invalid state when using listLazyRoutes
(#19953)
Previously, `listLazyRoute` would store invalid information in a compiler internal cache, which lead to incorrect paths that were used during emit. This commit fixes this. PR Close #19953
This commit is contained in:

committed by
Matias Niemelä

parent
eca822b756
commit
a869aeecd2
@ -617,6 +617,34 @@ describe('ng program', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should emit correctly after listing lazyRoutes', () => {
|
||||||
|
testSupport.writeFiles({
|
||||||
|
'src/main.ts': `
|
||||||
|
import {NgModule} from '@angular/core';
|
||||||
|
import {RouterModule} from '@angular/router';
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [RouterModule.forRoot([{loadChildren: './lazy/lazy#LazyModule'}])]
|
||||||
|
})
|
||||||
|
export class MainModule {}
|
||||||
|
`,
|
||||||
|
'src/lazy/lazy.ts': `
|
||||||
|
import {NgModule} from '@angular/core';
|
||||||
|
|
||||||
|
@NgModule()
|
||||||
|
export class ChildModule {}
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
const {program, options} = createProgram(['src/main.ts', 'src/lazy/lazy.ts']);
|
||||||
|
expectNoDiagnosticsInProgram(options, program);
|
||||||
|
program.listLazyRoutes();
|
||||||
|
program.emit();
|
||||||
|
|
||||||
|
const lazyNgFactory =
|
||||||
|
fs.readFileSync(path.resolve(testSupport.basePath, 'built/src/lazy/lazy.ngfactory.js'));
|
||||||
|
expect(lazyNgFactory).toContain('import * as i1 from "./lazy";');
|
||||||
|
});
|
||||||
|
|
||||||
it('should list lazyRoutes given an entryRoute recursively', () => {
|
it('should list lazyRoutes given an entryRoute recursively', () => {
|
||||||
writeSomeRoutes();
|
writeSomeRoutes();
|
||||||
const {program, options} = createProgram(['src/main.ts']);
|
const {program, options} = createProgram(['src/main.ts']);
|
||||||
|
@ -80,8 +80,10 @@ export class StaticReflector implements CompileReflector {
|
|||||||
const refSymbol =
|
const refSymbol =
|
||||||
this.symbolResolver.getSymbolByModule(ref.moduleName !, ref.name !, containingFile);
|
this.symbolResolver.getSymbolByModule(ref.moduleName !, ref.name !, containingFile);
|
||||||
const declarationSymbol = this.findSymbolDeclaration(refSymbol);
|
const declarationSymbol = this.findSymbolDeclaration(refSymbol);
|
||||||
this.symbolResolver.recordModuleNameForFileName(refSymbol.filePath, ref.moduleName !);
|
if (!containingFile) {
|
||||||
this.symbolResolver.recordImportAs(declarationSymbol, refSymbol);
|
this.symbolResolver.recordModuleNameForFileName(refSymbol.filePath, ref.moduleName !);
|
||||||
|
this.symbolResolver.recordImportAs(declarationSymbol, refSymbol);
|
||||||
|
}
|
||||||
return declarationSymbol;
|
return declarationSymbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1062,6 +1062,22 @@ describe('StaticReflector', () => {
|
|||||||
.useValue)
|
.useValue)
|
||||||
.toEqual({path: 'foo', data: {e: 1}});
|
.toEqual({path: 'foo', data: {e: 1}});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('resolveExternalReference', () => {
|
||||||
|
it('should register modules names in the StaticSymbolResolver if no containingFile is given',
|
||||||
|
() => {
|
||||||
|
init({
|
||||||
|
'/tmp/root.ts': ``,
|
||||||
|
'/tmp/a.ts': `export const x = 1;`,
|
||||||
|
});
|
||||||
|
let symbol =
|
||||||
|
reflector.resolveExternalReference({moduleName: './a', name: 'x'}, '/tmp/root.ts');
|
||||||
|
expect(symbolResolver.getKnownModuleName(symbol.filePath)).toBeFalsy();
|
||||||
|
|
||||||
|
symbol = reflector.resolveExternalReference({moduleName: 'a', name: 'x'});
|
||||||
|
expect(symbolResolver.getKnownModuleName(symbol.filePath)).toBe('a');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const DEFAULT_TEST_DATA: {[key: string]: any} = {
|
const DEFAULT_TEST_DATA: {[key: string]: any} = {
|
||||||
|
Reference in New Issue
Block a user