Skip to content

luaLibImport = inline produce multiple returns in output #186

Description

@gakada
const f = (xs: number[]) => xs.map(i => i + 1).push(42)

gives

-- Lua Library Imports
local exports = exports or {}
local function __TS__ArrayMap(arr,callbackfn)
    local newArray = {}

    local i = 0
    while(i<#arr) do
        do
            newArray[i+1] = callbackfn(arr[i+1],i,arr)
        end
        i = (i+1)
    end
    return newArray
end
return exports

local exports = exports or {}
local function __TS__ArrayPush(arr,...)
    local items = { ... }
    for _, item in ipairs(items) do
        do
            arr[#arr+1] = item
        end
    end
    return #arr
end
return exports

local exports = exports or {}
local f = function(xs) return __TS__ArrayPush(__TS__ArrayMap(xs, function(i) return i+1 end), 42) end

return exports

that is, with 3 returns. My config is

{
  "compilerOptions": {
    "esModuleInterop": false,
    "jsx": "react",
    "jsxFactory": "h",
    "lib": ["es6"],
    "module": "commonjs",
    "moduleResolution": "node",
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "outDir": "dist",
    "removeComments": true,
    "strict": true,
    "target": "es2017"
  },
  "include": ["example", "lib", "src", "test"],
  "luaTarget": "5.1",
  "luaLibImport": "inline"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions