Skip to content

Commit

Permalink
Merge 0292842 into 5b46d12
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad authored Apr 23, 2022
2 parents 5b46d12 + 0292842 commit 4b06192
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
1 change: 1 addition & 0 deletions boa_engine/src/syntax/parser/expression/primary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ where
TokenKind::BooleanLiteral(boolean) => Ok(Const::from(*boolean).into()),
TokenKind::NullLiteral => Ok(Const::Null.into()),
TokenKind::Identifier(ident) => Ok(Identifier::new(*ident).into()),
TokenKind::Keyword((Keyword::Let, _)) => Ok(Identifier::new(Sym::LET).into()),
TokenKind::Keyword((Keyword::Yield, _)) if self.allow_yield.0 => {
// Early Error: It is a Syntax Error if this production has a [Yield] parameter and StringValue of Identifier is "yield".
Err(ParseError::general(
Expand Down
42 changes: 36 additions & 6 deletions boa_engine/src/syntax/parser/statement/declaration/lexical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@
use crate::syntax::{
ast::{
node::{
declaration::{Declaration, DeclarationList},
Node,
declaration::{
Declaration, DeclarationList, DeclarationPatternArray, DeclarationPatternObject,
},
DeclarationPattern, Node,
},
Keyword, Punctuator,
},
lexer::TokenKind,
lexer::{Error as LexError, TokenKind},
parser::{
cursor::{Cursor, SemicolonResult},
expression::Initializer,
statement::{ArrayBindingPattern, BindingIdentifier, ObjectBindingPattern},
AllowAwait, AllowIn, AllowYield, ParseError, ParseResult, TokenParser,
},
};
use boa_interner::Interner;
use boa_interner::{Interner, Sym};
use boa_profiler::Profiler;
use std::io::Read;

Expand Down Expand Up @@ -268,6 +270,7 @@ where
let _timer = Profiler::global().start_event("LexicalBinding", "Parsing");

let peek_token = cursor.peek(0, interner)?.ok_or(ParseError::AbruptEnd)?;
let position = peek_token.span().start();

match peek_token.kind() {
TokenKind::Punctuator(Punctuator::OpenBlock) => {
Expand All @@ -293,7 +296,17 @@ where
None
};

Ok(Declaration::new_with_object_pattern(bindings, init))
let declaration =
DeclarationPattern::Object(DeclarationPatternObject::new(bindings, init));

if declaration.idents().contains(&Sym::LET) {
return Err(ParseError::lex(LexError::Syntax(
"'let' is disallowed as a lexically bound name".into(),
position,
)));
}

Ok(Declaration::Pattern(declaration))
}
TokenKind::Punctuator(Punctuator::OpenBracket) => {
let bindings =
Expand All @@ -318,12 +331,29 @@ where
None
};

Ok(Declaration::new_with_array_pattern(bindings, init))
let declaration =
DeclarationPattern::Array(DeclarationPatternArray::new(bindings, init));

if declaration.idents().contains(&Sym::LET) {
return Err(ParseError::lex(LexError::Syntax(
"'let' is disallowed as a lexically bound name".into(),
position,
)));
}

Ok(Declaration::Pattern(declaration))
}
_ => {
let ident = BindingIdentifier::new(self.allow_yield, self.allow_await)
.parse(cursor, interner)?;

if ident == Sym::LET {
return Err(ParseError::lex(LexError::Syntax(
"'let' is disallowed as a lexically bound name".into(),
position,
)));
}

let init = if let Some(t) = cursor.peek(0, interner)? {
if *t.kind() == TokenKind::Punctuator(Punctuator::Assign) {
Some(
Expand Down
7 changes: 7 additions & 0 deletions boa_engine/src/syntax/parser/statement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,13 @@ where
next_token.span().start(),
)))
}
TokenKind::Keyword((Keyword::Let, _)) if cursor.strict_mode() => {
Err(ParseError::lex(LexError::Syntax(
"unexpected identifier 'let' in strict mode".into(),
next_token.span().start(),
)))
}
TokenKind::Keyword((Keyword::Let, _)) => Ok(Sym::LET),
TokenKind::Identifier(ref s) => Ok(*s),
TokenKind::Keyword((Keyword::Yield, _)) if self.allow_yield.0 => {
// Early Error: It is a Syntax Error if this production has a [Yield] parameter and StringValue of Identifier is "yield".
Expand Down

0 comments on commit 4b06192

Please sign in to comment.