do {
next = peek();
- if (!next) {
+ if (next == Token::EOS) {
ReportMessageAt(Scanner::Location(start, peek_position()),
"unterminated_template");
*ok = false;
return Traits::EmptyExpression();
+ } else if (next == Token::ILLEGAL) {
+ Traits::ReportMessageAt(
+ Scanner::Location(position() + 1, peek_position()),
+ "unexpected_token", "ILLEGAL", false);
+ *ok = false;
+ return Traits::EmptyExpression();
}
int expr_pos = peek_position();
next = scanner()->ScanTemplateContinuation();
Next();
- if (!next) {
- ReportMessageAt(Scanner::Location(start, position()),
+ if (next == Token::EOS) {
+ ReportMessageAt(Scanner::Location(start, peek_position()),
"unterminated_template");
*ok = false;
return Traits::EmptyExpression();
+ } else if (next == Token::ILLEGAL) {
+ Traits::ReportMessageAt(
+ Scanner::Location(position() + 1, peek_position()),
+ "unexpected_token", "ILLEGAL", false);
+ *ok = false;
+ return Traits::EmptyExpression();
}
Traits::AddTemplateSpan(&ts, next == Token::TEMPLATE_TAIL);
}
+TEST(TemplateLiteralsIllegalTokens) {
+ const char* context_data[][2] = {{"'use strict';", ""},
+ {"function foo(){ 'use strict';"
+ " var a, b, c; return ", "}"},
+ {NULL, NULL}};
+ const char* data[] = {
+ "`hello\\x`",
+ "`hello\\x${1}`",
+ "`hello${1}\\x`",
+ "`hello${1}\\x${2}`",
+ "`hello\\x\n`",
+ "`hello\\x\n${1}`",
+ "`hello${1}\\x\n`",
+ "`hello${1}\\x\n${2}`",
+ NULL};
+
+ static const ParserFlag always_flags[] = {kAllowHarmonyTemplates};
+ RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
+ arraysize(always_flags));
+}
+
+
TEST(LexicalScopingSloppyMode) {
const char* context_data[][2] = {
{"", ""},