Skip to content

fix(vite): reset stateful regex cursors in compile filters - #19541

Merged
Single-Dancer merged 1 commit into
NervJS:mainfrom
Jarvis636431:fix/vite-stateful-regexp-filter
Oct 20, 2026
Merged

Single-Dancer merged 1 commit into
NervJS:mainfrom
Jarvis636431:fix/vite-stateful-regexp-filter

Conversation

@Jarvis636431

@Jarvis636431 Jarvis636431 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

这个 PR 做了什么?

Reset RegExp lastIndex before matching Vite compile include/exclude rules. A global or sticky regex previously retained its cursor, so matching the same path repeatedly could alternate between included and excluded.

Adds tests for global/sticky matchers, existing cursors, exclusion precedence, compile options, string globs and Windows paths. The change is limited to resetting RegExp matchers before each test.

这个 PR 是什么类型?

  • 错误修复 (Bugfix)

这个 PR 涉及以下平台:

  • 所有平台(Vite 构建)

验证

  • Vite runner test:ci: 2 suites / 13 tests passed.
  • ESLint for changed files: passed.
  • Vite runner build: passed with Node 20.19.4 / pnpm 10.0.0.
  • Original implementation fails 7 regression cases.

Closes #19540

Summary by CodeRabbit

  • Bug 修复
    • 修复过滤器在重复检查带状态标志的正则表达式时结果不一致的问题。
    • 确保排除规则优先级、路径匹配及空值输入等场景下的过滤结果符合预期。

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1d9d23e0-cd6d-4443-869f-832fee53aa35
📥 Commits

Reviewing files that changed from the base of the PR and between aabb3e4 and 730da9e.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6d9a88b2-8386-4d7d-888b-c98149c158a5
📥 Commits

Reviewing files that changed from the base of the PR and between 53b9d3f and aabb3e4.

📒 Files selected for processing: 2
  • packages/taro-vite-runner/src/utils/createFilter.ts
  • packages/taro-vite-runner/tests/utils/createFilter.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Walkthrough

过滤器现在会在测试排除和包含正则匹配器前重置 lastIndex。新增测试覆盖全局和粘滞正则的重复匹配,以及 glob、路径规范化和 null 输入。

Changes

过滤器正则状态

Layer / File(s) Summary
重置正则游标并验证过滤结果
packages/taro-vite-runner/src/utils/createFilter.ts, packages/taro-vite-runner/tests/utils/createFilter.spec.ts
过滤器在测试正则匹配器前将 lastIndex 设为 0。新增测试覆盖重复匹配、已有游标、排除规则优先级、glob、Windows 路径规范化及 null 输入。

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to aabb3

No merge-blocking issue is identified; the change is ready for normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题准确概括了主要变更:在 Vite 编译过滤器中重置有状态正则表达式的游标。标题简洁、明确,并与代码和测试变更一致。
Linked Issues check Passed PR 满足直接关联 issue #19540 的编码要求。createFilter 在每次执行排除和包含 RegExp.test 前将 lastIndex 设为 0。因此全局和 sticky 正则不会继承前一次匹配的游标。改动保留排除优先级、字符串 glob 和路径规范化行为。新增测试覆盖 g、y、gy 正则、已有游标、`createFilterWithCompileO…
Out of Scope Changes check Passed 改动与 issue #19540 直接相关。源代码只修改 compile filter 的正则匹配状态。新增测试只验证该修复及 issue 要求的既有行为。未发现无关的功能、接口或文件变更。
Full details: Linked Issues check

Explanation

PR 满足直接关联 issue #19540 的编码要求。createFilter 在每次执行排除和包含 RegExp.test 前将 lastIndex 设为 0。因此全局和 sticky 正则不会继承前一次匹配的游标。改动保留排除优先级、字符串 glob 和路径规范化行为。新增测试覆盖 g、y、gy 正则、已有游标、createFilterWithCompileOptions、排除规则、glob、Windows 路径和无效输入。

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

兔子检查正则游标,
每次匹配都从零起跑。
全局粘滞不再交替,
包含排除各有准则。
测试轻敲胡萝卜鼓,
路径稳稳跳过月桥。

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.82%. Comparing base (eb54af4) to head (730da9e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #19541      +/-   ##
==========================================
+ Coverage   54.26%   55.82%   +1.55%     
==========================================
  Files         258      467     +209     
  Lines       12322    25662   +13340     
  Branches     2942     6384    +3442     
==========================================
+ Hits         6687    14326    +7639     
- Misses       4656     9372    +4716     
- Partials      979     1964     +985     
Flag Coverage Δ
taro-cli 60.27% <ø> (+0.09%) ⬆️
taro-runtime 58.78% <ø> (ø)
taro-web 60.28% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.
see 210 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Single-Dancer
Single-Dancer force-pushed the fix/vite-stateful-regexp-filter branch from aabb3e4 to 730da9e Compare October 20, 2026 03:16
@Single-Dancer Single-Dancer added this to the 4.3.1 milestone Oct 20, 2026
@Single-Dancer
Single-Dancer merged commit 251d8fc into NervJS:main Oct 20, 2026
25 checks passed
@Jarvis636431
Jarvis636431 deleted the fix/vite-stateful-regexp-filter branch November 3, 2026 03:19
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]: Vite compile filters alternate results with global or sticky regexes

2 participants