Skip to content

Commit

Permalink
fix #3794: --supported:object-accessors=false
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jun 7, 2024
1 parent 67cbf87 commit ae8d1b4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

* Fix internal error with `--supported:object-accessors=false` ([#3794](https://github.com/evanw/esbuild/issues/3794))

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`.

## 0.21.4

* Update support for import assertions and import attributes in node ([#3778](https://github.com/evanw/esbuild/issues/3778))
Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func Source(unsupportedJSFeatures compat.JSFeature) logger.Source {
`

// Avoid object extensions when not using ES6
if !unsupportedJSFeatures.Has(compat.ObjectExtensions) {
if !unsupportedJSFeatures.Has(compat.ObjectExtensions) && !unsupportedJSFeatures.Has(compat.ObjectAccessors) {
text += `__getOwnPropDesc(k < 4 ? target : { get [name]() { return __privateGet(this, extra) }, set [name](x) { return __privateSet(this, extra, x) } }, name)`
} else {
text += `(k < 4 ? __getOwnPropDesc(target, name) : { get: () => __privateGet(this, extra), set: x => __privateSet(this, extra, x) })`
Expand Down
33 changes: 33 additions & 0 deletions internal/runtime/runtime_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package runtime_test

import (
"testing"

"github.com/evanw/esbuild/internal/compat"
"github.com/evanw/esbuild/internal/config"
"github.com/evanw/esbuild/internal/js_parser"
"github.com/evanw/esbuild/internal/logger"
"github.com/evanw/esbuild/internal/runtime"
)

func TestUnsupportedFeatures(t *testing.T) {
for key, feature := range compat.StringToJSFeature {
t.Run(key, func(t *testing.T) {
source := runtime.Source(feature)
log := logger.NewDeferLog(logger.DeferLogAll, nil)

js_parser.Parse(log, source, js_parser.OptionsFromConfig(&config.Options{
UnsupportedJSFeatures: feature,
TreeShaking: true,
}))

if log.HasErrors() {
msgs := "Internal error: failed to parse runtime:\n"
for _, msg := range log.Done() {
msgs += msg.String(logger.OutputOptions{IncludeSource: true}, logger.TerminalInfo{})
}
t.Fatal(msgs[:len(msgs)-1])
}
})
}
}

0 comments on commit ae8d1b4

Please sign in to comment.