From 58f7125d316deaf8ecb6f4daea2bf139e2a84d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 17 May 2023 16:30:38 -0400 Subject: [PATCH 1/4] remove regexpUnicodeSets parser plugin --- .../src/parser/util/missing-plugin-helper.ts | 20 +++++++++---------- packages/babel-parser/src/tokenizer/index.ts | 3 --- packages/babel-parser/src/typings.d.ts | 2 +- .../_no-plugin/regexp-unicode-sets/input.js | 1 - .../regexp-unicode-sets/options.json | 3 --- .../babel-parser/typings/babel-parser.d.ts | 2 +- 6 files changed, 12 insertions(+), 19 deletions(-) delete mode 100644 packages/babel-parser/test/fixtures/experimental/_no-plugin/regexp-unicode-sets/input.js delete mode 100644 packages/babel-parser/test/fixtures/experimental/_no-plugin/regexp-unicode-sets/options.json diff --git a/packages/babel-core/src/parser/util/missing-plugin-helper.ts b/packages/babel-core/src/parser/util/missing-plugin-helper.ts index f4eee3891e49..2d4d8751dd78 100644 --- a/packages/babel-core/src/parser/util/missing-plugin-helper.ts +++ b/packages/babel-core/src/parser/util/missing-plugin-helper.ts @@ -106,16 +106,6 @@ const pluginNameMap: Record< url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-record-and-tuple", }, }, - regexpUnicodeSets: { - syntax: { - name: "@babel/plugin-syntax-unicode-sets-regex", - url: "https://github.com/babel/babel/blob/main/packages/babel-plugin-syntax-unicode-sets-regex/README.md", - }, - transform: { - name: "@babel/plugin-proposal-unicode-sets-regex", - url: "https://github.com/babel/babel/blob/main/packages/babel-plugin-proposalunicode-sets-regex/README.md", - }, - }, throwExpressions: { syntax: { name: "@babel/plugin-syntax-throw-expressions", @@ -289,6 +279,16 @@ if (!process.env.BABEL_8_BREAKING) { url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-private-property-in-object", }, }, + regexpUnicodeSets: { + syntax: { + name: "@babel/plugin-syntax-unicode-sets-regex", + url: "https://github.com/babel/babel/blob/main/packages/babel-plugin-syntax-unicode-sets-regex/README.md", + }, + transform: { + name: "@babel/plugin-proposal-unicode-sets-regex", + url: "https://github.com/babel/babel/blob/main/packages/babel-plugin-proposalunicode-sets-regex/README.md", + }, + }, }); } diff --git a/packages/babel-parser/src/tokenizer/index.ts b/packages/babel-parser/src/tokenizer/index.ts index edd0c7649677..8750a3cf808c 100644 --- a/packages/babel-parser/src/tokenizer/index.ts +++ b/packages/babel-parser/src/tokenizer/index.ts @@ -57,7 +57,6 @@ const VALID_REGEX_FLAGS = new Set([ charCodes.lowercaseY, charCodes.lowercaseU, charCodes.lowercaseD, - // This is only valid when using the regexpUnicodeSets plugin charCodes.lowercaseV, ]); @@ -1100,8 +1099,6 @@ export default abstract class Tokenizer extends CommentsParser { // @ts-expect-error VALID_REGEX_FLAGS.has should accept expanded type: number if (VALID_REGEX_FLAGS.has(cp)) { if (cp === charCodes.lowercaseV) { - this.expectPlugin("regexpUnicodeSets", nextPos()); - if (mods.includes("u")) { this.raise(Errors.IncompatibleRegExpUVFlags, { at: nextPos() }); } diff --git a/packages/babel-parser/src/typings.d.ts b/packages/babel-parser/src/typings.d.ts index 3ed4a5c70b59..7eded8ebc8b6 100644 --- a/packages/babel-parser/src/typings.d.ts +++ b/packages/babel-parser/src/typings.d.ts @@ -34,7 +34,7 @@ export type Plugin = | "partialApplication" | "placeholders" | "privateIn" // Enabled by default - | "regexpUnicodeSets" + | "regexpUnicodeSets" // Enabled by default | "throwExpressions" | "topLevelAwait" | "v8intrinsic" diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/regexp-unicode-sets/input.js b/packages/babel-parser/test/fixtures/experimental/_no-plugin/regexp-unicode-sets/input.js deleted file mode 100644 index 04ee6ccf77ed..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/regexp-unicode-sets/input.js +++ /dev/null @@ -1 +0,0 @@ -/a/v; diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/regexp-unicode-sets/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/regexp-unicode-sets/options.json deleted file mode 100644 index a9aa871d03c7..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/regexp-unicode-sets/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "This experimental syntax requires enabling the parser plugin: \"regexpUnicodeSets\". (1:4)" -} diff --git a/packages/babel-parser/typings/babel-parser.d.ts b/packages/babel-parser/typings/babel-parser.d.ts index d80fff653c30..dc3623bc2d35 100644 --- a/packages/babel-parser/typings/babel-parser.d.ts +++ b/packages/babel-parser/typings/babel-parser.d.ts @@ -38,7 +38,7 @@ type Plugin = | "partialApplication" | "placeholders" | "privateIn" // Enabled by default - | "regexpUnicodeSets" + | "regexpUnicodeSets" // Enabled by default | "throwExpressions" | "topLevelAwait" | "v8intrinsic" From 1d633e2f336a750a163e8e634a93421a7252164d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 17 May 2023 16:31:12 -0400 Subject: [PATCH 2/4] move parser test cases to es2024 --- .../regexp-unicode-sets/basic/input.js | 0 .../regexp-unicode-sets/basic/output.json | 0 .../regexp-unicode-sets/uv-error/input.js | 0 .../regexp-unicode-sets/uv-error/output.json | 0 .../regexp-unicode-sets/vu-error/input.js | 0 .../regexp-unicode-sets/vu-error/output.json | 0 .../fixtures/experimental/regexp-unicode-sets/options.json | 3 --- 7 files changed, 3 deletions(-) rename packages/babel-parser/test/fixtures/{experimental => es2024}/regexp-unicode-sets/basic/input.js (100%) rename packages/babel-parser/test/fixtures/{experimental => es2024}/regexp-unicode-sets/basic/output.json (100%) rename packages/babel-parser/test/fixtures/{experimental => es2024}/regexp-unicode-sets/uv-error/input.js (100%) rename packages/babel-parser/test/fixtures/{experimental => es2024}/regexp-unicode-sets/uv-error/output.json (100%) rename packages/babel-parser/test/fixtures/{experimental => es2024}/regexp-unicode-sets/vu-error/input.js (100%) rename packages/babel-parser/test/fixtures/{experimental => es2024}/regexp-unicode-sets/vu-error/output.json (100%) delete mode 100644 packages/babel-parser/test/fixtures/experimental/regexp-unicode-sets/options.json diff --git a/packages/babel-parser/test/fixtures/experimental/regexp-unicode-sets/basic/input.js b/packages/babel-parser/test/fixtures/es2024/regexp-unicode-sets/basic/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/regexp-unicode-sets/basic/input.js rename to packages/babel-parser/test/fixtures/es2024/regexp-unicode-sets/basic/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/regexp-unicode-sets/basic/output.json b/packages/babel-parser/test/fixtures/es2024/regexp-unicode-sets/basic/output.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/regexp-unicode-sets/basic/output.json rename to packages/babel-parser/test/fixtures/es2024/regexp-unicode-sets/basic/output.json diff --git a/packages/babel-parser/test/fixtures/experimental/regexp-unicode-sets/uv-error/input.js b/packages/babel-parser/test/fixtures/es2024/regexp-unicode-sets/uv-error/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/regexp-unicode-sets/uv-error/input.js rename to packages/babel-parser/test/fixtures/es2024/regexp-unicode-sets/uv-error/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/regexp-unicode-sets/uv-error/output.json b/packages/babel-parser/test/fixtures/es2024/regexp-unicode-sets/uv-error/output.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/regexp-unicode-sets/uv-error/output.json rename to packages/babel-parser/test/fixtures/es2024/regexp-unicode-sets/uv-error/output.json diff --git a/packages/babel-parser/test/fixtures/experimental/regexp-unicode-sets/vu-error/input.js b/packages/babel-parser/test/fixtures/es2024/regexp-unicode-sets/vu-error/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/regexp-unicode-sets/vu-error/input.js rename to packages/babel-parser/test/fixtures/es2024/regexp-unicode-sets/vu-error/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/regexp-unicode-sets/vu-error/output.json b/packages/babel-parser/test/fixtures/es2024/regexp-unicode-sets/vu-error/output.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/regexp-unicode-sets/vu-error/output.json rename to packages/babel-parser/test/fixtures/es2024/regexp-unicode-sets/vu-error/output.json diff --git a/packages/babel-parser/test/fixtures/experimental/regexp-unicode-sets/options.json b/packages/babel-parser/test/fixtures/experimental/regexp-unicode-sets/options.json deleted file mode 100644 index a027295978f0..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/regexp-unicode-sets/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["regexpUnicodeSets"] -} From 8d2e89553c7a580e5439427c75470482094ba664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Thu, 18 May 2023 11:47:13 -0400 Subject: [PATCH 3/4] materialize the unicodeSetsFlag_syntax feature --- .../src/features.ts | 1 + .../babel-helper-create-regexp-features-plugin/src/util.ts | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/babel-helper-create-regexp-features-plugin/src/features.ts b/packages/babel-helper-create-regexp-features-plugin/src/features.ts index 4624d6cbcce2..f190fb84b189 100644 --- a/packages/babel-helper-create-regexp-features-plugin/src/features.ts +++ b/packages/babel-helper-create-regexp-features-plugin/src/features.ts @@ -3,6 +3,7 @@ export const FEATURES = Object.freeze({ dotAllFlag: 1 << 1, unicodePropertyEscape: 1 << 2, namedCaptureGroups: 1 << 3, + // Babel 8.1: remove unicodeSetsFlag_syntax unicodeSetsFlag_syntax: 1 << 4, unicodeSetsFlag: 1 << 5, duplicateNamedCaptureGroups: 1 << 6, diff --git a/packages/babel-helper-create-regexp-features-plugin/src/util.ts b/packages/babel-helper-create-regexp-features-plugin/src/util.ts index 7396baf3219a..94a00cc66365 100644 --- a/packages/babel-helper-create-regexp-features-plugin/src/util.ts +++ b/packages/babel-helper-create-regexp-features-plugin/src/util.ts @@ -33,9 +33,7 @@ export function generateRegexpuOptions( return { unicodeFlag: feat("unicodeFlag"), - unicodeSetsFlag: - feat("unicodeSetsFlag") || - feat("unicodeSetsFlag_syntax", "parse"), + unicodeSetsFlag: feat("unicodeSetsFlag") || "parse", dotAllFlag: feat("dotAllFlag"), unicodePropertyEscapes: feat("unicodePropertyEscape"), namedGroups: feat("namedCaptureGroups") || featDuplicateNamedGroups(), From b6e91883e22333110307723bbb194f7d18c8e602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 19 May 2023 14:29:30 -0400 Subject: [PATCH 4/4] unicodeSetsFlag_syntax bit should be preserved --- .../babel-helper-create-regexp-features-plugin/src/features.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-helper-create-regexp-features-plugin/src/features.ts b/packages/babel-helper-create-regexp-features-plugin/src/features.ts index f190fb84b189..9fd8d57d5295 100644 --- a/packages/babel-helper-create-regexp-features-plugin/src/features.ts +++ b/packages/babel-helper-create-regexp-features-plugin/src/features.ts @@ -3,7 +3,7 @@ export const FEATURES = Object.freeze({ dotAllFlag: 1 << 1, unicodePropertyEscape: 1 << 2, namedCaptureGroups: 1 << 3, - // Babel 8.1: remove unicodeSetsFlag_syntax + // Not used, for backward compatibility with syntax-unicode-sets-regex unicodeSetsFlag_syntax: 1 << 4, unicodeSetsFlag: 1 << 5, duplicateNamedCaptureGroups: 1 << 6,