You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+59
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,65 @@
2
2
3
3
## Unreleased
4
4
5
+
* Fix a regression regarding `super` ([#2158](https://github.com/evanw/esbuild/issues/2158))
6
+
7
+
This fixes a regression from the previous release regarding classes with a super class, a private member, and a static field in the scenario where the static field needs to be lowered but where private members are supported by the configured target environment. In this scenario, esbuild could incorrectly inject the instance field initializers that use `this` into the constructor before the call to `super()`, which is invalid. This problem has now been fixed (notice that `this` is now used after `super()` instead of before):
8
+
9
+
```js
10
+
// Original code
11
+
class Foo extends Object {
12
+
static FOO;
13
+
constructor() {
14
+
super();
15
+
}
16
+
#foo;
17
+
}
18
+
19
+
// Old output (with --bundle)
20
+
var _foo;
21
+
var Foo = class extends Object {
22
+
constructor() {
23
+
__privateAdd(this, _foo, void 0);
24
+
super();
25
+
}
26
+
};
27
+
_foo = new WeakMap();
28
+
__publicField(Foo, "FOO");
29
+
30
+
// New output (with --bundle)
31
+
var _foo;
32
+
var Foo = class extends Object {
33
+
constructor() {
34
+
super();
35
+
__privateAdd(this, _foo, void 0);
36
+
}
37
+
};
38
+
_foo = new WeakMap();
39
+
__publicField(Foo, "FOO");
40
+
```
41
+
42
+
During parsing, esbuild scans the class and makes certain decisions about the class such as whether to lower all static fields, whether to lower each private member, or whether calls to `super()` need to be tracked and adjusted. Previously esbuild made two passes through the class members to compute this information. However, with the new `super()` call lowering logic added in the previous release, we now need three passes to capture the whole dependency chain for this case: 1) lowering static fields requires 2) lowering private members which requires 3) adjusting `super()` calls.
43
+
44
+
The reason lowering static fields requires lowering private members is because lowering static fields moves their initializers outside of the class body, where they can't access private members anymore. Consider this code:
45
+
46
+
```js
47
+
class Foo {
48
+
get #foo() {}
49
+
static bar = new Foo().#foo
50
+
}
51
+
```
52
+
53
+
We can't just lower static fields without also lowering private members, since that causes a syntax error:
54
+
55
+
```js
56
+
class Foo {
57
+
get #foo() {}
58
+
}
59
+
Foo.bar = new Foo().#foo;
60
+
```
61
+
62
+
And the reason lowering private members requires adjusting `super()` calls is because the injected private member initializers use `this`, which is only accessible after `super()` calls in the constructor.
63
+
5
64
* Add Linux ARM64 support for Deno ([#2156](https://github.com/evanw/esbuild/issues/2156))
6
65
7
66
This release adds Linux ARM64 support to esbuild's [Deno](https://deno.land/) API implementation, which allows esbuild to be used with Deno on a Raspberry Pi.
0 commit comments