Browse Source

AsyncFunctionDecl parsing

pull/836/head
Paul Lancaster 4 years ago
parent
commit
0bfe141b6a
  1. 17
      boa/src/syntax/ast/node/declaration/async_function_decl/mod.rs
  2. 38
      boa/src/syntax/parser/statement/declaration/hoistable.rs

17
boa/src/syntax/ast/node/declaration/async_function_decl/mod.rs

@ -20,7 +20,7 @@ use serde::{Deserialize, Serialize};
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, Trace, Finalize, PartialEq)]
pub struct AsyncFunctionDecl {
name: Box<str>,
name: Option<Box<str>>,
parameters: Box<[FormalParameter]>,
body: StatementList,
}
@ -29,7 +29,7 @@ impl AsyncFunctionDecl {
/// Creates a new async function declaration.
pub(in crate::syntax) fn new<N, P, B>(name: N, parameters: P, body: B) -> Self
where
N: Into<Box<str>>,
N: Into<Option<Box<str>>>,
P: Into<Box<[FormalParameter]>>,
B: Into<StatementList>,
{
@ -41,8 +41,8 @@ impl AsyncFunctionDecl {
}
/// Gets the name of the async function declaration.
pub fn name(&self) -> &str {
&self.name
pub fn name(&self) -> Option<&str> {
self.name.as_deref()
}
/// Gets the list of parameters of the async function declaration.
@ -61,7 +61,14 @@ impl AsyncFunctionDecl {
f: &mut fmt::Formatter<'_>,
indentation: usize,
) -> fmt::Result {
write!(f, "async function {}(", self.name)?;
match &self.name {
Some(name) => {
write!(f, "async function {}(", name)?;
}
None => {
write!(f, "async function (")?;
}
}
join_nodes(f, &self.parameters)?;
f.write_str(") {{")?;

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

@ -173,13 +173,39 @@ where
fn parse(self, cursor: &mut Cursor<R>) -> Result<Self::Output, ParseError> {
cursor.expect(Keyword::Async, "async function declaration")?;
let tok = cursor.peek_expect_no_lineterminator(0)?;
cursor.expect_no_skip_lineterminator(Keyword::Function, "async function declaration")?;
let tok = cursor.peek(0)?;
let name = if let Some(token) = tok {
match token.kind() {
TokenKind::Punctuator(Punctuator::OpenParen) => {
if !self.is_default.0 {
return Err(ParseError::unexpected(
token.clone(),
"Unexpected missing identifier for async function decl",
));
}
None
}
_ => {
Some(BindingIdentifier::new(self.allow_yield, self.allow_await).parse(cursor)?)
}
}
} else {
return Err(ParseError::AbruptEnd);
};
match tok.kind() {
TokenKind::Keyword(Keyword::Function) => {}
_ => {}
}
cursor.expect(Punctuator::OpenParen, "async function declaration")?;
let params = FormalParameters::new(!self.allow_yield.0, true).parse(cursor)?;
cursor.expect(Punctuator::CloseParen, "async function declaration")?;
cursor.expect(Punctuator::OpenBlock, "async function declaration")?;
let body = FunctionBody::new(!self.allow_yield.0, true).parse(cursor)?;
cursor.expect(Punctuator::CloseBlock, "async function declaration")?;
unimplemented!("AsyncFunctionDecl parse");
Ok(AsyncFunctionDecl::new(name, params, body))
}
}

Loading…
Cancel
Save