fix(compiler-sfc): resolve top-level exports from files registered as global types#14805
fix(compiler-sfc): resolve top-level exports from files registered as global types#14805danielroe wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThis PR fixes global-scope type caching by introducing a separate cache for global-scope resolutions. Global type files added via ChangesGlobal-Scope Type Cache Separation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
Size ReportBundles
Usages
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts (1)
1769-1776: ⚡ Quick winAssert the priming failure explicitly instead of swallowing it.
At Line 1769, the empty
catch {}can hide regressions where the first compile no longer fails, weakening the test’s intended setup guarantee.Suggested test adjustment
- try { - resolve( - `defineProps<UnknownGlobal>()`, - files, - { globalTypeFiles: ['/globalTypes.d.ts'] }, - '/PrimeGlobal.vue', - ) - } catch {} + expect(() => + resolve( + `defineProps<UnknownGlobal>()`, + files, + { globalTypeFiles: ['/globalTypes.d.ts'] }, + '/PrimeGlobal.vue', + ), + ).toThrow('Unresolvable type reference')🤖 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 1769 - 1776, The test currently swallows the expected priming failure by using an empty catch block; instead assert the failure explicitly: call resolve(...) with the same arguments (the `resolve` invocation for "`defineProps<UnknownGlobal>()`" using `globalTypeFiles` and `'/PrimeGlobal.vue'`) inside an assertion that it throws (e.g. use the test framework's expect(...).toThrow or wrap in try/catch and call fail() when no error is thrown) so the test fails if the initial compile unexpectedly succeeds.
🤖 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 1769-1776: The test currently swallows the expected priming
failure by using an empty catch block; instead assert the failure explicitly:
call resolve(...) with the same arguments (the `resolve` invocation for
"`defineProps<UnknownGlobal>()`" using `globalTypeFiles` and
`'/PrimeGlobal.vue'`) inside an assertion that it throws (e.g. use the test
framework's expect(...).toThrow or wrap in try/catch and call fail() when no
error is thrown) so the test fails if the initial compile unexpectedly succeeds.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 30da15ee-fec1-4cab-b035-303d98725518
📒 Files selected for processing (2)
packages/compiler-sfc/__tests__/compileScript/resolveType.spec.tspackages/compiler-sfc/src/script/resolveType.ts
|
/ecosystem-ci run |
|
📝 Ran ecosystem CI: Open
|
resolves nuxt/nuxt#33694
the issue is that files registered as
globalTypeFilesthat contain plain top-levelexportdeclarations (nodeclare global { ... }) were cached with an empty TypeScope and that cached scope was then reused for regularimport { Foo } from '...'resolution, so imports of those types failed to resolve.Summary by CodeRabbit
Tests
Refactor