Skip to content

fix(compiler-sfc): no params were generated when using withDefaults#12823

Merged
edison1105 merged 3 commits intovuejs:mainfrom
inottn:fix/withDefaults
Feb 9, 2026
Merged

fix(compiler-sfc): no params were generated when using withDefaults#12823
edison1105 merged 3 commits intovuejs:mainfrom
inottn:fix/withDefaults

Conversation

@inottn
Copy link
Copy Markdown
Contributor

@inottn inottn commented Feb 7, 2025

fix #12822

Summary by CodeRabbit

  • Bug Fixes

    • Fixed handling of default functions in defineProps to properly preserve parameter lists in runtime prop definitions, ensuring complex default function signatures are accurately represented.
  • Tests

    • Extended test coverage for defineProps with complex default function scenarios.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 7, 2025

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 104 kB 39.3 kB 35.4 kB
vue.global.prod.js 162 kB 59.3 kB 52.8 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 47.2 kB 18.4 kB 16.9 kB
createApp 55.3 kB 21.5 kB 19.6 kB
createSSRApp 59.6 kB 23.2 kB 21.2 kB
defineCustomElement 60.9 kB 23.2 kB 21.2 kB
overall 69.7 kB 26.7 kB 24.4 kB

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Feb 7, 2025

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@12823
npm i https://pkg.pr.new/@vue/compiler-core@12823
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@12823
npm i https://pkg.pr.new/@vue/compiler-dom@12823
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@12823
npm i https://pkg.pr.new/@vue/compiler-sfc@12823
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@12823
npm i https://pkg.pr.new/@vue/compiler-ssr@12823
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@12823
npm i https://pkg.pr.new/@vue/reactivity@12823
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@12823
npm i https://pkg.pr.new/@vue/runtime-core@12823
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@12823
npm i https://pkg.pr.new/@vue/runtime-dom@12823
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@12823
npm i https://pkg.pr.new/@vue/server-renderer@12823
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@12823
npm i https://pkg.pr.new/@vue/shared@12823
yarn add https://pkg.pr.new/@vue/[email protected]

vue

pnpm add https://pkg.pr.new/vue@12823
npm i https://pkg.pr.new/vue@12823
yarn add https://pkg.pr.new/[email protected]

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@12823
npm i https://pkg.pr.new/@vue/compat@12823
yarn add https://pkg.pr.new/@vue/[email protected]

commit: 9fe7317

@edison1105 edison1105 added scope: sfc 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. wait changes ready to merge The PR is ready to be merged. and removed wait changes labels Feb 8, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 9, 2026

📝 Walkthrough

Walkthrough

The changes fix a bug where withDefaults fails when using method shorthand syntax for default prop factories. The implementation now extracts and preserves parameter lists from method nodes when generating runtime prop defaults, rather than calling the default function with empty parameters.

Changes

Cohort / File(s) Summary
Test Coverage for Method Syntax Defaults
packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts
Extended test suite with a new prop quuux that has a complex default function using method shorthand syntax with destructuring and rest parameters. Updated assertions for generated props and bindings expectations.
Parameter Preservation in Runtime Defaults
packages/compiler-sfc/src/script/defineProps.ts
Modified genRuntimePropFromType to extract parameter lists from method nodes and inject them into default function calls, changing from default() to default(params...) to preserve function signatures when using method shorthand syntax.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • LittleSound
  • Doctor-wu

Poem

🐰 A rabbit hops through props so fine,
Default parameters now align,
When methods speak in shorthand way,
Parameters bloom and save the day! 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly identifies the main fix: parameters not being generated when using withDefaults with object method syntax defaults.
Linked Issues check ✅ Passed The code changes directly address the linked issue #12822 by modifying genRuntimePropFromType to extract and inject function parameters from method nodes, enabling withDefaults to work with object method syntax.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the withDefaults issue: test updates validate the fix and implementation changes extract function parameters for default methods.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


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.

@edison1105
Copy link
Copy Markdown
Member

/ecosystem-ci run

@vue-bot
Copy link
Copy Markdown
Contributor

vue-bot commented Feb 9, 2026

📝 Ran ecosystem CI: Open

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

@edison1105 edison1105 merged commit b0a1f05 into vuejs:main Feb 9, 2026
13 of 14 checks passed
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. ready to merge The PR is ready to be merged. scope: sfc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: withDefaults Fails When Using Function Declarations With Props

3 participants