Skip to content

Conversation

@CPunisher
Copy link
Member

Description:

There's no ParenExpr ast type in estree spec: https://github.com/estree/estree/blob/master/es5.md

This PR is a simple and useful implementation to eliminate the usage of paren_remover.

@CPunisher CPunisher requested a review from a team as a code owner December 9, 2025 09:19
Copilot AI review requested due to automatic review settings December 9, 2025 09:19
@CPunisher CPunisher changed the title feat(es/parser): support no_paren syntax option feat(es/parser): support no_paren parser option Dec 9, 2025
@changeset-bot
Copy link

changeset-bot bot commented Dec 9, 2025

🦋 Changeset detected

Latest commit: 4b3aa19

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a no_paren syntax option to the SWC ECMAScript parser that allows eliminating ParenExpr AST nodes during parsing, aligning with the ESTree specification which doesn't include a ParenthesizedExpression type.

Key Changes:

  • Added no_paren boolean field to both EsSyntax and TsSyntax structs with corresponding serialization support
  • Introduced NO_PAREN flag to SyntaxFlags bitflags and implemented a helper method to check the flag
  • Modified the parenthesized expression parser to return the inner expression directly when no_paren is enabled, bypassing ParenExpr wrapping

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
crates/swc_ecma_parser/src/syntax.rs Adds no_paren configuration field to both ES and TS syntax structs, implements flag conversion, and adds a helper method
crates/swc_ecma_parser/src/parser/expr.rs Implements the core logic to unwrap parenthesized expressions when the no_paren option is enabled
crates/swc_ecma_transforms_base/src/fixer.rs Adds documentation pointing to the new no_paren option as an alternative to paren_remover

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

Binary Sizes

File Size
swc.linux-x64-gnu.node 31M (31811400 bytes)

Commit: 1ffd713

Copilot AI review requested due to automatic review settings December 9, 2025 09:29
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 9, 2025

CodSpeed Performance Report

Merging #11359 will not alter performance

Comparing CPunisher:12-09-feat/parser-no-paren (4b3aa19) with main (25f3a47)

Summary

✅ 138 untouched

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

kdy1
kdy1 previously approved these changes Dec 9, 2025
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

I have some concerns regarding comments, but I think it can be resolved in the follow-up PR for actually using this feature.

@kdy1 kdy1 added this to the Planned milestone Dec 9, 2025
Copilot AI review requested due to automatic review settings December 9, 2025 11:11
@kdy1 kdy1 requested a review from a team as a code owner December 9, 2025 11:11
@kdy1 kdy1 merged commit 5b9d77c into swc-project:main Dec 9, 2025
27 of 46 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2420 to +2421
if self.syntax().no_paren() {
return Ok(expr);
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

No tests have been added to verify the no_paren option works correctly. Consider adding tests that:

  1. Parse code with no_paren: true and verify ParenExpr nodes are not created
  2. Parse code with no_paren: false and verify ParenExpr nodes are created
  3. Test both single expressions (a) and sequence expressions (a, b) with the option enabled

Example test locations:

  • crates/swc_ecma_parser/src/parser/tests.rs for unit tests
  • crates/swc_ecma_parser/tests/js.rs or similar for integration tests

Copilot uses AI. Check for mistakes.
CPunisher added a commit to CPunisher/swc that referenced this pull request Dec 11, 2025
kdy1 pushed a commit that referenced this pull request Dec 11, 2025
**Description:**

This is introduced in #11359. But
I find some problems that are not easy to fix. So I revert it for now.
@kdy1 kdy1 modified the milestones: Planned, 1.15.4 Dec 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants