Skip to content

Commit c24e0cc

Browse files
liuxingbaoyuJLHwungnicolo-ribaudo
authored
Fix compiling v set notation to u with unicode properties (#70)
Co-authored-by: Huáng Jùnliàng <[email protected]> Co-authored-by: Nicolò Ribaudo <[email protected]>
1 parent 91ee342 commit c24e0cc

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

Diff for: rewrite-pattern.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ const computeCharacterClass = (characterClassItem, regenerateOptions) => {
456456
data.transformed =
457457
data.transformed ||
458458
config.transform.unicodePropertyEscapes ||
459-
(config.transform.unicodeSetsFlag && nestedData.maybeIncludesStrings);
459+
(config.transform.unicodeSetsFlag && (nestedData.maybeIncludesStrings || characterClassItem.kind !== "union"));
460460
break;
461461
case 'characterClass':
462462
const handler = item.negative ? handleNegative : handlePositive;
@@ -819,7 +819,7 @@ const rewritePattern = (pattern, flags, options) => {
819819
config.transform.unicodeSetsFlag = config.flags.unicodeSets && transform(options, 'unicodeSetsFlag');
820820

821821
// unicodeFlag: 'transform' implies unicodePropertyEscapes: 'transform'
822-
config.transform.unicodePropertyEscapes = config.flags.unicode && (
822+
config.transform.unicodePropertyEscapes = (config.flags.unicode || config.flags.unicodeSets) && (
823823
transform(options, 'unicodeFlag') || transform(options, 'unicodePropertyEscapes')
824824
);
825825
config.transform.namedGroups = transform(options, 'namedGroups');

Diff for: tests/fixtures/unicode-set.js

+17
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,23 @@ const unicodeSetFixtures = [
343343
pattern: '[\\p{ASCII}&&\\p{Control}]',
344344
expected: '[\\0-\\x1F\\x7F]',
345345
},
346+
{
347+
pattern: '\\P{ASCII}',
348+
expected: '[\\x80-\\u{10FFFF}]',
349+
options: { unicodeSetsFlag: "transform", unicodePropertyEscapes: "transform" }
350+
},
351+
{
352+
pattern: '[\\p{ASCII}\\p{Decimal_Number}]',
353+
expected: '[\\p{ASCII}\\p{Decimal_Number}]'
354+
},
355+
{
356+
pattern: '[\\p{Lowercase_Letter}]',
357+
expected: '[\\p{Lowercase_Letter}]'
358+
},
359+
{
360+
pattern: '^[\\p{Script=Arabic}&&\\p{Number}]$',
361+
expected: '^[\\u0660-\\u0669\\u06F0-\\u06F9\\u{10E60}-\\u{10E7E}]$'
362+
},
346363
{
347364
pattern: '.',
348365
flags: 'sv',

Diff for: tests/tests.js

-2
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,6 @@ describe('character classes', () => {
427427
}
428428
});
429429

430-
431-
432430
describe('unicodeSets (v) flag', () => {
433431
// Re-use the unicode fixtures but replacing the input pattern's `u` flag with `v` flag
434432
for (const fixture of unicodeFixtures) {

0 commit comments

Comments
 (0)