Repository navigation
Commit dd68d3a
committed
fix(@angular-devkit/build-angular): do not mark standalone expression statements as pure
Top-level call and new expressions that appear directly as expression
statements are executed solely for their side effects, such as class
property initialization, static blocks, and helper calls.
When targeting browsers requiring class static block or property lowering
(e.g., Chrome < 94), Babel's preset-env lowers self-referencing static
properties into zero-argument IIFEs (and static blocks into _staticBlock()
calls). Because pure-toplevel-functions previously only skipped IIFEs if
they had arguments, zero-argument IIFE statements were marked as pure.
Downstream minifiers (such as esbuild) then eliminated these standalone
pure statements as dead code, dropping essential class members like
Injector.ɵprov and causing NG0201 at bootstrap.
This change ensures that call and new expressions that are directly
expression statements are never annotated as pure, avoiding accidental
elimination of side-effecting statements without requiring hardcoded
whitelists of helper function names.
Fixes #340171 parent 4f19146 commit dd68d3a
2 files changed
Lines changed: 36 additions & 0 deletions
File tree
- packages/angular_devkit/build_angular/src/tools/babel/plugins
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
74 | 81 | | |
75 | 82 | | |
76 | 83 | | |
| |||
96 | 103 | | |
97 | 104 | | |
98 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
99 | 113 | | |
100 | 114 | | |
101 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
157 | 179 | | |
158 | 180 | | |
159 | 181 | | |
| |||
0 commit comments