Skip to content

Local Table Destructuring#223

Open
xHeptc wants to merge 5 commits into
luau-lang:masterfrom
xHeptc:master
Open

Local Table Destructuring#223
xHeptc wants to merge 5 commits into
luau-lang:masterfrom
xHeptc:master

Conversation

@xHeptc

@xHeptc xHeptc commented Jul 11, 2026

Copy link
Copy Markdown

rendered

Note: I am fully aware of RFC 'Granural Imports', 'Table Destructing Syntax' proposals made by other people.
My RFC proposes simpler syntax, doesn't require new keywords, and is not limited to top-level scope with the usage of require().

@jackhexed

Copy link
Copy Markdown
Contributor

const { foo } is valid syntax today, and while it is possible to parse, its really annoying.

@xHeptc

xHeptc commented Jul 11, 2026

Copy link
Copy Markdown
Author

const { foo } is valid syntax today, and while it is possible to parse, its really annoying.

Is this syntax reserved for future?

@deviaze

deviaze commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Could you put some simpler examples for clarity, and include notes on how this works with array-likes, classes, and extern types on the RHS?

@jackhexed

Copy link
Copy Markdown
Contributor

const { foo } is valid syntax today, and while it is possible to parse, its really annoying.

Is this syntax reserved for future?

No, its a function call.

@deviaze

deviaze commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

const { foo } is valid syntax today, and while it is possible to parse, its really annoying.

Is this syntax reserved for future?

This is already valid syntax for a table call on a function named const

const const = function(t: { s: string })
    print(t.s)
    -- do smth with t
end

const { s = "meow" } -- this is a function call

edit: jack hit post first and don't trust the syntax highlighter (it's wrong)

@xHeptc

xHeptc commented Jul 13, 2026

Copy link
Copy Markdown
Author

const { foo } is valid syntax today, and while it is possible to parse, its really annoying.

Is this syntax reserved for future?

This is already valid syntax for a table call on a function named const

const const = function(t: { s: string })
    print(t.s)
    -- do smth with t
end

const { s = "meow" } -- this is a function call

edit: jack hit post first and don't trust the syntax highlighter (it's wrong)

What about a special character indicating destructuring?

local @{ print, warn } = log
const @{ print, warn } = log

or, if this is not optimal, restricting this destructuring syntax to local declarations (exclude constants)

@Bottersnike

Copy link
Copy Markdown

Optimal way to distinguish destructuring syntax from function call now is to peek after } token and look for = token.

This isn't possible as outlined, at least not trivially. We could consider const {foo=bar} is the simplest case where looking for a = token has failed us. Parsing decisions would need to be made then later decide what it was that was actually parsed.

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.

4 participants