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

hashbang, if exists and if wanted, stays on line 1 #730

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 12 additions & 0 deletions spec/cli/gen_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local util = require("spec.util")

local input_file = [[
#!/usr/bin/env lua
global type1 = 2

global type type_g = record
Expand Down Expand Up @@ -37,6 +38,7 @@ local c = 100
]]

local output_file = [[

type1 = 2

type_g = {}
Expand Down Expand Up @@ -195,6 +197,16 @@ describe("tl gen", function()
end)
end)

it("*equality test* to confirm preserves hashbang with --keep-hashbang", function()
local name = util.write_tmp_file(finally, script_with_hashbang)
local pd = io.popen(util.tl_cmd("gen", "--keep-hashbang", name), "r")
local output = pd:read("*a")
util.assert_popen_close(0, pd:close())
local lua_name = tl_to_lua(name)
assert.match("Wrote: " .. lua_name, output, 1, true)
assert.equal(script_with_hashbang, util.read_file(lua_name))
end)

it("preserves hashbang with --keep-hashbang", function()
local name = util.write_tmp_file(finally, script_with_hashbang)
local pd = io.popen(util.tl_cmd("gen", "--keep-hashbang", name), "r")
Expand Down
5 changes: 4 additions & 1 deletion tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4356,7 +4356,10 @@ function tl.pretty_print_ast(ast, gen_target, mode)
end

local code
if opts.preserve_newlines then
if opts.preserve_hashbang and opts.preserve_newlines then
code = { y = out.y, h = 0 }
add_child(code, out)
elseif opts.preserve_newlines then
code = { y = 1, h = 0 }
add_child(code, out)
else
Expand Down
5 changes: 4 additions & 1 deletion tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -4356,7 +4356,10 @@ function tl.pretty_print_ast(ast: Node, gen_target: TargetMode, mode: boolean |
end

local code: Output
if opts.preserve_newlines then
if opts.preserve_hashbang and opts.preserve_newlines then
code = { y = out.y, h = 0}
add_child(code, out)
elseif opts.preserve_newlines then
code = { y = 1, h = 0 }
add_child(code, out)
else
Expand Down
Loading