diff --git a/spec/code_gen/linebreak_spec.lua b/spec/code_gen/linebreak_spec.lua index d4338ed3c..ed81fd58e 100644 --- a/spec/code_gen/linebreak_spec.lua +++ b/spec/code_gen/linebreak_spec.lua @@ -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) diff --git a/tl.lua b/tl.lua index 8b9cef708..748b34e05 100644 --- a/tl.lua +++ b/tl.lua @@ -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]) diff --git a/tl.tl b/tl.tl index d87ffe46d..0d33e085a 100644 --- a/tl.tl +++ b/tl.tl @@ -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])