Skip to content

Conversation

KazariEX
Copy link
Member

@KazariEX KazariEX commented Jul 4, 2025

Use non-capturing groups or remove them as far as possible.

Summary by CodeRabbit

  • Refactor
    • Improved internal pattern matching and regex usage across directive/attribute handling for greater consistency.
    • Refined string transformation and style-related processing to reduce unnecessary captures and simplify matching.
    • No changes to public APIs or user-visible behavior; no impact on existing features or functionality is expected.

Copy link

coderabbitai bot commented Jul 4, 2025

Walkthrough

This update replaces several capturing regex groups with non-capturing groups or equivalent string checks across multiple packages; behavior and public APIs remain unchanged.

Changes

Cohort / File(s) Change Summary
Directive regexes
packages/compiler-core/src/transforms/vIf.ts, packages/compiler-ssr/src/transforms/ssrVIf.ts
Replaced capturing group in directive-name regex with a non-capturing group.
Slot directive regexes
packages/compiler-core/src/transforms/vSlot.ts
Updated v-else / v-else-if matching patterns to use non-capturing groups.
Function expression detection
packages/compiler-core/src/utils.ts
Converted capture groups in the function-expression regex to non-capturing groups.
Static attribute matching
packages/compiler-dom/src/transforms/stringifyStatic.ts
dataAriaRE changed to use a non-capturing group for data/aria prefix.
Scoped style regexes
packages/compiler-sfc/src/style/pluginScoped.ts
Vendor-prefix groups in animationNameRE and animationRE made non-capturing.
External URL detection
packages/compiler-sfc/src/template/templateUtils.ts
externalRE updated to use a non-capturing group around the optional scheme.
Mount attribute checks
packages/runtime-core/src/compat/global.ts, packages/runtime-dom/src/index.ts
Attribute-prefix regex updated to use a non-capturing group for `(v-
Classify / camelize helpers
packages/runtime-core/src/component.ts, packages/shared/src/general.ts
Removed reliance on capture groups: classifyRE adjusted and replacement callback updated; camelizeRE changed and replacement uses substring slicing.
Transition matching
packages/runtime-dom/src/components/Transition.ts
Transition property regex altered to use non-capturing groups.
TransitionGroup property check
packages/runtime-dom/src/components/TransitionGroup.ts
Replaced /transform$/ regex test with endsWith('transform') string check.
Style display detection
packages/runtime-dom/src/modules/style.ts
`( ^

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Code using regex
    participant Regex as Regex engine / String API

    Caller->>Regex: match pattern with capturing groups (old)
    Note over Regex: engine captures subgroups

    Caller->>Regex: match pattern with non-capturing groups or use string methods (new)
    Note over Regex: matches without creating capture results
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇
I nibble at groups in the midnight code,
swapping captures for quieter mode.
Non-capturing hops, light on their feet,
patterns purr tidy and neat.
A carrot for nuance—regex trimmed and sweet.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Jul 4, 2025

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB (+7 B) 38.5 kB 34.6 kB (-27 B)
vue.global.prod.js 159 kB (+21 B) 58.6 kB (-2 B) 52.2 kB (-21 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.6 kB 18.2 kB (-6 B) 16.7 kB (-14 B)
createApp 54.6 kB 21.3 kB (-6 B) 19.4 kB (+6 B)
createSSRApp 58.9 kB 23 kB (-8 B) 21 kB (+6 B)
defineCustomElement 59.6 kB 22.8 kB (-11 B) 20.8 kB (+1 B)
overall 68.7 kB (+4 B) 26.4 kB (-2 B) 24.1 kB (+4 B)

Copy link

pkg-pr-new bot commented Jul 4, 2025

Open in StackBlitz

@vue/compiler-core

npm i https://pkg.pr.new/@vue/compiler-core@13567

@vue/compiler-dom

npm i https://pkg.pr.new/@vue/compiler-dom@13567

@vue/compiler-sfc

npm i https://pkg.pr.new/@vue/compiler-sfc@13567

@vue/compiler-ssr

npm i https://pkg.pr.new/@vue/compiler-ssr@13567

@vue/reactivity

npm i https://pkg.pr.new/@vue/reactivity@13567

@vue/runtime-core

npm i https://pkg.pr.new/@vue/runtime-core@13567

@vue/runtime-dom

npm i https://pkg.pr.new/@vue/runtime-dom@13567

@vue/server-renderer

npm i https://pkg.pr.new/@vue/server-renderer@13567

@vue/shared

npm i https://pkg.pr.new/@vue/shared@13567

vue

npm i https://pkg.pr.new/vue@13567

@vue/compat

npm i https://pkg.pr.new/@vue/compat@13567

commit: 26763ca

@edison1105 edison1105 added ready to merge The PR is ready to be merged. 🧹 p1-chore Priority 1: this doesn't change code behavior. labels Jul 5, 2025
@KazariEX KazariEX force-pushed the perf/regex-group branch from 58faa41 to 1779b63 Compare July 5, 2025 03:50
@edison1105
Copy link
Member

/ecosystem-ci run

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/compiler-core/src/utils.ts (2)

191-193: Also recognize generator function expressions (function*).

Browser-side check currently misses function*/async function* (Node path via Babel covers it). Low risk to include.

Apply:

-  /^\s*(?:async\s*)?(?:\([^)]*?\)|[\w$_]+)\s*(?::[^=]+)?=>|^\s*(?:async\s+)?function(?:\s+[\w$]+)?\s*\(/
+  /^\s*(?:async\s*)?(?:\([^)]*?\)|[\w$_]+)\s*(?::[^=]+)?=>|^\s*(?:async\s+)?function\s*\*?\s*(?:\s+[\w$]+)?\s*\(/

191-193: Minor regex cleanup: dedupe the start anchor.

Tiny simplification, same behavior.

-  /^\s*(?:async\s*)?(?:\([^)]*?\)|[\w$_]+)\s*(?::[^=]+)?=>|^\s*(?:async\s+)?function\s*\*?\s*(?:\s+[\w$]+)?\s*\(/
+  /^\s*(?:(?:async\s*)?(?:\([^)]*?\)|[\w$_]+)\s*(?::[^=]+)?=>|(?:async\s+)?function\s*\*?\s*(?:\s+[\w$]+)?\s*\()/
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e80b7ed and 26763ca.

📒 Files selected for processing (2)
  • packages/compiler-core/src/transforms/vIf.ts (1 hunks)
  • packages/compiler-core/src/utils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/compiler-core/src/transforms/vIf.ts
🔇 Additional comments (2)
packages/compiler-core/src/utils.ts (2)

191-193: Non-capturing groups change is good.

Semantics preserved; avoids needless capture allocation in a hot regex.


191-193: Add a couple of TS edge-case tests.

Ensure the browser regex returns true for tricky but valid cases:

  • (x: number): ((y: string) => void) => () => {}
  • async function* foo() {}
    And false for non-functions:
  • async (x) (no arrow)
  • (x: number): Foo (type-only)

@vuejs vuejs deleted a comment from edison1105 Sep 2, 2025
@vue-bot
Copy link
Contributor

vue-bot commented Sep 2, 2025

📝 Ran ecosystem CI: Open

suite result latest scheduled
nuxt success success
language-tools success success
primevue success success
quasar success success
pinia success success
radix-vue success success
test-utils success success
router success success
vitepress success success
vue-macros failure failure
vite-plugin-vue success success
vue-i18n success success
vue-simple-compiler success success
vueuse success success
vuetify success success
vant success failure

@edison1105 edison1105 merged commit 1e8b65a into vuejs:main Sep 2, 2025
14 checks passed
@KazariEX KazariEX deleted the perf/regex-group branch September 2, 2025 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧹 p1-chore Priority 1: this doesn't change code behavior. ready to merge The PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants