@ -36,7 +36,10 @@ use self::{
try_stm ::TryStatement ,
try_stm ::TryStatement ,
variable ::VariableStatement ,
variable ::VariableStatement ,
} ;
} ;
use super ::{ AllowAwait , AllowIn , AllowReturn , AllowYield , Cursor , ParseError , TokenParser } ;
use super ::{
expression ::PropertyName , AllowAwait , AllowIn , AllowReturn , AllowYield , Cursor , ParseError ,
TokenParser ,
} ;
use crate ::syntax ::{
use crate ::syntax ::{
ast ::{
ast ::{
node ::{
node ::{
@ -48,7 +51,7 @@ use crate::syntax::{
} ,
} ,
Keyword , Node , Position , Punctuator ,
Keyword , Node , Position , Punctuator ,
} ,
} ,
lexer ::{ Error as LexError , InputElement , TokenKind } ,
lexer ::{ Error as LexError , InputElement , Token , Token Kind} ,
parser ::expression ::{ await_expr ::AwaitExpression , Initializer } ,
parser ::expression ::{ await_expr ::AwaitExpression , Initializer } ,
} ;
} ;
use boa_interner ::{ Interner , Sym } ;
use boa_interner ::{ Interner , Sym } ;
@ -650,11 +653,13 @@ where
let mut rest_property_name = None ;
let mut rest_property_name = None ;
loop {
loop {
let property_name = match cursor
let next_token_is_colon = * cursor
. peek ( 0 , interner ) ?
. peek ( 1 , interner ) ?
. ok_or ( ParseError ::AbruptEnd ) ?
. ok_or ( ParseError ::AbruptEnd ) ?
. kind ( )
. kind ( )
{
= = TokenKind ::Punctuator ( Punctuator ::Colon ) ;
let token = cursor . peek ( 0 , interner ) ? . ok_or ( ParseError ::AbruptEnd ) ? ;
match token . kind ( ) {
TokenKind ::Punctuator ( Punctuator ::CloseBlock ) = > {
TokenKind ::Punctuator ( Punctuator ::CloseBlock ) = > {
cursor . expect (
cursor . expect (
TokenKind ::Punctuator ( Punctuator ::CloseBlock ) ,
TokenKind ::Punctuator ( Punctuator ::CloseBlock ) ,
@ -680,35 +685,27 @@ where
) ? ;
) ? ;
break ;
break ;
}
}
_ = > BindingIdentifier ::new ( self . allow_yield , self . allow_await )
_ = > {
. parse ( cursor , interner ) ? ,
let is_property_name = match token . kind ( ) {
} ;
TokenKind ::Punctuator ( Punctuator ::OpenBracket )
| TokenKind ::StringLiteral ( _ )
property_names . push ( property_name ) ;
| TokenKind ::NumericLiteral ( _ ) = > true ,
TokenKind ::Identifier ( _ ) if next_token_is_colon = > true ,
if let Some ( peek_token ) = cursor . peek ( 0 , interner ) ? {
TokenKind ::Keyword ( _ ) if next_token_is_colon = > true ,
match peek_token . kind ( ) {
_ = > false ,
TokenKind ::Punctuator ( Punctuator ::Assign ) = > {
} ;
let init = Initializer ::new (
Some ( property_name ) ,
if is_property_name {
self . allow_in ,
let property_name = PropertyName ::new ( self . allow_yield , self . allow_await )
self . allow_yield ,
. parse ( cursor , interner ) ? ;
self . allow_await ,
if let Some ( name ) = property_name . prop_name ( ) {
)
property_names . push ( name ) ;
. parse ( cursor , interner ) ? ;
}
patterns . push ( BindingPatternTypeObject ::SingleName {
ident : property_name ,
property_name ,
default_init : Some ( init ) ,
} ) ;
}
TokenKind ::Punctuator ( Punctuator ::Colon ) = > {
cursor . expect (
cursor . expect (
TokenKind ::Punctuator ( Punctuator ::Colon ) ,
TokenKind ::Punctuator ( Punctuator ::Colon ) ,
"object binding pattern" ,
"object binding pattern" ,
interner ,
interner ,
) ? ;
) ? ;
if let Some ( peek_token ) = cursor . peek ( 0 , interner ) ? {
if let Some ( peek_token ) = cursor . peek ( 0 , interner ) ? {
match peek_token . kind ( ) {
match peek_token . kind ( ) {
TokenKind ::Punctuator ( Punctuator ::OpenBlock ) = > {
TokenKind ::Punctuator ( Punctuator ::OpenBlock ) = > {
@ -842,13 +839,33 @@ where
}
}
}
}
}
}
}
} else {
_ = > {
let name = BindingIdentifier ::new ( self . allow_yield , self . allow_await )
patterns . push ( BindingPatternTypeObject ::SingleName {
. parse ( cursor , interner ) ? ;
ident : property_name ,
property_names . push ( name ) ;
property_name ,
match cursor . peek ( 0 , interner ) ? . map ( Token ::kind ) {
default_init : None ,
Some ( TokenKind ::Punctuator ( Punctuator ::Assign ) ) = > {
} ) ;
let init = Initializer ::new (
Some ( name ) ,
self . allow_in ,
self . allow_yield ,
self . allow_await ,
)
. parse ( cursor , interner ) ? ;
patterns . push ( BindingPatternTypeObject ::SingleName {
ident : name ,
property_name : name . into ( ) ,
default_init : Some ( init ) ,
} ) ;
}
_ = > {
patterns . push ( BindingPatternTypeObject ::SingleName {
ident : name ,
property_name : name . into ( ) ,
default_init : None ,
} ) ;
}
}
}
}
}
}
}
}