Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Currently no way to define structs? #37

Open
waldemarhorwat opened this issue Oct 7, 2024 · 7 comments
Open

Currently no way to define structs? #37

waldemarhorwat opened this issue Oct 7, 2024 · 7 comments

Comments

@waldemarhorwat
Copy link

The proposed spec does not currently provide any way to define structs or struct expressions — there's nothing I can find that references those productions from elsewhere in the grammar other than export.

I'm curious how syntactic collisions will be resolved once such expressions are defined.

@syg
Copy link
Collaborator

syg commented Oct 7, 2024

Oops, good catch on the omission. I was intending to add StructDeclaration as another production inside Declaration. Is struct [no new line terminator] insufficient to resolve the collisions?

Edit: and also StructExpression added as another production inside PrimaryExpression.

Also cc @rbuckton who works with the spec grammar much more than I do.

@waldemarhorwat
Copy link
Author

You'll also have to resolve collisions between struct declarations and expressions.

@rbuckton
Copy link
Collaborator

rbuckton commented Oct 7, 2024

For shared structs at least, there is no expression version as they must be top level declarations. I can't recall if we wanted to enforce that rule for non-shared structs as well, however.

@waldemarhorwat
Copy link
Author

So you'd just drop the expression versions?

That would take care of the declaration-vs-expression conflict, as well as some other conflicts such as a struct expression whose name happens to be of.

@syg
Copy link
Collaborator

syg commented Oct 7, 2024

The expressions were added to the spec text more because I was copying class expression stuff from the main spec as a starting point than anything else. I think the utility of struct expressions is pretty low, so I've opened #38.

@acutmore
Copy link

acutmore commented Oct 8, 2024

I think the utility of struct expressions is pretty low

Was just chatting with @jridgewell who mentioned AMP (? if memory correct) has a transform to convert class declarations into class expressions to avoid TDZ checks.

Do structs follow suite, or maybe a chance to avoid TDZ checks?

@syg
Copy link
Collaborator

syg commented Oct 9, 2024

has a transform to convert class declarations into class expressions to avoid TDZ checks.

Interesting. I guess we'd have to weigh that against the grammar complexities for supporting expressions and declarations at the same time.

The correlation problem strongly favors restricting shared struct declarations to top-level only, which also implies no expressions.

As much as I hate TDZ it seems like a smaller issue here.

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

No branches or pull requests

4 participants