fix(parser): do not skip parsing expression inside require.resolve#11133
Merged
fix(parser): do not skip parsing expression inside require.resolve#11133
Conversation
✅ Deploy Preview for rspack canceled.
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a parser bug where expressions inside require.resolve() calls were being skipped when requireResolve parsing was disabled. The fix ensures that expressions within require.resolve() are still parsed and transformed properly even when the require.resolve feature itself is disabled.
Key changes:
- Moved the
require.resolveconfiguration check to occur after expression parsing - Added test cases to verify expressions inside
require.resolve()are properly transformed - Updated existing test expectations to include the new transformation behavior
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
crates/rspack_plugin_javascript/src/parser_plugin/common_js_imports_parse_plugin.rs |
Moved the require_resolve configuration check from process_resolve method to the plugin hook to allow expression parsing |
packages/rspack-test-tools/tests/configCases/parsing/require-resolve/index.js |
Added test cases with path.resolve() expressions inside require.resolve() calls |
packages/rspack-test-tools/tests/configCases/parsing/require-resolve/test.js |
Added test expectations for the new transformation behavior |
packages/rspack-test-tools/tests/configCases/parsing/require-resolve/index.js
Show resolved
Hide resolved
c2d8154 to
2279fde
Compare
Contributor
📦 Binary Size-limit
🙈 Size remains the same at 48.97MB |
CodSpeed Performance ReportMerging #11133 will not alter performanceComparing Summary
|
JSerFeng
approved these changes
Jul 22, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
when i was migrating Rsdoctor from Modern Module to Rslib, i found the following code and its wrong output due to the skip of expression in
require.resolvesource:
output:
Related links
Checklist