diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ae0ac2e763..c9131748129 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/internal/runtime/runtime.go b/internal/runtime/runtime.go index b3bf41616f1..a56c7bed444 100644 --- a/internal/runtime/runtime.go +++ b/internal/runtime/runtime.go @@ -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) })` diff --git a/internal/runtime/runtime_test.go b/internal/runtime/runtime_test.go new file mode 100644 index 00000000000..108b2da4654 --- /dev/null +++ b/internal/runtime/runtime_test.go @@ -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]) + } + }) + } +}