Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(897)

Unified Diff: src/parsing/parser.cc

Issue 2447143005: [parsing] When failing due to variable redeclaration, point at the variable. (Closed)
Patch Set: Address review comments. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/pattern-rewriter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser.cc
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc
index 6d78caf103489252d5e1a510fad2ba239a6c6f9b..7ab02d6a1beca263ca9fc7c208074f99ff5e881e 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -1475,7 +1475,9 @@ Declaration* Parser::DeclareVariable(const AstRawString* name,
name, NORMAL_VARIABLE, scanner()->location().beg_pos);
Declaration* declaration =
factory()->NewVariableDeclaration(proxy, this->scope(), pos);
- Declare(declaration, DeclarationDescriptor::NORMAL, mode, init, CHECK_OK);
+ Declare(declaration, DeclarationDescriptor::NORMAL, mode, init, ok, nullptr,
+ scanner()->location().end_pos);
+ if (!*ok) return nullptr;
return declaration;
}
@@ -1497,7 +1499,7 @@ Declaration* Parser::DeclareModuleImport(const AstRawString* name, int pos,
Variable* Parser::Declare(Declaration* declaration,
DeclarationDescriptor::Kind declaration_kind,
VariableMode mode, InitializationFlag init, bool* ok,
- Scope* scope) {
+ Scope* scope, int var_end_pos) {
if (scope == nullptr) {
scope = this->scope();
}
@@ -1506,11 +1508,18 @@ Variable* Parser::Declare(Declaration* declaration,
declaration, mode, init, allow_harmony_restrictive_generators(),
&sloppy_mode_block_scope_function_redefinition, ok);
if (!*ok) {
+ // If we only have the start position of a proxy, we can't highlight the
+ // whole variable name. Pretend its length is 1 so that we highlight at
+ // least the first character.
+ Scanner::Location loc(declaration->proxy()->position(),
+ var_end_pos != kNoSourcePosition
+ ? var_end_pos
+ : declaration->proxy()->position() + 1);
if (declaration_kind == DeclarationDescriptor::NORMAL) {
- ReportMessage(MessageTemplate::kVarRedeclaration,
- declaration->proxy()->raw_name());
+ ReportMessageAt(loc, MessageTemplate::kVarRedeclaration,
+ declaration->proxy()->raw_name());
} else {
- ReportMessage(MessageTemplate::kParamDupe);
+ ReportMessageAt(loc, MessageTemplate::kParamDupe);
}
return nullptr;
}
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/pattern-rewriter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698