Skip to content

Commit

Permalink
add an "es2022" target (#2012)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Mar 3, 2022
1 parent d40ff59 commit 7835274
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 3 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

## Unreleased

* Allow `es2022` as a target environment ([#2012](https://github.com/evanw/esbuild/issues/2012))

TypeScript recently [added support for `es2022`](https://devblogs.microsoft.com/typescript/announcing-typescript-4-6/#target-es2022) as a compilation target so esbuild now supports this too. Support for this is preliminary as there is no published ES2022 specification yet (i.e. https://tc39.es/ecma262/2021/ exists but https://tc39.es/ecma262/2022/ is a 404 error). The meaning of esbuild's `es2022` target may change in the future when the specification is finalized. Right now I have made the `es2022` target enable support for the syntax-related [finished proposals](https://github.com/tc39/proposals/blob/main/finished-proposals.md) that are marked as `2022`:

* Class fields
* Class private members
* Class static blocks
* Ergonomic class private member checks
* Top-level await

I have also included the "arbitrary module namespace names" feature since I'm guessing it will end up in the ES2022 specification (this syntax feature was added to the specification without a proposal). TypeScript has [not added support for this yet](https://github.com/microsoft/TypeScript/issues/40594).

* Match `define` to strings in index expressions ([#2050](https://github.com/evanw/esbuild/issues/2050))

With this release, configuring `--define:foo.bar=baz` now matches and replaces both `foo.bar` and `foo['bar']` expressions in the original source code. This is necessary for people who have enabled TypeScript's [`noPropertyAccessFromIndexSignature` feature](https://www.typescriptlang.org/tsconfig#noPropertyAccessFromIndexSignature), which prevents you from using normal property access syntax on a type with an index signature such as in the following code:
Expand Down
12 changes: 12 additions & 0 deletions internal/compat/js_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (features JSFeature) Has(feature JSFeature) bool {
var jsTable = map[JSFeature]map[Engine][]versionRange{
ArbitraryModuleNamespaceNames: {
Chrome: {{start: v{90, 0, 0}}},
ES: {{start: v{2022, 0, 0}}},
Firefox: {{start: v{87, 0, 0}}},
Node: {{start: v{16, 0, 0}}},
},
Expand Down Expand Up @@ -164,6 +165,7 @@ var jsTable = map[JSFeature]map[Engine][]versionRange{
ClassField: {
Chrome: {{start: v{73, 0, 0}}},
Edge: {{start: v{79, 0, 0}}},
ES: {{start: v{2022, 0, 0}}},
Firefox: {{start: v{69, 0, 0}}},
IOS: {{start: v{14, 0, 0}}},
Node: {{start: v{12, 0, 0}}},
Expand All @@ -173,6 +175,7 @@ var jsTable = map[JSFeature]map[Engine][]versionRange{
ClassPrivateAccessor: {
Chrome: {{start: v{84, 0, 0}}},
Edge: {{start: v{84, 0, 0}}},
ES: {{start: v{2022, 0, 0}}},
Firefox: {{start: v{90, 0, 0}}},
IOS: {{start: v{15, 0, 0}}},
Node: {{start: v{14, 6, 0}}},
Expand All @@ -182,6 +185,7 @@ var jsTable = map[JSFeature]map[Engine][]versionRange{
ClassPrivateBrandCheck: {
Chrome: {{start: v{91, 0, 0}}},
Edge: {{start: v{91, 0, 0}}},
ES: {{start: v{2022, 0, 0}}},
Firefox: {{start: v{90, 0, 0}}},
IOS: {{start: v{15, 0, 0}}},
Node: {{start: v{16, 9, 0}}},
Expand All @@ -191,6 +195,7 @@ var jsTable = map[JSFeature]map[Engine][]versionRange{
ClassPrivateField: {
Chrome: {{start: v{84, 0, 0}}},
Edge: {{start: v{84, 0, 0}}},
ES: {{start: v{2022, 0, 0}}},
Firefox: {{start: v{90, 0, 0}}},
IOS: {{start: v{15, 0, 0}}},
Node: {{start: v{14, 6, 0}}},
Expand All @@ -200,6 +205,7 @@ var jsTable = map[JSFeature]map[Engine][]versionRange{
ClassPrivateMethod: {
Chrome: {{start: v{84, 0, 0}}},
Edge: {{start: v{84, 0, 0}}},
ES: {{start: v{2022, 0, 0}}},
Firefox: {{start: v{90, 0, 0}}},
IOS: {{start: v{15, 0, 0}}},
Node: {{start: v{14, 6, 0}}},
Expand All @@ -209,6 +215,7 @@ var jsTable = map[JSFeature]map[Engine][]versionRange{
ClassPrivateStaticAccessor: {
Chrome: {{start: v{84, 0, 0}}},
Edge: {{start: v{84, 0, 0}}},
ES: {{start: v{2022, 0, 0}}},
Firefox: {{start: v{90, 0, 0}}},
IOS: {{start: v{15, 0, 0}}},
Node: {{start: v{14, 6, 0}}},
Expand All @@ -218,6 +225,7 @@ var jsTable = map[JSFeature]map[Engine][]versionRange{
ClassPrivateStaticField: {
Chrome: {{start: v{74, 0, 0}}},
Edge: {{start: v{79, 0, 0}}},
ES: {{start: v{2022, 0, 0}}},
Firefox: {{start: v{90, 0, 0}}},
IOS: {{start: v{15, 0, 0}}},
Node: {{start: v{12, 0, 0}}},
Expand All @@ -227,6 +235,7 @@ var jsTable = map[JSFeature]map[Engine][]versionRange{
ClassPrivateStaticMethod: {
Chrome: {{start: v{84, 0, 0}}},
Edge: {{start: v{84, 0, 0}}},
ES: {{start: v{2022, 0, 0}}},
Firefox: {{start: v{90, 0, 0}}},
IOS: {{start: v{15, 0, 0}}},
Node: {{start: v{14, 6, 0}}},
Expand All @@ -235,11 +244,13 @@ var jsTable = map[JSFeature]map[Engine][]versionRange{
},
ClassStaticBlocks: {
Chrome: {{start: v{91, 0, 0}}},
ES: {{start: v{2022, 0, 0}}},
Node: {{start: v{16, 11, 0}}},
},
ClassStaticField: {
Chrome: {{start: v{73, 0, 0}}},
Edge: {{start: v{79, 0, 0}}},
ES: {{start: v{2022, 0, 0}}},
Firefox: {{start: v{75, 0, 0}}},
IOS: {{start: v{15, 0, 0}}},
Node: {{start: v{12, 0, 0}}},
Expand Down Expand Up @@ -483,6 +494,7 @@ var jsTable = map[JSFeature]map[Engine][]versionRange{
TopLevelAwait: {
Chrome: {{start: v{89, 0, 0}}},
Edge: {{start: v{89, 0, 0}}},
ES: {{start: v{2022, 0, 0}}},
Firefox: {{start: v{89, 0, 0}}},
Node: {{start: v{14, 8, 0}}},
Safari: {{start: v{15, 0, 0}}},
Expand Down
2 changes: 2 additions & 0 deletions internal/resolver/tsconfig_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ func ParseTSConfigJSON(
constraints[compat.ES] = []int{2020}
case "es2021":
constraints[compat.ES] = []int{2021}
case "es2022":
constraints[compat.ES] = []int{2022}
case "esnext":
// Nothing to do in this case
default:
Expand Down
1 change: 1 addition & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ const (
ES2019
ES2020
ES2021
ES2022
)

type Loader uint8
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/api_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ func validateFeatures(log logger.Log, target Target, engines []Engine) (config.T
constraints[compat.ES] = []int{2020}
case ES2021:
constraints[compat.ES] = []int{2021}
case ES2022:
constraints[compat.ES] = []int{2022}
case ESNext:
targetFromAPI = config.TargetWasConfiguredIncludingESNext
case DefaultTarget:
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/cli_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ func parseTargets(targets []string, arg string) (target api.Target, engines []ap
"es2019": api.ES2019,
"es2020": api.ES2020,
"es2021": api.ES2021,
"es2022": api.ES2022,
}

validEngines := map[string]api.EngineName{
Expand Down
15 changes: 12 additions & 3 deletions scripts/compat-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,19 @@ mergeVersions('NullishCoalescing', { es2020: true })
mergeVersions('OptionalChain', { es2020: true })
mergeVersions('TypeofExoticObjectIsObject', { es2020: true }) // https://github.com/tc39/ecma262/pull/1441
mergeVersions('LogicalAssignment', { es2021: true })
mergeVersions('TopLevelAwait', {})
mergeVersions('ArbitraryModuleNamespaceNames', {})
mergeVersions('ClassField', { es2022: true })
mergeVersions('ClassPrivateAccessor', { es2022: true })
mergeVersions('ClassPrivateBrandCheck', { es2022: true })
mergeVersions('ClassPrivateField', { es2022: true })
mergeVersions('ClassPrivateMethod', { es2022: true })
mergeVersions('ClassPrivateStaticAccessor', { es2022: true })
mergeVersions('ClassPrivateStaticField', { es2022: true })
mergeVersions('ClassPrivateStaticMethod', { es2022: true })
mergeVersions('ClassStaticBlocks', { es2022: true })
mergeVersions('ClassStaticField', { es2022: true })
mergeVersions('TopLevelAwait', { es2022: true })
mergeVersions('ArbitraryModuleNamespaceNames', { es2022: true })
mergeVersions('ImportAssertions', {})
mergeVersions('ClassStaticBlocks', {})

// Manually copied from https://caniuse.com/?search=export%20*%20as
mergeVersions('ExportStarAs', {
Expand Down

0 comments on commit 7835274

Please sign in to comment.