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

[Feature]: Rule.with support match LogicalCondition not #8267

Closed
9aoy opened this issue Oct 30, 2024 · 0 comments · Fixed by #8809
Closed

[Feature]: Rule.with support match LogicalCondition not #8267

9aoy opened this issue Oct 30, 2024 · 0 comments · Fixed by #8809
Labels
feat New feature or request team The issue/pr is created by the member of Rspack.

Comments

@9aoy
Copy link
Contributor

9aoy commented Oct 30, 2024

What problem does this feature solve?

I have the configuration and script as follows. I expect that the swc-loader rule will be matched when without import attributes, but it actually does not. Btw, it works as expected in webpack.

import testStr from "./test.tsx" with { type: "raw" }; // => expect match `asset/source` rule
import test from "./test.tsx"; // => expect match `swc-loader` rule, actually no
module: {
  rules: [
    {
      test: /\.(jsx?|tsx?)$/,
      with: {
        type: {
          not: "raw"
        }
      },
      use: [
        {
          loader: "builtin:swc-loader", 
         }
      ]
    },
    {
      with: { type: "raw" },
      type: "asset/source"
    }
  ]
}

What does the proposed API of configuration look like?

I think the problem is when attributes does not exist, it should return true if LogicalCondition not exists.

if let Some(with) = &module_rule.with {
if let Some(attributes) = attributes {
for (k, matcher) in with {
if let Some(v) = attributes.get(k) {
if !matcher.try_match(v.into()).await? {
return Ok(false);
}
} else {
return Ok(false);
}
}
} else {
return Ok(false);
}
}

Maybe we can refer to webpack's design and set a matchWhenEmpty flag for each condition.
https://github.com/webpack/webpack/blob/8b864dbe81bd73f0e7d101f7c9563bdedf00c392/lib/rules/RuleSetCompiler.js#L326

@9aoy 9aoy added feat New feature or request pending triage The issue/PR is currently untouched. labels Oct 30, 2024
@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Oct 30, 2024
@chenjiahan chenjiahan removed the pending triage The issue/PR is currently untouched. label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants