Skip to content

Commit

Permalink
Merge 3d06106 into 6baf455
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad authored Apr 3, 2022
2 parents 6baf455 + 3d06106 commit 0c9582d
Showing 1 changed file with 45 additions and 32 deletions.
77 changes: 45 additions & 32 deletions boa_engine/src/syntax/parser/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,50 +316,63 @@ where
if let Some(t) = cursor.peek(0, interner)? {
let declaration = match *t.kind() {
TokenKind::Punctuator(Punctuator::OpenBlock) => {
let param = ObjectBindingPattern::new(true, self.allow_yield, self.allow_await)
.parse(cursor, interner)?;

let init = cursor
let bindings =
ObjectBindingPattern::new(true, self.allow_yield, self.allow_await)
.parse(cursor, interner)?;
let init = if *cursor
.peek(0, interner)?
.cloned()
.filter(|t| {
// Check that this is an initializer before attempting parse.
*t.kind() == TokenKind::Punctuator(Punctuator::Assign)
})
.map(|_| {
.ok_or(ParseError::AbruptEnd)?
.kind()
== TokenKind::Punctuator(Punctuator::Assign)
{
Some(
Initializer::new(None, true, self.allow_yield, self.allow_await)
.parse(cursor, interner)
})
.transpose()?;
.parse(cursor, interner)?,
)
} else {
None
};

Declaration::new_with_object_pattern(param, init)
Declaration::new_with_object_pattern(bindings, init)
}

TokenKind::Punctuator(Punctuator::OpenBracket) => {
Declaration::new_with_array_pattern(
let bindings =
ArrayBindingPattern::new(true, self.allow_yield, self.allow_await)
.parse(cursor, interner)?,
None,
)
}
.parse(cursor, interner)?;
let init = if *cursor
.peek(0, interner)?
.ok_or(ParseError::AbruptEnd)?
.kind()
== TokenKind::Punctuator(Punctuator::Assign)
{
Some(
Initializer::new(None, true, self.allow_yield, self.allow_await)
.parse(cursor, interner)?,
)
} else {
None
};

Declaration::new_with_array_pattern(bindings, init)
}
_ => {
let params = BindingIdentifier::new(self.allow_yield, self.allow_await)
let ident = BindingIdentifier::new(self.allow_yield, self.allow_await)
.parse(cursor, interner)?;
let init = cursor
let init = if *cursor
.peek(0, interner)?
.cloned()
.filter(|t| {
// Check that this is an initializer before attempting parse.
*t.kind() == TokenKind::Punctuator(Punctuator::Assign)
})
.map(|_| {
.ok_or(ParseError::AbruptEnd)?
.kind()
== TokenKind::Punctuator(Punctuator::Assign)
{
Some(
Initializer::new(None, true, self.allow_yield, self.allow_await)
.parse(cursor, interner)
})
.transpose()?;
.parse(cursor, interner)?,
)
} else {
None
};

Declaration::new_with_identifier(params, init)
Declaration::new_with_identifier(ident, init)
}
};
Ok(Self::Output::new(declaration, false))
Expand Down

0 comments on commit 0c9582d

Please sign in to comment.