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

Enable regexp unicode sets parsing by default #15638

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
20 changes: 10 additions & 10 deletions packages/babel-core/src/parser/util/missing-plugin-helper.ts
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
},
},
});
}

Expand Down
Expand Up @@ -3,6 +3,7 @@ export const FEATURES = Object.freeze({
dotAllFlag: 1 << 1,
unicodePropertyEscape: 1 << 2,
namedCaptureGroups: 1 << 3,
// Babel 8.1: remove unicodeSetsFlag_syntax
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not 8.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type FeatureType depends on the value here, I was worrying plugging in BABEL_8_BREAKING switch here will confuse TypeScript. It seems that it can handle that well.

However, now I think we should preserve this bit even if it is no long used. The bits here decides how we interpret the filePass.get("@babel/plugin-regexp-features/featuresKey"). If we preserve this bit, then the featureKey defined by a Babel 7 plugin will still be respected by a Babel 8 regex plugin. Doing so should help the migration as mis-interpreting feature bits will result to confusing regex feature compilation: Babel is transpiling regex features other than what is perceived by users.

Therefore, unless we run out of all 53 bits, I don't think we have to remove any unused syntax bits. It suffices to just note that this bit is not used and is for compatibility with archived plugins.

unicodeSetsFlag_syntax: 1 << 4,
unicodeSetsFlag: 1 << 5,
duplicateNamedCaptureGroups: 1 << 6,
Expand Down
Expand Up @@ -33,9 +33,7 @@ export function generateRegexpuOptions(

return {
unicodeFlag: feat("unicodeFlag"),
unicodeSetsFlag:
feat<Experimental>("unicodeSetsFlag") ||
feat<Experimental>("unicodeSetsFlag_syntax", "parse"),
unicodeSetsFlag: feat<Experimental>("unicodeSetsFlag") || "parse",
dotAllFlag: feat("dotAllFlag"),
unicodePropertyEscapes: feat("unicodePropertyEscape"),
namedGroups: feat("namedCaptureGroups") || featDuplicateNamedGroups(),
Expand Down
3 changes: 0 additions & 3 deletions packages/babel-parser/src/tokenizer/index.ts
Expand Up @@ -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,
]);

Expand Down Expand Up @@ -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() });
}
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/typings.d.ts
Expand Up @@ -34,7 +34,7 @@ export type Plugin =
| "partialApplication"
| "placeholders"
| "privateIn" // Enabled by default
| "regexpUnicodeSets"
| "regexpUnicodeSets" // Enabled by default
| "throwExpressions"
| "topLevelAwait"
| "v8intrinsic"
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion packages/babel-parser/typings/babel-parser.d.ts
Expand Up @@ -38,7 +38,7 @@ type Plugin =
| "partialApplication"
| "placeholders"
| "privateIn" // Enabled by default
| "regexpUnicodeSets"
| "regexpUnicodeSets" // Enabled by default
| "throwExpressions"
| "topLevelAwait"
| "v8intrinsic"
Expand Down