Skip to content

refactor(compiler): add dedicated transform for vbind shorthand #13438

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

edison1105
Copy link
Member

@edison1105 edison1105 commented Jun 5, 2025

close #13169
close #13170
close #11321
close #12298
close #12828

use tests from #13170 and #12298 and #12828

The current handing logic for v-bind shorthand is rather scattered, which results in many edge cases where transformBindShorthand needs to be called additionally. these cases occur because vbind shorthand has not been processed when reading properties from props.

This PR introduces a dedicated transform specifically for handling v-bind shorthand, and makes it the first transform to be called. This ensures that vbind shorthand has already been processed before any subsequent logic read from props


Special handling is required for double bind in vue-macros. PR vue-macros/vue-macros#960

Copy link

coderabbitai bot commented Jun 5, 2025

Walkthrough

A new node transform, transformVBindShorthand, is introduced to handle shorthand v-bind syntax (e.g., :foo) across the compiler's core, DOM, and SSR pipelines. Related logic is removed from other transforms, and tests are updated or added to verify correct handling of shorthand bindings in various scenarios.

Changes

File(s) Change Summary
.../src/transforms/transformVBindShorthand.ts New node transform transformVBindShorthand added to expand shorthand v-bind syntax and handle errors.
.../src/compile.ts, .../src/index.ts, .../ssr/src/index.ts Integrate and export transformVBindShorthand into core, DOM, and SSR compilation pipelines.
.../src/transforms/vBind.ts, .../src/transforms/vFor.ts Remove previous inline handling of v-bind shorthand; rely on new dedicated transform.
.../tests/transforms/vBind.spec.ts, .../vFor.spec.ts, .../vIf.spec.ts Update test helpers to include transformVBindShorthand in transformation pipeline.
.../tests/transforms/vIf.spec.ts, .../vModel.spec.ts, .../ssrTransitionGroup.spec.ts Add new test cases for shorthand v-bind scenarios to ensure correct transformation and SSR output.

Sequence Diagram(s)

sequenceDiagram
    participant Parser
    participant AST
    participant transformVBindShorthand
    participant OtherTransforms

    Parser->>AST: Parse template to AST
    AST->>transformVBindShorthand: Apply shorthand v-bind expansion
    transformVBindShorthand->>AST: Update nodes with expanded expressions
    AST->>OtherTransforms: Continue with other node transforms (e.g., vIf, vFor, vModel)
    OtherTransforms->>AST: Further transform AST
Loading

Poem

In the garden of code where the bindings grow,
A rabbit hops by, making shorthand flow.
No more tangled vines of :foo left behind,
Now camelCase blooms, with errors in mind.
With tests and transforms, the fields are all neat—
Shorthand or longhand, the syntax is sweet! 🥕

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai 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

Documentation and Community

  • 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 Jun 5, 2025

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB 38.4 kB 34.6 kB
vue.global.prod.js 159 kB (+26 B) 58.6 kB (+2 B) 52.1 kB (-11 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.7 kB 18.2 kB 16.7 kB
createApp 54.6 kB 21.3 kB 19.4 kB
createSSRApp 58.9 kB 23 kB 21 kB
defineCustomElement 59.6 kB 22.9 kB 20.9 kB
overall 68.7 kB 26.4 kB 24.1 kB

Copy link

pkg-pr-new bot commented Jun 5, 2025

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: fd7d6cf

@edison1105 edison1105 changed the title refactor(compile): add independent transform for VBindShorthand refactor(compiler): add independent transform for VBindShorthand Jun 5, 2025
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 (1)
packages/compiler-core/src/transforms/transformVBindShorthand.ts (1)

19-19: Consider safer handling of directive argument access.

The non-null assertion prop.arg! assumes the argument will always exist for bind directives without expressions. While this may be valid for shorthand syntax, consider adding a guard check for robustness.

-        const arg = prop.arg!
+        const arg = prop.arg
+        if (!arg) continue
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a47832e and fd7d6cf.

⛔ Files ignored due to path filters (1)
  • packages/compiler-dom/__tests__/transforms/__snapshots__/vModel.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (11)
  • packages/compiler-core/__tests__/transforms/vBind.spec.ts (2 hunks)
  • packages/compiler-core/__tests__/transforms/vFor.spec.ts (2 hunks)
  • packages/compiler-core/__tests__/transforms/vIf.spec.ts (3 hunks)
  • packages/compiler-core/src/compile.ts (2 hunks)
  • packages/compiler-core/src/index.ts (1 hunks)
  • packages/compiler-core/src/transforms/transformVBindShorthand.ts (1 hunks)
  • packages/compiler-core/src/transforms/vBind.ts (2 hunks)
  • packages/compiler-core/src/transforms/vFor.ts (0 hunks)
  • packages/compiler-dom/__tests__/transforms/vModel.spec.ts (3 hunks)
  • packages/compiler-ssr/__tests__/ssrTransitionGroup.spec.ts (1 hunks)
  • packages/compiler-ssr/src/index.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • packages/compiler-core/src/transforms/vFor.ts
🧰 Additional context used
🧬 Code Graph Analysis (6)
packages/compiler-core/src/compile.ts (2)
packages/compiler-core/src/index.ts (1)
  • transformVBindShorthand (69-69)
packages/compiler-core/src/transforms/transformVBindShorthand.ts (1)
  • transformVBindShorthand (10-36)
packages/compiler-ssr/__tests__/ssrTransitionGroup.spec.ts (1)
packages/compiler-ssr/src/index.ts (1)
  • compile (32-94)
packages/compiler-ssr/src/index.ts (1)
packages/compiler-core/src/transforms/transformVBindShorthand.ts (1)
  • transformVBindShorthand (10-36)
packages/compiler-core/__tests__/transforms/vBind.spec.ts (1)
packages/compiler-core/src/transforms/transformVBindShorthand.ts (1)
  • transformVBindShorthand (10-36)
packages/compiler-core/src/transforms/vBind.ts (1)
packages/compiler-core/src/ast.ts (1)
  • createObjectProperty (673-683)
packages/compiler-core/__tests__/transforms/vFor.spec.ts (1)
packages/compiler-core/src/transforms/transformVBindShorthand.ts (1)
  • transformVBindShorthand (10-36)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules
  • GitHub Check: Header rules
  • GitHub Check: Pages changed
🔇 Additional comments (17)
packages/compiler-core/__tests__/transforms/vBind.spec.ts (1)

20-20: LGTM! Proper integration of transformVBindShorthand into test pipeline.

The import and placement as the first transform in the test pipeline is correct, ensuring that shorthand v-bind syntax is properly expanded before other transforms process the AST.

Also applies to: 29-29

packages/compiler-core/src/index.ts (1)

69-69: LGTM! Proper public API exposure.

Adding the export for transformVBindShorthand correctly exposes the new transform as part of the compiler-core public API, consistent with other transform exports.

packages/compiler-core/src/compile.ts (1)

25-25: LGTM! Correct integration into core compilation pipeline.

The import and placement as the first transform in getBaseTransformPreset is architecturally correct. This ensures shorthand v-bind directives are expanded before other transforms process them, maintaining the proper transformation order.

Also applies to: 37-37

packages/compiler-ssr/src/index.ts (1)

16-16: LGTM! Consistent SSR pipeline integration.

The import from @vue/compiler-dom and placement as the first transform in the SSR nodeTransforms array ensures consistent handling of shorthand v-bind syntax between client-side and server-side rendering pipelines.

Also applies to: 59-59

packages/compiler-ssr/__tests__/ssrTransitionGroup.spec.ts (1)

104-125: LGTM! Well-structured test for SSR shorthand v-bind handling.

The test correctly verifies that shorthand :tag syntax is properly transformed to use _ctx.tag in SSR compilation output. The inline snapshot expectation captures both the dynamic opening tag <${_ctx.tag} and closing tag </${_ctx.tag}> rendering, ensuring complete SSR functionality.

packages/compiler-core/__tests__/transforms/vFor.spec.ts (2)

24-24: Import addition looks good.

The transformVBindShorthand import is correctly added to support shorthand v-bind processing in v-for tests.


36-36: Correct transform order placement.

Adding transformVBindShorthand as the first node transform ensures that shorthand v-bind syntax (like :key) is expanded before the v-for transform processes it. This maintains proper dependency order in the transform pipeline.

packages/compiler-dom/__tests__/transforms/vModel.spec.ts (3)

6-6: Import addition is correct.

The transformVBindShorthand import enables shorthand v-bind processing in v-model tests.


22-22: Proper transform integration.

Adding transformVBindShorthand to the nodeTransforms ensures shorthand v-bind syntax is processed before element transformation, maintaining the correct pipeline order.


67-74: Excellent test case for edge case handling.

This test addresses issue #13169 and correctly verifies that shorthand :type binding after v-model triggers dynamic model behavior (V_MODEL_DYNAMIC helper). This is crucial because the input type affects which v-model transformation is applied, and shorthand syntax should be properly recognized.

packages/compiler-core/__tests__/transforms/vIf.spec.ts (3)

20-25: Clean import restructuring.

The import statement is properly restructured to include transformVBindShorthand along with other necessary imports.


43-48: Consistent transform pipeline setup.

The addition of transformVBindShorthand as the first node transform maintains consistency with other test suites and ensures proper processing order for shorthand v-bind syntax.


223-232: Thorough test for shorthand key binding.

This test correctly verifies that shorthand :key syntax on v-if elements is properly processed. The expectation that both arg.content and exp.content equal 'key' confirms that the shorthand is expanded to :key="key" as intended. This addresses issue #11321 and ensures proper key handling in conditional rendering.

packages/compiler-core/src/transforms/transformVBindShorthand.ts (3)

20-28: Error handling for invalid shorthand arguments is well-implemented.

The validation correctly restricts shorthand syntax to static simple expressions only, and provides appropriate error reporting with fallback to an empty expression.


30-31: Camelization logic is correct for JavaScript property naming conventions.

Converting the argument content to camelCase and creating a non-static expression properly handles the shorthand expansion (e.g., :foo-bar:foo-bar="fooBar").


10-36: Well-structured transform that effectively modularizes shorthand v-bind handling.

This dedicated transform cleanly separates the shorthand expansion logic from other bind-related transforms, improving maintainability and reducing complexity in other parts of the codebase.

packages/compiler-core/src/transforms/vBind.ts (1)

71-71: Non-null assertion on expression is safe in this context.

The exp! assertion is appropriate here since the earlier logic (lines 22-38) handles empty expressions, and at this point exp should be a valid expression node.

@edison1105 edison1105 changed the title refactor(compiler): add independent transform for VBindShorthand refactor(compiler): add dedicated transform for same-name shorthand Jun 5, 2025
@edison1105
Copy link
Member Author

/ecosystem-ci run

@edison1105 edison1105 added scope: compiler 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Jun 5, 2025
@vue-bot
Copy link
Contributor

vue-bot commented Jun 5, 2025

📝 Ran ecosystem CI: Open

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

@edison1105 edison1105 changed the title refactor(compiler): add dedicated transform for same-name shorthand refactor(compiler): add dedicated transform for vbind shorthand Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. scope: compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Same-name shorthand (:type) breaks radio group behavior CompilerDOM.compile incorrectly parsing <template v-if="true" :key>
4 participants