diff --git a/src/common/message-template.h b/src/common/message-template.h index c2ae2c8fd6..8bcc1952d3 100644 --- a/src/common/message-template.h +++ b/src/common/message-template.h @@ -605,7 +605,7 @@ namespace internal { T(UnexpectedTokenUnaryExponentiation, \ "Unary operator used immediately before exponentiation expression. " \ "Parenthesis must be used to disambiguate operator precedence") \ - T(UnexpectedTokenIdentifier, "Unexpected identifier") \ + T(UnexpectedTokenIdentifier, "Unexpected identifier '%'") \ T(UnexpectedTokenNumber, "Unexpected number") \ T(UnexpectedTokenString, "Unexpected string") \ T(UnexpectedTokenRegExp, "Unexpected regular expression") \ diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc index 93ae96a2ae..262175487f 100644 --- a/src/parsing/parser.cc +++ b/src/parsing/parser.cc @@ -107,7 +107,10 @@ void Parser::ReportUnexpectedTokenAt(Scanner::Location location, case Token::PRIVATE_NAME: case Token::IDENTIFIER: message = MessageTemplate::kUnexpectedTokenIdentifier; - break; + // Use ReportMessageAt with the AstRawString parameter; skip the + // ReportMessageAt below. + ReportMessageAt(location, message, GetIdentifier()); + return; case Token::AWAIT: case Token::ENUM: message = MessageTemplate::kUnexpectedReserved; @@ -119,6 +122,7 @@ void Parser::ReportUnexpectedTokenAt(Scanner::Location location, message = is_strict(language_mode()) ? MessageTemplate::kUnexpectedStrictReserved : MessageTemplate::kUnexpectedTokenIdentifier; + arg = Token::String(token); break; case Token::TEMPLATE_SPAN: case Token::TEMPLATE_TAIL: diff --git a/test/inspector/debugger/break-on-exception-compiler-errors-expected.txt b/test/inspector/debugger/break-on-exception-compiler-errors-expected.txt index 43021bd29c..497de516aa 100644 --- a/test/inspector/debugger/break-on-exception-compiler-errors-expected.txt +++ b/test/inspector/debugger/break-on-exception-compiler-errors-expected.txt @@ -25,7 +25,7 @@ Runtime.evaluate exceptionDetails: columnNumber : 2 exception : { className : SyntaxError - description : SyntaxError: Unexpected identifier + description : SyntaxError: Unexpected identifier 'x' objectId : subtype : error type : object @@ -68,7 +68,7 @@ Runs eval('x x') paused on exception: { className : SyntaxError - description : SyntaxError: Unexpected identifier at :1:1 + description : SyntaxError: Unexpected identifier 'x' at :1:1 objectId : subtype : error type : object @@ -79,7 +79,7 @@ Runtime.evaluate exceptionDetails: columnNumber : 2 exception : { className : SyntaxError - description : SyntaxError: Unexpected identifier at :1:1 + description : SyntaxError: Unexpected identifier 'x' at :1:1 objectId : subtype : error type : object diff --git a/test/inspector/runtime/compile-script-expected.txt b/test/inspector/runtime/compile-script-expected.txt index 7058da9c75..9c68f19f55 100644 --- a/test/inspector/runtime/compile-script-expected.txt +++ b/test/inspector/runtime/compile-script-expected.txt @@ -52,7 +52,7 @@ compilation result: columnNumber : 13 exception : { className : SyntaxError - description : SyntaxError: Unexpected identifier + description : SyntaxError: Unexpected identifier 'f' objectId : subtype : error type : object diff --git a/test/message/fail/destructuring-object-private-name.out b/test/message/fail/destructuring-object-private-name.out index 6a3ecd37c3..6fb4c0410a 100644 --- a/test/message/fail/destructuring-object-private-name.out +++ b/test/message/fail/destructuring-object-private-name.out @@ -1,4 +1,4 @@ -*%(basename)s:8: SyntaxError: Unexpected identifier +*%(basename)s:8: SyntaxError: Unexpected identifier '#x' const { #x: x } = this; ^^ -SyntaxError: Unexpected identifier +SyntaxError: Unexpected identifier '#x' diff --git a/test/message/fail/nf-yield-in-generator.out b/test/message/fail/nf-yield-in-generator.out index 91986dfffc..c71400e80f 100644 --- a/test/message/fail/nf-yield-in-generator.out +++ b/test/message/fail/nf-yield-in-generator.out @@ -1,4 +1,4 @@ -*%(basename)s:6: SyntaxError: Unexpected identifier +*%(basename)s:6: SyntaxError: Unexpected identifier 'yield' function yield() {} ^^^^^ -SyntaxError: Unexpected identifier +SyntaxError: Unexpected identifier 'yield' diff --git a/test/message/fail/nfe-yield-generator.out b/test/message/fail/nfe-yield-generator.out index 75cc9a559b..07a07edeb6 100644 --- a/test/message/fail/nfe-yield-generator.out +++ b/test/message/fail/nfe-yield-generator.out @@ -1,4 +1,4 @@ -*%(basename)s:5: SyntaxError: Unexpected identifier +*%(basename)s:5: SyntaxError: Unexpected identifier 'yield' (function* yield() {}) ^^^^^ -SyntaxError: Unexpected identifier +SyntaxError: Unexpected identifier 'yield' diff --git a/test/message/fail/unexpected-identifier.js b/test/message/fail/unexpected-identifier.js new file mode 100644 index 0000000000..a721c92979 --- /dev/null +++ b/test/message/fail/unexpected-identifier.js @@ -0,0 +1,5 @@ +// Copyright 2022 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +foo bar diff --git a/test/message/fail/unexpected-identifier.out b/test/message/fail/unexpected-identifier.out new file mode 100644 index 0000000000..a3844b898a --- /dev/null +++ b/test/message/fail/unexpected-identifier.out @@ -0,0 +1,8 @@ +# Copyright 2016 the V8 project authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +*%(basename)s:5: SyntaxError: Unexpected identifier 'bar' +foo bar + ^^^ +SyntaxError: Unexpected identifier 'bar'