angular-cn/packages/compiler/src/render3
Alex Rickabaugh b54ed980ed fix(ivy): retain JIT metadata unless JIT mode is explicitly disabled (#33671)
NgModules in Ivy have a definition which contains various different bits
of metadata about the module. In particular, this metadata falls into two
categories:

* metadata required to use the module at runtime (for bootstrapping, etc)
in AOT-only applications.
* metadata required to depend on the module from a JIT-compiled app.

The latter metadata consists of the module's declarations, imports, and
exports. To support JIT usage, this metadata must be included in the
generated code, especially if that code is shipped to NPM. However, because
this metadata preserves the entire NgModule graph (references to all
directives and components in the app), it needs to be removed during
optimization for AOT-only builds.

Previously, this was done with a clever design:

1. The extra metadata was added by a function called `setNgModuleScope`.
A call to this function was generated after each NgModule.
2. This function call was marked as "pure" with a comment and used
`noSideEffects` internally, which causes optimizers to remove it.

The effect was that in dev mode or test mode (which use JIT), no optimizer
runs and the full NgModule metadata was available at runtime. But in
production (presumably AOT) builds, the optimizer runs and removes the JIT-
specific metadata.

However, there are cases where apps that want to use JIT in production, and
still make an optimized build. In this case, the JIT-specific metadata would
be erroneously removed. This commit solves that problem by adding an
`ngJitMode` global variable which guards all `setNgModuleScope` calls. An
optimizer can be configured to statically define this global to be `false`
for AOT-only builds, causing the extra metadata to be stripped.

A configuration for Terser used by the CLI is provided in `tooling.ts` which
sets `ngJitMode` to `false` when building AOT apps.

PR Close #33671
2019-11-20 12:55:43 -08:00
..
view perf(ivy): chain styling instructions (#33837) 2019-11-19 11:44:29 -08:00
r3_ast.ts refactor(compiler): rename i18n `AST` to `i18nMeta` (#33318) 2019-10-22 13:30:16 -04:00
r3_factory.ts refactor(ivy): split `type` into `type`, `internalType` and `adjacentType` (#33533) 2019-11-05 17:25:01 +00:00
r3_identifiers.ts refactor(ivy): remove ngBaseDef (#33264) 2019-10-25 13:11:34 -07:00
r3_jit.ts refactor(compiler): wrap the jit evaluation in an injectable class (#28055) 2019-02-12 20:58:27 -08:00
r3_module_compiler.ts fix(ivy): retain JIT metadata unless JIT mode is explicitly disabled (#33671) 2019-11-20 12:55:43 -08:00
r3_module_factory_compiler.ts feat(ivy): add an IVY local the compiler which avoids analyzeModule (#23441) 2018-04-19 16:32:09 -07:00
r3_pipe_compiler.ts refactor(ivy): split `type` into `type`, `internalType` and `adjacentType` (#33533) 2019-11-05 17:25:01 +00:00
r3_template_transform.ts fix(ivy): more descriptive errors for nested i18n sections (#33583) 2019-11-05 17:20:47 +00:00
r3_types.ts refactor(ivy): remove the backpatch compiler (#23441) 2018-04-19 16:32:09 -07:00
util.ts fix(ivy): retain JIT metadata unless JIT mode is explicitly disabled (#33671) 2019-11-20 12:55:43 -08:00