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 compiling v set notation to u with unicode properties #70

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rewrite-pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ const computeCharacterClass = (characterClassItem, regenerateOptions) => {
data.transformed =
data.transformed ||
config.transform.unicodePropertyEscapes ||
(config.transform.unicodeSetsFlag && nestedData.maybeIncludesStrings);
(config.transform.unicodeSetsFlag && (nestedData.maybeIncludesStrings || characterClassItem.kind !== "union"));
break;
case 'characterClass':
const handler = item.negative ? handleNegative : handlePositive;
Expand Down Expand Up @@ -700,7 +700,7 @@ const rewritePattern = (pattern, flags, options) => {
config.transform.unicodeSetsFlag = config.flags.unicodeSets && transform(options, 'unicodeSetsFlag');

// unicodeFlag: 'transform' implies unicodePropertyEscapes: 'transform'
config.transform.unicodePropertyEscapes = config.flags.unicode && (
config.transform.unicodePropertyEscapes = (config.flags.unicode || config.flags.unicodeSets) && (
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am still not convinced that we should always transform unicode property escape if unicodeSets flag is set. Can you add a new test case?

/[\p{ASCII}]/v

should be transformed to

/[\p{ASCII}]/u

Of course if user wants to further transform /u, then we should transform \p{ASCII}, too.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I see, there is a transform(options, 'unicodePropertyEscapes') check later so that unicodePropertyEscapes: false will still preserve the property escapes.

transform(options, 'unicodeFlag') || transform(options, 'unicodePropertyEscapes')
);
config.transform.namedGroups = transform(options, 'namedGroups');
Expand Down
Loading