Repository navigation
Commit ac70f86
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 #34017
(cherry picked from commit dd68d3a)1 parent 90ee193 commit ac70f86
2 files changed
Lines changed: 36 additions & 0 deletions
File tree
- packages/angular_devkit/build_angular/src/tools/babel/plugins
Lines changed: 14 additions & 0 deletions
| 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 | | |
| |||
Lines changed: 22 additions & 0 deletions
| 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