refactor(ivy): ngcc - no need to pass `isCore` explicitly (#30591)
It is part of `EntryPointBundle` so we can just use that, which is generally already passed around. PR Close #30591
This commit is contained in:
parent
e943859843
commit
74f637f98d
|
@ -58,25 +58,23 @@ export class Transformer {
|
||||||
* @returns information about the files that were transformed.
|
* @returns information about the files that were transformed.
|
||||||
*/
|
*/
|
||||||
transform(bundle: EntryPointBundle): FileToWrite[] {
|
transform(bundle: EntryPointBundle): FileToWrite[] {
|
||||||
const isCore = bundle.isCore;
|
const reflectionHost = this.getHost(bundle);
|
||||||
const reflectionHost = this.getHost(isCore, bundle);
|
|
||||||
|
|
||||||
// Parse and analyze the files.
|
// Parse and analyze the files.
|
||||||
const {decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
const {decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||||
moduleWithProvidersAnalyses} = this.analyzeProgram(reflectionHost, isCore, bundle);
|
moduleWithProvidersAnalyses} = this.analyzeProgram(reflectionHost, bundle);
|
||||||
|
|
||||||
// Transform the source files and source maps.
|
// Transform the source files and source maps.
|
||||||
const srcFormatter = this.getRenderingFormatter(reflectionHost, isCore, bundle);
|
const srcFormatter = this.getRenderingFormatter(reflectionHost, bundle);
|
||||||
|
|
||||||
const renderer =
|
const renderer = new Renderer(srcFormatter, this.fs, this.logger, bundle);
|
||||||
new Renderer(srcFormatter, this.fs, this.logger, reflectionHost, isCore, bundle);
|
|
||||||
let renderedFiles = renderer.renderProgram(
|
let renderedFiles = renderer.renderProgram(
|
||||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||||
|
|
||||||
if (bundle.dts) {
|
if (bundle.dts) {
|
||||||
const dtsFormatter = new EsmRenderingFormatter(reflectionHost, isCore);
|
const dtsFormatter = new EsmRenderingFormatter(reflectionHost, bundle.isCore);
|
||||||
const dtsRenderer =
|
const dtsRenderer =
|
||||||
new DtsRenderer(dtsFormatter, this.fs, this.logger, reflectionHost, isCore, bundle);
|
new DtsRenderer(dtsFormatter, this.fs, this.logger, reflectionHost, bundle);
|
||||||
const renderedDtsFiles = dtsRenderer.renderProgram(
|
const renderedDtsFiles = dtsRenderer.renderProgram(
|
||||||
decorationAnalyses, privateDeclarationsAnalyses, moduleWithProvidersAnalyses);
|
decorationAnalyses, privateDeclarationsAnalyses, moduleWithProvidersAnalyses);
|
||||||
renderedFiles = renderedFiles.concat(renderedDtsFiles);
|
renderedFiles = renderedFiles.concat(renderedDtsFiles);
|
||||||
|
@ -85,45 +83,43 @@ export class Transformer {
|
||||||
return renderedFiles;
|
return renderedFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
getHost(isCore: boolean, bundle: EntryPointBundle): NgccReflectionHost {
|
getHost(bundle: EntryPointBundle): NgccReflectionHost {
|
||||||
const typeChecker = bundle.src.program.getTypeChecker();
|
const typeChecker = bundle.src.program.getTypeChecker();
|
||||||
switch (bundle.format) {
|
switch (bundle.format) {
|
||||||
case 'esm2015':
|
case 'esm2015':
|
||||||
return new Esm2015ReflectionHost(this.logger, isCore, typeChecker, bundle.dts);
|
return new Esm2015ReflectionHost(this.logger, bundle.isCore, typeChecker, bundle.dts);
|
||||||
case 'esm5':
|
case 'esm5':
|
||||||
return new Esm5ReflectionHost(this.logger, isCore, typeChecker, bundle.dts);
|
return new Esm5ReflectionHost(this.logger, bundle.isCore, typeChecker, bundle.dts);
|
||||||
case 'umd':
|
case 'umd':
|
||||||
return new UmdReflectionHost(
|
return new UmdReflectionHost(
|
||||||
this.logger, isCore, bundle.src.program, bundle.src.host, bundle.dts);
|
this.logger, bundle.isCore, bundle.src.program, bundle.src.host, bundle.dts);
|
||||||
case 'commonjs':
|
case 'commonjs':
|
||||||
return new CommonJsReflectionHost(
|
return new CommonJsReflectionHost(
|
||||||
this.logger, isCore, bundle.src.program, bundle.src.host, bundle.dts);
|
this.logger, bundle.isCore, bundle.src.program, bundle.src.host, bundle.dts);
|
||||||
default:
|
default:
|
||||||
throw new Error(`Reflection host for "${bundle.format}" not yet implemented.`);
|
throw new Error(`Reflection host for "${bundle.format}" not yet implemented.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getRenderingFormatter(host: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle):
|
getRenderingFormatter(host: NgccReflectionHost, bundle: EntryPointBundle): RenderingFormatter {
|
||||||
RenderingFormatter {
|
|
||||||
switch (bundle.format) {
|
switch (bundle.format) {
|
||||||
case 'esm2015':
|
case 'esm2015':
|
||||||
return new EsmRenderingFormatter(host, isCore);
|
return new EsmRenderingFormatter(host, bundle.isCore);
|
||||||
case 'esm5':
|
case 'esm5':
|
||||||
return new Esm5RenderingFormatter(host, isCore);
|
return new Esm5RenderingFormatter(host, bundle.isCore);
|
||||||
case 'umd':
|
case 'umd':
|
||||||
if (!(host instanceof UmdReflectionHost)) {
|
if (!(host instanceof UmdReflectionHost)) {
|
||||||
throw new Error('UmdRenderer requires a UmdReflectionHost');
|
throw new Error('UmdRenderer requires a UmdReflectionHost');
|
||||||
}
|
}
|
||||||
return new UmdRenderingFormatter(host, isCore);
|
return new UmdRenderingFormatter(host, bundle.isCore);
|
||||||
case 'commonjs':
|
case 'commonjs':
|
||||||
return new CommonJsRenderingFormatter(host, isCore);
|
return new CommonJsRenderingFormatter(host, bundle.isCore);
|
||||||
default:
|
default:
|
||||||
throw new Error(`Renderer for "${bundle.format}" not yet implemented.`);
|
throw new Error(`Renderer for "${bundle.format}" not yet implemented.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
analyzeProgram(reflectionHost: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle):
|
analyzeProgram(reflectionHost: NgccReflectionHost, bundle: EntryPointBundle): ProgramAnalyses {
|
||||||
ProgramAnalyses {
|
|
||||||
const typeChecker = bundle.src.program.getTypeChecker();
|
const typeChecker = bundle.src.program.getTypeChecker();
|
||||||
const referencesRegistry = new NgccReferencesRegistry(reflectionHost);
|
const referencesRegistry = new NgccReferencesRegistry(reflectionHost);
|
||||||
|
|
||||||
|
@ -132,7 +128,7 @@ export class Transformer {
|
||||||
|
|
||||||
const decorationAnalyzer = new DecorationAnalyzer(
|
const decorationAnalyzer = new DecorationAnalyzer(
|
||||||
this.fs, bundle.src.program, bundle.src.options, bundle.src.host, typeChecker,
|
this.fs, bundle.src.program, bundle.src.options, bundle.src.host, typeChecker,
|
||||||
reflectionHost, referencesRegistry, bundle.rootDirs, isCore);
|
reflectionHost, referencesRegistry, bundle.rootDirs, bundle.isCore);
|
||||||
const decorationAnalyses = decorationAnalyzer.analyzeProgram();
|
const decorationAnalyses = decorationAnalyzer.analyzeProgram();
|
||||||
|
|
||||||
const moduleWithProvidersAnalyzer =
|
const moduleWithProvidersAnalyzer =
|
||||||
|
|
|
@ -53,8 +53,7 @@ export interface DtsClassInfo {
|
||||||
export class DtsRenderer {
|
export class DtsRenderer {
|
||||||
constructor(
|
constructor(
|
||||||
private dtsFormatter: RenderingFormatter, private fs: FileSystem, private logger: Logger,
|
private dtsFormatter: RenderingFormatter, private fs: FileSystem, private logger: Logger,
|
||||||
private host: NgccReflectionHost, private isCore: boolean, private bundle: EntryPointBundle) {
|
private host: NgccReflectionHost, private bundle: EntryPointBundle) {}
|
||||||
}
|
|
||||||
|
|
||||||
renderProgram(
|
renderProgram(
|
||||||
decorationAnalyses: DecorationAnalyses,
|
decorationAnalyses: DecorationAnalyses,
|
||||||
|
@ -84,7 +83,8 @@ export class DtsRenderer {
|
||||||
const outputText = new MagicString(input.source);
|
const outputText = new MagicString(input.source);
|
||||||
const printer = ts.createPrinter();
|
const printer = ts.createPrinter();
|
||||||
const importManager = new ImportManager(
|
const importManager = new ImportManager(
|
||||||
getImportRewriter(this.bundle.dts !.r3SymbolsFile, this.isCore, false), IMPORT_PREFIX);
|
getImportRewriter(this.bundle.dts !.r3SymbolsFile, this.bundle.isCore, false),
|
||||||
|
IMPORT_PREFIX);
|
||||||
|
|
||||||
renderInfo.classInfo.forEach(dtsClass => {
|
renderInfo.classInfo.forEach(dtsClass => {
|
||||||
const endOfClass = dtsClass.dtsDeclaration.getEnd();
|
const endOfClass = dtsClass.dtsDeclaration.getEnd();
|
||||||
|
|
|
@ -15,7 +15,6 @@ import {PrivateDeclarationsAnalyses} from '../analysis/private_declarations_anal
|
||||||
import {SwitchMarkerAnalyses, SwitchMarkerAnalysis} from '../analysis/switch_marker_analyzer';
|
import {SwitchMarkerAnalyses, SwitchMarkerAnalysis} from '../analysis/switch_marker_analyzer';
|
||||||
import {IMPORT_PREFIX} from '../constants';
|
import {IMPORT_PREFIX} from '../constants';
|
||||||
import {FileSystem} from '../../../src/ngtsc/file_system';
|
import {FileSystem} from '../../../src/ngtsc/file_system';
|
||||||
import {NgccReflectionHost} from '../host/ngcc_host';
|
|
||||||
import {EntryPointBundle} from '../packages/entry_point_bundle';
|
import {EntryPointBundle} from '../packages/entry_point_bundle';
|
||||||
import {Logger} from '../logging/logger';
|
import {Logger} from '../logging/logger';
|
||||||
import {FileToWrite, getImportRewriter, stripExtension} from './utils';
|
import {FileToWrite, getImportRewriter, stripExtension} from './utils';
|
||||||
|
@ -31,8 +30,7 @@ import {extractSourceMap, renderSourceAndMap} from './source_maps';
|
||||||
export class Renderer {
|
export class Renderer {
|
||||||
constructor(
|
constructor(
|
||||||
private srcFormatter: RenderingFormatter, private fs: FileSystem, private logger: Logger,
|
private srcFormatter: RenderingFormatter, private fs: FileSystem, private logger: Logger,
|
||||||
private host: NgccReflectionHost, private isCore: boolean, private bundle: EntryPointBundle) {
|
private bundle: EntryPointBundle) {}
|
||||||
}
|
|
||||||
|
|
||||||
renderProgram(
|
renderProgram(
|
||||||
decorationAnalyses: DecorationAnalyses, switchMarkerAnalyses: SwitchMarkerAnalyses,
|
decorationAnalyses: DecorationAnalyses, switchMarkerAnalyses: SwitchMarkerAnalyses,
|
||||||
|
@ -72,7 +70,8 @@ export class Renderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
const importManager = new ImportManager(
|
const importManager = new ImportManager(
|
||||||
getImportRewriter(this.bundle.src.r3SymbolsFile, this.isCore, this.bundle.isFlatCore),
|
getImportRewriter(
|
||||||
|
this.bundle.src.r3SymbolsFile, this.bundle.isCore, this.bundle.isFlatCore),
|
||||||
IMPORT_PREFIX);
|
IMPORT_PREFIX);
|
||||||
|
|
||||||
if (compiledFile) {
|
if (compiledFile) {
|
||||||
|
|
|
@ -82,7 +82,7 @@ function createTestRenderer(
|
||||||
spyOn(testFormatter, 'rewriteSwitchableDeclarations').and.callThrough();
|
spyOn(testFormatter, 'rewriteSwitchableDeclarations').and.callThrough();
|
||||||
spyOn(testFormatter, 'addModuleWithProvidersParams').and.callThrough();
|
spyOn(testFormatter, 'addModuleWithProvidersParams').and.callThrough();
|
||||||
|
|
||||||
const renderer = new DtsRenderer(testFormatter, fs, logger, host, isCore, bundle);
|
const renderer = new DtsRenderer(testFormatter, fs, logger, host, bundle);
|
||||||
|
|
||||||
return {renderer,
|
return {renderer,
|
||||||
testFormatter,
|
testFormatter,
|
||||||
|
|
|
@ -83,7 +83,7 @@ function createTestRenderer(
|
||||||
spyOn(testFormatter, 'rewriteSwitchableDeclarations').and.callThrough();
|
spyOn(testFormatter, 'rewriteSwitchableDeclarations').and.callThrough();
|
||||||
spyOn(testFormatter, 'addModuleWithProvidersParams').and.callThrough();
|
spyOn(testFormatter, 'addModuleWithProvidersParams').and.callThrough();
|
||||||
|
|
||||||
const renderer = new Renderer(testFormatter, fs, logger, host, isCore, bundle);
|
const renderer = new Renderer(testFormatter, fs, logger, bundle);
|
||||||
|
|
||||||
return {renderer,
|
return {renderer,
|
||||||
testFormatter,
|
testFormatter,
|
||||||
|
|
Loading…
Reference in New Issue