Skip to content
This repository was archived by the owner on Apr 10, 2023. It is now read-only.

Commit 10c1581

Browse files
committed
fix(parse): 🐛 Fix escaped quotes in string
1 parent e43dc99 commit 10c1581

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
'\''
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"type": "Program",
3+
"body": [
4+
{
5+
"type": "ExpressionStatement",
6+
"expression": {
7+
"type": "Literal",
8+
"value": "'"
9+
}
10+
}
11+
]
12+
}

lib/parse.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ module.exports = function parse(input) {
7878
if (isStringStart(code)) {
7979
const startIndex = i;
8080
const endIndex = getStringEndIndex(code, startIndex, input);
81-
consumeNode(
82-
new astFactory.Literal(input.slice(startIndex + 1, endIndex))
83-
);
81+
const quote = String.fromCharCode(code);
82+
const string = input
83+
.slice(startIndex + 1, endIndex)
84+
.replace(new RegExp('\\\\' + quote, 'g'), quote);
85+
consumeNode(new astFactory.Literal(string));
8486
i = endIndex + 1;
8587
continue;
8688
}
@@ -591,6 +593,7 @@ function getStringEndIndex(startCode, startIndex, input) {
591593
i++;
592594
code = input.charCodeAt(i);
593595
if (code === codes['\\']) {
596+
i++;
594597
continue;
595598
}
596599
if (code === startCode) {

0 commit comments

Comments
 (0)