Skip to content

Commit

Permalink
fix: error in expression character class with nested character class (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored Sep 11, 2023
1 parent 89cfbd0 commit 97c3ce6
Show file tree
Hide file tree
Showing 3 changed files with 410 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,7 @@ class RegExpParserState {
if (
node.type !== "CharacterClass" ||
(node.parent.type !== "Alternative" &&
node.parent.type !== "CharacterClass") ||
(this._expressionBuffer && node.elements.length > 0)
node.parent.type !== "CharacterClass")
) {
throw new Error("UnknownError")
}
Expand All @@ -540,10 +539,15 @@ class RegExpParserState {
this._node = parent

const expression = this._expressionBuffer
this._expressionBuffer = null
if (!expression) {
if (
expression?.parent !== (node as unknown as ExpressionCharacterClass)
) {
return
}
if (node.elements.length > 0) {
throw new Error("UnknownError")
}
this._expressionBuffer = null

// Replace with ExpressionCharacterClass.
const newNode: ExpressionCharacterClass = {
Expand Down
Loading

0 comments on commit 97c3ce6

Please sign in to comment.