E529 Add parse support for the "structs" proposal (only non-shared) by JLHwung · Pull Request #17624 · babel/babel · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@JLHwung
Copy link
Contributor
@JLHwung JLHwung commented Nov 28, 2025
Q                       A
Fixed Issues? Parse & print the non-shared struct proposed in https://github.com/tc39/proposal-structs
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This PR adds support of the non-shared structs with the following AST design:

interface StructDeclaration <: Declaration {
  type: "StructDeclaration";
  id: Identifier | null;
  superClass: Expression | null;
  body: StructBody;
}
interface StructBody <: Node {
  type: "StructBody";
  body: [ ClassMethod | ClassPrivateMethod | ClassProperty | ClassPrivateProperty | StaticBlock ];
}

The member within the struct body is still class members. I have not yet decided whether we should leave it as-is or rename them from Class* to Struct*.

@JLHwung JLHwung added the PR: New Feature 🚀 A type of pull request used for our changelog categories label Nov 28, 2025
@babel-bot
Copy link
Collaborator
babel-bot commented Nov 28, 2025

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/60657

@pkg-pr-new
Copy link
pkg-pr-new bot commented Nov 28, 2025

Open in StackBlitz

commit: 7f6e64d

@JLHwung JLHwung force-pushed the parse-structs branch 2 times, most recently from 7ecda07 to 7f6e64d Compare December 1, 2025 21:46
@JLHwung JLHwung marked this pull request as ready for review December 2, 2025 13:51
@nicolo-ribaudo nicolo-ribaudo self-requested a review December 5, 2025 16:34
@@ -0,0 +1,4 @@
@f
struct S {}
Copy link
Member

Choose a reason for hiding this comment

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

Agree with disallowing this but allowing accessors

Copy link
Contributor Author
@JLHwung JLHwung Jan 24, 2026

Choose a reason for hiding this comment

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

Right, and the member decorators are not allowed as well.

IMO accessors are essentially syntax sugar serving for the purpose of decorating otherwise accessor pairs once. They can be decoupled from decorators so I see no reason to ban them in non-shared structs.

Copy link
Member
@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

Nice :)

@nicolo-ribaudo nicolo-ribaudo changed the title Parse structs Add parse support for the "structs" proposal (only non-shared) Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: New Feature 🚀 A type of pull request used for our changelog categories Spec: JavaScript Structs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0