-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
fix(compiler-sfc): add error handling for defineModel() without variable assignment #13352
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughA new error code and message were introduced to enforce that Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (5)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Size ReportBundles
Usages
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/shared
vue
@vue/compat
@vue/server-renderer
commit: |
export enum DOMErrorCodes {
X_V_HTML_NO_EXPRESSION = 53 /* ErrorCodes.__EXTEND_POINT__ */,
|
@edison1105 I have updated it for testing but forgot to commit. I will commit this change soon. Thank you so much. |
@runyasak |
@edison1105 I apologize for not running all the tests. |
There was a problem hiding this 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-sfc/__tests__/compileScript.spec.ts (1)
982-984
: Missing space after the equals signThere should be a space between
=
anddefineModel
for consistent code style.- const model =defineModel({ + const model = defineModel({ default: () => bar
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (1)
packages/compiler-sfc/__tests__/compileScript.spec.ts
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Redirect rules
- GitHub Check: Header rules
- GitHub Check: Pages changed
🔇 Additional comments (3)
packages/compiler-sfc/__tests__/compileScript.spec.ts (3)
982-986
: LGTM: Good test case for variable reference restrictionThis test correctly validates that
defineModel()
with locally declaredlet
variables in the default function will throw an error, while ensuringdefineModel()
is assigned to a variable.
992-996
: LGTM: Good test case for const variablesThis test correctly verifies that using
const
variables indefineModel()
is allowed, while ensuring proper variable assignment.
1002-1007
: LGTM: Good test case for get/set handlersThis test correctly verifies that using
let
variables indefineModel()
is allowed when they're used within get/set handlers, while ensuring proper variable assignment.
@edison1105 Oh, I forgot a space. 😂 |
LGTM~ |
@edison1105 @KazariEX Thank you so much for helping me. 😁 |
@@ -179,6 +179,7 @@ export const errorMessages: Record<ErrorCodes, string> = { | |||
[ErrorCodes.X_INVALID_EXPRESSION]: `Error parsing JavaScript expression: `, | |||
[ErrorCodes.X_KEEP_ALIVE_INVALID_CHILDREN]: `<KeepAlive> expects exactly one child component.`, | |||
[ErrorCodes.X_VNODE_HOOKS]: `@vnode-* hooks in templates are no longer supported. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support has been removed in 3.4.`, | |||
[ErrorCodes.X_DEFINE_MODEL_NO_ASSIGNMENT]: `defineModel() must be assigned to a variable. For example: const model = defineModel()`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ErrorCodes
are used in compiler-core/dom, but in compiler-sfc, we can inline error messages directly to reduce bundle size.
@@ -21,7 +21,7 @@ export function createDOMCompilerError( | |||
} | |||
|
|||
export enum DOMErrorCodes { | |||
X_V_HTML_NO_EXPRESSION = 53 /* ErrorCodes.__EXTEND_POINT__ */, | |||
X_V_HTML_NO_EXPRESSION = 54 /* ErrorCodes.__EXTEND_POINT__ */, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaking change here
@@ -22,6 +27,10 @@ export function processDefineModel( | |||
return false | |||
} | |||
|
|||
if (!declId) { | |||
ctx.error(errorMessages[ErrorCodes.X_DEFINE_MODEL_NO_ASSIGNMENT], node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just inline message
Overview
This PR is related to #13280.
I added validation to ensure
defineModel()
is always assigned to a variable, throwing an error message if used incorrectly.Scope of work
add verified error message:
defineModel() must be assigned to a variable
Screenshots
If you have any feedback or suggestions, please let me know and I will update the code accordingly.
Summary by CodeRabbit
New Features
Bug Fixes
Tests