Skip to content

Commit

Permalink
Fix using syntax-unicode-sets-regex in standalone (#15675)
Browse files Browse the repository at this point in the history
* Fix using `syntax-unicode-sets-regex` in standalone

* Test
  • Loading branch information
nicolo-ribaudo committed Jun 1, 2023
1 parent ecc819b commit 6a84bde
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/babel-preset-env/src/available-plugins.ts
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions packages/babel-standalone/test/babel.js
Expand Up @@ -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;"`);
});
});
});

0 comments on commit 6a84bde

Please sign in to comment.