DmitrySoshnikov / regexp-tree

Regular expressions processor in JavaScript
MIT License
400 stars 45 forks source link

Broken optimization `/^[\p{Mc}\p{Me}\p{Mn}]$/` -> `/^[Mcen\p{}]$/` #239

Closed coderaiser closed 3 months ago

coderaiser commented 2 years ago
invalid Unicode escape \p

Or

SyntaxError: Invalid regular expression: /^[Mcen\p{}]$/: Invalid property name in character class
coderaiser commented 2 years ago

Also when trying to optimize /^[\p{Mc}\p{Me}\p{Mn}]$/u:

TypeError: Cannot read properties of undefined (reading 'codePoint')
    at getSortValue (/Users/coderaiser/putout/node_modules/regexp-tree/dist/optimizer/transforms/char-class-classranges-merge-transform.js:103:26)
    at sortCharClass (/Users/coderaiser/putout/node_modules/regexp-tree/dist/optimizer/transforms/char-class-classranges-merge-transform.js:63:16)
    at Array.sort (<anonymous>)
    at Object.CharacterClass (/Users/coderaiser/putout/node_modules/regexp-tree/dist/optimizer/transforms/char-class-classranges-merge-transform.js:35:17)
    at pre (/Users/coderaiser/putout/node_modules/regexp-tree/dist/traverse/index.js:218:55)
    at visit (/Users/coderaiser/putout/node_modules/regexp-tree/dist/traverse/index.js:41:13)
    at visit (/Users/coderaiser/putout/node_modules/regexp-tree/dist/traverse/index.js:80:15)
    at visit (/Users/coderaiser/putout/node_modules/regexp-tree/dist/traverse/index.js:88:15)
    at astTraverse (/Users/coderaiser/putout/node_modules/regexp-tree/dist/traverse/index.js:99:3)
    at Object.traverse (/Users/coderaiser/putout/node_modules/regexp-tree/dist/traverse/index.js:172:5)
DmitrySoshnikov commented 2 years ago

@coderaiser – thanks for reporting. I'll appreciate a PR on fixing this issue. CC @Golmote