refactor(ivy): move analysis side effects into a register phase (#34288)
Previously 'analyze' in the various `DecoratorHandler`s not only extracts information from the decorators on the classes being analyzed, but also has several side effects within the compiler: * it can register metadata about the types involved in global metadata trackers. * it can register information about which .ngfactory symbols are actually needed. In this commit, these side-effects are moved into a new 'register' phase, which runs after the 'analyze' step. Currently this is a no-op refactoring as 'register' is always called directly after 'analyze'. In the future this opens the door for re-use of prior analysis work (with only 'register' being called, to apply the above side effects). Also as part of this refactoring, the reification of NgModule scope information into the incremental dependency graph is moved to the `NgtscProgram` instead of the `TraitCompiler` (which now only manages trait compilation and does not have other side effects). PR Close #34288
This commit is contained in:

committed by
Kara Erickson

parent
252e3e9487
commit
50cdc0ac1b
@ -9,6 +9,7 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
export {FactoryGenerator, FactoryInfo, generatedFactoryTransform} from './src/factory_generator';
|
||||
export {FactoryTracker} from './src/factory_tracker';
|
||||
export {GeneratedShimsHostWrapper, ShimGenerator} from './src/host';
|
||||
export {SummaryGenerator} from './src/summary_generator';
|
||||
export {TypeCheckShimGenerator} from './src/typecheck_shim';
|
||||
|
38
packages/compiler-cli/src/ngtsc/shims/src/factory_tracker.ts
Normal file
38
packages/compiler-cli/src/ngtsc/shims/src/factory_tracker.ts
Normal file
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {FactoryGenerator, FactoryInfo} from './factory_generator';
|
||||
|
||||
/**
|
||||
* Maintains a mapping of which symbols in a .ngfactory file have been used.
|
||||
*
|
||||
* .ngfactory files are generated with one symbol per defined class in the source file, regardless
|
||||
* of whether the classes in the source files are NgModules (because that isn't known at the time
|
||||
* the factory files are generated). The `FactoryTracker` exists to support removing factory symbols
|
||||
* which didn't end up being NgModules, by tracking the ones which are.
|
||||
*/
|
||||
export class FactoryTracker {
|
||||
readonly sourceInfo = new Map<string, FactoryInfo>();
|
||||
private sourceToFactorySymbols = new Map<string, Set<string>>();
|
||||
|
||||
constructor(generator: FactoryGenerator) {
|
||||
generator.factoryFileMap.forEach((sourceFilePath, factoryPath) => {
|
||||
const moduleSymbolNames = new Set<string>();
|
||||
this.sourceToFactorySymbols.set(sourceFilePath, moduleSymbolNames);
|
||||
this.sourceInfo.set(factoryPath, {sourceFilePath, moduleSymbolNames});
|
||||
});
|
||||
}
|
||||
|
||||
track(sf: ts.SourceFile, factorySymbolName: string): void {
|
||||
if (this.sourceToFactorySymbols.has(sf.fileName)) {
|
||||
this.sourceToFactorySymbols.get(sf.fileName) !.add(factorySymbolName);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user