diff --git a/src/tree/definition/function.rs b/src/tree/definition/function.rs index 44b00da..4074d5b 100644 --- a/src/tree/definition/function.rs +++ b/src/tree/definition/function.rs @@ -507,6 +507,10 @@ impl std::fmt::Display for FunctionLikeParameterDefaultValueDefinition { impl std::fmt::Display for FunctionDefinition { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + if !self.modifiers.modifiers.is_empty() { + write!(f, "{} ", self.modifiers)?; + } + write!(f, "{} {}", self.function, self.name)?; if let Some(templates) = &self.templates { @@ -598,6 +602,13 @@ mod tests { #[test] fn test_function_definition_display() { let function_definition = FunctionDefinition { + modifiers: ModifierGroupDefinition { + position: 0, + modifiers: vec![ModifierDefinition::Async(Keyword::new( + ByteString::from("async"), + 0, + ))], + }, function: Keyword::new(ByteString::from("function"), 0), name: Identifier { position: 0, @@ -646,7 +657,7 @@ mod tests { assert_eq!( function_definition.to_string(), - "function Foo(i32 $foo): i64 { /* ... */ }" + "async function Foo(i32 $foo): i64 { /* ... */ }" ); } diff --git a/src/tree/expression/function.rs b/src/tree/expression/function.rs index ee2c042..c93ba96 100644 --- a/src/tree/expression/function.rs +++ b/src/tree/expression/function.rs @@ -195,9 +195,10 @@ impl Node for AnonymousFunctionUseClauseVariableExpression { impl std::fmt::Display for ArrowFunctionExpression { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - if let Some(r#static) = &self.r#static { - write!(f, "{} ", r#static)?; + if !self.modifiers.modifiers.is_empty() { + write!(f, "{} ", self.modifiers)?; } + write!( f, "{} {}{} => {};", @@ -208,9 +209,10 @@ impl std::fmt::Display for ArrowFunctionExpression { impl std::fmt::Display for AnonymousFunctionExpression { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - if let Some(r#static) = &self.r#static { - write!(f, "{} ", r#static)?; + if !self.modifiers.modifiers.is_empty() { + write!(f, "{} ", self.modifiers)?; } + write!(f, "{} {}", self.function, self.parameters)?; if let Some(use_clause) = &self.use_clause { @@ -238,6 +240,7 @@ mod tests { use super::*; use crate::lexer::byte_string::ByteString; use crate::tree::definition::function::FunctionLikeParameterDefinition; + use crate::tree::definition::modifier::ModifierDefinition; use crate::tree::definition::r#type::SignedIntegerTypeDefinition; use crate::tree::definition::r#type::TypeDefinition; @@ -246,7 +249,13 @@ mod tests { let arrow_function_expression = ArrowFunctionExpression { attributes: vec![], comments: CommentGroup { comments: vec![] }, - r#static: Some(Keyword::new(ByteString::from("static"), 0)), + modifiers: ModifierGroupDefinition { + position: 0, + modifiers: vec![ModifierDefinition::Static(Keyword::new( + ByteString::from("static"), + 0, + ))], + }, r#fn: Keyword::new(ByteString::from("fn"), 0), parameters: FunctionLikeParameterListDefinition { comments: CommentGroup { comments: vec![] }, @@ -296,7 +305,13 @@ mod tests { let anonymous_function_expression = AnonymousFunctionExpression { attributes: vec![], comments: CommentGroup { comments: vec![] }, - r#static: Some(Keyword::new(ByteString::from("static"), 0)), + modifiers: ModifierGroupDefinition { + position: 0, + modifiers: vec![ModifierDefinition::Static(Keyword::new( + ByteString::from("static"), + 0, + ))], + }, function: Keyword::new(ByteString::from("function"), 0), parameters: FunctionLikeParameterListDefinition { comments: CommentGroup { comments: vec![] }, diff --git a/tests/samples/0111/tree.txt b/tests/samples/0111/tree.txt index c682818..917662c 100644 --- a/tests/samples/0111/tree.txt +++ b/tests/samples/0111/tree.txt @@ -2,10 +2,14 @@ DefinitionTree { definitions: [ Function( FunctionDefinition { + attributes: [], comments: CommentGroup { comments: [], }, - attributes: [], + modifiers: ModifierGroupDefinition { + position: 0, + modifiers: [], + }, function: Keyword { value: "function", position: 0, diff --git a/tests/samples/0112/tree.txt b/tests/samples/0112/tree.txt index dfaf090..8035fc5 100644 --- a/tests/samples/0112/tree.txt +++ b/tests/samples/0112/tree.txt @@ -2,10 +2,14 @@ DefinitionTree { definitions: [ Function( FunctionDefinition { + attributes: [], comments: CommentGroup { comments: [], }, - attributes: [], + modifiers: ModifierGroupDefinition { + position: 0, + modifiers: [], + }, function: Keyword { value: "function", position: 0, diff --git a/tests/samples/0113/tree.txt b/tests/samples/0113/tree.txt index f5b8098..0aa830c 100644 --- a/tests/samples/0113/tree.txt +++ b/tests/samples/0113/tree.txt @@ -2,10 +2,14 @@ DefinitionTree { definitions: [ Function( FunctionDefinition { + attributes: [], comments: CommentGroup { comments: [], }, - attributes: [], + modifiers: ModifierGroupDefinition { + position: 0, + modifiers: [], + }, function: Keyword { value: "function", position: 0, diff --git a/tests/samples/0114/tree.txt b/tests/samples/0114/tree.txt index f7eb29f..6eb403b 100644 --- a/tests/samples/0114/tree.txt +++ b/tests/samples/0114/tree.txt @@ -2,10 +2,14 @@ DefinitionTree { definitions: [ Function( FunctionDefinition { + attributes: [], comments: CommentGroup { comments: [], }, - attributes: [], + modifiers: ModifierGroupDefinition { + position: 0, + modifiers: [], + }, function: Keyword { value: "function", position: 0, diff --git a/tests/samples/0115/tree.txt b/tests/samples/0115/tree.txt index 171eafb..e1cd525 100644 --- a/tests/samples/0115/tree.txt +++ b/tests/samples/0115/tree.txt @@ -2,10 +2,14 @@ DefinitionTree { definitions: [ Function( FunctionDefinition { + attributes: [], comments: CommentGroup { comments: [], }, - attributes: [], + modifiers: ModifierGroupDefinition { + position: 0, + modifiers: [], + }, function: Keyword { value: "function", position: 0,