Skip to content

Conversation

ShenQingchuan
Copy link

@ShenQingchuan ShenQingchuan commented Oct 11, 2025

Description

This non-nullish assertion is harmful that it will be broken on language service when user has only typed : on an element, in that case we shouldn't treat the single : as a VBindShorthand

We got error thrown below

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'type')
    at Array.yX (index-C2PqwR5h.js:108:3591)
    at bS (index-C2PqwR5h.js:91:9055)
    at iRe (index-C2PqwR5h.js:91:8941)
    at bS (index-C2PqwR5h.js:91:9320)

How to reproduce

https://play.vuejs.org/#eNp9UbFOwzAQ/ZXDS5cmGWCKIiRAHWAoCDp6CcnRpCS2ZV/SoCoDCz/Awsa/8QV8AudEbTqgDrZ8997zvWfvxJUxYdugiEXiMlsaAofUmEupogiWmopSrcMwhN/vr3epkmgkMcwFYW2qlJArgOQsCODn4xNWbwYhBcfCCmEWz+AZK72F1EFKZCEIJj6sClSgDW+ZVk6zwCECFX5ZvcUc0Fo9ifKyhRgiLpLoaLyYC3J8w0u5DjdOK46z83wpMl2bskJ7b6jkCVLEMCAeSyv2dTf0yDY43/ezArPXf/ob1/meFA8WHdoWpThglNo10ggvnpbY8fkA1jpvKmafAB+R0zfe40i7blTOto94g9vb2mhL/LQrt+gIlduH8kY9sx/4UvCf3pyIPtk9Dy8GnVS96P8Ayt+tIA==

Summary by CodeRabbit

  • Bug Fixes

    • Corrected handling of v-bind same-name shorthand to require a non-empty argument, preventing accidental matches and reducing false positives.
    • Improved compile-time stability by safely processing arguments only when present.
    • Aligned error reporting for invalid shorthand arguments with existing behaviors for clearer, consistent messages.
  • Developer Experience

    • More predictable template compilation in edge cases involving v-bind shorthand, reducing confusion and unexpected warnings.

Copy link

coderabbitai bot commented Oct 11, 2025

Walkthrough

Tightens v-bind shorthand processing in transformVBindShorthand by requiring a non-empty directive argument when handling same-name shorthand. The condition now checks both missing expression and presence of arg, and uses arg directly when present, aligning invalid-arg error reporting with existing logic.

Changes

Cohort / File(s) Summary of Edits
Compiler v-bind shorthand handling
packages/compiler-core/src/transforms/transformVBindShorthand.ts
Updated condition to require both no expression and a present arg for same-name shorthand; replaced non-null assertion on arg with direct access; relies on existing error path for invalid arg types.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Template Author
  participant P as Parser
  participant T as transformVBindShorthand
  participant E as ErrorReporter

  Dev->>P: Uses v-bind shorthand (e.g., :foo or :)
  P->>T: Directive node (prop) with arg/exp
  T->>T: Check: !prop.exp AND prop.arg
  alt arg present and exp missing
    T->>T: Treat as same-name shorthand using arg
  else arg missing or invalid
    T->>E: Report X_V_BIND_INVALID_SAME_NAME_ARGUMENT
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

scope: compiler, :hammer: p3-minor-bug

Suggested reviewers

  • sxzz
  • baiwusanyu-c
  • KazariEX

Poem

I nibble at args with careful delight,
A colon’s whisper, now parsed just right.
When exp is empty and names align,
I hop to the shorthand, a tidy sign.
If arg goes missing—thump!—I warn,
Then bound I am to code well-worn. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately describes the main change—replacing the non-nullish assertion with a guard in the compiler transform—and follows the conventional commit style used in the repository.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 079010a and 5f4825e.

📒 Files selected for processing (1)
  • packages/compiler-core/src/transforms/transformVBindShorthand.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Redirect rules
  • GitHub Check: Header rules
  • GitHub Check: Pages changed
🔇 Additional comments (2)
packages/compiler-core/src/transforms/transformVBindShorthand.ts (2)

18-19: LGTM! Guard prevents runtime error on malformed input.

Adding prop.arg to the condition correctly ensures the argument exists before processing. This prevents the "Cannot read properties of undefined (reading 'type')" error when a user types only ":" in the template, as described in the PR.


21-21: LGTM! Assertion removal is safe with the guard.

Removing the non-null assertion operator is correct since the guard on line 19 ensures prop.arg is truthy before reaching this line. TypeScript's control flow analysis will narrow the type automatically.


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 and usage tips.

@ShenQingchuan ShenQingchuan marked this pull request as ready for review October 11, 2025 14:57
@edison1105 edison1105 added the ready to merge The PR is ready to be merged. label Oct 12, 2025
Copy link

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 102 kB 38.6 kB 34.8 kB
vue.global.prod.js 160 kB (+7 B) 58.7 kB (+4 B) 52.2 kB (-9 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.7 kB 18.3 kB 16.7 kB
createApp 54.7 kB 21.3 kB 19.5 kB
createSSRApp 58.9 kB 23 kB 21 kB
defineCustomElement 60 kB 23 kB 21 kB
overall 68.8 kB 26.5 kB 24.2 kB

Copy link

pkg-pr-new bot commented Oct 12, 2025

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: 5f4825e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to merge The PR is ready to be merged. scope: compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants