Skip to content

Conversation

@CPunisher
Copy link
Contributor

Summary

This PR refactors the JavaScript parser to use a new Pattern enum instead of Cow<Pat> for representing AST patterns.

Key Changes:

  • Introduced Pattern<'ast> enum in estree.rs to wrap various SWC AST pattern types.
  • Replaced Cow<Pat> usage with Pattern<'ast> across JavascriptParser and its plugins.
  • Removed deprecated warp_ident_to_pat helper.
  • Updated walk_pattern, enter_pattern, and related methods to handle the new Pattern enum.

Rationale:

Using Pattern<'ast> allows us to work with references to the AST more directly, reducing the need for Cow and unnecessary cloning of Pat nodes, which should improve performance and simplify the code.

Related links

None.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings January 5, 2026 07:27
@netlify
Copy link

netlify bot commented Jan 5, 2026

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 817b70f
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/695b6d53e25a300008ae562f

@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: refactor labels Jan 5, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @CPunisher, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the JavaScript parser by introducing a dedicated Pattern enum. This change aims to improve performance and simplify the codebase by allowing the parser to work with direct references to the Abstract Syntax Tree (AST) patterns, thereby reducing the need for Cow (Clone-on-Write) and avoiding unnecessary cloning of Pat nodes.

Highlights

  • New Pattern Enum: Introduced a Pattern<'ast> enum in estree.rs to represent various SWC AST pattern types, providing a more direct way to work with AST references.
  • Cow Replacement: Replaced all instances of Cow<Pat> with the new Pattern<'ast> enum across the JavascriptParser and its associated plugins, simplifying type handling.
  • Deprecated Helper Removal: The warp_ident_to_pat helper function has been removed as it is no longer needed with the new Pattern enum, streamlining the codebase.
  • Parser Method Updates: walk_pattern, enter_pattern, and other related methods within the JavascriptParser have been updated to correctly handle the new Pattern enum, ensuring compatibility and proper AST traversal.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@CPunisher CPunisher changed the title refactor: use Pattern enum instead of Cow<Pat> in javascript parser refactor: use Pattern enum instead of Cow<Pat> in javascript parser Jan 5, 2026
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 refactors the JavaScript parser to replace Cow<Pat> with a new Pattern<'ast> enum for representing AST patterns. The refactoring aims to work with AST references more directly, reducing cloning and improving performance.

Key Changes:

  • Introduced Pattern<'ast> enum with variants for Identifier, ObjectPattern, ArrayPattern, RestElement, AssignmentPattern, and Expression
  • Removed Cow<Pat> usage and the deprecated warp_ident_to_pat helper function
  • Updated pattern walking and entering methods to use the new Pattern type with proper lifetime annotations

Reviewed changes

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

Show a summary per file
File Description
crates/rspack_plugin_javascript/src/visitors/dependency/parser/estree.rs Defines new Pattern<'ast> enum and From<&'ast Pat> implementation
crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk_pre.rs Removes Cow import and updates to use Pattern::from
crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs Removes warp_ident_to_pat, updates walk_pattern and related methods to use Pattern, replaces Cow::Borrowed/Cow::Owned with Pattern variants
crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs Updates enter_pattern signature and removes Pat import
crates/rspack_plugin_javascript/src/parser_plugin/import_parser_plugin.rs Updates to use Pattern instead of Cow<Pat> in scope parameters
crates/rspack_plugin_javascript/src/parser_plugin/amd/amd_require_dependencies_block_parser_plugin.rs Removes Cow import and converts to Pattern
crates/rspack_plugin_javascript/src/parser_plugin/amd/amd_define_dependency_parser_plugin.rs Updates to use Pattern and refactors get_ident_name to accept Pattern

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

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a great refactoring that replaces Cow<Pat> with a new Pattern enum, which should improve performance and code clarity by reducing cloning. The changes are well-executed and consistent across the codebase. I've found one potential issue regarding the handling of invalid AST patterns that could lead to a panic, and I've provided suggestions to improve robustness.

@CPunisher CPunisher changed the title refactor: use Pattern enum instead of Cow<Pat> in javascript parser refactor: use Pattern enum instead of Cow<Pat> in javascript parser Jan 5, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2026

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
react-10k 5.7 MB 0
react-1k 825.4 KB 0
react-5k 2.7 MB 0
ui-components 2.1 MB 0
rome 984.3 KB 0

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2026

📦 Binary Size-limit

Comparing 817b70f to chore: limit workers for loader parallel tests (#12620) by CPunisher

❌ Size increased by 5.50KB from 47.87MB to 47.87MB (⬆️0.01%)

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 5, 2026

CodSpeed Performance Report

Merging #12625 will not alter performance

Comparing 01-05-refactor/pattern-ref (817b70f) with main (cd97e3b)

Summary

✅ 16 untouched
⏩ 1 skipped1

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: refactor team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants