Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Allow Initializer after ArrayBindingPattern in FormalParameter #2002

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -399,50 +399,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