Skip to content

Commit 0dc0b65

Browse files
committed
1 parent 813344e commit 0dc0b65

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/validator.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,9 @@ export class RegExpValidator {
902902
if (cp === RightParenthesis) {
903903
this.raise("Unmatched ')'")
904904
}
905+
if (cp === ReverseSolidus) {
906+
this.raise("\\ at end of pattern")
907+
}
905908
if (cp === RightSquareBracket || cp === RightCurlyBracket) {
906909
this.raise("Lone quantifier brackets")
907910
}
@@ -1176,6 +1179,7 @@ export class RegExpValidator {
11761179
return (
11771180
this.eatDot() ||
11781181
this.eatReverseSolidusAtomEscape() ||
1182+
this.eatReverseSolidusFollowedByC() ||
11791183
this.eatCharacterClass() ||
11801184
this.eatUncapturingGroup() ||
11811185
this.eatCapturingGroup() ||
@@ -1184,6 +1188,20 @@ export class RegExpValidator {
11841188
)
11851189
}
11861190

1191+
// \ [lookahead = c]
1192+
private eatReverseSolidusFollowedByC(): boolean {
1193+
if (
1194+
this.currentCodePoint === ReverseSolidus &&
1195+
this.nextCodePoint === LatinSmallLetterC
1196+
) {
1197+
this._lastIntValue = this.currentCodePoint
1198+
this.advance()
1199+
this.onCharacter(this.index - 1, this.index, ReverseSolidus)
1200+
return true
1201+
}
1202+
return false
1203+
}
1204+
11871205
// https://www.ecma-international.org/ecma-262/8.0/#prod-strict-InvalidBracedQuantifier
11881206
private eatInvalidBracedQuantifier(): boolean {
11891207
if (this.eatBracedQuantifier(true)) {
@@ -1222,6 +1240,7 @@ export class RegExpValidator {
12221240
cp !== -1 &&
12231241
cp !== CircumflexAccent &&
12241242
cp !== DollarSign &&
1243+
cp !== ReverseSolidus &&
12251244
cp !== FullStop &&
12261245
cp !== Asterisk &&
12271246
cp !== PlusSign &&
@@ -1457,6 +1476,7 @@ export class RegExpValidator {
14571476
}
14581477

14591478
// https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence
1479+
//eslint-disable-next-line complexity
14601480
private eatRegExpUnicodeEscapeSequence(): boolean {
14611481
const start = this.index
14621482

test/parser.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,14 @@ describe("parseRegExpLiteral function:", () => {
7474
assert.deepStrictEqual(actual, expected)
7575
})
7676
})
77+
78+
describe("RegExpParser:", () => {
79+
describe("parsePattern function", () => {
80+
it("should throw syntax error on '\\'.", () => {
81+
assert.throws(
82+
() => new RegExpParser().parsePattern("\\"),
83+
/\\ at end of pattern/,
84+
)
85+
})
86+
})
87+
})

0 commit comments

Comments
 (0)