Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix using syntax-unicode-sets-regex in standalone #15675

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/babel-preset-env/src/available-plugins.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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;"`);
});
});
});