Skip to content

fix: compile-time evaluation of optional chaining#12494

Merged
LingyuCoder merged 2 commits intomainfrom
feat-optional-chaining-eval
Dec 18, 2025
Merged

fix: compile-time evaluation of optional chaining#12494
LingyuCoder merged 2 commits intomainfrom
feat-optional-chaining-eval

Conversation

@LingyuCoder
Copy link
Copy Markdown
Contributor

Summary

This PR enables compile-time evaluation and member expression analysis for import.meta and optional chaining expressions in the JavaScript parser. It generalizes the member expression utilities to work on Expr (including Expr::OptChain) and removes the optional-chaining test filter so that the config case now runs as part of the normal test suite.

Checklist

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

Copilot AI review requested due to automatic review settings December 18, 2025 04:09
@netlify
Copy link
Copy Markdown

netlify bot commented Dec 18, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 938c2f7
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/69437fc514a4e00008aedfb6

@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: feature release: feature related release(mr only) labels Dec 18, 2025
@LingyuCoder LingyuCoder changed the title feat: support compile-time evaluation of optional chaining fix: compile-time evaluation of optional chaining Dec 18, 2025
@github-actions github-actions bot added release: bug fix release: bug related release(mr only) and removed release: feature release: feature related release(mr only) labels Dec 18, 2025
Copy link
Copy Markdown
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 enables compile-time evaluation and member expression analysis for optional chaining expressions in the JavaScript parser. It refactors the member expression utilities to work with the Expr enum (which includes both Expr::Member and Expr::OptChain) rather than just MemberExpr directly, and removes the test filter that was blocking the optional chaining test case.

  • Generalizes get_member_expression_info and extract_member_expression_chain to accept Expr instead of &MemberExpr
  • Updates all call sites to wrap MemberExpr with Expr::Member() when calling these functions
  • Enables the previously disabled optional chaining test to verify compile-time evaluation works with DefinePlugin

Reviewed changes

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

Show a summary per file
File Description
tests/rspack-test/configCases/parsing/optional-chaining/test.filter.js Removes test filter to enable optional chaining test case
crates/rspack_plugin_javascript/src/visitors/dependency/parser/walk.rs Updates call sites to wrap MemberExpr with Expr::Member when calling get_member_expression_info
crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs Refactors member expression utilities to accept Expr instead of &MemberExpr, adds OptChain handling
crates/rspack_plugin_javascript/src/visitors/dependency/parser/call_hooks_name.rs Updates MemberExpr::call_hooks_name to wrap with Expr::Member
crates/rspack_plugin_javascript/src/utils/eval/eval_member_expr.rs Updates call site to wrap MemberExpr with Expr::Member
crates/rspack_plugin_javascript/src/parser_plugin/url_plugin.rs Updates call site to wrap MemberExpr with Expr::Member
crates/rspack_plugin_javascript/src/parser_plugin/import_meta_plugin.rs Updates call site to wrap MemberExpr with Expr::Member

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

…/mod.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 5 project(s) in monorepo.

📊 Quick Summary (Click to expand)
Project Total Size Change
react-10k 5.7 MB ➡️ 0 B (0.0%)
react-1k 823.4 KB ➡️ 0 B (0.0%)
react-5k 2.7 MB ➡️ 0 B (0.0%)
ui-components 2.1 MB ➡️ 0 B (0.0%)
rome 984.3 KB ➡️ 0 B (0.0%)
📋 Detailed Reports (Click to expand)

📁 react-10k

Path: ../build-tools-performance/cases/react-10k/dist/rsdoctor-data.json

📌 Baseline Commit: 5c119b1f5c | PR: #12489

Metric Current Baseline Change
📊 Total Size 5.7 MB 5.7 MB 0 B (0.0%)
📄 JavaScript 5.7 MB 5.7 MB 0 B (0.0%)
🎨 CSS 21.0 B 21.0 B 0 B (0.0%)
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: react-10k Bundle Diff

📁 react-1k

Path: ../build-tools-performance/cases/react-1k/dist/rsdoctor-data.json

📌 Baseline Commit: 5c119b1f5c | PR: #12489

Metric Current Baseline Change
📊 Total Size 823.4 KB 823.4 KB 0 B (0.0%)
📄 JavaScript 823.4 KB 823.4 KB 0 B (0.0%)
🎨 CSS 0 B 0 B N/A
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: react-1k Bundle Diff

📁 react-5k

Path: ../build-tools-performance/cases/react-5k/dist/rsdoctor-data.json

📌 Baseline Commit: 5c119b1f5c | PR: #12489

Metric Current Baseline Change
📊 Total Size 2.7 MB 2.7 MB 0 B (0.0%)
📄 JavaScript 2.7 MB 2.7 MB 0 B (0.0%)
🎨 CSS 21.0 B 21.0 B 0 B (0.0%)
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: react-5k Bundle Diff

📁 ui-components

Path: ../build-tools-performance/cases/ui-components/dist/rsdoctor-data.json

📌 Baseline Commit: 5c119b1f5c | PR: #12489

Metric Current Baseline Change
📊 Total Size 2.1 MB 2.1 MB 0 B (0.0%)
📄 JavaScript 2.0 MB 2.0 MB 0 B (0.0%)
🎨 CSS 83.0 KB 83.0 KB 0 B (0.0%)
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: ui-components Bundle Diff

📁 rome

Path: ../build-tools-performance/cases/rome/dist/rsdoctor-data.json

📌 Baseline Commit: 5c119b1f5c | PR: #12489

Metric Current Baseline Change
📊 Total Size 984.3 KB 984.3 KB 0 B (0.0%)
📄 JavaScript 984.3 KB 984.3 KB 0 B (0.0%)
🎨 CSS 0 B 0 B N/A
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: rome Bundle Diff

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing 938c2f7 to chore(ci): update windows zstd version (#12489) by pshu

❌ Size increased by 2.38KB from 48.26MB to 48.27MB (⬆️0.00%)

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Dec 18, 2025

CodSpeed Performance Report

Merging #12494 will not alter performance

Comparing feat-optional-chaining-eval (938c2f7) with main (5c119b1)

Summary

✅ 17 untouched

@LingyuCoder LingyuCoder requested a review from ahabhgk December 18, 2025 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants