fix(compiler): don't typecheck all inputs (#22899)
ngc knows to filter out d.ts inputs, but the logic accidentally depended on whether it had a previous Program lying around. Fixing that logic puts ngc on the fast code path, but in that code path it must be able to merge tsickle EmitResults, so we need to plumb the tsickle.mergeEmitResults function through all the intervening APIs. The bulk of this change is that plumbing. PR Close #22899
This commit is contained in:
parent
f461f43d72
commit
838a610197
|
@ -238,8 +238,12 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
|
|||
gatherDiagnostics = (program) =>
|
||||
gatherDiagnosticsForInputsOnly(compilerOpts, bazelOpts, program);
|
||||
}
|
||||
const {diagnostics, emitResult, program} = ng.performCompilation(
|
||||
{rootNames: files, options: compilerOpts, host: ngHost, emitCallback, gatherDiagnostics});
|
||||
const {diagnostics, emitResult, program} = ng.performCompilation({
|
||||
rootNames: files,
|
||||
options: compilerOpts,
|
||||
host: ngHost, emitCallback,
|
||||
mergeEmitResultsCallback: tsickle.mergeEmitResults, gatherDiagnostics
|
||||
});
|
||||
const tsickleEmitResult = emitResult as tsickle.EmitResult;
|
||||
let externs = '/** @externs */\n';
|
||||
if (!diagnostics.length) {
|
||||
|
|
|
@ -186,6 +186,7 @@ export function exitCodeFromResult(diags: Diagnostics | undefined): number {
|
|||
}
|
||||
|
||||
export function performCompilation({rootNames, options, host, oldProgram, emitCallback,
|
||||
mergeEmitResultsCallback,
|
||||
gatherDiagnostics = defaultGatherDiagnostics,
|
||||
customTransformers, emitFlags = api.EmitFlags.Default}: {
|
||||
rootNames: string[],
|
||||
|
@ -193,6 +194,7 @@ export function performCompilation({rootNames, options, host, oldProgram, emitCa
|
|||
host?: api.CompilerHost,
|
||||
oldProgram?: api.Program,
|
||||
emitCallback?: api.TsEmitCallback,
|
||||
mergeEmitResultsCallback?: api.TsMergeEmitResultsCallback,
|
||||
gatherDiagnostics?: (program: api.Program) => Diagnostics,
|
||||
customTransformers?: api.CustomTransformers,
|
||||
emitFlags?: api.EmitFlags
|
||||
|
@ -216,7 +218,8 @@ export function performCompilation({rootNames, options, host, oldProgram, emitCa
|
|||
}
|
||||
|
||||
if (!hasErrors(allDiagnostics)) {
|
||||
emitResult = program !.emit({emitCallback, customTransformers, emitFlags});
|
||||
emitResult =
|
||||
program !.emit({emitCallback, mergeEmitResultsCallback, customTransformers, emitFlags});
|
||||
allDiagnostics.push(...emitResult.diagnostics);
|
||||
return {diagnostics: allDiagnostics, program, emitResult};
|
||||
}
|
||||
|
|
|
@ -260,6 +260,7 @@ export interface TsEmitArguments {
|
|||
}
|
||||
|
||||
export interface TsEmitCallback { (args: TsEmitArguments): ts.EmitResult; }
|
||||
export interface TsMergeEmitResultsCallback { (results: ts.EmitResult[]): ts.EmitResult; }
|
||||
|
||||
/**
|
||||
* @internal
|
||||
|
@ -353,11 +354,13 @@ export interface Program {
|
|||
*
|
||||
* Angular structural information is required to emit files.
|
||||
*/
|
||||
emit({emitFlags, cancellationToken, customTransformers, emitCallback}?: {
|
||||
emit({emitFlags, cancellationToken, customTransformers, emitCallback,
|
||||
mergeEmitResultsCallback}?: {
|
||||
emitFlags?: EmitFlags,
|
||||
cancellationToken?: ts.CancellationToken,
|
||||
customTransformers?: CustomTransformers,
|
||||
emitCallback?: TsEmitCallback
|
||||
emitCallback?: TsEmitCallback,
|
||||
mergeEmitResultsCallback?: TsMergeEmitResultsCallback
|
||||
}): ts.EmitResult;
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,7 +15,7 @@ import * as ts from 'typescript';
|
|||
import {TypeCheckHost, translateDiagnostics} from '../diagnostics/translate_diagnostics';
|
||||
import {MetadataCollector, ModuleMetadata, createBundleIndexHost} from '../metadata/index';
|
||||
|
||||
import {CompilerHost, CompilerOptions, CustomTransformers, DEFAULT_ERROR_CODE, Diagnostic, DiagnosticMessageChain, EmitFlags, LazyRoute, LibrarySummary, Program, SOURCE, TsEmitArguments, TsEmitCallback} from './api';
|
||||
import {CompilerHost, CompilerOptions, CustomTransformers, DEFAULT_ERROR_CODE, Diagnostic, DiagnosticMessageChain, EmitFlags, LazyRoute, LibrarySummary, Program, SOURCE, TsEmitArguments, TsEmitCallback, TsMergeEmitResultsCallback} from './api';
|
||||
import {CodeGenerator, TsCompilerAotCompilerTypeCheckHostAdapter, getOriginalReferences} from './compiler_host';
|
||||
import {InlineResourcesMetadataTransformer, getInlineResourcesTransformFactory} from './inline_resources';
|
||||
import {LowerMetadataTransform, getExpressionLoweringTransformFactory} from './lower_expressions';
|
||||
|
@ -270,7 +270,8 @@ class AngularCompilerProgram implements Program {
|
|||
emitFlags?: EmitFlags,
|
||||
cancellationToken?: ts.CancellationToken,
|
||||
customTransformers?: CustomTransformers,
|
||||
emitCallback?: TsEmitCallback
|
||||
emitCallback?: TsEmitCallback,
|
||||
mergeEmitResultsCallback?: TsMergeEmitResultsCallback,
|
||||
} = {}): ts.EmitResult {
|
||||
return this.options.enableIvy === true ? this._emitRender3(parameters) :
|
||||
this._emitRender2(parameters);
|
||||
|
@ -281,12 +282,15 @@ class AngularCompilerProgram implements Program {
|
|||
}
|
||||
|
||||
private _emitRender3(
|
||||
{emitFlags = EmitFlags.Default, cancellationToken, customTransformers,
|
||||
emitCallback = defaultEmitCallback}: {
|
||||
{
|
||||
emitFlags = EmitFlags.Default, cancellationToken, customTransformers,
|
||||
emitCallback = defaultEmitCallback, mergeEmitResultsCallback = mergeEmitResults,
|
||||
}: {
|
||||
emitFlags?: EmitFlags,
|
||||
cancellationToken?: ts.CancellationToken,
|
||||
customTransformers?: CustomTransformers,
|
||||
emitCallback?: TsEmitCallback
|
||||
emitCallback?: TsEmitCallback,
|
||||
mergeEmitResultsCallback?: TsMergeEmitResultsCallback,
|
||||
} = {}): ts.EmitResult {
|
||||
const emitStart = Date.now();
|
||||
if ((emitFlags & (EmitFlags.JS | EmitFlags.DTS | EmitFlags.Metadata | EmitFlags.Codegen)) ===
|
||||
|
@ -328,12 +332,15 @@ class AngularCompilerProgram implements Program {
|
|||
}
|
||||
|
||||
private _emitRender2(
|
||||
{emitFlags = EmitFlags.Default, cancellationToken, customTransformers,
|
||||
emitCallback = defaultEmitCallback}: {
|
||||
{
|
||||
emitFlags = EmitFlags.Default, cancellationToken, customTransformers,
|
||||
emitCallback = defaultEmitCallback, mergeEmitResultsCallback = mergeEmitResults,
|
||||
}: {
|
||||
emitFlags?: EmitFlags,
|
||||
cancellationToken?: ts.CancellationToken,
|
||||
customTransformers?: CustomTransformers,
|
||||
emitCallback?: TsEmitCallback
|
||||
emitCallback?: TsEmitCallback,
|
||||
mergeEmitResultsCallback?: TsMergeEmitResultsCallback,
|
||||
} = {}): ts.EmitResult {
|
||||
const emitStart = Date.now();
|
||||
if (emitFlags & EmitFlags.I18nBundle) {
|
||||
|
@ -416,7 +423,7 @@ class AngularCompilerProgram implements Program {
|
|||
(sourceFilesToEmit.length + genTsFiles.length) < MAX_FILE_COUNT_FOR_SINGLE_FILE_EMIT) {
|
||||
const fileNamesToEmit =
|
||||
[...sourceFilesToEmit.map(sf => sf.fileName), ...genTsFiles.map(gf => gf.genFileUrl)];
|
||||
emitResult = mergeEmitResults(
|
||||
emitResult = mergeEmitResultsCallback(
|
||||
fileNamesToEmit.map((fileName) => emitResult = emitCallback({
|
||||
program: this.tsProgram,
|
||||
host: this.host,
|
||||
|
@ -777,11 +784,12 @@ class AngularCompilerProgram implements Program {
|
|||
private getSourceFilesForEmit(): ts.SourceFile[]|undefined {
|
||||
// TODO(tbosch): if one of the files contains a `const enum`
|
||||
// always emit all files -> return undefined!
|
||||
let sourceFilesToEmit: ts.SourceFile[]|undefined;
|
||||
let sourceFilesToEmit = this.tsProgram.getSourceFiles().filter(
|
||||
sf => { return !sf.isDeclarationFile && !GENERATED_FILES.test(sf.fileName); });
|
||||
if (this.oldProgramEmittedSourceFiles) {
|
||||
sourceFilesToEmit = this.tsProgram.getSourceFiles().filter(sf => {
|
||||
sourceFilesToEmit = sourceFilesToEmit.filter(sf => {
|
||||
const oldFile = this.oldProgramEmittedSourceFiles !.get(sf.fileName);
|
||||
return !sf.isDeclarationFile && !GENERATED_FILES.test(sf.fileName) && sf !== oldFile;
|
||||
return sf !== oldFile;
|
||||
});
|
||||
}
|
||||
return sourceFilesToEmit;
|
||||
|
@ -1020,7 +1028,7 @@ function mergeEmitResults(emitResults: ts.EmitResult[]): ts.EmitResult {
|
|||
for (const er of emitResults) {
|
||||
diagnostics.push(...er.diagnostics);
|
||||
emitSkipped = emitSkipped || er.emitSkipped;
|
||||
emittedFiles.push(...er.emittedFiles);
|
||||
emittedFiles.push(...(er.emittedFiles || []));
|
||||
}
|
||||
return {diagnostics, emitSkipped, emittedFiles};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue