Skip to content

Commit

Permalink
refactor(@ngtools/webpack): integrate compiler-cli Angular decorator …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
clydin authored and dgp1130 committed Jun 15, 2020
1 parent e7e2349 commit 0a0be3b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 588 deletions.
15 changes: 13 additions & 2 deletions packages/ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
formatDiagnostics,
readConfiguration,
} from '@angular/compiler-cli';
import { constructorParametersDownlevelTransform } from '@angular/compiler-cli/src/tooling';
import { ChildProcess, ForkOptions, fork } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
Expand Down Expand Up @@ -59,7 +60,6 @@ import {
replaceServerBootstrap,
} from './transformers';
import { collectDeepNodes } from './transformers/ast_helpers';
import { downlevelConstructorParameters } from './transformers/ctor-parameters';
import { removeIvyJitSupportCalls } from './transformers/remove-ivy-jit-support-calls';
import {
AUTO_START_ARG,
Expand Down Expand Up @@ -245,6 +245,11 @@ export class AngularCompilerPlugin {
options.missingTranslation as 'error' | 'warning' | 'ignore';
}

// For performance, disable AOT decorator downleveling transformer for applications in the CLI.
// The transformer is not needed for VE or Ivy in this plugin since Angular decorators are removed.
// While the transformer would make no changes, it would still need to walk each source file AST.
this._compilerOptions.annotationsAs = 'decorators' as 'decorators';

// Process forked type checker options.
if (options.forkTypeChecker !== undefined) {
this._forkTypeChecker = options.forkTypeChecker;
Expand Down Expand Up @@ -1021,7 +1026,13 @@ export class AngularCompilerPlugin {
replaceResources(isAppPath, getTypeChecker, this._options.directTemplateLoading));
// Downlevel constructor parameters for DI support
// This is required to support forwardRef in ES2015 due to TDZ issues
this._transformers.push(downlevelConstructorParameters(getTypeChecker));
// This wrapper is needed here due to the program not being available until after the transformers are created.
const downlevelFactory: ts.TransformerFactory<ts.SourceFile> = (context) => {
const factory = constructorParametersDownlevelTransform(this._getTsProgram() as ts.Program);

return factory(context);
};
this._transformers.push(downlevelFactory);
} else {
if (!this._compilerOptions.enableIvy) {
// Remove unneeded angular decorators in VE.
Expand Down
335 changes: 0 additions & 335 deletions packages/ngtools/webpack/src/transformers/ctor-parameters.ts

This file was deleted.

0 comments on commit 0a0be3b

Please sign in to comment.