Browse Source

Add async to HoistableDeclaration

pull/836/head
Paul Lancaster 4 years ago
parent
commit
5bc89413de
  1. 22
      boa/src/syntax/parser/statement/declaration/hoistable.rs
  2. 2
      boa/src/syntax/parser/statement/declaration/mod.rs

22
boa/src/syntax/parser/statement/declaration/hoistable.rs

@ -11,6 +11,7 @@ use crate::{
node::{AsyncFunctionDecl, FunctionDecl},
Keyword, Node, Punctuator,
},
lexer::TokenKind,
parser::{
function::FormalParameters, function::FunctionBody, statement::BindingIdentifier,
AllowAwait, AllowDefault, AllowYield, Cursor, ParseError, ParseResult, TokenParser,
@ -18,7 +19,6 @@ use crate::{
},
BoaProfiler,
};
use std::io::Read;
/// Hoistable declaration parsing.
@ -58,10 +58,21 @@ where
fn parse(self, cursor: &mut Cursor<R>) -> ParseResult {
let _timer = BoaProfiler::global().start_event("HoistableDeclaration", "Parsing");
// TODO: check for generators and async functions + generators
FunctionDeclaration::new(self.allow_yield, self.allow_await, self.is_default)
.parse(cursor)
.map(Node::from)
let tok = cursor.peek(0)?.ok_or(ParseError::AbruptEnd)?;
match tok.kind() {
TokenKind::Keyword(Keyword::Function) => {
FunctionDeclaration::new(self.allow_yield, self.allow_await, self.is_default)
.parse(cursor)
.map(Node::from)
}
TokenKind::Keyword(Keyword::Async) => {
AsyncFunctionDeclaration::new(self.allow_yield, self.allow_await, false)
.parse(cursor)
.map(Node::from)
}
_ => unreachable!("unknown token found: {:?}", tok),
}
}
}
@ -161,6 +172,7 @@ where
type Output = AsyncFunctionDecl;
fn parse(self, cursor: &mut Cursor<R>) -> Result<Self::Output, ParseError> {
cursor.expect(Keyword::Async, "async function declaration")?;
unimplemented!("AsyncFunctionDecl parse");
}
}

2
boa/src/syntax/parser/statement/declaration/mod.rs

@ -63,7 +63,7 @@ where
let tok = cursor.peek(0)?.ok_or(ParseError::AbruptEnd)?;
match tok.kind() {
TokenKind::Keyword(Keyword::Function) => {
TokenKind::Keyword(Keyword::Function) | TokenKind::Keyword(Keyword::Async) => {
HoistableDeclaration::new(self.allow_yield, self.allow_await, false).parse(cursor)
}
TokenKind::Keyword(Keyword::Const) | TokenKind::Keyword(Keyword::Let) => {

Loading…
Cancel
Save