Skip to content

Commit 8a772ae

Browse files
Protryonbakkot
authored andcommitted
fix lone unicode properties
1 parent 527be28 commit 8a772ae

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/index.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import matchPropertyValue from 'unicode-match-property-value-ecmascript';
2020

21+
import matchPropertyValueMappings from 'unicode-match-property-value-ecmascript/data/mappings';
22+
2123
import matchProperty from 'unicode-match-property-ecmascript';
2224

2325
import propertyAliases from 'unicode-property-aliases-ecmascript';
@@ -472,9 +474,26 @@ const acceptUnicodePropertyValue = state => {
472474
return { matched: characters.length > 0, data: characters.join('') };
473475
};
474476

477+
// excluding nonbinary properties from mathias' list
478+
// https://www.ecma-international.org/ecma-262/9.0/index.html#table-nonbinary-unicode-properties
479+
const illegalLoneUnicodePropertyNames = [
480+
'General_Category',
481+
'Script',
482+
'Script_Extensions',
483+
'scx',
484+
'sc',
485+
'gc',
486+
];
487+
488+
const generalCategoryValues = matchPropertyValueMappings.get('General_Category');
489+
475490
const acceptLoneUnicodePropertyNameOrValue = state => {
476491
let loneValue = acceptUnicodePropertyValue(state);
477-
return { matched: loneValue.matched && catchIsFalse(() => matchProperty(loneValue.data)) };
492+
if (!loneValue.matched || illegalLoneUnicodePropertyNames.includes(loneValue.data)) {
493+
return { matched: false };
494+
}
495+
496+
return { matched: catchIsFalse(() => matchProperty(loneValue.data)) || generalCategoryValues.get(loneValue.data) != null };
478497
};
479498

480499
const acceptUnicodePropertyValueExpression = state =>

test/literal-regexp-expression.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ suite('Parser', () => {
177177
/\p{General_Category=LC}/u
178178
/\p{General_Category=Cased_Letter}/u
179179
/\P{gc=LC}/u
180+
/\P{LC}/u
181+
/\p{Other_Number}/u
182+
/\p{No}/u
180183
/\k/
181184
/\k</
182185
/\k<x/
@@ -233,7 +236,10 @@ suite('Parser', () => {
233236
/(?<a>a)\k/
234237
/(?<a>a)\k</
235238
/(?<a>a)\k<a/
236-
/(?<a>a)\k<x>/`);
239+
/(?<a>a)\k<x>/
240+
/\p{Script_Extensions}/u
241+
/\p{Ahom}/u
242+
/\p{gc}/u`);
237243
regexToPass.forEach(args => testRegexSuccess(...args));
238244
regexToFail.forEach(args => testRegexFailure(...args));
239245
});

0 commit comments

Comments
 (0)