fix(core): use shakeable global definitions (#29929)

The `ngDevMode` and `ngI18nClosureMode` are special in that they should be set to `false` on production builds in order to shake out code associated with it.

Angular CLI does this in 5fc1f2499c/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts (L279-L282).

But in https://github.com/angular/angular/pull/28689 the toplevel usage was changed from `ngDevMode` to `global['ngDevMode']` (and the same for `ngI18nClosureMode`). This indirection prevents the static analysis in Terser from effecting the replacement.

PR Close #29929
This commit is contained in:
Filipe Silva 2019-04-16 16:52:44 +01:00 committed by Ben Lesh
parent b9251fd707
commit e5905bb035
2 changed files with 9 additions and 2 deletions

View File

@ -82,7 +82,10 @@ export function ngDevModeResetPerfCounters(): NgDevModePerfCounters {
* The idea is that unless we are doing production build where we explicitly
* set `ngDevMode == false` we should be helping the developer by providing
* as much early warning and errors as possible.
*
* NOTE: changes to the `ngDevMode` name must be synced with the CLI and
* possibly other third party tooling. Check with them before altering it.
*/
if (typeof global['ngDevMode'] === 'undefined' || global['ngDevMode']) {
if (typeof ngDevMode === 'undefined' || ngDevMode) {
ngDevModeResetPerfCounters();
}

View File

@ -12,7 +12,11 @@ declare global {
const ngI18nClosureMode: boolean;
}
if (typeof global['ngI18nClosureMode'] === 'undefined') {
/**
* NOTE: changes to the `ngI18nClosureMode` name must be synced with the CLI and
* possibly other third party tooling. Check with them before altering it.
*/
if (typeof ngI18nClosureMode === 'undefined') {
// Make sure to refer to ngI18nClosureMode as ['ngI18nClosureMode'] for closure.
global['ngI18nClosureMode'] =
// TODO(FW-1250): validate that this actually, you know, works.