Commit d5143f3f authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Change how we detect let as lexical declaration

Change-Id: I907ace62da903dd57cb86b608c0f96ac49623976
Reviewed-on: https://chromium-review.googlesource.com/c/1426130
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58991}
parent e5b77388
......@@ -282,7 +282,12 @@ class VariableDeclarationParsingScope : public ExpressionScope<Types> {
this->parser()->ReportMessage(MessageTemplate::kTooManyVariables);
}
if (names_) names_->Add(proxy->raw_name(), this->parser()->zone());
if (!this->IsLexicalDeclaration()) {
if (this->IsLexicalDeclaration()) {
if (this->parser()->IsLet(proxy->raw_name())) {
this->parser()->ReportMessageAt(proxy->location(),
MessageTemplate::kLetInLexicalBinding);
}
} else {
if (this->parser()->loop_nesting_depth() > 0) {
// Due to hoisting, the value of a 'var'-declared variable may actually
// change even if the code contains only the "initial" assignment,
......
......@@ -1158,6 +1158,10 @@ class ParserBase {
ZonePtrList<const AstRawString>* labels,
ZonePtrList<const AstRawString>* own_labels);
V8_INLINE bool IsLet(const AstRawString* identifier) const {
return identifier == ast_value_factory()->let_string();
}
void DesugarBindingInForEachStatement(ForInfo* for_info, BlockT* body_block,
ExpressionT* each_variable) {
// Annex B.3.5 prohibits the form
......@@ -3488,16 +3492,6 @@ void ParserBase<Impl>::ParseVariableDeclarations(
int decl_pos = peek_position();
ExpressionT pattern = ParseBindingPattern();
if (IsLexicalVariableMode(parsing_result->descriptor.mode)) {
if (impl()->IsIdentifier(pattern)) {
if (impl()->IsLet(impl()->AsIdentifier(pattern))) {
impl()->ReportMessageAt(
Scanner::Location(bindings_start, end_position()),
MessageTemplate::kLetInLexicalBinding);
}
}
}
Scanner::Location variable_loc = scanner()->location();
ExpressionT value = impl()->NullExpression();
......@@ -4376,11 +4370,6 @@ ParserBase<Impl>::ParsePossibleDestructuringSubPattern(
}
IdentifierT identifier = impl()->AsIdentifier(result);
ClassifyParameter(identifier, begin, end_position());
if (impl()->IsLet(identifier)) {
expression_scope()->RecordLexicalDeclarationError(
Scanner::Location(begin, end_position()),
MessageTemplate::kLetInLexicalBinding);
}
} else {
DCHECK(result->IsProperty());
expression_scope()->RecordDeclarationError(
......
......@@ -568,10 +568,6 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
return identifier == ast_value_factory()->arguments_string();
}
V8_INLINE bool IsLet(const AstRawString* identifier) const {
return identifier == ast_value_factory()->let_string();
}
V8_INLINE bool IsEvalOrArguments(const AstRawString* identifier) const {
return IsEval(identifier) || IsArguments(identifier);
}
......
......@@ -28,8 +28,6 @@ PreParserIdentifier GetSymbolHelper(Scanner* scanner,
// - 'contextual' keywords (and may contain escaped; treated in 2nd switch.)
// - 'contextual' keywords, but may not be escaped (3rd switch).
switch (scanner->current_token()) {
case Token::LET:
return PreParserIdentifier::Let();
case Token::AWAIT:
return PreParserIdentifier::Await();
case Token::ASYNC:
......@@ -46,9 +44,6 @@ PreParserIdentifier GetSymbolHelper(Scanner* scanner,
return PreParserIdentifier::Name();
}
if (scanner->literal_contains_escapes()) {
if (string == avf->let_string()) {
return PreParserIdentifier::Let();
}
return PreParserIdentifier::Default();
}
if (string == avf->eval_string()) {
......
......@@ -45,9 +45,6 @@ class PreParserIdentifier {
static PreParserIdentifier Await() {
return PreParserIdentifier(kAwaitIdentifier);
}
static PreParserIdentifier Let() {
return PreParserIdentifier(kLetIdentifier);
}
static PreParserIdentifier Async() {
return PreParserIdentifier(kAsyncIdentifier);
}
......@@ -67,7 +64,6 @@ class PreParserIdentifier {
}
bool IsConstructor() const { return type_ == kConstructorIdentifier; }
bool IsAwait() const { return type_ == kAwaitIdentifier; }
bool IsLet() const { return type_ == kLetIdentifier; }
bool IsName() const { return type_ == kNameIdentifier; }
bool IsPrivateName() const { return type_ == kPrivateNameIdentifier; }
......@@ -79,7 +75,6 @@ class PreParserIdentifier {
kArgumentsIdentifier,
kConstructorIdentifier,
kAwaitIdentifier,
kLetIdentifier,
kAsyncIdentifier,
kNameIdentifier,
kPrivateNameIdentifier
......@@ -1288,10 +1283,6 @@ class PreParser : public ParserBase<PreParser> {
return identifier.IsAwait();
}
V8_INLINE bool IsLet(const PreParserIdentifier& identifier) const {
return identifier.IsLet();
}
// Returns true if the expression is of type "this.foo".
V8_INLINE static bool IsThisProperty(const PreParserExpression& expression) {
return expression.IsThisProperty();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment