Skip to content

Commit

Permalink
Updated arrow_function to make it more clear that the (expr) case sho…
Browse files Browse the repository at this point in the history
…uld have already been handled
  • Loading branch information
Paul Lancaster committed Aug 22, 2020
1 parent d9a53c3 commit a579cf9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
13 changes: 3 additions & 10 deletions boa/src/syntax/parser/expression/assignment/arrow_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,9 @@ where

cursor.peek_expect_no_lineterminator(0)?;

if cursor
.next_if(TokenKind::Punctuator(Punctuator::Arrow))?
.is_some()
{
let body = ConciseBody::new(self.allow_in).parse(cursor)?;
Ok(ArrowFunctionDecl::new(params, body))
} else {
// This might actually be an expresison.
unimplemented!("Todo handle this might be an expression");
}
cursor.expect(TokenKind::Punctuator(Punctuator::Arrow), "arrow function")?;
let body = ConciseBody::new(self.allow_in).parse(cursor)?;
Ok(ArrowFunctionDecl::new(params, body))
}
}

Expand Down
25 changes: 23 additions & 2 deletions boa/src/syntax/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
use super::Parser;
use crate::syntax::ast::{
node::{
field::GetConstField, Assign, BinOp, Call, FunctionDecl, Identifier, LetDecl, LetDeclList,
New, Node, Return, StatementList, UnaryOp, VarDecl, VarDeclList,
field::GetConstField, ArrowFunctionDecl, Assign, BinOp, Call, FormalParameter,
FunctionDecl, Identifier, LetDecl, LetDeclList, New, Node, Return, StatementList, UnaryOp,
VarDecl, VarDeclList,
},
op::{self, CompOp, LogOp, NumOp},
Const,
Expand Down Expand Up @@ -288,3 +289,23 @@ fn increment_in_comma_op() {
.into()],
);
}

#[test]
fn spread_in_arrow_function() {
let s = r#"
(...b) => {
b
}
"#;

check_parser(
s,
vec![
ArrowFunctionDecl::new::<Box<[FormalParameter]>, StatementList>(
Box::new([FormalParameter::new("b", None, true)]),
vec![Identifier::from("b").into()].into(),
)
.into(),
],
);
}

0 comments on commit a579cf9

Please sign in to comment.