Browse Source

Fixed empty returns (#251) (#257)

pull/261/head
Iban Eguia 5 years ago committed by GitHub
parent
commit
f628f4cc8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      boa/src/syntax/parser/mod.rs
  2. 48
      boa/src/syntax/parser/tests.rs

8
boa/src/syntax/parser/mod.rs

@ -222,7 +222,13 @@ impl Parser {
Ok(Expr::new(ExprDef::ConstDecl(vars))) Ok(Expr::new(ExprDef::ConstDecl(vars)))
} }
Keyword::Return => Ok(Expr::new(ExprDef::Return(Some(Box::new(self.parse()?))))), Keyword::Return => match self.get_token(self.pos)?.data {
TokenData::Punctuator(Punctuator::Semicolon)
| TokenData::Punctuator(Punctuator::CloseBlock) => {
Ok(Expr::new(ExprDef::Return(None)))
}
_ => Ok(Expr::new(ExprDef::Return(Some(Box::new(self.parse()?))))),
},
Keyword::New => { Keyword::New => {
let call = self.parse()?; let call = self.parse()?;
match call.def { match call.def {

48
boa/src/syntax/parser/tests.rs

@ -631,6 +631,28 @@ fn check_function_declarations() {
))], ))],
); );
check_parser(
"function foo(a) { return; }",
&[Expr::new(ExprDef::FunctionDecl(
Some(String::from("foo")),
vec![Expr::new(ExprDef::Local(String::from("a")))],
Box::new(Expr::new(ExprDef::Block(vec![Expr::new(ExprDef::Return(
None,
))]))),
))],
);
check_parser(
"function foo(a) { return }",
&[Expr::new(ExprDef::FunctionDecl(
Some(String::from("foo")),
vec![Expr::new(ExprDef::Local(String::from("a")))],
Box::new(Expr::new(ExprDef::Block(vec![Expr::new(ExprDef::Return(
None,
))]))),
))],
);
check_parser( check_parser(
"function (a, ...b) {}", "function (a, ...b) {}",
&[Expr::new(ExprDef::FunctionDecl( &[Expr::new(ExprDef::FunctionDecl(
@ -688,4 +710,30 @@ fn check_function_declarations() {
))]))), ))]))),
))], ))],
); );
check_parser(
"(a, b) => { return; }",
&[Expr::new(ExprDef::ArrowFunctionDecl(
vec![
Expr::new(ExprDef::Local(String::from("a"))),
Expr::new(ExprDef::Local(String::from("b"))),
],
Box::new(Expr::new(ExprDef::Block(vec![Expr::new(ExprDef::Return(
None,
))]))),
))],
);
check_parser(
"(a, b) => { return }",
&[Expr::new(ExprDef::ArrowFunctionDecl(
vec![
Expr::new(ExprDef::Local(String::from("a"))),
Expr::new(ExprDef::Local(String::from("b"))),
],
Box::new(Expr::new(ExprDef::Block(vec![Expr::new(ExprDef::Return(
None,
))]))),
))],
);
} }

Loading…
Cancel
Save