Skip to content

Commit 08278f9

Browse files
clydindgp1130
authored andcommitted
refactor(@ngtools/webpack): integrate compiler-cli Angular decorator downlevel transformer
As of 10.0.0, the `@angular/compiler-cli` package provides a TypeScript transformer to downlevel Angular decorators. This change switches the tooling webpack plugin from using an internal variant of the transformer to the new one within the compiler-cli. For details on why this type of transformation is needed, please see: angular/angular@401ef71 (cherry picked from commit 0a0be3b)
1 parent 89c956b commit 08278f9

File tree

3 files changed

+13
-588
lines changed

3 files changed

+13
-588
lines changed

packages/ngtools/webpack/src/angular_compiler_plugin.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
formatDiagnostics,
3030
readConfiguration,
3131
} from '@angular/compiler-cli';
32+
import { constructorParametersDownlevelTransform } from '@angular/compiler-cli/src/tooling';
3233
import { ChildProcess, ForkOptions, fork } from 'child_process';
3334
import * as fs from 'fs';
3435
import * as path from 'path';
@@ -59,7 +60,6 @@ import {
5960
replaceServerBootstrap,
6061
} from './transformers';
6162
import { collectDeepNodes } from './transformers/ast_helpers';
62-
import { downlevelConstructorParameters } from './transformers/ctor-parameters';
6363
import { removeIvyJitSupportCalls } from './transformers/remove-ivy-jit-support-calls';
6464
import {
6565
AUTO_START_ARG,
@@ -245,6 +245,11 @@ export class AngularCompilerPlugin {
245245
options.missingTranslation as 'error' | 'warning' | 'ignore';
246246
}
247247

248+
// For performance, disable AOT decorator downleveling transformer for applications in the CLI.
249+
// The transformer is not needed for VE or Ivy in this plugin since Angular decorators are removed.
250+
// While the transformer would make no changes, it would still need to walk each source file AST.
251+
this._compilerOptions.annotationsAs = 'decorators' as 'decorators';
252+
248253
// Process forked type checker options.
249254
if (options.forkTypeChecker !== undefined) {
250255
this._forkTypeChecker = options.forkTypeChecker;
@@ -1021,7 +1026,13 @@ export class AngularCompilerPlugin {
10211026
replaceResources(isAppPath, getTypeChecker, this._options.directTemplateLoading));
10221027
// Downlevel constructor parameters for DI support
10231028
// This is required to support forwardRef in ES2015 due to TDZ issues
1024-
this._transformers.push(downlevelConstructorParameters(getTypeChecker));
1029+
// This wrapper is needed here due to the program not being available until after the transformers are created.
1030+
const downlevelFactory: ts.TransformerFactory<ts.SourceFile> = (context) => {
1031+
const factory = constructorParametersDownlevelTransform(this._getTsProgram() as ts.Program);
1032+
1033+
return factory(context);
1034+
};
1035+
this._transformers.push(downlevelFactory);
10251036
} else {
10261037
if (!this._compilerOptions.enableIvy) {
10271038
// Remove unneeded angular decorators in VE.

packages/ngtools/webpack/src/transformers/ctor-parameters.ts

Lines changed: 0 additions & 335 deletions
This file was deleted.

0 commit comments

Comments
 (0)