Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doc (pretty printing) for function declaration without function block #2774

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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