// If we didn't die parsing that expression, our next token should be a
// TEMPLATE_SPAN or TEMPLATE_TAIL.
- next = scanner()->ScanTemplateSpan();
+ next = scanner()->ScanTemplateContinuation();
Next();
if (!next) {
case '`':
if (HarmonyTemplates()) {
- token = ScanTemplateSpan();
+ token = ScanTemplateStart();
break;
}
// A TEMPLATE_SPAN should always be followed by an Expression, while a
// TEMPLATE_TAIL terminates a TemplateLiteral and does not need to be
// followed by an Expression.
- //
-
- if (next_.token == Token::RBRACE) {
- // After parsing an Expression, the source position is incorrect due to
- // having scanned the brace. Push the RBRACE back into the stream.
- PushBack('}');
- }
- next_.location.beg_pos = source_pos();
Token::Value result = Token::TEMPLATE_SPAN;
- DCHECK(c0_ == '`' || c0_ == '}');
- Advance(); // Consume ` or }
-
LiteralScope literal(this, true);
while (true) {
}
+Token::Value Scanner::ScanTemplateStart() {
+ DCHECK(c0_ == '`');
+ next_.location.beg_pos = source_pos();
+ Advance(); // Consume `
+ return ScanTemplateSpan();
+}
+
+
+Token::Value Scanner::ScanTemplateContinuation() {
+ DCHECK_EQ(next_.token, Token::RBRACE);
+ next_.location.beg_pos = source_pos() - 1; // We already consumed }
+ return ScanTemplateSpan();
+}
+
+
void Scanner::ScanDecimalDigits() {
while (IsDecimalDigit(c0_))
AddLiteralCharAdvance();
bool ScanRegExpFlags();
// Scans the input as a template literal
- Token::Value ScanTemplateSpan();
+ Token::Value ScanTemplateStart();
+ Token::Value ScanTemplateContinuation();
const LiteralBuffer* source_url() const { return &source_url_; }
const LiteralBuffer* source_mapping_url() const {
// Helper for the above functions.
uc32 ScanUnicodeEscape();
+ Token::Value ScanTemplateSpan();
+
// Return the current source position.
int source_pos() {
return source_->pos() - kCharacterLookaheadBufferSize;
assertEquals(`a\u{62}c`, "abc");
assertEquals(`a\u{000062}c`, "abc");
})();
+
+
+(function testLiteralAfterRightBrace() {
+ // Regression test for https://code.google.com/p/v8/issues/detail?id=3734
+ function f() {}
+ `abc`;
+
+ function g() {}`def`;
+
+ {
+ // block
+ }
+ `ghi`;
+
+ {
+ // block
+ }`jkl`;
+})();