Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move context dependency walk_expression into create_context_dependency #6963

Merged
merged 11 commits into from
Jul 16, 2024

Conversation

CPunisher
Copy link
Contributor

@CPunisher CPunisher commented Jun 27, 2024

Summary

fix #6874

The cause of the problem is the direct walking of import call expression, which led to a conflict between the replacement generated by this walk and the replacement handled by ConstPlugin.

Webpack handles the import call expression in three cases:
TemplateLiteral: walk the parts with odd indices, see https://github.com/webpack/webpack/blob/8241da7f1e75c5581ba535d127fa66aeb9eb2ac8/lib/dependencies/ContextDependencyHelpers.js#L151
Wrapped expr: process the inner expressions, see https://github.com/webpack/webpack/blob/8241da7f1e75c5581ba535d127fa66aeb9eb2ac8/lib/dependencies/ContextDependencyHelpers.js#L218
Other cases: directly walk the import call expression, see https://github.com/webpack/webpack/blob/8241da7f1e75c5581ba535d127fa66aeb9eb2ac8/lib/dependencies/ContextDependencyHelpers.js#L241

My solution is to use a visitor to traverse the expression and find the corresponding Expr for BasicEvaluatedExpressionVisitor based on span. A better solution might be to add a reference to the corresponding Expr for BasicEvaluatedExpressionVisitor like webpack does. I tried this but couldn't resolve the lifetime issues.

Checklist

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

@github-actions github-actions bot added the release: bug fix release: bug related release(mr only) label Jun 27, 2024
Copy link

netlify bot commented Jun 27, 2024

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit b27fb13
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/669614aaf9372f000899ab5d

h-a-n-a
h-a-n-a previously approved these changes Jun 28, 2024
Copy link
Collaborator

@h-a-n-a h-a-n-a left a comment

Choose a reason for hiding this comment

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

Thank you!

@h-a-n-a
Copy link
Collaborator

h-a-n-a commented Jun 28, 2024

Do you need a double check? @ahabhgk

@ahabhgk ahabhgk changed the title fix: align parser.walk_expression to webpack, which put into context_dependency_helper refactor: move context dependency walk_expression into create_context_dependency Jul 16, 2024
@github-actions github-actions bot removed the release: bug fix release: bug related release(mr only) label Jul 16, 2024
@ahabhgk ahabhgk merged commit 7a66fab into web-infra-dev:main Jul 16, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Evaluating context request with conditional expression
3 participants