mirror of
https://github.com/RGBCube/serenity
synced 2025-05-15 07:24:58 +00:00
LibJS: Implement const variable declarations
This also tightens the means of redeclaration of a variable by proxy, since we now have a way of knowing how a variable was initially declared, we can check if it was declared using `let` or `const` and not tolerate redeclaration like we did previously.
This commit is contained in:
parent
8557bc56f7
commit
ee5a49e2fe
5 changed files with 46 additions and 13 deletions
|
@ -66,6 +66,7 @@ NonnullOwnPtr<Statement> Parser::parse_statement()
|
|||
return parse_return_statement();
|
||||
case TokenType::Var:
|
||||
case TokenType::Let:
|
||||
case TokenType::Const:
|
||||
return parse_variable_declaration();
|
||||
case TokenType::For:
|
||||
return parse_for_statement();
|
||||
|
@ -261,6 +262,10 @@ NonnullOwnPtr<VariableDeclaration> Parser::parse_variable_declaration()
|
|||
declaration_type = DeclarationType::Let;
|
||||
consume(TokenType::Let);
|
||||
break;
|
||||
case TokenType::Const:
|
||||
declaration_type = DeclarationType::Const;
|
||||
consume(TokenType::Const);
|
||||
break;
|
||||
default:
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue