Skip to content

Commit 501abf7

Browse files
committed
fix #2497: correct invalid feature configurations
1 parent 2026535 commit 501abf7

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

CHANGELOG.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
* Automatically fix invalid `supported` configurations ([#2497](https://github.com/evanw/esbuild/issues/2497))
6+
7+
The `--target=` setting lets you tell esbuild to target a specific version of one or more JavaScript runtimes such as `chrome80,node14` and esbuild will restrict its output to only those features supported by all targeted JavaScript runtimes. More recently, esbuild introduced the `--supported:` setting that lets you override which features are supported on a per-feature basis. However, this now lets you configure nonsensical things such as `--supported:async-await=false --supported:async-generator=true`. Previously doing this could result in esbuild building successfully but producing invalid output.
8+
9+
Starting with this release, esbuild will now attempt to automatically fix nonsensical feature override configurations by introducing more overrides until the configuration makes sense. So now the configuration from previous example will be changed such that `async-await=false` implies `async-generator=false`. The full list of implications that were introduced is below:
10+
11+
* `async-await=false` implies:
12+
* `async-generator=false`
13+
* `for-await=false`
14+
* `top-level-await=false`
15+
16+
* `generator=false` implies:
17+
* `async-generator=false`
18+
* `for-await=false`
19+
20+
* `class-field=false` implies:
21+
* `class-private-field=false`
22+
23+
* `class-static-field=false` implies:
24+
* `class-private-static-field=false`
25+
26+
* `class=false` implies:
27+
* `class-field=false`
28+
* `class-private-accessor=false`
29+
* `class-private-brand-check=false`
30+
* `class-private-field=false`
31+
* `class-private-method=false`
32+
* `class-private-static-accessor=false`
33+
* `class-private-static-field=false`
34+
* `class-private-static-method=false`
35+
* `class-static-blocks=false`
36+
* `class-static-field=false`
37+
338
## 0.15.5
439

540
* Fix issues with Yarn PnP and Yarn's workspaces feature ([#2476](https://github.com/evanw/esbuild/issues/2476))

internal/bundler/bundler.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,6 +2131,25 @@ func applyOptionDefaults(options *config.Options) {
21312131
}
21322132

21332133
options.ProfilerNames = !options.MinifyIdentifiers
2134+
2135+
// Automatically fix invalid configurations of unsupported features
2136+
fixInvalidUnsupportedJSFeatureOverrides(options, compat.AsyncAwait, compat.AsyncGenerator|compat.ForAwait|compat.TopLevelAwait)
2137+
fixInvalidUnsupportedJSFeatureOverrides(options, compat.Generator, compat.AsyncGenerator|compat.ForAwait)
2138+
fixInvalidUnsupportedJSFeatureOverrides(options, compat.ClassField, compat.ClassPrivateField)
2139+
fixInvalidUnsupportedJSFeatureOverrides(options, compat.ClassStaticField, compat.ClassPrivateStaticField)
2140+
fixInvalidUnsupportedJSFeatureOverrides(options, compat.Class,
2141+
compat.ClassField|compat.ClassPrivateAccessor|compat.ClassPrivateBrandCheck|compat.ClassPrivateField|
2142+
compat.ClassPrivateMethod|compat.ClassPrivateStaticAccessor|compat.ClassPrivateStaticField|
2143+
compat.ClassPrivateStaticMethod|compat.ClassStaticBlocks|compat.ClassStaticField)
2144+
}
2145+
2146+
func fixInvalidUnsupportedJSFeatureOverrides(options *config.Options, implies compat.JSFeature, implied compat.JSFeature) {
2147+
// If this feature is unsupported, that implies that the other features must also be unsupported
2148+
if options.UnsupportedJSFeatureOverrides.Has(implies) {
2149+
options.UnsupportedJSFeatures |= implied
2150+
options.UnsupportedJSFeatureOverrides |= implied
2151+
options.UnsupportedJSFeatureOverridesMask |= implied
2152+
}
21342153
}
21352154

21362155
func (b *Bundle) Compile(log logger.Log, options config.Options, timer *helpers.Timer, mangleCache map[string]interface{}) ([]graph.OutputFile, string) {

0 commit comments

Comments
 (0)