seaofvoices / darklua

A command line tool that transforms Lua code
https://darklua.com/
MIT License
90 stars 12 forks source link

Fix bundling modules with early returns #143

Closed jeparlefrancais closed 12 months ago

jeparlefrancais commented 12 months ago

Bundling with modules that contains an early return causes a bug where the single file will also have the same early returns:

-- file A
do
    return "a"
end

return "b"
-- main
local A = require("A")

return { A = A }

So when bundling from main, darklua produces the incorrect code:

local __DARKLUA_BUNDLE_MODULES={}do do
    return "a"
end

__DARKLUA_BUNDLE_MODULES.a="b"
end

local A = __DARKLUA_BUNDLE_MODULES.a

return { A = A }