Skip to content

Commit

Permalink
Merge pull request #2774 from onflow/bastian/fix-function-declaration…
Browse files Browse the repository at this point in the history
…-doc
  • Loading branch information
turbolent authored Sep 11, 2023
2 parents 75f6616 + a3ee92d commit eb7b365
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
10 changes: 4 additions & 6 deletions runtime/ast/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion runtime/ast/expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4591,7 +4591,8 @@ func TestFunctionExpression_Doc(t *testing.T) {
prettier.Text("()"),
},
},
prettier.Text(" {}"),
prettier.Text(" "),
prettier.Text("{}"),
}

assert.Equal(t, expected, expr.Doc())
Expand Down
6 changes: 4 additions & 2 deletions runtime/ast/function_declaration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ func TestFunctionDeclaration_Doc(t *testing.T) {
},
},
},
prettier.Text(" {}"),
prettier.Text(" "),
prettier.Text("{}"),
},
decl.Doc(),
)
Expand Down Expand Up @@ -828,7 +829,8 @@ func TestSpecialFunctionDeclaration_Doc(t *testing.T) {
},
},
},
prettier.Text(" {}"),
prettier.Text(" "),
prettier.Text("{}"),
},
decl.Doc(),
)
Expand Down
13 changes: 12 additions & 1 deletion runtime/ast/transaction_declaration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ func TestTransactionDeclaration_Doc(t *testing.T) {
},
},
},
FunctionBlock: &FunctionBlock{
Block: &Block{
Statements: []Statement{},
},
},
},
},
PreConditions: &Conditions{
Expand Down Expand Up @@ -251,7 +256,8 @@ func TestTransactionDeclaration_Doc(t *testing.T) {
},
},
},
prettier.Text(" {}"),
prettier.Text(" "),
prettier.Text("{}"),
},
},
prettier.HardLine{},
Expand Down Expand Up @@ -399,6 +405,11 @@ func TestTransactionDeclaration_String(t *testing.T) {
},
},
},
FunctionBlock: &FunctionBlock{
Block: &Block{
Statements: []Statement{},
},
},
},
},
PreConditions: &Conditions{
Expand Down

0 comments on commit eb7b365

Please sign in to comment.