refactor(compiler-cli): skip class decorators in tooling constructor parameters transform (#37545)
We recently added a transformer to NGC that is responsible for downleveling Angular
decorators and constructor parameter types. The primary goal was to mitigate a
TypeScript limitation/issue that surfaces in Angular projects due to the heavy
reliance on type metadata being captured for DI. Additionally this is a pre-requisite
of making `tsickle` optional in the Angular bazel toolchain.
See: 401ef71ae5
for more context on this.
Another (less important) goal was to make sure that the CLI can re-use
this transformer for its JIT mode compilation. The CLI (as outlined in
the commit mentioned above), already has a transformer for downleveling
constructor parameters. We want to avoid this duplication and exported
the transform through the tooling-private compiler entry-point.
Early experiments in using this transformer over the current one, highlighted
that in JIT, class decorators cannot be downleveled. Angular relies on those
to be invoked immediately for JIT (so that factories etc. are generated upon loading)
The transformer we exposed, always downlevels such class decorators
though, so that would break CLI's JIT mode. We can address the CLI's
needs by adding another flag to skip class decorators. This will allow
us to continue with the goal of de-duplication.
PR Close #37545
This commit is contained in:

committed by
Misko Hevery

parent
cc49a91de7
commit
66e6b932d8
@ -35,15 +35,15 @@ export const GLOBAL_DEFS_FOR_TERSER_WITH_AOT = {
|
||||
/**
|
||||
* Transform for downleveling Angular decorators and Angular-decorated class constructor
|
||||
* parameters for dependency injection. This transform can be used by the CLI for JIT-mode
|
||||
* compilation where decorators should be preserved, but downleveled so that apps are not
|
||||
* exposed to the ES2015 temporal dead zone limitation in TypeScript's metadata.
|
||||
* See https://github.com/angular/angular-cli/pull/14473 for more details.
|
||||
* compilation where constructor parameters and associated Angular decorators should be
|
||||
* downleveled so that apps are not exposed to the ES2015 temporal dead zone limitation
|
||||
* in TypeScript. See https://github.com/angular/angular-cli/pull/14473 for more details.
|
||||
*/
|
||||
export function decoratorDownlevelTransformerFactory(program: ts.Program):
|
||||
export function constructorParametersDownlevelTransform(program: ts.Program):
|
||||
ts.TransformerFactory<ts.SourceFile> {
|
||||
const typeChecker = program.getTypeChecker();
|
||||
const reflectionHost = new TypeScriptReflectionHost(typeChecker);
|
||||
return getDownlevelDecoratorsTransform(
|
||||
typeChecker, reflectionHost, [], /* isCore */ false,
|
||||
/* enableClosureCompiler */ false);
|
||||
/* enableClosureCompiler */ false, /* skipClassDecorators */ true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user