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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optional-dependency #3050

Merged
merged 10 commits into from
May 9, 2023

Conversation

suxin2017
Copy link
Collaborator

@suxin2017 suxin2017 commented May 7, 2023

Related issue (if exists)

#3042

Summary

馃 Generated by Copilot at 0064be7

This pull request adds support for ignoring require calls inside try-catch blocks in the rspack_plugin_javascript crate. It also adds a new test case with fixture files to verify the functionality.

Walkthrough

馃 Generated by Copilot at 0064be7

  • Add a field in_try to DependencyScanner to track try statements (link)
  • Implement visit_try_stmt method to set and reset in_try field (link)
  • Modify visit_expr method to skip require calls inside try blocks (link)
  • Add a test fixture index.js with a require call inside a try-catch block (link)
  • Add a test fixture expected/main.js with the expected output of the plugin (link)
  • Add a test fixture test.config.json with the configuration for the plugin (link)

@changeset-bot
Copy link

changeset-bot bot commented May 7, 2023

鈿狅笍 No Changeset found

Latest commit: 3cea917

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@hyf0 hyf0 linked an issue May 7, 2023 that may be closed by this pull request
@suxin2017 suxin2017 marked this pull request as ready for review May 8, 2023 00:47
@suxin2017 suxin2017 marked this pull request as draft May 8, 2023 01:13
@suxin2017 suxin2017 marked this pull request as ready for review May 8, 2023 01:46
@hyf0 hyf0 self-assigned this May 8, 2023
@hyf0 hyf0 added this to the 0.1.11 - Patch milestone May 8, 2023
@hardfist hardfist added this pull request to the merge queue May 9, 2023
Merged via the queue into web-infra-dev:main with commit 884b7ca May 9, 2023
11 checks passed
node: &'ast swc_core::ecma::ast::TryStmt,
ast_path: &mut swc_core::ecma::visit::AstNodePath<'r>,
) {
self.in_try = true;
Copy link
Collaborator

@hyf0 hyf0 May 9, 2023

Choose a reason for hiding this comment

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

I currently could not come up with a problem case. But the code is kind of buggy.

It's better to store the old in_try value and then recover it for the nested try-catch block.

let old_in_try = self.in_try;
self.in_try = true
node.visit_children_with_path(self, ast_path);
self.in_try = old_in_try

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I currently could not come up with a problem case. But the code is kind of buggy.

It's better to store the old in_try value and then recover it for the nested try-catch block.

let old_in_try = self.in_try;
self.in_try = true
node.visit_children_with_path(self, ast_path);
self.in_try = old_in_try

Do I need to submit an mr Again?

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.

flag commonjs dependency in try block as optional
3 participants