Skip to content

Commit

Permalink
Merge pull request #151 from babel/fix-annex-b-reverse-solidus-c
Browse files Browse the repository at this point in the history
annex-b: \ can be ClassAtomNoDash if followed by c
  • Loading branch information
jviereck authored Oct 25, 2024
2 parents f2b6095 + 0868c5d commit fd2bc4d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1386,13 +1386,19 @@
// ClassAtomNoDash ::
// SourceCharacter but not one of \ or ] or -
// \ ClassEscape
//
// ClassAtomNoDash (Annex B)::
// \ [lookahead = c]

var res;
if (res = matchReg(/^[^\\\]-]/)) {
return createCharacter(res[0]);
} else if (match('\\')) {
res = parseClassEscape();
if (!res) {
if (!isUnicodeMode && lookahead() == 'c') {
return createCharacter('\\');
}
bail('classEscape');
}

Expand Down
6 changes: 6 additions & 0 deletions test/test-data-unicode.json
Original file line number Diff line number Diff line change
Expand Up @@ -1872,5 +1872,11 @@
"name": "SyntaxError",
"message": "Expected atom at position 2\n \\B{1}\n ^",
"input": "\\B{1}"
},
"[\\c]": {
"type": "error",
"name": "SyntaxError",
"message": "classEscape at position 2\n [\\c]\n ^",
"input": "[\\c]"
}
}
32 changes: 32 additions & 0 deletions test/test-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -38627,6 +38627,38 @@
],
"raw": ".(?!.){2,3}"
},
"[\\c]": {
"type": "characterClass",
"kind": "union",
"body": [
{
"type": "value",
"kind": "symbol",
"codePoint": 92,
"range": [
1,
2
],
"raw": "\\"
},
{
"type": "value",
"kind": "symbol",
"codePoint": 99,
"range": [
2,
3
],
"raw": "c"
}
],
"negative": false,
"range": [
0,
4
],
"raw": "[\\c]"
},
"^*": {
"type": "error",
"name": "SyntaxError",
Expand Down

0 comments on commit fd2bc4d

Please sign in to comment.