refactor(ivy): remove the tsc passthrough option (#32219)
This option makes ngc behave as tsc, and was originally implemented before ngtsc existed. It was designed so we could build JIT-only versions of Angular packages to begin testing Ivy early, and is not used at all in our current setup. PR Close #32219
This commit is contained in:
parent
388578fec9
commit
2b64031ddc
|
@ -184,15 +184,10 @@ export function compile({allDepsCompiledWithBazel = true, compilerOpts, tsHost,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect from compilerOpts whether the entrypoint is being invoked in Ivy mode.
|
// Detect from compilerOpts whether the entrypoint is being invoked in Ivy mode.
|
||||||
const isInIvyMode = compilerOpts.enableIvy === 'ngtsc' || compilerOpts.enableIvy === 'tsc';
|
const isInIvyMode = compilerOpts.enableIvy === 'ngtsc';
|
||||||
|
|
||||||
// Disable downleveling and Closure annotation if in Ivy mode.
|
// Disable downleveling and Closure annotation if in Ivy mode.
|
||||||
if (isInIvyMode) {
|
if (isInIvyMode) {
|
||||||
// In pass-through mode for TypeScript, we want to turn off decorator transpilation entirely.
|
|
||||||
// This causes ngc to be have exactly like tsc.
|
|
||||||
if (compilerOpts.enableIvy === 'tsc') {
|
|
||||||
compilerOpts.annotateForClosureCompiler = false;
|
|
||||||
}
|
|
||||||
compilerOpts.annotationsAs = 'decorators';
|
compilerOpts.annotationsAs = 'decorators';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -196,11 +196,10 @@ export interface CompilerOptions extends ts.CompilerOptions {
|
||||||
* `false` - run ngc normally
|
* `false` - run ngc normally
|
||||||
* `true` - run the ngtsc compiler instead of the normal ngc compiler
|
* `true` - run the ngtsc compiler instead of the normal ngc compiler
|
||||||
* `ngtsc` - alias for `true`
|
* `ngtsc` - alias for `true`
|
||||||
* `tsc` - behave like plain tsc as much as possible (used for testing JIT code)
|
|
||||||
*
|
*
|
||||||
* @publicApi
|
* @publicApi
|
||||||
*/
|
*/
|
||||||
enableIvy?: boolean|'ngtsc'|'tsc';
|
enableIvy?: boolean|'ngtsc';
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
collectAllErrors?: boolean;
|
collectAllErrors?: boolean;
|
||||||
|
|
|
@ -27,7 +27,6 @@ import {getAngularEmitterTransformFactory} from './node_emitter_transform';
|
||||||
import {PartialModuleMetadataTransformer} from './r3_metadata_transform';
|
import {PartialModuleMetadataTransformer} from './r3_metadata_transform';
|
||||||
import {StripDecoratorsMetadataTransformer, getDecoratorStripTransformerFactory} from './r3_strip_decorators';
|
import {StripDecoratorsMetadataTransformer, getDecoratorStripTransformerFactory} from './r3_strip_decorators';
|
||||||
import {getAngularClassTransformerFactory} from './r3_transform';
|
import {getAngularClassTransformerFactory} from './r3_transform';
|
||||||
import {TscPassThroughProgram} from './tsc_pass_through';
|
|
||||||
import {DTS, GENERATED_FILES, StructureIsReused, TS, createMessageDiagnostic, isInRootDir, ngToTsDiagnostic, tsStructureIsReused, userError} from './util';
|
import {DTS, GENERATED_FILES, StructureIsReused, TS, createMessageDiagnostic, isInRootDir, ngToTsDiagnostic, tsStructureIsReused, userError} from './util';
|
||||||
|
|
||||||
|
|
||||||
|
@ -900,10 +899,9 @@ export function createProgram({rootNames, options, host, oldProgram}: {
|
||||||
}): Program {
|
}): Program {
|
||||||
if (options.enableIvy === true) {
|
if (options.enableIvy === true) {
|
||||||
return new NgtscProgram(rootNames, options, host, oldProgram as NgtscProgram);
|
return new NgtscProgram(rootNames, options, host, oldProgram as NgtscProgram);
|
||||||
} else if (options.enableIvy === 'tsc') {
|
} else {
|
||||||
return new TscPassThroughProgram(rootNames, options, host, oldProgram);
|
return new AngularCompilerProgram(rootNames, options, host, oldProgram);
|
||||||
}
|
}
|
||||||
return new AngularCompilerProgram(rootNames, options, host, oldProgram);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the AotCompiler options
|
// Compute the AotCompiler options
|
||||||
|
|
|
@ -1,112 +0,0 @@
|
||||||
/**
|
|
||||||
* @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 {GeneratedFile} from '@angular/compiler';
|
|
||||||
import * as path from 'path';
|
|
||||||
import * as ts from 'typescript';
|
|
||||||
|
|
||||||
import {ivySwitchTransform} from '../ngtsc/switch';
|
|
||||||
import * as api from '../transformers/api';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An implementation of the `Program` API which behaves similarly to plain `tsc`.
|
|
||||||
*
|
|
||||||
* The only Angular specific behavior included in this `Program` is the operation of the Ivy
|
|
||||||
* switch to turn on render3 behavior.
|
|
||||||
*
|
|
||||||
* This allows `ngc` to behave like `tsc` in cases where JIT code needs to be tested.
|
|
||||||
*/
|
|
||||||
export class TscPassThroughProgram implements api.Program {
|
|
||||||
private tsProgram: ts.Program;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
rootNames: ReadonlyArray<string>, private options: api.CompilerOptions,
|
|
||||||
private host: api.CompilerHost, oldProgram?: api.Program) {
|
|
||||||
this.tsProgram =
|
|
||||||
ts.createProgram(rootNames, options, host, oldProgram && oldProgram.getTsProgram());
|
|
||||||
}
|
|
||||||
|
|
||||||
getTsProgram(): ts.Program { return this.tsProgram; }
|
|
||||||
|
|
||||||
getTsOptionDiagnostics(cancellationToken?: ts.CancellationToken|
|
|
||||||
undefined): ReadonlyArray<ts.Diagnostic> {
|
|
||||||
return this.tsProgram.getOptionsDiagnostics(cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken|
|
|
||||||
undefined): ReadonlyArray<api.Diagnostic> {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
getTsSyntacticDiagnostics(
|
|
||||||
sourceFile?: ts.SourceFile|undefined,
|
|
||||||
cancellationToken?: ts.CancellationToken|undefined): ReadonlyArray<ts.Diagnostic> {
|
|
||||||
return this.tsProgram.getSyntacticDiagnostics(sourceFile, cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken|
|
|
||||||
undefined): ReadonlyArray<api.Diagnostic> {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
getTsSemanticDiagnostics(
|
|
||||||
sourceFile?: ts.SourceFile|undefined,
|
|
||||||
cancellationToken?: ts.CancellationToken|undefined): ReadonlyArray<ts.Diagnostic> {
|
|
||||||
return this.tsProgram.getSemanticDiagnostics(sourceFile, cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
getNgSemanticDiagnostics(
|
|
||||||
fileName?: string|undefined,
|
|
||||||
cancellationToken?: ts.CancellationToken|undefined): ReadonlyArray<api.Diagnostic> {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
loadNgStructureAsync(): Promise<void> { return Promise.resolve(); }
|
|
||||||
|
|
||||||
listLazyRoutes(entryRoute?: string|undefined): api.LazyRoute[] {
|
|
||||||
throw new Error('Method not implemented.');
|
|
||||||
}
|
|
||||||
|
|
||||||
getLibrarySummaries(): Map<string, api.LibrarySummary> {
|
|
||||||
throw new Error('Method not implemented.');
|
|
||||||
}
|
|
||||||
|
|
||||||
getEmittedGeneratedFiles(): Map<string, GeneratedFile> {
|
|
||||||
throw new Error('Method not implemented.');
|
|
||||||
}
|
|
||||||
|
|
||||||
getEmittedSourceFiles(): Map<string, ts.SourceFile> {
|
|
||||||
throw new Error('Method not implemented.');
|
|
||||||
}
|
|
||||||
|
|
||||||
emit(opts?: {
|
|
||||||
emitFlags?: api.EmitFlags,
|
|
||||||
cancellationToken?: ts.CancellationToken,
|
|
||||||
customTransformers?: api.CustomTransformers,
|
|
||||||
emitCallback?: api.TsEmitCallback,
|
|
||||||
mergeEmitResultsCallback?: api.TsMergeEmitResultsCallback
|
|
||||||
}): ts.EmitResult {
|
|
||||||
const emitCallback = opts && opts.emitCallback || defaultEmitCallback;
|
|
||||||
|
|
||||||
const emitResult = emitCallback({
|
|
||||||
program: this.tsProgram,
|
|
||||||
host: this.host,
|
|
||||||
options: this.options,
|
|
||||||
emitOnlyDtsFiles: false,
|
|
||||||
customTransformers: {before: [ivySwitchTransform]},
|
|
||||||
});
|
|
||||||
return emitResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const defaultEmitCallback: api.TsEmitCallback =
|
|
||||||
({program, targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles,
|
|
||||||
customTransformers}) =>
|
|
||||||
program.emit(
|
|
||||||
targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers);
|
|
|
@ -19,6 +19,6 @@ export interface AotCompilerOptions {
|
||||||
fullTemplateTypeCheck?: boolean;
|
fullTemplateTypeCheck?: boolean;
|
||||||
allowEmptyCodegenFiles?: boolean;
|
allowEmptyCodegenFiles?: boolean;
|
||||||
strictInjectionParameters?: boolean;
|
strictInjectionParameters?: boolean;
|
||||||
enableIvy?: boolean|'ngtsc'|'tsc';
|
enableIvy?: boolean|'ngtsc';
|
||||||
createExternalSymbolFactoryReexports?: boolean;
|
createExternalSymbolFactoryReexports?: boolean;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue