Skip to content

Commit 9b048cc

Browse files
filipesilvaBioPhoton
authored andcommitted
fix(core): use shakeable global definitions (angular#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 angular#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 angular#29929
1 parent fb73315 commit 9b048cc

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/core/src/util/ng_dev_mode.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ export function ngDevModeResetPerfCounters(): NgDevModePerfCounters {
8282
* The idea is that unless we are doing production build where we explicitly
8383
* set `ngDevMode == false` we should be helping the developer by providing
8484
* as much early warning and errors as possible.
85+
*
86+
* NOTE: changes to the `ngDevMode` name must be synced with the CLI and
87+
* possibly other third party tooling. Check with them before altering it.
8588
*/
86-
if (typeof global['ngDevMode'] === 'undefined' || global['ngDevMode']) {
89+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
8790
ngDevModeResetPerfCounters();
8891
}

packages/core/src/util/ng_i18n_closure_mode.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ declare global {
1212
const ngI18nClosureMode: boolean;
1313
}
1414

15-
if (typeof global['ngI18nClosureMode'] === 'undefined') {
15+
/**
16+
* NOTE: changes to the `ngI18nClosureMode` name must be synced with the CLI and
17+
* possibly other third party tooling. Check with them before altering it.
18+
*/
19+
if (typeof ngI18nClosureMode === 'undefined') {
1620
// Make sure to refer to ngI18nClosureMode as ['ngI18nClosureMode'] for closure.
1721
global['ngI18nClosureMode'] =
1822
// TODO(FW-1250): validate that this actually, you know, works.

0 commit comments

Comments
 (0)