refactor(ngcc): use bundle src to create reflection hosts (#34254)

Previously individual properties of the src bundle program were
passed to the reflection host constructors. But going forward,
more properties will be required. To prevent the signature getting
continually larger and more unwieldy, this change just passes the
whole src bundle to the constructor, allowing it to extract what it
needs.

PR Close #34254
This commit is contained in:
Pete Bacon Darwin
2019-12-18 14:03:04 +00:00
committed by Kara Erickson
parent 5ec4fb2f2a
commit b2a8466e45
24 changed files with 1428 additions and 1459 deletions

View File

@ -19,10 +19,12 @@ import {NgccClassSymbol} from './ngcc_host';
export class CommonJsReflectionHost extends Esm5ReflectionHost {
protected commonJsExports = new Map<ts.SourceFile, Map<string, Declaration>|null>();
protected topLevelHelperCalls = new Map<string, Map<ts.SourceFile, ts.CallExpression[]>>();
constructor(
logger: Logger, isCore: boolean, protected program: ts.Program,
protected compilerHost: ts.CompilerHost, dts?: BundleProgram|null) {
super(logger, isCore, program.getTypeChecker(), dts);
protected program: ts.Program;
protected compilerHost: ts.CompilerHost;
constructor(logger: Logger, isCore: boolean, src: BundleProgram, dts?: BundleProgram|null) {
super(logger, isCore, src, dts);
this.program = src.program;
this.compilerHost = src.host;
}
getImportOfIdentifier(id: ts.Identifier): Import|null {

View File

@ -83,9 +83,9 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N
protected decoratorCache = new Map<ClassDeclaration, DecoratorInfo>();
constructor(
protected logger: Logger, protected isCore: boolean, checker: ts.TypeChecker,
protected logger: Logger, protected isCore: boolean, src: BundleProgram,
dts?: BundleProgram|null) {
super(checker);
super(src.program.getTypeChecker());
this.dtsDeclarationMap =
dts && this.computeDtsDeclarationMap(dts.path, dts.program, dts.package) || null;
}

View File

@ -18,10 +18,12 @@ export class UmdReflectionHost extends Esm5ReflectionHost {
protected umdModules = new Map<ts.SourceFile, UmdModule|null>();
protected umdExports = new Map<ts.SourceFile, Map<string, Declaration>|null>();
protected umdImportPaths = new Map<ts.ParameterDeclaration, string|null>();
constructor(
logger: Logger, isCore: boolean, protected program: ts.Program,
protected compilerHost: ts.CompilerHost, dts?: BundleProgram|null) {
super(logger, isCore, program.getTypeChecker(), dts);
protected program: ts.Program;
protected compilerHost: ts.CompilerHost;
constructor(logger: Logger, isCore: boolean, src: BundleProgram, dts?: BundleProgram|null) {
super(logger, isCore, src, dts);
this.program = src.program;
this.compilerHost = src.host;
}
getImportOfIdentifier(id: ts.Identifier): Import|null {

View File

@ -100,18 +100,15 @@ export class Transformer {
}
getHost(bundle: EntryPointBundle): NgccReflectionHost {
const typeChecker = bundle.src.program.getTypeChecker();
switch (bundle.format) {
case 'esm2015':
return new Esm2015ReflectionHost(this.logger, bundle.isCore, typeChecker, bundle.dts);
return new Esm2015ReflectionHost(this.logger, bundle.isCore, bundle.src, bundle.dts);
case 'esm5':
return new Esm5ReflectionHost(this.logger, bundle.isCore, typeChecker, bundle.dts);
return new Esm5ReflectionHost(this.logger, bundle.isCore, bundle.src, bundle.dts);
case 'umd':
return new UmdReflectionHost(
this.logger, bundle.isCore, bundle.src.program, bundle.src.host, bundle.dts);
return new UmdReflectionHost(this.logger, bundle.isCore, bundle.src, bundle.dts);
case 'commonjs':
return new CommonJsReflectionHost(
this.logger, bundle.isCore, bundle.src.program, bundle.src.host, bundle.dts);
return new CommonJsReflectionHost(this.logger, bundle.isCore, bundle.src, bundle.dts);
default:
throw new Error(`Reflection host for "${bundle.format}" not yet implemented.`);
}