Skip to content

fix(rstest): dedicated to hoist @rstest/core declaration#12302

Merged
fi3ework merged 1 commit intomainfrom
hoist
Dec 2, 2025
Merged

fix(rstest): dedicated to hoist @rstest/core declaration#12302
fi3ework merged 1 commit intomainfrom
hoist

Conversation

@fi3ework
Copy link
Copy Markdown
Member

@fi3ework fi3ework commented Nov 26, 2025

Summary

this PR mainly did two features:

  1. rs.hoisted, will be hoisting to the top of the module. if there's a statement declaration, it will be hoisted alongside.
// source
rs.hoisted(()=> {})
const a = rs.hoisted(()=> {})

// output
__webapack_require__.rstest_hoisted(()=> {}) // top of the module
const a = __webapack_require__.rstest_hoisted(()=> {}) // top of the module
  1. dedicated hoisting @rstest/core to the top of the module, this is for the common use with rs.hoisted.
    the implementation is to find the @rstest/core ESM import init fragment. then, copy the content and insert the fragment with the same key at the beginning of the init fragments (-1 position), using the key deduplication principle of init fragments. this way, the init fragment corresponding to the @rstest/core ESM dependency will be placed before rs.hoisted (0 position).

it might be a bit hacky to find the target init fragment by key (although the key is consistent).

Related links

Checklist

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

@netlify
Copy link
Copy Markdown

netlify bot commented Nov 26, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 796d36a
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/692e810fd5434a000856c977

@github-actions github-actions bot added release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack. labels Nov 26, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Nov 26, 2025

📦 Binary Size-limit

Comparing 796d36a to fix(diagnostic): dim gutter style for better visual hierarchy (#12341) by neverland

❌ Size increased by 4.25KB from 47.70MB to 47.70MB (⬆️0.01%)

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Nov 26, 2025

CodSpeed Performance Report

Merging #12302 will not alter performance

Comparing hoist (796d36a) with main (9723c1b)

Summary

✅ 17 untouched

@fi3ework fi3ework marked this pull request as ready for review November 27, 2025 07:39
Copilot AI review requested due to automatic review settings November 27, 2025 07:39
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 implements two key features for rstest plugin hoisting: 1) rs.hoisted() method that hoists code to the top of the module along with its statement declaration if present, and 2) dedicated hoisting of @rstest/core imports to ensure they appear before hoisted code that depends on them.

  • Adds statement_span tracking to distinguish between standalone calls and variable declaration hoisting
  • Implements @rstest/core import hoisting by inserting a higher-priority fragment with the same key
  • Updates parser plugin to pass statement context through method call chain

Reviewed changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/rspack-test/configCases/rstest/mock/rspack.config.js Adds rstest_hoisted runtime function and test configuration for hoisted functionality
tests/rspack-test/configCases/rstest/mock/node_modules/@rstest/core/package.json Creates mock @rstest/core package for testing
tests/rspack-test/configCases/rstest/mock/node_modules/@rstest/core/index.js Implements mock @rstest/core module with rs.hoisted() and rs.fn() methods
tests/rspack-test/configCases/rstest/mock/hoisted.js Adds test case for rs.hoisted() with variable declaration and rs.fn() usage
crates/rspack_plugin_rstest/src/plugin.rs Updates regex pattern to recognize HOISTED markers
crates/rspack_plugin_rstest/src/parser_plugin.rs Adds statement_span parameter to hoisted() and handle_rstest_method_call() methods for statement-level hoisting
crates/rspack_plugin_rstest/src/mock_method_dependency.rs Implements statement-level hoisting, @rstest/core import hoisting, and refactors code generation into helper methods
crates/rspack_core/src/init_fragment.rs Adds content() getter method to ConditionalInitFragment

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 2, 2025

Rsdoctor Bundle Diff Analysis

Found 5 project(s) in monorepo.

📁 react-1k

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

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 822.6 KB - -
📄 JavaScript 822.6 KB - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 react-10k

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

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 5.7 MB - -
📄 JavaScript 5.7 MB - -
🎨 CSS 21.0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 react-5k

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

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 2.7 MB - -
📄 JavaScript 2.7 MB - -
🎨 CSS 21.0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 rome

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

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 984.3 KB - -
📄 JavaScript 984.3 KB - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 ui-components

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

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 2.1 MB - -
📄 JavaScript 2.0 MB - -
🎨 CSS 83.0 KB - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

Generated by Rsdoctor GitHub Action

@fi3ework fi3ework merged commit cc79127 into main Dec 2, 2025
52 checks passed
@fi3ework fi3ework deleted the hoist branch December 2, 2025 07:06
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