diff --git a/packages/babel-preset-env/src/available-plugins.ts b/packages/babel-preset-env/src/available-plugins.ts index 7728ba05e88c..47bb4cf511f5 100644 --- a/packages/babel-preset-env/src/available-plugins.ts +++ b/packages/babel-preset-env/src/available-plugins.ts @@ -110,6 +110,13 @@ export default { // syntax enabled by default, we can safely skip enabling it. "syntax-unicode-sets-regex": USE_ESM ? null + : // We cannot use the require call when bundling, because this is an ESM file. + // Babel standalone uses a modern parser, so just include a known noop plugin. + // Use `bind` so that it's not detected as a duplicate plugin when using it + // together with the TLA + IS_STANDALONE + ? // @ts-expect-error syntaxTopLevelAwait is a function when bundled + () => syntaxTopLevelAwait.bind() : // eslint-disable-next-line no-restricted-globals () => require("@babel/plugin-syntax-unicode-sets-regex"), "transform-arrow-functions": () => transformArrowFunctions, diff --git a/packages/babel-standalone/test/babel.js b/packages/babel-standalone/test/babel.js index 5fe7b0262814..ae230e155db0 100644 --- a/packages/babel-standalone/test/babel.js +++ b/packages/babel-standalone/test/babel.js @@ -261,5 +261,26 @@ describe("@babel/standalone", () => { it("#14425 - numeric separators should be parsed correctly", () => { expect(() => Babel.transform("1_1", {})).not.toThrow(); }); + it("#15674 - supports unicode sets regex", () => { + expect( + Babel.transform("/[\\w--[b]]/v", { + plugins: ["transform-unicode-sets-regex"], + }).code, + ).toMatchInlineSnapshot(`"/[0-9A-Z_ac-z]/u;"`); + + expect( + Babel.transform("/[\\w--[b]]/v", { + targets: { chrome: 90 }, + presets: [["env", { modules: false }]], + }).code, + ).toMatchInlineSnapshot(`"/[0-9A-Z_ac-z]/u;"`); + + expect( + Babel.transform("/[\\w--[b]]/v", { + targets: { chrome: 113 }, + presets: [["env", { modules: false }]], + }).code, + ).toMatchInlineSnapshot(`"/[\\\\w--[b]]/v;"`); + }); }); });