Skip to content

fix(isolated-declarations): incorrectly dropping namespace even if it is being referenced#15123

Merged
Dunqing merged 4 commits intomainfrom
copilot/fix-namespaced-type-export
Oct 31, 2025
Merged

fix(isolated-declarations): incorrectly dropping namespace even if it is being referenced#15123
Dunqing merged 4 commits intomainfrom
copilot/fix-namespaced-type-export

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

When an exported type references a namespaced type (e.g., export type A = Foo.Bar), the namespace declaration was being dropped from the output, causing the type reference to resolve to any.

// Input
export type A = Foo.Bar;

namespace Foo {
  export type Bar = "bar"
}

// Before: namespace dropped
export type A = Foo.Bar;

// After: namespace included
export type A = Foo.Bar;
declare namespace Foo {
  type Bar = "bar";
}
export {};

Changes

  • declaration.rs: Changed namespace inclusion check from has_value_reference() to has_reference() to account for type-position references. This aligns with enum handling, which also uses has_reference() since both can serve dual roles as types and values.

  • Test coverage: Added test cases for simple, nested, and multiple namespace references in various type positions (aliases, unions, interfaces).

Technical Details

Namespaces are bound with KindFlags::All (both type and value), but the transform logic was only checking for value references. Type references like Foo.Bar are tracked as KindFlags::Type through visit_ts_type_name(), so the previous check excluded legitimately referenced namespaces.

Original prompt

This section details on the original issue you should resolve

<issue_title>Isolated declarations emit drops namespaced types</issue_title>
<issue_description>When an exported type references a namespaced one, the namespace is not included in the output.

// This ends up being `any` 
export type A = Foo.Bar;

namespace Foo {
  export type Bar = "bar"
}

emits:

// This ends up being `any`
export type A = Foo.Bar;

playground</issue_description>

<agent_instructions>We should look into the oxc_isolated_declaration crate to fix this bug.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@graphite-app
Copy link
Contributor

graphite-app bot commented Oct 30, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

Copilot AI and others added 3 commits October 30, 2025 09:48
Co-authored-by: Dunqing <29533304+Dunqing@users.noreply.github.com>
Changed namespace reference check from has_value_reference() to has_reference()
to include both type and value references. This ensures that namespaces referenced
in type positions (e.g., Foo.Bar in type aliases) are included in the output.

Also fixes the shadowed.ts test case where Module namespace is now correctly
included when referenced in a type.

Co-authored-by: Dunqing <29533304+Dunqing@users.noreply.github.com>
Add test cases covering:
- Simple namespace reference
- Nested namespace reference
- Multiple references to same namespace
- Namespace in union types
- Namespace in interfaces
- Unreferenced namespace (should be excluded)

Co-authored-by: Dunqing <29533304+Dunqing@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix isolated declarations emitting drops for namespaced types Fix isolated declarations dropping namespaced types Oct 30, 2025
Copilot AI requested a review from Dunqing October 30, 2025 09:57
@github-actions github-actions bot added the A-isolated-declarations Isolated Declarations label Oct 30, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 30, 2025

CodSpeed Performance Report

Merging #15123 will not alter performance

Comparing copilot/fix-namespaced-type-export (2af8192) with main (d78419f)1

Summary

✅ 33 untouched
⏩ 4 skipped2

Footnotes

  1. No successful run was found on main (e25bc6f) during the generation of this report, so d78419f was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Dunqing Dunqing changed the title Fix isolated declarations dropping namespaced types fix(isolated-declarations): incorrectly dropping namespace even if it is being referenced Oct 30, 2025
@github-actions github-actions bot added the C-bug Category - Bug label Oct 30, 2025
@Dunqing Dunqing marked this pull request as ready for review October 30, 2025 15:46
Copilot AI review requested due to automatic review settings October 30, 2025 15:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where TypeScript namespaces were incorrectly excluded from generated declaration files when they were only referenced in type positions (e.g., Foo.Bar in type aliases). The change ensures namespaces are included when referenced as either types or values.

Key changes:

  • Updated namespace reference checking from value-only to all references (type and value)
  • Added test cases for namespace type references in various scenarios

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/oxc_isolated_declarations/src/declaration.rs Changed namespace reference check from has_value_reference to has_reference to include both type and value references
crates/oxc_isolated_declarations/tests/snapshots/shadowed.snap Updated snapshot showing namespace now correctly included when referenced in type position
crates/oxc_isolated_declarations/tests/snapshots/namespace-type-reference.snap New test snapshot for simple namespace type reference scenario
crates/oxc_isolated_declarations/tests/snapshots/namespace-type-reference-complex.snap New test snapshot for complex namespace type reference scenarios
crates/oxc_isolated_declarations/tests/fixtures/namespace-type-reference.ts New test fixture for basic namespace type reference
crates/oxc_isolated_declarations/tests/fixtures/namespace-type-reference-complex.ts New test fixture covering various namespace reference patterns

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Dunqing Dunqing merged commit 2c23e15 into main Oct 31, 2025
40 of 55 checks passed
@Dunqing Dunqing deleted the copilot/fix-namespaced-type-export branch October 31, 2025 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-isolated-declarations Isolated Declarations C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Isolated declarations emit drops namespaced types

2 participants

Comments