From ab9b0021f1b0b878cd746eaba07f45d4786ec461 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Sat, 29 Jun 2024 10:37:39 -0400 Subject: [PATCH] allow `es2024` as a target environment --- CHANGELOG.md | 4 ++++ compat-table/src/index.ts | 3 +++ internal/compat/js_table.go | 4 +++- pkg/api/api.go | 1 + pkg/api/api_impl.go | 2 ++ pkg/cli/cli_impl.go | 1 + scripts/js-api-tests.js | 2 +- 7 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0ed8097194..41feb076023 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,10 @@ TypeScript 5.5 subtly changes the way `await using` behaves. This release updates esbuild to match these changes in TypeScript. You can read more about these changes in [microsoft/TypeScript#58624](https://github.com/microsoft/TypeScript/pull/58624). +* Allow `es2024` as a target environment + + The ECMAScript 2024 specification was just approved, so it has been added to esbuild as a possible compilation target. You can read more about the features that it adds here: [https://2ality.com/2024/06/ecmascript-2024.html](https://2ality.com/2024/06/ecmascript-2024.html). The only addition that's relevant for esbuild is the regular expression `/v` flag. With `--target=es2024`, regular expressions that use the `/v` flag will now be passed through untransformed instead of being transformed into a call to `new RegExp`. + ## 0.21.5 * Fix `Symbol.metadata` on classes without a class decorator ([#3781](https://github.com/evanw/esbuild/issues/3781)) diff --git a/compat-table/src/index.ts b/compat-table/src/index.ts index f98c081f9c1..2ff8a2bffd7 100644 --- a/compat-table/src/index.ts +++ b/compat-table/src/index.ts @@ -392,6 +392,9 @@ import('./kangax').then(kangax => { js.ArbitraryModuleNamespaceNames.ES = { 2022: { force: true } } js.RegexpMatchIndices.ES = { 2022: { force: true } } + // ES2024 features + js.RegexpSetNotation.ES = { 2024: { force: true } } + // This is a problem specific to Internet Explorer. See https://github.com/tc39/ecma262/issues/1440 for (const engine in engines) { if (engine as Engine !== 'ES' && engine as Engine !== 'IE') { diff --git a/internal/compat/js_table.go b/internal/compat/js_table.go index 81192513d9f..23656e3ac4c 100644 --- a/internal/compat/js_table.go +++ b/internal/compat/js_table.go @@ -792,7 +792,9 @@ var jsTable = map[JSFeature]map[Engine][]versionRange{ Opera: {{start: v{51, 0, 0}}}, Safari: {{start: v{11, 1, 0}}}, }, - RegexpSetNotation: {}, + RegexpSetNotation: { + ES: {{start: v{2024, 0, 0}}}, + }, RegexpStickyAndUnicodeFlags: { // Note: The latest version of "IE" failed 6 tests including: RegExp "y" and "u" flags: "u" flag // Note: The latest version of "Rhino" failed 4 tests including: RegExp "y" and "u" flags: "u" flag diff --git a/pkg/api/api.go b/pkg/api/api.go index a1ea52fd1de..69ba4193d24 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -133,6 +133,7 @@ const ( ES2021 ES2022 ES2023 + ES2024 ) type Loader uint16 diff --git a/pkg/api/api_impl.go b/pkg/api/api_impl.go index 843f7f81b87..ba120affa52 100644 --- a/pkg/api/api_impl.go +++ b/pkg/api/api_impl.go @@ -307,6 +307,8 @@ func validateFeatures(log logger.Log, target Target, engines []Engine) (compat.J constraints[compat.ES] = compat.Semver{Parts: []int{2022}} case ES2023: constraints[compat.ES] = compat.Semver{Parts: []int{2023}} + case ES2024: + constraints[compat.ES] = compat.Semver{Parts: []int{2024}} case ESNext, DefaultTarget: default: panic("Invalid target") diff --git a/pkg/cli/cli_impl.go b/pkg/cli/cli_impl.go index 396023ebf7d..2f591b784df 100644 --- a/pkg/cli/cli_impl.go +++ b/pkg/cli/cli_impl.go @@ -981,6 +981,7 @@ func parseTargets(targets []string, arg string) (target api.Target, engines []ap "es2021": api.ES2021, "es2022": api.ES2022, "es2023": api.ES2023, + "es2024": api.ES2024, } outer: diff --git a/scripts/js-api-tests.js b/scripts/js-api-tests.js index 7d5b847ca72..77d7a3ebf5b 100644 --- a/scripts/js-api-tests.js +++ b/scripts/js-api-tests.js @@ -6824,7 +6824,7 @@ class Foo { check('es2021', `x2 = /y/d`, `x2 = new RegExp("y", "d");\n`), // RegExpSetNotation - check('esnext', `x1 = /[\\p{White_Space}&&\\p{ASCII}]/v`, `x1 = /[\\p{White_Space}&&\\p{ASCII}]/v;\n`), + check('es2024', `x1 = /[\\p{White_Space}&&\\p{ASCII}]/v`, `x1 = /[\\p{White_Space}&&\\p{ASCII}]/v;\n`), check('es2022', `x2 = /[\\p{White_Space}&&\\p{ASCII}]/v`, `x2 = new RegExp("[\\\\p{White_Space}&&\\\\p{ASCII}]", "v");\n`), ]) },