| Index: src/scanner.cc
|
| diff --git a/src/scanner.cc b/src/scanner.cc
|
| index ddcd937584d50fc45fa921a25e2a5d21fcf5697e..8bfde053b207f8c7aaa3bbd270adab3efe161c4c 100644
|
| --- a/src/scanner.cc
|
| +++ b/src/scanner.cc
|
| @@ -626,6 +626,12 @@ void Scanner::Scan() {
|
| token = Select(Token::BIT_NOT);
|
| break;
|
|
|
| + case '`':
|
| + if (HarmonyTemplates()) {
|
| + token = ScanTemplateSpan();
|
| + break;
|
| + }
|
| +
|
| default:
|
| if (c0_ < 0) {
|
| token = Token::EOS;
|
| @@ -770,6 +776,78 @@ Token::Value Scanner::ScanString() {
|
| }
|
|
|
|
|
| +Token::Value Scanner::ScanTemplateSpan() {
|
| + // When scanning a TemplateSpan, we are looking for the following construct:
|
| + // TEMPLATE_SPAN ::
|
| + // ` LiteralChars* ${
|
| + // | } LiteralChars* ${
|
| + //
|
| + // TEMPLATE_TAIL ::
|
| + // ` LiteralChars* `
|
| + // | } LiteralChar* `
|
| + //
|
| + // 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::ILLEGAL;
|
| + DCHECK(c0_ == '`' || c0_ == '}');
|
| + Advance(); // Consume ` or }
|
| +
|
| + LiteralScope literal(this);
|
| + while (true) {
|
| + uc32 c = c0_;
|
| + Advance();
|
| + if (c == '`') {
|
| + result = Token::TEMPLATE_TAIL;
|
| + break;
|
| + } else if (c == '$' && c0_ == '{') {
|
| + Advance(); // Consume '{'
|
| + result = Token::TEMPLATE_SPAN;
|
| + break;
|
| + } else if (c == '\\') {
|
| + if (unicode_cache_->IsLineTerminator(c0_)) {
|
| + // The TV of LineContinuation :: \ LineTerminatorSequence is the empty
|
| + // code unit sequence.
|
| + uc32 lastChar = c0_;
|
| + Advance();
|
| + if (lastChar == '\r' && c0_ == '\n') Advance();
|
| + } else if (c0_ == '0') {
|
| + Advance();
|
| + AddLiteralChar('0');
|
| + } else {
|
| + ScanEscape();
|
| + }
|
| + } else if (c < 0) {
|
| + // Unterminated template literal
|
| + PushBack(c);
|
| + break;
|
| + } else {
|
| + // The TRV of LineTerminatorSequence :: <CR> is the CV 0x000A.
|
| + // The TRV of LineTerminatorSequence :: <CR><LF> is the sequence
|
| + // consisting of the CV 0x000A.
|
| + if (c == '\r') {
|
| + if (c0_ == '\n') Advance();
|
| + c = '\n';
|
| + }
|
| + AddLiteralChar(c);
|
| + }
|
| + }
|
| + literal.Complete();
|
| + next_.location.end_pos = source_pos();
|
| + next_.token = result;
|
| + return result;
|
| +}
|
| +
|
| +
|
| void Scanner::ScanDecimalDigits() {
|
| while (IsDecimalDigit(c0_))
|
| AddLiteralCharAdvance();
|
|
|