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> { ...@@ -282,7 +282,12 @@ class VariableDeclarationParsingScope : public ExpressionScope<Types> {
this->parser()->ReportMessage(MessageTemplate::kTooManyVariables); this->parser()->ReportMessage(MessageTemplate::kTooManyVariables);
} }
if (names_) names_->Add(proxy->raw_name(), this->parser()->zone()); 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) { if (this->parser()->loop_nesting_depth() > 0) {
// Due to hoisting, the value of a 'var'-declared variable may actually // Due to hoisting, the value of a 'var'-declared variable may actually
// change even if the code contains only the "initial" assignment, // change even if the code contains only the "initial" assignment,
......
...@@ -1158,6 +1158,10 @@ class ParserBase { ...@@ -1158,6 +1158,10 @@ class ParserBase {
ZonePtrList<const AstRawString>* labels, ZonePtrList<const AstRawString>* labels,
ZonePtrList<const AstRawString>* own_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, void DesugarBindingInForEachStatement(ForInfo* for_info, BlockT* body_block,
ExpressionT* each_variable) { ExpressionT* each_variable) {
// Annex B.3.5 prohibits the form // Annex B.3.5 prohibits the form
...@@ -3488,16 +3492,6 @@ void ParserBase<Impl>::ParseVariableDeclarations( ...@@ -3488,16 +3492,6 @@ void ParserBase<Impl>::ParseVariableDeclarations(
int decl_pos = peek_position(); int decl_pos = peek_position();
ExpressionT pattern = ParseBindingPattern(); 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(); Scanner::Location variable_loc = scanner()->location();
ExpressionT value = impl()->NullExpression(); ExpressionT value = impl()->NullExpression();
...@@ -4376,11 +4370,6 @@ ParserBase<Impl>::ParsePossibleDestructuringSubPattern( ...@@ -4376,11 +4370,6 @@ ParserBase<Impl>::ParsePossibleDestructuringSubPattern(
} }
IdentifierT identifier = impl()->AsIdentifier(result); IdentifierT identifier = impl()->AsIdentifier(result);
ClassifyParameter(identifier, begin, end_position()); ClassifyParameter(identifier, begin, end_position());
if (impl()->IsLet(identifier)) {
expression_scope()->RecordLexicalDeclarationError(
Scanner::Location(begin, end_position()),
MessageTemplate::kLetInLexicalBinding);
}
} else { } else {
DCHECK(result->IsProperty()); DCHECK(result->IsProperty());
expression_scope()->RecordDeclarationError( expression_scope()->RecordDeclarationError(
......
...@@ -568,10 +568,6 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -568,10 +568,6 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
return identifier == ast_value_factory()->arguments_string(); 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 { V8_INLINE bool IsEvalOrArguments(const AstRawString* identifier) const {
return IsEval(identifier) || IsArguments(identifier); return IsEval(identifier) || IsArguments(identifier);
} }
......
...@@ -28,8 +28,6 @@ PreParserIdentifier GetSymbolHelper(Scanner* scanner, ...@@ -28,8 +28,6 @@ PreParserIdentifier GetSymbolHelper(Scanner* scanner,
// - 'contextual' keywords (and may contain escaped; treated in 2nd switch.) // - 'contextual' keywords (and may contain escaped; treated in 2nd switch.)
// - 'contextual' keywords, but may not be escaped (3rd switch). // - 'contextual' keywords, but may not be escaped (3rd switch).
switch (scanner->current_token()) { switch (scanner->current_token()) {
case Token::LET:
return PreParserIdentifier::Let();
case Token::AWAIT: case Token::AWAIT:
return PreParserIdentifier::Await(); return PreParserIdentifier::Await();
case Token::ASYNC: case Token::ASYNC:
...@@ -46,9 +44,6 @@ PreParserIdentifier GetSymbolHelper(Scanner* scanner, ...@@ -46,9 +44,6 @@ PreParserIdentifier GetSymbolHelper(Scanner* scanner,
return PreParserIdentifier::Name(); return PreParserIdentifier::Name();
} }
if (scanner->literal_contains_escapes()) { if (scanner->literal_contains_escapes()) {
if (string == avf->let_string()) {
return PreParserIdentifier::Let();
}
return PreParserIdentifier::Default(); return PreParserIdentifier::Default();
} }
if (string == avf->eval_string()) { if (string == avf->eval_string()) {
......
...@@ -45,9 +45,6 @@ class PreParserIdentifier { ...@@ -45,9 +45,6 @@ class PreParserIdentifier {
static PreParserIdentifier Await() { static PreParserIdentifier Await() {
return PreParserIdentifier(kAwaitIdentifier); return PreParserIdentifier(kAwaitIdentifier);
} }
static PreParserIdentifier Let() {
return PreParserIdentifier(kLetIdentifier);
}
static PreParserIdentifier Async() { static PreParserIdentifier Async() {
return PreParserIdentifier(kAsyncIdentifier); return PreParserIdentifier(kAsyncIdentifier);
} }
...@@ -67,7 +64,6 @@ class PreParserIdentifier { ...@@ -67,7 +64,6 @@ class PreParserIdentifier {
} }
bool IsConstructor() const { return type_ == kConstructorIdentifier; } bool IsConstructor() const { return type_ == kConstructorIdentifier; }
bool IsAwait() const { return type_ == kAwaitIdentifier; } bool IsAwait() const { return type_ == kAwaitIdentifier; }
bool IsLet() const { return type_ == kLetIdentifier; }
bool IsName() const { return type_ == kNameIdentifier; } bool IsName() const { return type_ == kNameIdentifier; }
bool IsPrivateName() const { return type_ == kPrivateNameIdentifier; } bool IsPrivateName() const { return type_ == kPrivateNameIdentifier; }
...@@ -79,7 +75,6 @@ class PreParserIdentifier { ...@@ -79,7 +75,6 @@ class PreParserIdentifier {
kArgumentsIdentifier, kArgumentsIdentifier,
kConstructorIdentifier, kConstructorIdentifier,
kAwaitIdentifier, kAwaitIdentifier,
kLetIdentifier,
kAsyncIdentifier, kAsyncIdentifier,
kNameIdentifier, kNameIdentifier,
kPrivateNameIdentifier kPrivateNameIdentifier
...@@ -1288,10 +1283,6 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1288,10 +1283,6 @@ class PreParser : public ParserBase<PreParser> {
return identifier.IsAwait(); return identifier.IsAwait();
} }
V8_INLINE bool IsLet(const PreParserIdentifier& identifier) const {
return identifier.IsLet();
}
// Returns true if the expression is of type "this.foo". // Returns true if the expression is of type "this.foo".
V8_INLINE static bool IsThisProperty(const PreParserExpression& expression) { V8_INLINE static bool IsThisProperty(const PreParserExpression& expression) {
return expression.IsThisProperty(); 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