Skip to content

Commit

Permalink
fix: codegen linebreak for multiline methods
Browse files Browse the repository at this point in the history
Fixes #807
  • Loading branch information
hishamhm committed Oct 8, 2024
1 parent e179555 commit ebf7467
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
17 changes: 17 additions & 0 deletions spec/code_gen/linebreak_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,21 @@ describe("improved line break heuristics", function()
(t):meth1()
end
]]))
it("break line correctly in multiline method declarations (regression test for #807)", util.gen([[
local record Foo
end
function Foo:greet(
greeting:string)
print(greeting)
end
]], [[
local Foo = {}
function Foo:greet(
greeting)
print(greeting)
end
]]))
end)
4 changes: 3 additions & 1 deletion tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5478,7 +5478,9 @@ function tl.generate(ast, gen_target, opts)
table.remove(children[3], 1)
if children[3][1] == "," then
table.remove(children[3], 1)
table.remove(children[3], 1)
if children[3][1] == " " then
table.remove(children[3], 1)
end
end
end
add_child(out, children[3])
Expand Down
4 changes: 3 additions & 1 deletion tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -5478,7 +5478,9 @@ function tl.generate(ast: tl.Node, gen_target: GenTarget, opts?: GenerateOptions
table.remove(children[3], 1)
if children[3][1] == "," then
table.remove(children[3], 1)
table.remove(children[3], 1)
if children[3][1] == " " then
table.remove(children[3], 1)
end
end
end
add_child(out, children[3])
Expand Down

0 comments on commit ebf7467

Please sign in to comment.