Skip to content

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Mar 5, 2025

Q                       A
Fixed Issues? Support Discard Binding Proposal in @babel/parser and @babel/generator
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

The AST design is aligned to the current ESTree proposal: https://github.com/estree/estree/blob/master/experimental/discard-binding.md

This PR will be merged to the umbrella branch feat-discard-binding.

@JLHwung JLHwung added PR: New Feature 🚀 A type of pull request used for our changelog categories Spec: Discard Binding labels Mar 5, 2025
@babel-bot
Copy link
Collaborator

babel-bot commented Mar 5, 2025

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

}
{
// using declarator in for-of
for(using void of []);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although the parser currently accepts this production, it is not allowed in the draft spec. I have filed an issue tc39/proposal-discard-binding#14

Copy link
Member

Choose a reason for hiding this comment

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

Yeah this seems like a spec bug.

@JLHwung JLHwung force-pushed the parse-discard-binding branch from 08d4b6c to f2dd864 Compare March 6, 2025 20:32
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.

I believe multiple delegates are still unhappy with the idea of using void. Could we maybe add a required syntax: "void" option to the parser plugin?

@JLHwung
Copy link
Contributor Author

JLHwung commented Mar 7, 2025

Could we maybe add a required syntax: "void" option to the parser plugin?

Sure, I will add a syntaxType option since we already have one for the record and tuple transform.

I believe multiple delegates are still unhappy with the idea of using void.

Out of curiosity, do you know if there are other type candidates? If void will not be likely adopted, then we should consider rename VoidPattern to DiscardPattern so that it is not tied to the void token.

@JLHwung JLHwung force-pushed the parse-discard-binding branch from 4aaac4a to a4d2855 Compare March 7, 2025 15:28
@nicolo-ribaudo
Copy link
Member

Out of curiosity, do you know if there are other type candidates? If void will not be likely adopted, then we should consider rename VoidPattern to DiscardPattern so that it is not tied to the void token.

The other possible approach is to relax the existing "duplicated declaration" errors in case where something is declared twice but not read, so that { let _ = 1; let _ = 2; } would be valid. I think the current AST is fine, as in that case we would just use an Identifier node.

@JLHwung JLHwung force-pushed the parse-discard-binding branch from d2c943a to a068f39 Compare March 7, 2025 16:38
@JLHwung JLHwung force-pushed the parse-discard-binding branch 2 times, most recently from 21e672b to 7675a3c Compare March 24, 2025 22:32
@JLHwung JLHwung force-pushed the parse-discard-binding branch from 7675a3c to 1a4fc60 Compare April 16, 2025 18:15
@JLHwung
Copy link
Contributor Author

JLHwung commented Apr 16, 2025

Rebased. Now that #17217 has been merged, the last two validation harden commits are now replaced by 1a4fc60.

@JLHwung JLHwung requested a review from nicolo-ribaudo April 16, 2025 18:22
@nicolo-ribaudo
Copy link
Member

@liuxingbaoyu Do you think you could review this in the next few days? It would be great to include it as merged in the STA report for April :)

@liuxingbaoyu
Copy link
Member

Of course! I will finish it soon. :)

@nicolo-ribaudo
Copy link
Member

(actually, I realized this will wait anyway because it's a new feature, but reviewing it will still unlock work on the transform!)

JLHwung and others added 2 commits April 27, 2025 22:14
Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>
@JLHwung JLHwung force-pushed the parse-discard-binding branch from ee42611 to 137501b Compare April 28, 2025 18:22
@nicolo-ribaudo
Copy link
Member

@JLHwung As this PR is ready, let's merge it to the feat-discard-binding branch so that you can open the transform PR on top of it?

@JLHwung JLHwung merged commit e8a66ca into babel:feat-discard-binding Apr 30, 2025
55 checks passed
@JLHwung JLHwung deleted the parse-discard-binding branch April 30, 2025 12:07
@JLHwung JLHwung mentioned this pull request Apr 30, 2025
2 tasks
JLHwung added a commit that referenced this pull request Apr 30, 2025
* add VoidPattern definition

* update types artifacts

* parse void binding

* print void binding

* fix typing errors

* update parser typings

* fix: remove VoidPattern from ForXStatement.left

* fix typing errors

* add Babel 8 tests

* require syntaxType option

* add test for object-rest-spread change

* feat(types): disallow void pattern in var/let/const declaration

* fix: allow nested void pattern in catch param

* improve UnexpectedVoidPattern error message

* remove R&T integration parser tests

* polish: throw different error when CoverDiscardElement is parsed

* Update expression.ts

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>

* update discardBinding plugin option types

---------

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>
JLHwung added a commit to JLHwung/babel that referenced this pull request May 2, 2025
* add VoidPattern definition

* update types artifacts

* parse void binding

* print void binding

* fix typing errors

* update parser typings

* fix: remove VoidPattern from ForXStatement.left

* fix typing errors

* add Babel 8 tests

* require syntaxType option

* add test for object-rest-spread change

* feat(types): disallow void pattern in var/let/const declaration

* fix: allow nested void pattern in catch param

* improve UnexpectedVoidPattern error message

* remove R&T integration parser tests

* polish: throw different error when CoverDiscardElement is parsed

* Update expression.ts

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>

* update discardBinding plugin option types

---------

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>
JLHwung added a commit to JLHwung/babel that referenced this pull request May 5, 2025
* add VoidPattern definition

* update types artifacts

* parse void binding

* print void binding

* fix typing errors

* update parser typings

* fix: remove VoidPattern from ForXStatement.left

* fix typing errors

* add Babel 8 tests

* require syntaxType option

* add test for object-rest-spread change

* feat(types): disallow void pattern in var/let/const declaration

* fix: allow nested void pattern in catch param

* improve UnexpectedVoidPattern error message

* remove R&T integration parser tests

* polish: throw different error when CoverDiscardElement is parsed

* Update expression.ts

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>

* update discardBinding plugin option types

---------

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>
JLHwung added a commit that referenced this pull request May 5, 2025
* add VoidPattern definition

* update types artifacts

* parse void binding

* print void binding

* fix typing errors

* update parser typings

* fix: remove VoidPattern from ForXStatement.left

* fix typing errors

* add Babel 8 tests

* require syntaxType option

* add test for object-rest-spread change

* feat(types): disallow void pattern in var/let/const declaration

* fix: allow nested void pattern in catch param

* improve UnexpectedVoidPattern error message

* remove R&T integration parser tests

* polish: throw different error when CoverDiscardElement is parsed

* Update expression.ts

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>

* update discardBinding plugin option types

---------

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>
JLHwung added a commit that referenced this pull request May 7, 2025
* add VoidPattern definition

* update types artifacts

* parse void binding

* print void binding

* fix typing errors

* update parser typings

* fix: remove VoidPattern from ForXStatement.left

* fix typing errors

* add Babel 8 tests

* require syntaxType option

* add test for object-rest-spread change

* feat(types): disallow void pattern in var/let/const declaration

* fix: allow nested void pattern in catch param

* improve UnexpectedVoidPattern error message

* remove R&T integration parser tests

* polish: throw different error when CoverDiscardElement is parsed

* Update expression.ts

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>

* update discardBinding plugin option types

---------

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>
JLHwung added a commit that referenced this pull request May 9, 2025
* add VoidPattern definition

* update types artifacts

* parse void binding

* print void binding

* fix typing errors

* update parser typings

* fix: remove VoidPattern from ForXStatement.left

* fix typing errors

* add Babel 8 tests

* require syntaxType option

* add test for object-rest-spread change

* feat(types): disallow void pattern in var/let/const declaration

* fix: allow nested void pattern in catch param

* improve UnexpectedVoidPattern error message

* remove R&T integration parser tests

* polish: throw different error when CoverDiscardElement is parsed

* Update expression.ts

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>

* update discardBinding plugin option types

---------

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>
JLHwung added a commit that referenced this pull request May 26, 2025
* add VoidPattern definition

* update types artifacts

* parse void binding

* print void binding

* fix typing errors

* update parser typings

* fix: remove VoidPattern from ForXStatement.left

* fix typing errors

* add Babel 8 tests

* require syntaxType option

* add test for object-rest-spread change

* feat(types): disallow void pattern in var/let/const declaration

* fix: allow nested void pattern in catch param

* improve UnexpectedVoidPattern error message

* remove R&T integration parser tests

* polish: throw different error when CoverDiscardElement is parsed

* Update expression.ts

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>

* update discardBinding plugin option types

---------

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>
JLHwung added a commit that referenced this pull request Jun 16, 2025
* add VoidPattern definition

* update types artifacts

* parse void binding

* print void binding

* fix typing errors

* update parser typings

* fix: remove VoidPattern from ForXStatement.left

* fix typing errors

* add Babel 8 tests

* require syntaxType option

* add test for object-rest-spread change

* feat(types): disallow void pattern in var/let/const declaration

* fix: allow nested void pattern in catch param

* improve UnexpectedVoidPattern error message

* remove R&T integration parser tests

* polish: throw different error when CoverDiscardElement is parsed

* Update expression.ts

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>

* update discardBinding plugin option types

---------

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>
JLHwung added a commit that referenced this pull request Jun 23, 2025
* add VoidPattern definition

* update types artifacts

* parse void binding

* print void binding

* fix typing errors

* update parser typings

* fix: remove VoidPattern from ForXStatement.left

* fix typing errors

* add Babel 8 tests

* require syntaxType option

* add test for object-rest-spread change

* feat(types): disallow void pattern in var/let/const declaration

* fix: allow nested void pattern in catch param

* improve UnexpectedVoidPattern error message

* remove R&T integration parser tests

* polish: throw different error when CoverDiscardElement is parsed

* Update expression.ts

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>

* update discardBinding plugin option types

---------

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>
JLHwung added a commit that referenced this pull request Jun 27, 2025
* add VoidPattern definition

* update types artifacts

* parse void binding

* print void binding

* fix typing errors

* update parser typings

* fix: remove VoidPattern from ForXStatement.left

* fix typing errors

* add Babel 8 tests

* require syntaxType option

* add test for object-rest-spread change

* feat(types): disallow void pattern in var/let/const declaration

* fix: allow nested void pattern in catch param

* improve UnexpectedVoidPattern error message

* remove R&T integration parser tests

* polish: throw different error when CoverDiscardElement is parsed

* Update expression.ts

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>

* update discardBinding plugin option types

---------

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>
nicolo-ribaudo pushed a commit that referenced this pull request Jun 28, 2025
* add VoidPattern definition

* update types artifacts

* parse void binding

* print void binding

* fix typing errors

* update parser typings

* fix: remove VoidPattern from ForXStatement.left

* fix typing errors

* add Babel 8 tests

* require syntaxType option

* add test for object-rest-spread change

* feat(types): disallow void pattern in var/let/const declaration

* fix: allow nested void pattern in catch param

* improve UnexpectedVoidPattern error message

* remove R&T integration parser tests

* polish: throw different error when CoverDiscardElement is parsed

* Update expression.ts

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>

* update discardBinding plugin option types

---------

Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com>
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jul 31, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: New Feature 🚀 A type of pull request used for our changelog categories Spec: Discard Binding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants