-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
fix(compiler-sfc): support global augments with named exports #13789
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
WalkthroughAdds a test for resolving named exports inside declare global, and updates resolveType.ts to record inner declarations from ExportNamedDeclaration within ambient global modules during type collection. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant R as resolveType
participant RT as recordTypes
participant AST as TS AST
participant G as declare global Block
R->>RT: collect type/decl nodes
RT->>AST: traverse statements
AST-->>RT: TSModuleDeclaration(global) found
RT->>G: iterate moduleBlock.statements
alt ExportNamedDeclaration with declaration
note over RT,G: New behavior: unwrap and record inner declaration
RT->>RT: record(s.declaration)
else Other statements
RT->>RT: record(statement) (unchanged)
end
RT-->>R: return recorded types/declares
R->>R: resolve global named exports (e.g., interfaces/types)
R-->>R: provide props shape from resolved types
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Size ReportBundles
Usages
|
the failing test isn't related to this PR - I think a temporary glitch from pkg.pr.new that will probably be resolved on rerunning... |
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 (2)
packages/compiler-sfc/src/script/resolveType.ts (1)
1299-1304
: Consider handling edge cases or asserting assumptions for safety.Two optional hardening ideas:
- If future TS/Babel nodes allow specifier-only exports inside declare global (unlikely/invalid today), we could explicitly ignore them with an assertion to make intent clear.
- Optionally gate on
s.exportKind === 'type'
when present (Babel sets it for type-only exports) to document that only type space is relevant here.No action required for this PR; offered as a readability/defensive nit.
packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts (1)
1345-1371
: Optionally add a companion test for namespaces inside declare global.A follow-up test like
declare global { export namespace N { export interface X { ... } } }
would exerciseTSModuleDeclaration
within this path and ensure nested members also record correctly after this change. Not a blocker.If helpful, I can draft the additional test case snippet.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
(1 hunks)packages/compiler-sfc/src/script/resolveType.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). (4)
- GitHub Check: Redirect rules
- GitHub Check: Header rules
- GitHub Check: Pages changed
- GitHub Check: test / e2e-test
🔇 Additional comments (2)
packages/compiler-sfc/src/script/resolveType.ts (1)
1299-1304
: Correctly unwrap ExportNamedDeclaration inside declare global.This precisely addresses TS’s “exported declarations within declare global” pattern by recording the inner declaration rather than the export wrapper. The change is scoped to the ambient-global branch, so it won’t affect normal module export handling. Looks good.
packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts (1)
1345-1371
: Great targeted test covering named exports in declare global.The fixture mirrors the real-world pattern (
declare global { export ... }
+export {}
) and asserts both interface and type aliases resolve at call sites. This should prevent regressions for the Nuxt-reported case.
@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: |
spotted in nuxt/nuxt#29757
although a bit strange, it is valid typescript:
typescript playground
Summary by CodeRabbit