diff --git a/runtime/ast/expression.go b/runtime/ast/expression.go index aa3eeb1580..267c7ac989 100644 --- a/runtime/ast/expression.go +++ b/runtime/ast/expression.go @@ -1387,8 +1387,6 @@ func (e *FunctionExpression) String() string { var functionFunKeywordSpaceDoc prettier.Doc = prettier.Text("fun ") -var functionExpressionEmptyBlockDoc prettier.Doc = prettier.Text(" {}") - func FunctionDocument( access Access, isStatic bool, @@ -1482,17 +1480,17 @@ func FunctionDocument( ) } - if block.IsEmpty() { - return append(doc, functionExpressionEmptyBlockDoc) - } else { + if block != nil { blockDoc := block.Doc() - return append( + doc = append( doc, prettier.Space, blockDoc, ) } + + return doc } func (e *FunctionExpression) Doc() prettier.Doc { diff --git a/runtime/ast/expression_test.go b/runtime/ast/expression_test.go index 41b60691ac..65bf79d97d 100644 --- a/runtime/ast/expression_test.go +++ b/runtime/ast/expression_test.go @@ -4591,7 +4591,8 @@ func TestFunctionExpression_Doc(t *testing.T) { prettier.Text("()"), }, }, - prettier.Text(" {}"), + prettier.Text(" "), + prettier.Text("{}"), } assert.Equal(t, expected, expr.Doc()) diff --git a/runtime/ast/function_declaration_test.go b/runtime/ast/function_declaration_test.go index 81fd9bb623..efff16250f 100644 --- a/runtime/ast/function_declaration_test.go +++ b/runtime/ast/function_declaration_test.go @@ -364,7 +364,8 @@ func TestFunctionDeclaration_Doc(t *testing.T) { }, }, }, - prettier.Text(" {}"), + prettier.Text(" "), + prettier.Text("{}"), }, decl.Doc(), ) @@ -828,7 +829,8 @@ func TestSpecialFunctionDeclaration_Doc(t *testing.T) { }, }, }, - prettier.Text(" {}"), + prettier.Text(" "), + prettier.Text("{}"), }, decl.Doc(), ) diff --git a/runtime/ast/transaction_declaration_test.go b/runtime/ast/transaction_declaration_test.go index 8a323b25fd..e8b250e403 100644 --- a/runtime/ast/transaction_declaration_test.go +++ b/runtime/ast/transaction_declaration_test.go @@ -137,6 +137,11 @@ func TestTransactionDeclaration_Doc(t *testing.T) { }, }, }, + FunctionBlock: &FunctionBlock{ + Block: &Block{ + Statements: []Statement{}, + }, + }, }, }, PreConditions: &Conditions{ @@ -251,7 +256,8 @@ func TestTransactionDeclaration_Doc(t *testing.T) { }, }, }, - prettier.Text(" {}"), + prettier.Text(" "), + prettier.Text("{}"), }, }, prettier.HardLine{}, @@ -399,6 +405,11 @@ func TestTransactionDeclaration_String(t *testing.T) { }, }, }, + FunctionBlock: &FunctionBlock{ + Block: &Block{ + Statements: []Statement{}, + }, + }, }, }, PreConditions: &Conditions{