When reading a new string, U+2028/2029 should correctly set th… (#10944)

* test: add test on template

* fix: update lineStart when string contains U+2028/U+2029
This commit is contained in:
Huáng Jùnliàng 2020-01-03 17:07:54 -05:00 committed by Nicolò Ribaudo
parent 6ee8c97e6a
commit 467667af88
9 changed files with 269 additions and 8 deletions

View File

@ -1155,6 +1155,7 @@ export default class Tokenizer extends LocationParser {
) { ) {
++this.state.pos; ++this.state.pos;
++this.state.curLine; ++this.state.curLine;
this.state.lineStart = this.state.pos;
} else if (isNewLine(ch)) { } else if (isNewLine(ch)) {
throw this.raise(this.state.start, "Unterminated string constant"); throw this.raise(this.state.start, "Unterminated string constant");
} else { } else {

View File

@ -41,7 +41,7 @@
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 15 "column": 7
} }
}, },
"value": { "value": {
@ -55,7 +55,7 @@
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 14 "column": 6
} }
}, },
"value": "beforeafter", "value": "beforeafter",

View File

@ -41,7 +41,7 @@
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 15 "column": 7
} }
}, },
"value": { "value": {
@ -55,7 +55,7 @@
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 14 "column": 6
} }
}, },
"value": "beforeafter", "value": "beforeafter",

View File

@ -40,7 +40,7 @@
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 17 "column": 8
} }
}, },
"expression": { "expression": {
@ -54,7 +54,7 @@
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 15 "column": 6
} }
}, },
"extra": { "extra": {

View File

@ -40,7 +40,7 @@
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 17 "column": 8
} }
}, },
"expression": { "expression": {
@ -54,7 +54,7 @@
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 15 "column": 6
} }
}, },
"extra": { "extra": {

View File

@ -0,0 +1,2 @@
(`beforeafter`);
// ^ That's a U+2028 LINE SEPARATOR UTF-16 char (between 'before' and 'after')

View File

@ -0,0 +1,128 @@
{
"type": "File",
"start": 0,
"end": 101,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 83
}
},
"program": {
"type": "Program",
"start": 0,
"end": 101,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 83
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 8
}
},
"expression": {
"type": "TemplateLiteral",
"start": 1,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 2,
"column": 6
}
},
"expressions": [],
"quasis": [
{
"type": "TemplateElement",
"start": 2,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 2,
"column": 5
}
},
"value": {
"raw": "beforeafter",
"cooked": "beforeafter"
},
"tail": true
}
],
"extra": {
"parenthesized": true,
"parenStart": 0
}
},
"trailingComments": [
{
"type": "CommentLine",
"value": " ^ That's a U+2028 LINE SEPARATOR UTF-16 char (between 'before' and 'after')",
"start": 18,
"end": 101,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 83
}
}
}
]
}
],
"directives": []
},
"comments": [
{
"type": "CommentLine",
"value": " ^ That's a U+2028 LINE SEPARATOR UTF-16 char (between 'before' and 'after')",
"start": 18,
"end": 101,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 83
}
}
}
]
}

View File

@ -0,0 +1,2 @@
(`beforeafter`);
// ^ That's a U+2029 PARAGRAPH SEPARATOR UTF-16 char (between 'before' and 'after')

View File

@ -0,0 +1,128 @@
{
"type": "File",
"start": 0,
"end": 106,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 88
}
},
"program": {
"type": "Program",
"start": 0,
"end": 106,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 88
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 8
}
},
"expression": {
"type": "TemplateLiteral",
"start": 1,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 2,
"column": 6
}
},
"expressions": [],
"quasis": [
{
"type": "TemplateElement",
"start": 2,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 2,
"column": 5
}
},
"value": {
"raw": "beforeafter",
"cooked": "beforeafter"
},
"tail": true
}
],
"extra": {
"parenthesized": true,
"parenStart": 0
}
},
"trailingComments": [
{
"type": "CommentLine",
"value": " ^ That's a U+2029 PARAGRAPH SEPARATOR UTF-16 char (between 'before' and 'after')",
"start": 18,
"end": 106,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 88
}
}
}
]
}
],
"directives": []
},
"comments": [
{
"type": "CommentLine",
"value": " ^ That's a U+2029 PARAGRAPH SEPARATOR UTF-16 char (between 'before' and 'after')",
"start": 18,
"end": 106,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 88
}
}
}
]
}