Skip to content

Support rest pattern in destructuring#568

Merged
Perryvw merged 9 commits intoTypeScriptToLua:masterfrom
ark120202:destructuring-rest-patterns
Aug 18, 2019
Merged

Support rest pattern in destructuring#568
Perryvw merged 9 commits intoTypeScriptToLua:masterfrom
ark120202:destructuring-rest-patterns

Conversation

@ark120202
Copy link
Copy Markdown
Contributor

Resolves #545.

@tomblind
Copy link
Copy Markdown
Collaborator

One way ObjectRest could be improved is by passing a set-like object for usedProperties instead of an array that has to be manually searched:

const {a, b, ...rest} = {a: "A", b: "B", c: "C", d: "D"};
function __TS__ObjectRest(target, usedProperties)
    local result = {}
    for property in pairs(target) do
        if usedProperties[property] == nil then
            result[property] = target[property]
        end
    end
    return result
end

local ____ = {
    a = "A",
    b = "B",
    c = "C",
    d = "D",
}
a = ____.a
b = ____.b
rest = __TS__ObjectRest(____, {
    a = true,
    b = true,
    rest = true,
})

@ark120202 ark120202 force-pushed the destructuring-rest-patterns branch from 2059140 to f7d6497 Compare August 1, 2019 07:16
@ark120202 ark120202 marked this pull request as ready for review August 1, 2019 14:24
return ts.isObjectLiteralExpression(node) || ts.isArrayLiteralExpression(node);
}

export function isDestructuringAssignment(node: ts.Node): node is ts.DestructuringAssignment {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typescript has this one too, any reason we're not using that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about that? I couldn't find any functions that have a is ts.DestructuringAssignment type guard

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in the block with @internal annotation, so can't be used directly

@Perryvw Perryvw merged commit 2c271d7 into TypeScriptToLua:master Aug 18, 2019
@ark120202 ark120202 deleted the destructuring-rest-patterns branch November 26, 2019 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ellipsis destruction is not allowed

3 participants