Skip to content

Binding Pattern Assignment Statements #574

@hazzard993

Description

@hazzard993

The AST for this a bit odd

[ObjectLiteralExpression] = [Expression] = Syntax error
([ObjectLiteralExpression] = [Expression]) = left is treated like an object binding pattern
[ArrayLiteralExpression] = [Expression] = left is treated like an array binding pattern
([ObjectLiteralExpression | ArrayLiteralExpression]) = [Expression] Syntax error

// assigns load() to love.load, update() to love.update and draw() to love.draw
({ load: love.load, update: love.update, draw: love.draw } = {

    load() {
        print("Load");
    },

    update(dt) {
        print("Update")
    },

    draw() {
        print("Draw");
    }

});

tsc output

var _a;
(_a = {
    load: function () {
        print("Load");
    },
    update: function (dt) {
        print("Update");
    },
    draw: function () {
        print("Draw");
    }
}, love.load = _a.load, love.update = _a.update, love.draw = _a.draw);

tstl output (v0.19.0)

--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
local ____ = ((function()
    { -- fails here
        load = love.load,
        update = love.update,
        draw = love.draw,
    } = {
        load = function(self)
            print("Load")
        end,
        update = function(self, dt)
            print("Update")
        end,
        draw = function(self)
            print("Draw")
        end,
    }
    return {
        load = love.load,
        update = love.update,
        draw = love.draw,
    }
end)())

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions