mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(localize): ensure transitively loaded compiler code is tree-shakable (#45405)
The localize primary entry-point (used at runtime in application code) indirectly loads from the compiler package for computing message ids. The compiler package has a couple of constants which cannot be DCE-ded/ tree-shaken due to side-effect reliance that is detected by Terser. We fix these constants to be three-shakable. Note that another issue technically would be that the compiler package has a side-effect call for `publishFacade` (for JIT), but that invocation is marked as pure by the Angular CLI babel optimization pipeline. So this results is no unused code currently but is risky and should be addressed in the future. PR Close #45405
This commit is contained in:
committed by
Andrew Scott
parent
4c56c45075
commit
a50e2da64a
@@ -13,16 +13,16 @@ declare var WorkerGlobalScope: any /** TODO #9100 */;
|
||||
// the global "global" var for now.
|
||||
declare var global: any /** TODO #9100 */;
|
||||
|
||||
const __globalThis = typeof globalThis !== 'undefined' && globalThis;
|
||||
const __window = typeof window !== 'undefined' && window;
|
||||
const __self = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' &&
|
||||
self instanceof WorkerGlobalScope && self;
|
||||
const __global = typeof global !== 'undefined' && global;
|
||||
|
||||
// Always use __globalThis if available, which is the spec-defined global variable across all
|
||||
// environments, then fallback to __global first, because in Node tests both __global and
|
||||
// __window may be defined and _global should be __global in that case.
|
||||
const _global = __globalThis || __global || __window || __self;
|
||||
// __window may be defined and _global should be __global in that case. Note: Typeof/Instanceof
|
||||
// checks are considered side-effects in Terser. We explicitly mark this as side-effect free:
|
||||
// https://github.com/terser/terser/issues/250.
|
||||
const _global: any = (/* @__PURE__ */ (
|
||||
() => (typeof globalThis !== 'undefined' && globalThis) ||
|
||||
(typeof global !== 'undefined' && global) || (typeof window !== 'undefined' && window) ||
|
||||
(typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' &&
|
||||
self instanceof WorkerGlobalScope && self))());
|
||||
|
||||
/**
|
||||
* Attention: whenever providing a new value, be sure to add an
|
||||
|
||||
Reference in New Issue
Block a user