From 2b64031ddc1bb90b1e7a7da04937763c7a49b567 Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Tue, 20 Aug 2019 10:54:02 -0700 Subject: [PATCH] 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 --- packages/bazel/src/ngc-wrapped/index.ts | 7 +- packages/compiler-cli/src/transformers/api.ts | 3 +- .../compiler-cli/src/transformers/program.ts | 6 +- .../src/transformers/tsc_pass_through.ts | 112 ------------------ packages/compiler/src/aot/compiler_options.ts | 2 +- 5 files changed, 5 insertions(+), 125 deletions(-) delete mode 100644 packages/compiler-cli/src/transformers/tsc_pass_through.ts diff --git a/packages/bazel/src/ngc-wrapped/index.ts b/packages/bazel/src/ngc-wrapped/index.ts index 74b2c7b47f..6fe195894b 100644 --- a/packages/bazel/src/ngc-wrapped/index.ts +++ b/packages/bazel/src/ngc-wrapped/index.ts @@ -184,15 +184,10 @@ export function compile({allDepsCompiledWithBazel = true, compilerOpts, tsHost, } // 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. 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'; } diff --git a/packages/compiler-cli/src/transformers/api.ts b/packages/compiler-cli/src/transformers/api.ts index 314e7b54b6..d17d0fd0ea 100644 --- a/packages/compiler-cli/src/transformers/api.ts +++ b/packages/compiler-cli/src/transformers/api.ts @@ -196,11 +196,10 @@ export interface CompilerOptions extends ts.CompilerOptions { * `false` - run ngc normally * `true` - run the ngtsc compiler instead of the normal ngc compiler * `ngtsc` - alias for `true` - * `tsc` - behave like plain tsc as much as possible (used for testing JIT code) * * @publicApi */ - enableIvy?: boolean|'ngtsc'|'tsc'; + enableIvy?: boolean|'ngtsc'; /** @internal */ collectAllErrors?: boolean; diff --git a/packages/compiler-cli/src/transformers/program.ts b/packages/compiler-cli/src/transformers/program.ts index 92d3f618dc..1f0c5f7246 100644 --- a/packages/compiler-cli/src/transformers/program.ts +++ b/packages/compiler-cli/src/transformers/program.ts @@ -27,7 +27,6 @@ import {getAngularEmitterTransformFactory} from './node_emitter_transform'; import {PartialModuleMetadataTransformer} from './r3_metadata_transform'; import {StripDecoratorsMetadataTransformer, getDecoratorStripTransformerFactory} from './r3_strip_decorators'; import {getAngularClassTransformerFactory} from './r3_transform'; -import {TscPassThroughProgram} from './tsc_pass_through'; 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 { if (options.enableIvy === true) { return new NgtscProgram(rootNames, options, host, oldProgram as NgtscProgram); - } else if (options.enableIvy === 'tsc') { - return new TscPassThroughProgram(rootNames, options, host, oldProgram); + } else { + return new AngularCompilerProgram(rootNames, options, host, oldProgram); } - return new AngularCompilerProgram(rootNames, options, host, oldProgram); } // Compute the AotCompiler options diff --git a/packages/compiler-cli/src/transformers/tsc_pass_through.ts b/packages/compiler-cli/src/transformers/tsc_pass_through.ts deleted file mode 100644 index c54800c894..0000000000 --- a/packages/compiler-cli/src/transformers/tsc_pass_through.ts +++ /dev/null @@ -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, 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 { - return this.tsProgram.getOptionsDiagnostics(cancellationToken); - } - - getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken| - undefined): ReadonlyArray { - return []; - } - - getTsSyntacticDiagnostics( - sourceFile?: ts.SourceFile|undefined, - cancellationToken?: ts.CancellationToken|undefined): ReadonlyArray { - return this.tsProgram.getSyntacticDiagnostics(sourceFile, cancellationToken); - } - - getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken| - undefined): ReadonlyArray { - return []; - } - - getTsSemanticDiagnostics( - sourceFile?: ts.SourceFile|undefined, - cancellationToken?: ts.CancellationToken|undefined): ReadonlyArray { - return this.tsProgram.getSemanticDiagnostics(sourceFile, cancellationToken); - } - - getNgSemanticDiagnostics( - fileName?: string|undefined, - cancellationToken?: ts.CancellationToken|undefined): ReadonlyArray { - return []; - } - - loadNgStructureAsync(): Promise { return Promise.resolve(); } - - listLazyRoutes(entryRoute?: string|undefined): api.LazyRoute[] { - throw new Error('Method not implemented.'); - } - - getLibrarySummaries(): Map { - throw new Error('Method not implemented.'); - } - - getEmittedGeneratedFiles(): Map { - throw new Error('Method not implemented.'); - } - - getEmittedSourceFiles(): Map { - 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); diff --git a/packages/compiler/src/aot/compiler_options.ts b/packages/compiler/src/aot/compiler_options.ts index 4a0e3f9532..02058cff73 100644 --- a/packages/compiler/src/aot/compiler_options.ts +++ b/packages/compiler/src/aot/compiler_options.ts @@ -19,6 +19,6 @@ export interface AotCompilerOptions { fullTemplateTypeCheck?: boolean; allowEmptyCodegenFiles?: boolean; strictInjectionParameters?: boolean; - enableIvy?: boolean|'ngtsc'|'tsc'; + enableIvy?: boolean|'ngtsc'; createExternalSymbolFactoryReexports?: boolean; }