Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Aug 21, 2025

spotted in nuxt/nuxt#29757

although a bit strange, it is valid typescript:

declare global {
    export interface Test2 {
        prop2: number
    }
}
export {}

typescript playground

Summary by CodeRabbit

  • Bug Fixes
    • Correctly resolves ambient global types that use named exports inside declare global blocks, ensuring globally exported interfaces/types are detected and usable (e.g., in defineProps). Previously, these could be missed during type collection, leading to unresolved props.
  • Tests
    • Added test coverage for global types with named exports via a global declaration block to prevent regressions.

Copy link

coderabbitai bot commented Aug 21, 2025

Walkthrough

Adds 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

Cohort / File(s) Summary
Tests: global named exports resolution
packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
Adds "global types with named exports" test using a global.d.ts with declare global and named exports; asserts defineProps resolution for interface and type.
Type resolver: ambient global handling
packages/compiler-sfc/src/script/resolveType.ts
In recordTypes, when visiting declare global blocks, unwraps ExportNamedDeclaration with a declaration and records the inner declaration; otherwise records the statement as before. Affects only ambient/global path.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I twitch my ears at types that roam,
In global fields they’ve found a home.
Unwrap the cloak, reveal the name,
Exports declare their rightful claim.
Tests now nibble every byte—
Hop! The props resolve just right. 🥕✨

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 Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB 38.4 kB 34.6 kB
vue.global.prod.js 159 kB 58.5 kB 52.1 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.5 kB 18.2 kB 16.7 kB
createApp 54.5 kB 21.2 kB 19.4 kB
createSSRApp 58.7 kB 22.9 kB 20.9 kB
defineCustomElement 59.5 kB 22.8 kB 20.8 kB
overall 68.5 kB 26.4 kB 24.1 kB

@danielroe
Copy link
Member Author

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...

Copy link

@coderabbitai coderabbitai bot left a 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 exercise TSModuleDeclaration 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.

📥 Commits

Reviewing files that changed from the base of the PR and between a48ffda and 19d2ada.

📒 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.

Copy link

pkg-pr-new bot commented Aug 21, 2025

Open in StackBlitz

@vue/compiler-core

npm i https://pkg.pr.new/@vue/compiler-core@13789

@vue/compiler-dom

npm i https://pkg.pr.new/@vue/compiler-dom@13789

@vue/compiler-sfc

npm i https://pkg.pr.new/@vue/compiler-sfc@13789

@vue/compiler-ssr

npm i https://pkg.pr.new/@vue/compiler-ssr@13789

@vue/reactivity

npm i https://pkg.pr.new/@vue/reactivity@13789

@vue/runtime-core

npm i https://pkg.pr.new/@vue/runtime-core@13789

@vue/runtime-dom

npm i https://pkg.pr.new/@vue/runtime-dom@13789

@vue/server-renderer

npm i https://pkg.pr.new/@vue/server-renderer@13789

@vue/shared

npm i https://pkg.pr.new/@vue/shared@13789

vue

npm i https://pkg.pr.new/vue@13789

@vue/compat

npm i https://pkg.pr.new/@vue/compat@13789

commit: 19d2ada

@edison1105 edison1105 added ready to merge The PR is ready to be merged. scope: sfc labels Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

2 participants