Skip to content

Commit 7b81a2e

Browse files
committed
Merge remote-tracking branch 'origin/main' into aperture
Signed-off-by: Christian Stewart <christian@aperture.us>
2 parents 27d23cb + 2b426b7 commit 7b81a2e

File tree

16 files changed

+469
-370
lines changed

16 files changed

+469
-370
lines changed

.github/workflows/ci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,3 @@ jobs:
215215

216216
- name: make test-old-ts
217217
run: make test-old-ts
218-

CHANGELOG.md

+75
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,80 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
* Optimize the generated code for private methods
6+
7+
Previously when lowering private methods for old browsers, esbuild would generate one `WeakSet` for each private method. This mirrors similar logic for generating one `WeakSet` for each private field. Using a separate `WeakMap` for private fields is necessary as their assignment can be observable:
8+
9+
```js
10+
let it
11+
class Bar {
12+
constructor() {
13+
it = this
14+
}
15+
}
16+
class Foo extends Bar {
17+
#x = 1
18+
#y = null.foo
19+
static check() {
20+
console.log(#x in it, #y in it)
21+
}
22+
}
23+
try { new Foo } catch {}
24+
Foo.check()
25+
```
26+
27+
This prints `true false` because this partially-initialized instance has `#x` but not `#y`. In other words, it's not true that all class instances will always have all of their private fields. However, the assignment of private methods to a class instance is not observable. In other words, it's true that all class instances will always have all of their private methods. This means esbuild can lower private methods into code where all methods share a single `WeakSet`, which is smaller, faster, and uses less memory. Other JavaScript processing tools such as the TypeScript compiler already make this optimization. Here's what this change looks like:
28+
29+
```js
30+
// Original code
31+
class Foo {
32+
#x() { return this.#x() }
33+
#y() { return this.#y() }
34+
#z() { return this.#z() }
35+
}
36+
37+
// Old output (--supported:class-private-method=false)
38+
var _x, x_fn, _y, y_fn, _z, z_fn;
39+
class Foo {
40+
constructor() {
41+
__privateAdd(this, _x);
42+
__privateAdd(this, _y);
43+
__privateAdd(this, _z);
44+
}
45+
}
46+
_x = new WeakSet();
47+
x_fn = function() {
48+
return __privateMethod(this, _x, x_fn).call(this);
49+
};
50+
_y = new WeakSet();
51+
y_fn = function() {
52+
return __privateMethod(this, _y, y_fn).call(this);
53+
};
54+
_z = new WeakSet();
55+
z_fn = function() {
56+
return __privateMethod(this, _z, z_fn).call(this);
57+
};
58+
59+
// New output (--supported:class-private-method=false)
60+
var _Foo_instances, x_fn, y_fn, z_fn;
61+
class Foo {
62+
constructor() {
63+
__privateAdd(this, _Foo_instances);
64+
}
65+
}
66+
_Foo_instances = new WeakSet();
67+
x_fn = function() {
68+
return __privateMethod(this, _Foo_instances, x_fn).call(this);
69+
};
70+
y_fn = function() {
71+
return __privateMethod(this, _Foo_instances, y_fn).call(this);
72+
};
73+
z_fn = function() {
74+
return __privateMethod(this, _Foo_instances, z_fn).call(this);
75+
};
76+
```
77+
378
## 0.20.2
479
580
* Support TypeScript experimental decorators on `abstract` class fields ([#3684](https://github.com/evanw/esbuild/issues/3684))

cmd/esbuild/main.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ var helpText = func(colors logger.Colors) string {
127127
--supported:F=... Consider syntax F to be supported (true | false)
128128
--tree-shaking=... Force tree shaking on or off (false | true)
129129
--tsconfig=... Use this tsconfig.json file instead of other ones
130+
--tsconfig-raw=... Override all tsconfig.json files with this string
130131
--version Print the current version (` + esbuildVersion + `) and exit
131132
132133
` + colors.Bold + `Examples:` + colors.Reset + `
@@ -331,12 +332,16 @@ func main() {
331332
for {
332333
_, err := os.Stdin.Read(buffer)
333334
if err != nil {
334-
// Mention why watch mode was stopped to reduce confusion, and
335-
// call out "--watch=forever" to get the alternative behavior
336-
if isWatch {
337-
if options := logger.OutputOptionsForArgs(osArgs); options.LogLevel <= logger.LevelInfo {
335+
if options := logger.OutputOptionsForArgs(osArgs); options.LogLevel <= logger.LevelInfo {
336+
if isWatch {
337+
// Mention why watch mode was stopped to reduce confusion, and
338+
// call out "--watch=forever" to get the alternative behavior
338339
logger.PrintTextWithColor(os.Stderr, options.Color, func(colors logger.Colors) string {
339-
return fmt.Sprintf("%s[watch] stopped because stdin was closed (use \"--watch=forever\" to keep watching even after stdin is closed)%s\n", colors.Dim, colors.Reset)
340+
return fmt.Sprintf("%s[watch] stopped automatically because stdin was closed (use \"--watch=forever\" to keep watching even after stdin is closed)%s\n", colors.Dim, colors.Reset)
341+
})
342+
} else if isServeOrWatch {
343+
logger.PrintTextWithColor(os.Stderr, options.Color, func(colors logger.Colors) string {
344+
return fmt.Sprintf("%s[serve] stopped automatically because stdin was closed (keep stdin open to continue serving)%s\n", colors.Dim, colors.Reset)
340345
})
341346
}
342347
}

compat-table/package-lock.json

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compat-table/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"githubDependencies": {
33
"kangax/compat-table": "1a1ccdc02b8b2158ab39a6146d8a7308f43c830b",
4-
"williamkapke/node-compat-table": "cd9bf26864ac83dea133bf50059c5eb81e4518df"
4+
"williamkapke/node-compat-table": "3b8791b9f31a4f7c14f4c5f496fff8a27c566ae6"
55
},
66
"dependencies": {
7-
"@mdn/browser-compat-data": "5.5.4",
7+
"@mdn/browser-compat-data": "5.5.23",
88
"@types/caniuse-lite": "1.0.1",
99
"@types/node": "20.3.2",
10-
"caniuse-lite": "1.0.30001574"
10+
"caniuse-lite": "1.0.30001612"
1111
}
1212
}

compat-table/src/mdn.ts

-3
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,9 @@ const cssFeatures: Partial<Record<CSSFeature, string | string[]>> = {
6666
Modern_RGB_HSL: [
6767
'css.types.color.hsl.alpha_parameter',
6868
'css.types.color.hsl.space_separated_parameters',
69-
'css.types.color.hsla.space_separated_parameters',
7069
'css.types.color.rgb.alpha_parameter',
7170
'css.types.color.rgb.float_values',
7271
'css.types.color.rgb.space_separated_parameters',
73-
'css.types.color.rgba.float_values',
74-
'css.types.color.rgba.space_separated_parameters',
7572
],
7673
Nesting: 'css.selectors.nesting',
7774
RebeccaPurple: 'css.types.color.named-color.rebeccapurple',

0 commit comments

Comments
 (0)