- Notifications
You must be signed in to change notification settings - Fork11.9k
Commit25eaaa2
fix(@angular-devkit/build-angular): downlevel class properties when targeting Safari <=v15
The Angular compiler is dependent on static fields being attached touser-defined classes. e.g. `static ecmp = defineComponent`.These static fields sometimes rely on variables from outside of theclass. e.g. the Angular compiler generates constants for contentprojection that are then accessed in the static field initializer.Surprisingly such access to these variables may break in Safari <=v15when a page is loaded without devtools open. The bug (already solved inv16 of Safari)- is very subtle, hard to re-reproduce but basicallyvariable scope tracking is broken. This bug is triggered by additionalparenthesis in the initializer expression. See:https://bugs.webkit.org/show_bug.cgi?id=236843.The TypeScript compiler may generate such additional parenthesis whenit tries to adjust the `this` context when invoking methods, such as fordefining animations in the `ecmp` definition.More details can be found here:#24355 (comment)To ensure Angular applications are not subject to this bug whentargeting Safari <=v15. v15 Safari, both for iOS and Mac is still part ofthe default CLI browserslist with `last 2 Safari majors` (at time ofwriting).Note that it is important that the Babel plugin properly handles thedownleveling of static block-defined members. TypeScript will transformstatic fields, like `static ecmp` into `static { this.ecmp = X }` when`useDefineForClassFields = false` (which is the case for CLI apps). Theclass properties plugin from Babel seems to handle this in an acceptableway. Unlike actual static fields, Babel will not use helpers like`defineProperty` for such extracted static blocks though. e.g.See repro:https://gist.github.com/devversion/dec0dea26e348c509921bf62079b60be```jsclass Test { x = true; static b = true; static { this.a = true; }}// intoclass X { constructor() { _defineProperty(this, "x", true); }}_defineProperty(X, "b", true);X.a = true;```note that in practice TypeScript with `useDefineForClassFields = false`will put non-static members into the constructor as normal assignmentsregardless- so there would be no change by the Babel plugin.Fixes#24355.1 parent49b313f commit25eaaa2
File tree
3 files changed
+90
-12
lines changed- packages/angular_devkit/build_angular/src/babel
- presets
- tests/legacy-cli/e2e/tests/misc
3 files changed
+90
-12
lines changedLines changed: 31 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
20 | 37 | | |
21 | 38 | | |
22 | 39 | | |
| |||
45 | 62 | | |
46 | 63 | | |
47 | 64 | | |
48 | | - | |
49 | 65 | | |
50 | 66 | | |
51 | 67 | | |
| |||
171 | 187 | | |
172 | 188 | | |
173 | 189 | | |
174 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
175 | 203 | | |
176 | 204 | | |
177 | 205 | | |
178 | 206 | | |
179 | 207 | | |
180 | 208 | | |
| 209 | + | |
181 | 210 | | |
182 | 211 | | |
183 | 212 | | |
| |||
Lines changed: 3 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | 82 | | |
84 | 83 | | |
85 | 84 | | |
| |||
105 | 104 | | |
106 | 105 | | |
107 | 106 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | 107 | | |
117 | 108 | | |
118 | 109 | | |
| |||
121 | 112 | | |
122 | 113 | | |
123 | 114 | | |
124 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
125 | 118 | | |
126 | 119 | | |
127 | 120 | | |
| |||
Lines changed: 56 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
0 commit comments
Comments
(0)