Skip to content

fix(compiler-sfc): handle vue-ignore on leading intersection type#14950

Merged
edison1105 merged 2 commits into
vuejs:mainfrom
ifer47:fix-sfc-vue-ignore-leading-intersection
Jun 11, 2026
Merged

fix(compiler-sfc): handle vue-ignore on leading intersection type#14950
edison1105 merged 2 commits into
vuejs:mainfrom
ifer47:fix-sfc-vue-ignore-leading-intersection

Conversation

@ifer47

@ifer47 ifer47 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #12254.

When @vue-ignore is placed before the first member of an intersection type, Babel attaches the leading comment to the parent TSIntersectionType instead of the first type reference. The SFC type resolver then treats the whole intersection as ignored, so later members are skipped and their runtime prop types are not generated.

This changes that specific case so a leading @vue-ignore on an intersection/union parent is treated as applying to the first member only. Other members continue to be resolved normally, preserving boolean runtime prop inference for cases like defineProps</* @vue-ignore */ A & B>().

Test

  • pnpm vitest run packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts packages/compiler-sfc/__tests__/compileScript.spec.ts
  • pnpm exec prettier --check packages/compiler-sfc/src/script/resolveType.ts packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts
  • pnpm exec eslint packages/compiler-sfc/src/script/resolveType.ts packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts
  • pnpm check
  • git diff --check

Summary by CodeRabbit

  • Bug Fixes

    • Corrected handling of the ignore directive for composite prop types so leading ignored members are skipped and only remaining members are recognized as props.
  • Tests

    • Added coverage for leading-ignored intersection and union scenarios to ensure only non-ignored members are treated as component props.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 02d3ddf5-d839-4787-96ea-80a1a2ee4ce7

📥 Commits

Reviewing files that changed from the base of the PR and between 89c08ab and 19672bb.

📒 Files selected for processing (3)
  • packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts
  • packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
  • packages/compiler-sfc/src/script/resolveType.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/compiler-sfc/tests/compileScript/defineProps.spec.ts
  • packages/compiler-sfc/tests/compileScript/resolveType.spec.ts
  • packages/compiler-sfc/src/script/resolveType.ts

📝 Walkthrough

Walkthrough

Centralizes @vue-ignore detection via hasVueIgnore() and updates innerResolveTypeElements to skip a leading ignored member when resolving multi-member TS intersections/unions; adds unit tests for resolveType and an integration defineProps test asserting ignored members are not emitted.

Changes

Leading Intersection/Union Ignore Support

Layer / File(s) Summary
hasVueIgnore helper utility
packages/compiler-sfc/src/script/resolveType.ts
New hasVueIgnore(node: Node): boolean utility centralizes detection of @vue-ignore in node leading comments.
Intersection/union type ignore resolution
packages/compiler-sfc/src/script/resolveType.ts
innerResolveTypeElements now uses hasVueIgnore() and, for multi-member TSIntersectionType/TSUnionType with a leading @vue-ignore, skips the first member and resolves/merges the remaining members; other ignored nodes return empty props.
Unit and integration tests
packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts, packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts
Adds tests for leading ignored intersection and union members in resolveType and an end-to-end defineProps test asserting the ignored member's prop is not generated and bindings reflect only the non-ignored member.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • vuejs/core#13906: Also adjusts resolveType.ts handling of /* @vue-ignore */ and runtime/type inference interactions.

Suggested labels

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

Suggested reviewers

  • edison1105
  • LittleSound

Poem

🐰 I found a comment, tucked and small,
The first type bowed and left the hall,
The others stepped up, tidy and bright,
Props lined up neat, in compile light,
A rabbit cheers the quieter sight.

🚥 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 title accurately describes the main code change: handling @vue-ignore on leading intersection types in the compiler-sfc package.
Linked Issues check ✅ Passed The PR fixes the core requirement from #12254: enabling @vue-ignore before defineProps generic params to ignore only the first member while resolving subsequent members.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the linked issue: tests validate the fix and the implementation handles @vue-ignore on intersection/union types as required.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@github-actions

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 106 kB 40.1 kB 36 kB
vue.global.prod.js 164 kB 60.1 kB 53.5 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 48.8 kB 19 kB 17.4 kB
createApp 56.9 kB 22 kB 20.1 kB
createSSRApp 61.2 kB 23.8 kB 21.7 kB
defineCustomElement 63.1 kB 23.9 kB 21.8 kB
overall 71.7 kB 27.4 kB 25 kB

@pkg-pr-new

pkg-pr-new Bot commented Jun 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@14950
npm i https://pkg.pr.new/@vue/compiler-core@14950
yarn add https://pkg.pr.new/@vue/compiler-core@14950.tgz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@14950
npm i https://pkg.pr.new/@vue/compiler-dom@14950
yarn add https://pkg.pr.new/@vue/compiler-dom@14950.tgz

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@14950
npm i https://pkg.pr.new/@vue/compiler-sfc@14950
yarn add https://pkg.pr.new/@vue/compiler-sfc@14950.tgz

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@14950
npm i https://pkg.pr.new/@vue/compiler-ssr@14950
yarn add https://pkg.pr.new/@vue/compiler-ssr@14950.tgz

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@14950
npm i https://pkg.pr.new/@vue/reactivity@14950
yarn add https://pkg.pr.new/@vue/reactivity@14950.tgz

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@14950
npm i https://pkg.pr.new/@vue/runtime-core@14950
yarn add https://pkg.pr.new/@vue/runtime-core@14950.tgz

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@14950
npm i https://pkg.pr.new/@vue/runtime-dom@14950
yarn add https://pkg.pr.new/@vue/runtime-dom@14950.tgz

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@14950
npm i https://pkg.pr.new/@vue/server-renderer@14950
yarn add https://pkg.pr.new/@vue/server-renderer@14950.tgz

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@14950
npm i https://pkg.pr.new/@vue/shared@14950
yarn add https://pkg.pr.new/@vue/shared@14950.tgz

vue

pnpm add https://pkg.pr.new/vue@14950
npm i https://pkg.pr.new/vue@14950
yarn add https://pkg.pr.new/vue@14950.tgz

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@14950
npm i https://pkg.pr.new/@vue/compat@14950
yarn add https://pkg.pr.new/@vue/compat@14950.tgz

commit: 19672bb

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts (1)

156-166: ⚡ Quick win

Add a leading-union ignore regression case next to this test.

Line 156 covers the new leading-intersection behavior, but the same resolver branch also handles leading unions. A sibling test would lock that path too.

Suggested test addition
+  test('leading union type with ignore', () => {
+    expect(
+      resolve(`
+    type Foo = { foo: number }
+    type Bar = { bar: boolean }
+    defineProps</* `@vue-ignore` */ Foo | Bar>()
+    `).props,
+    ).toStrictEqual({
+      bar: ['Boolean'],
+    })
+  })
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts` around
lines 156 - 166, Add a sibling test case to cover the leading-union with ignore
scenario next to the existing test 'leading intersection type with ignore';
specifically, add a test that calls resolve(...) with a leading union type
annotated like defineProps</* `@vue-ignore` */ Foo | Bar>() (matching the
structure used in the intersection test) and assert the resulting .props shape
(e.g., that only the expected prop from the non-ignored type is present). Use
the same resolve helper and test structure as the existing test to lock the
resolver branch that handles leading unions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts`:
- Around line 156-166: Add a sibling test case to cover the leading-union with
ignore scenario next to the existing test 'leading intersection type with
ignore'; specifically, add a test that calls resolve(...) with a leading union
type annotated like defineProps</* `@vue-ignore` */ Foo | Bar>() (matching the
structure used in the intersection test) and assert the resulting .props shape
(e.g., that only the expected prop from the non-ignored type is present). Use
the same resolve helper and test structure as the existing test to lock the
resolver branch that handles leading unions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8844ccf4-536b-437b-8af2-2e65a83c0baf

📥 Commits

Reviewing files that changed from the base of the PR and between 48ad452 and 3279350.

📒 Files selected for processing (3)
  • packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts
  • packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
  • packages/compiler-sfc/src/script/resolveType.ts

@edison1105 edison1105 added the 🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. label Jun 10, 2026

@edison1105 edison1105 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The fix direction looks correct to me.

Comment thread packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
@edison1105 edison1105 added the ready to merge The PR is ready to be merged. label Jun 10, 2026
@edison1105

Copy link
Copy Markdown
Member

/ecosystem-ci run

@vue-bot

vue-bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

📝 Ran ecosystem CI: Open

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

@ifer47 ifer47 force-pushed the fix-sfc-vue-ignore-leading-intersection branch from 89c08ab to 19672bb Compare June 10, 2026 14:09
@edison1105 edison1105 merged commit 0dcd225 into vuejs:main Jun 11, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. ready to merge The PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@vue-ignore before defineProps generic params breaks compilation

3 participants