[error messages] Enhance the "unexpected identifier" error message
Bug: chromium:1338838 Change-Id: I1b8c54b460d272b19a4faa180a491e725bee4b79 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3726147 Reviewed-by: Leszek Swirski <leszeks@chromium.org> Commit-Queue: Marja Hölttä <marja@chromium.org> Cr-Commit-Position: refs/heads/main@{#81658}
This commit is contained in:
parent
d385d4116b
commit
7f11bf4e90
@ -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") \
|
||||
|
@ -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:
|
||||
|
@ -25,7 +25,7 @@ Runtime.evaluate exceptionDetails:
|
||||
columnNumber : 2
|
||||
exception : {
|
||||
className : SyntaxError
|
||||
description : SyntaxError: Unexpected identifier
|
||||
description : SyntaxError: Unexpected identifier 'x'
|
||||
objectId : <objectId>
|
||||
subtype : error
|
||||
type : object
|
||||
@ -68,7 +68,7 @@ Runs eval('x x')
|
||||
paused on exception:
|
||||
{
|
||||
className : SyntaxError
|
||||
description : SyntaxError: Unexpected identifier at <anonymous>:1:1
|
||||
description : SyntaxError: Unexpected identifier 'x' at <anonymous>:1:1
|
||||
objectId : <objectId>
|
||||
subtype : error
|
||||
type : object
|
||||
@ -79,7 +79,7 @@ Runtime.evaluate exceptionDetails:
|
||||
columnNumber : 2
|
||||
exception : {
|
||||
className : SyntaxError
|
||||
description : SyntaxError: Unexpected identifier at <anonymous>:1:1
|
||||
description : SyntaxError: Unexpected identifier 'x' at <anonymous>:1:1
|
||||
objectId : <objectId>
|
||||
subtype : error
|
||||
type : object
|
||||
|
@ -52,7 +52,7 @@ compilation result:
|
||||
columnNumber : 13
|
||||
exception : {
|
||||
className : SyntaxError
|
||||
description : SyntaxError: Unexpected identifier
|
||||
description : SyntaxError: Unexpected identifier 'f'
|
||||
objectId : <objectId>
|
||||
subtype : error
|
||||
type : object
|
||||
|
@ -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'
|
||||
|
@ -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'
|
||||
|
@ -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'
|
||||
|
5
test/message/fail/unexpected-identifier.js
Normal file
5
test/message/fail/unexpected-identifier.js
Normal file
@ -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
|
8
test/message/fail/unexpected-identifier.out
Normal file
8
test/message/fail/unexpected-identifier.out
Normal file
@ -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'
|
Loading…
Reference in New Issue
Block a user