Skip to content
Permalink
Browse files

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 https://github.com/angular/angular-cli/blob/5fc1f2499cbe57f9a95e4b0dfced130eb3a8046d/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts#L279-L282.

But in #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
  • Loading branch information...
filipesilva authored and benlesh committed Apr 16, 2019
1 parent b9251fd commit e5905bb035d0e1f2eb9af2c5c6f09eb51fb0bff0
Showing with 9 additions and 2 deletions.
  1. +4 −1 packages/core/src/util/ng_dev_mode.ts
  2. +5 −1 packages/core/src/util/ng_i18n_closure_mode.ts
@@ -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();
}
@@ -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.

0 comments on commit e5905bb

Please sign in to comment.
You can’t perform that action at this time.