diff --git a/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts b/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts index 950ae78b98..e83ced30ad 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts @@ -307,7 +307,10 @@ export class NgModuleDecoratorHandler implements }); if (this.factoryTracker !== null) { - this.factoryTracker.track(node.getSourceFile(), analysis.factorySymbolName); + this.factoryTracker.track(node.getSourceFile(), { + name: analysis.factorySymbolName, + hasId: !!analysis.id, + }); } this.injectableRegistry.registerInjectable(node); diff --git a/packages/compiler-cli/src/ngtsc/shims/api.ts b/packages/compiler-cli/src/ngtsc/shims/api.ts index 68cfbdb017..ec1e943c13 100644 --- a/packages/compiler-cli/src/ngtsc/shims/api.ts +++ b/packages/compiler-cli/src/ngtsc/shims/api.ts @@ -61,10 +61,15 @@ export interface PerFileShimGenerator { export interface FactoryTracker { readonly sourceInfo: Map; - track(sf: ts.SourceFile, factorySymbolName: string): void; + track(sf: ts.SourceFile, moduleInfo: ModuleInfo): void; } export interface FactoryInfo { sourceFilePath: string; - moduleSymbolNames: Set; -} \ No newline at end of file + moduleSymbols: Map; +} + +export interface ModuleInfo { + name: string; + hasId: boolean; +} diff --git a/packages/compiler-cli/src/ngtsc/shims/src/factory_generator.ts b/packages/compiler-cli/src/ngtsc/shims/src/factory_generator.ts index 8e54e282a5..f9dcf6de28 100644 --- a/packages/compiler-cli/src/ngtsc/shims/src/factory_generator.ts +++ b/packages/compiler-cli/src/ngtsc/shims/src/factory_generator.ts @@ -9,7 +9,7 @@ import * as ts from 'typescript'; import {absoluteFromSourceFile, AbsoluteFsPath, basename} from '../../file_system'; import {ImportRewriter} from '../../imports'; -import {FactoryInfo, FactoryTracker, PerFileShimGenerator} from '../api'; +import {FactoryInfo, FactoryTracker, ModuleInfo, PerFileShimGenerator} from '../api'; import {generatedModuleName} from './util'; @@ -22,7 +22,7 @@ const STRIP_NG_FACTORY = /(.*)NgFactory$/; */ export class FactoryGenerator implements PerFileShimGenerator, FactoryTracker { readonly sourceInfo = new Map(); - private sourceToFactorySymbols = new Map>(); + private sourceToFactorySymbols = new Map>(); readonly shouldEmit = true; readonly extensionPrefix = 'ngfactory'; @@ -85,16 +85,19 @@ export class FactoryGenerator implements PerFileShimGenerator, FactoryTracker { genFile.moduleName = generatedModuleName(sf.moduleName, sf.fileName, '.ngfactory'); } - const moduleSymbolNames = new Set(); - this.sourceToFactorySymbols.set(absoluteSfPath, moduleSymbolNames); - this.sourceInfo.set(genFilePath, {sourceFilePath: absoluteSfPath, moduleSymbolNames}); + const moduleSymbols = new Map(); + this.sourceToFactorySymbols.set(absoluteSfPath, moduleSymbols); + this.sourceInfo.set(genFilePath, { + sourceFilePath: absoluteSfPath, + moduleSymbols, + }); return genFile; } - track(sf: ts.SourceFile, factorySymbolName: string): void { + track(sf: ts.SourceFile, moduleInfo: ModuleInfo): void { if (this.sourceToFactorySymbols.has(sf.fileName)) { - this.sourceToFactorySymbols.get(sf.fileName)!.add(factorySymbolName); + this.sourceToFactorySymbols.get(sf.fileName)!.set(moduleInfo.name, moduleInfo); } } } @@ -123,7 +126,7 @@ function transformFactorySourceFile( return file; } - const {moduleSymbolNames, sourceFilePath} = factoryMap.get(file.fileName)!; + const {moduleSymbols, sourceFilePath} = factoryMap.get(file.fileName)!; file = ts.getMutableClone(file); @@ -183,7 +186,7 @@ function transformFactorySourceFile( // Otherwise, check if this export is a factory for a known NgModule, and retain it if so. const match = STRIP_NG_FACTORY.exec(decl.name.text); - if (match !== null && moduleSymbolNames.has(match[1])) { + if (match !== null && moduleSymbols.has(match[1])) { transformedStatements.push(stmt); } } else {