-
-
Notifications
You must be signed in to change notification settings - Fork 905
fix(isolated-declarations): incorrectly dropping namespace even if it is being referenced #15123
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
67f52d5
Initial plan
Copilot 9964968
Initial plan: Fix isolated declarations dropping namespaced types
Copilot 968d96e
Fix isolated declarations dropping namespaced types
Copilot 2af8192
Add comprehensive namespace type reference test cases
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
crates/oxc_isolated_declarations/tests/fixtures/namespace-type-reference-complex.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Test various namespace reference scenarios | ||
|
|
||
| // Simple namespace reference | ||
| export type SimpleRef = NS1.Type1; | ||
|
|
||
| namespace NS1 { | ||
| export type Type1 = string; | ||
| } | ||
|
|
||
| // Nested namespace reference | ||
| export type NestedRef = Outer.Inner.Type2; | ||
|
|
||
| namespace Outer { | ||
| export namespace Inner { | ||
| export type Type2 = number; | ||
| } | ||
| } | ||
|
|
||
| // Multiple references to same namespace | ||
| export type Ref1 = NS2.TypeA; | ||
| export type Ref2 = NS2.TypeB; | ||
|
|
||
| namespace NS2 { | ||
| export type TypeA = boolean; | ||
| export type TypeB = symbol; | ||
| } | ||
|
|
||
| // Namespace used in union type | ||
| export type UnionRef = NS3.Type3 | string; | ||
|
|
||
| namespace NS3 { | ||
| export type Type3 = "literal"; | ||
| } | ||
|
|
||
| // Namespace used in interface | ||
| export interface InterfaceWithNS { | ||
| field: NS4.Type4; | ||
| } | ||
|
|
||
| namespace NS4 { | ||
| export type Type4 = bigint; | ||
| } | ||
|
|
||
| // Unreferenced namespace should not be included | ||
| namespace UnusedNS { | ||
| export type UnusedType = never; | ||
| } |
6 changes: 6 additions & 0 deletions
6
crates/oxc_isolated_declarations/tests/fixtures/namespace-type-reference.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // This ends up being `any` | ||
| export type A = Foo.Bar; | ||
|
|
||
| namespace Foo { | ||
| export type Bar = "bar" | ||
| } |
40 changes: 40 additions & 0 deletions
40
crates/oxc_isolated_declarations/tests/snapshots/namespace-type-reference-complex.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| --- | ||
| source: crates/oxc_isolated_declarations/tests/mod.rs | ||
| input_file: crates/oxc_isolated_declarations/tests/fixtures/namespace-type-reference-complex.ts | ||
| --- | ||
| ``` | ||
| ==================== .D.TS ==================== | ||
|
|
||
| // Test various namespace reference scenarios | ||
| // Simple namespace reference | ||
| export type SimpleRef = NS1.Type1; | ||
| declare namespace NS1 { | ||
| type Type1 = string; | ||
| } | ||
| // Nested namespace reference | ||
| export type NestedRef = Outer.Inner.Type2; | ||
| declare namespace Outer { | ||
| namespace Inner { | ||
| type Type2 = number; | ||
| } | ||
| } | ||
| // Multiple references to same namespace | ||
| export type Ref1 = NS2.TypeA; | ||
| export type Ref2 = NS2.TypeB; | ||
| declare namespace NS2 { | ||
| type TypeA = boolean; | ||
| type TypeB = symbol; | ||
| } | ||
| // Namespace used in union type | ||
| export type UnionRef = NS3.Type3 | string; | ||
| declare namespace NS3 { | ||
| type Type3 = "literal"; | ||
| } | ||
| // Namespace used in interface | ||
| export interface InterfaceWithNS { | ||
| field: NS4.Type4; | ||
| } | ||
| declare namespace NS4 { | ||
| type Type4 = bigint; | ||
| } | ||
| export {}; |
13 changes: 13 additions & 0 deletions
13
crates/oxc_isolated_declarations/tests/snapshots/namespace-type-reference.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| source: crates/oxc_isolated_declarations/tests/mod.rs | ||
| input_file: crates/oxc_isolated_declarations/tests/fixtures/namespace-type-reference.ts | ||
| --- | ||
| ``` | ||
| ==================== .D.TS ==================== | ||
|
|
||
| // This ends up being `any` | ||
| export type A = Foo.Bar; | ||
| declare namespace Foo { | ||
| type Bar = "bar"; | ||
| } | ||
| export {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.