perf(ivy): ngcc - only render .d.ts analysis when necessary (#26403)

For each package entry-point there is only one format that
is used to compile the typings files (.d.ts). This will be
either esm2015 or fesm2015 (preferred). So we would not run
any dts processing in the renderer if we are not compiling
the appropriate format.

PR Close #26403
This commit is contained in:
Pete Bacon Darwin 2018-10-16 09:46:59 +01:00 committed by Kara Erickson
parent 603e7935aa
commit 2f30bbb495
6 changed files with 15 additions and 13 deletions

View File

@ -85,8 +85,8 @@ export class Transformer {
console.time(entryPoint.name + '(rendering)');
// Transform the source files and source maps.
const renderer =
this.getRenderer(format, packageProgram, reflectionHost, isCore, r3SymbolsFile);
const renderer = this.getRenderer(
format, packageProgram, reflectionHost, isCore, r3SymbolsFile, transformDts);
const renderedFiles =
renderer.renderProgram(packageProgram, decorationAnalyses, switchMarkerAnalyses);
console.timeEnd(entryPoint.name + '(rendering)');
@ -125,14 +125,14 @@ export class Transformer {
getRenderer(
format: string, program: ts.Program, host: NgccReflectionHost, isCore: boolean,
rewriteCoreImportsTo: ts.SourceFile|null): Renderer {
rewriteCoreImportsTo: ts.SourceFile|null, transformDts: boolean): Renderer {
switch (format) {
case 'esm2015':
case 'esm5':
case 'fesm2015':
case 'fesm5':
return new EsmRenderer(
host, isCore, rewriteCoreImportsTo, this.sourcePath, this.targetPath);
host, isCore, rewriteCoreImportsTo, this.sourcePath, this.targetPath, transformDts);
default:
throw new Error(`Renderer for "${format}" not yet implemented.`);
}

View File

@ -15,8 +15,8 @@ export class EsmRenderer extends Renderer {
constructor(
protected host: NgccReflectionHost, protected isCore: boolean,
protected rewriteCoreImportsTo: ts.SourceFile|null, protected sourcePath: string,
protected targetPath: string) {
super(host, isCore, rewriteCoreImportsTo, sourcePath, targetPath);
protected targetPath: string, transformDts: boolean) {
super(host, isCore, rewriteCoreImportsTo, sourcePath, targetPath, transformDts);
}
/**

View File

@ -57,7 +57,7 @@ export abstract class Renderer {
constructor(
protected host: NgccReflectionHost, protected isCore: boolean,
protected rewriteCoreImportsTo: ts.SourceFile|null, protected sourcePath: string,
protected targetPath: string) {}
protected targetPath: string, protected transformDts: boolean) {}
renderProgram(
program: ts.Program, decorationAnalyses: DecorationAnalyses,
@ -74,9 +74,11 @@ export abstract class Renderer {
}
});
// Transform the .d.ts files
const dtsFiles = this.getTypingsFilesToRender(decorationAnalyses);
dtsFiles.forEach((classes, file) => renderedFiles.push(...this.renderDtsFile(file, classes)));
if (this.transformDts) {
// Transform the .d.ts files
const dtsFiles = this.getTypingsFilesToRender(decorationAnalyses);
dtsFiles.forEach((classes, file) => renderedFiles.push(...this.renderDtsFile(file, classes)));
}
return renderedFiles;
}

View File

@ -23,7 +23,7 @@ function setup(file: {name: string, contents: string}, transformDts: boolean = f
const decorationAnalyses =
new DecorationAnalyzer(program.getTypeChecker(), host, [''], false).analyzeProgram(program);
const switchMarkerAnalyses = new SwitchMarkerAnalyzer(host).analyzeProgram(program);
const renderer = new EsmRenderer(host, false, null, dir, dir);
const renderer = new EsmRenderer(host, false, null, dir, dir, false);
return {host, program, sourceFile, renderer, decorationAnalyses, switchMarkerAnalyses};
}

View File

@ -20,7 +20,7 @@ function setup(file: {name: string, contents: string}) {
const decorationAnalyses =
new DecorationAnalyzer(program.getTypeChecker(), host, [''], false).analyzeProgram(program);
const switchMarkerAnalyses = new SwitchMarkerAnalyzer(host).analyzeProgram(program);
const renderer = new EsmRenderer(host, false, null, '', '');
const renderer = new EsmRenderer(host, false, null, '', '', false);
return {host, program, sourceFile, renderer, decorationAnalyses, switchMarkerAnalyses};
}

View File

@ -17,7 +17,7 @@ import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
import {Renderer} from '../../src/rendering/renderer';
class TestRenderer extends Renderer {
constructor(host: Esm2015ReflectionHost) { super(host, false, null, '/src', '/dist'); }
constructor(host: Esm2015ReflectionHost) { super(host, false, null, '/src', '/dist', false); }
addImports(output: MagicString, imports: {name: string, as: string}[]) {
output.prepend('\n// ADD IMPORTS\n');
}