Repository navigation
fix(vue-directives): avoid stale lastIndex on the global directive regex - #579
NgoQuocViet2001 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Directive check and transform coverage src/addons/vue-directives.ts, test/vue-directives.test.ts |
The addon uses search to check for remaining directive references. Tests verify direct imports for registered directives, runtime resolution for unresolved directives, and identical output across repeated import injections. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers: antfu
Merge Risk: 
Minimal · up to 29ca7
-
The reported directive-transform instability is addressed, with no merge-blocking risk established.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Linked Issues check
-
Explanation
The change satisfies issue
#578.src/addons/vue-directives.tsusess.toString().search(RE_DIRECTIVE), so the global regexlastIndexis not changed before the next scan. The restored snapshots show known directives imported directly without_resolveDirectivecalls. The new repeated-transform test verifies identical output on both calls when a known directive andv-missingare present. The test preserves runtime resolution for the unresolved directive.
Full details: Out of Scope Changes check
-
Explanation
The changes stay within issue
#578. The source change fixes the Vue directive leftover check. The snapshot updates and repeated-transform test verify the requested behavior. No unrelated source, API, or feature changes appear in the whole-pull-request diff.
-
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Some tools did not complete. Review the errors below.
🔧 ESLint
-
If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.
src/addons/vue-directives.ts
-
ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.
test/vue-directives.test.ts
-
ESLint skipped: the matched ESLint configuration already failed (missing-dependency).
-
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.
Comment @coderabbitai help to get the list of available commands.
resolves #578
RE_DIRECTIVEhas thegflag, and the check for leftover directives callsRE_DIRECTIVE.test(), which leaveslastIndexset after a match.matchAllcopies thatlastIndex, so the next transform starts scanning partway into the file. With<div v-awesome-directive v-missing></div>, the firstinjectImportscall addsimport _directive_awesome_directive from ..., but a second call on the same code returns it unchanged, still calling_resolveDirective("awesome-directive"). A different file transformed next can also lose theresolveDirectiveimport while keeping a_resolveDirective(...)call, which throws at render.The check now uses
String#search, which does not touchlastIndex. Going back to.match()is not an option becausee18e/prefer-regex-testautofixes it to.test(), which is how this changed in 62a9ede. The "single named directive" and "single mixed directives" snapshots were regenerated with the broken output in 429d84a, so they are restored, and a new test transforms the same code twice and expects the same result.Ran:
pnpm exec vitest run test/vue-directives.test.ts: 3 failed without the fix (the two restored snapshots and the new test), 14 passed with itpnpm exec vitest run: 28 files, 255 tests passedpnpm run typecheck,pnpm run lint,pnpm run build: no errorsChecked:
Summary by CodeRabbit