Skip to content

Commit ae8d1b4

Browse files
committed
fix #3794: --supported:object-accessors=false
1 parent 67cbf87 commit ae8d1b4

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

CHANGELOG.md

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

3+
## Unreleased
4+
5+
* Fix internal error with `--supported:object-accessors=false` ([#3794](https://github.com/evanw/esbuild/issues/3794))
6+
7+
This release fixes a regression in 0.21.0 where some code that was added to esbuild's internal runtime library of helper functions for JavaScript decorators fails to parse when you configure esbuild with `--supported:object-accessors=false`. The reason is that esbuild introduced code that does `{ get [name]() {} }` which uses both the `object-extensions` feature for the `[name]` and the `object-accessors` feature for the `get`, but esbuild was incorrectly only checking for `object-extensions` and not for `object-accessors`. Additional tests have been added to avoid this type of issue in the future. A workaround for this issue in earlier releases is to also add `--supported:object-extensions=false`.
8+
39
## 0.21.4
410

511
* Update support for import assertions and import attributes in node ([#3778](https://github.com/evanw/esbuild/issues/3778))

internal/runtime/runtime.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func Source(unsupportedJSFeatures compat.JSFeature) logger.Source {
280280
`
281281

282282
// Avoid object extensions when not using ES6
283-
if !unsupportedJSFeatures.Has(compat.ObjectExtensions) {
283+
if !unsupportedJSFeatures.Has(compat.ObjectExtensions) && !unsupportedJSFeatures.Has(compat.ObjectAccessors) {
284284
text += `__getOwnPropDesc(k < 4 ? target : { get [name]() { return __privateGet(this, extra) }, set [name](x) { return __privateSet(this, extra, x) } }, name)`
285285
} else {
286286
text += `(k < 4 ? __getOwnPropDesc(target, name) : { get: () => __privateGet(this, extra), set: x => __privateSet(this, extra, x) })`

internal/runtime/runtime_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package runtime_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/evanw/esbuild/internal/compat"
7+
"github.com/evanw/esbuild/internal/config"
8+
"github.com/evanw/esbuild/internal/js_parser"
9+
"github.com/evanw/esbuild/internal/logger"
10+
"github.com/evanw/esbuild/internal/runtime"
11+
)
12+
13+
func TestUnsupportedFeatures(t *testing.T) {
14+
for key, feature := range compat.StringToJSFeature {
15+
t.Run(key, func(t *testing.T) {
16+
source := runtime.Source(feature)
17+
log := logger.NewDeferLog(logger.DeferLogAll, nil)
18+
19+
js_parser.Parse(log, source, js_parser.OptionsFromConfig(&config.Options{
20+
UnsupportedJSFeatures: feature,
21+
TreeShaking: true,
22+
}))
23+
24+
if log.HasErrors() {
25+
msgs := "Internal error: failed to parse runtime:\n"
26+
for _, msg := range log.Done() {
27+
msgs += msg.String(logger.OutputOptions{IncludeSource: true}, logger.TerminalInfo{})
28+
}
29+
t.Fatal(msgs[:len(msgs)-1])
30+
}
31+
})
32+
}
33+
}

0 commit comments

Comments
 (0)