Skip to content

Arrow functions should not be transpiled to functions with this as the first argument #740

Description

@nawordar

Arrow functions don't have this binding by design. Despite that, the following:

let setWallpaper = (screenNumber: number) => {
    if (!beautiful.wallpaper) {
        return;
    }

    // If wallpaper is a function, call it with the screenNumber
    const wallpaper = typeof beautiful.wallpaper == "function"
        ? beautiful.wallpaper(screenNumber)
        : beautiful.wallpaper;

    gears.wallpaper.maximized(wallpaper, screenNumber, true);
};

is transpiled to:

local setWallpaper
setWallpaper = function(____, screenNumber)
    if not beautiful.wallpaper then
        return
    end
    local wallpaper = (type(beautiful.wallpaper) == "function") and beautiful.wallpaper(screenNumber) or beautiful.wallpaper
    gears.wallpaper.maximized(wallpaper, screenNumber, true)
end

I think that let setWallpaper = (screenNumber: number) => {... should transpile to:

local setWallpaper
setWallpaper = function(screenNumber)
    if not beautiful.wallpaper then
        return
    end
    local wallpaper = (type(beautiful.wallpaper) == "function") and beautiful.wallpaper(screenNumber) or beautiful.wallpaper
    gears.wallpaper.maximized(wallpaper, screenNumber, true)
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions