Skip to content

Add extra tests for type and value symbol merging #55387

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 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/baselines/reference/typeValueMerge1.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//// [tests/cases/conformance/externalModules/typeValueMerge1.ts] ////

=== other.ts ===
export type A = string;
>A : Symbol(A, Decl(other.ts, 0, 0), Decl(other.ts, 2, 8))

function A() {}
>A : Symbol(A, Decl(other.ts, 0, 23), Decl(other.ts, 0, 0))

export { A };
>A : Symbol(A, Decl(other.ts, 0, 0), Decl(other.ts, 2, 8))

export type B = string;
>B : Symbol(B, Decl(other.ts, 2, 13), Decl(other.ts, 6, 8))

var B = 10;
>B : Symbol(B, Decl(other.ts, 2, 13), Decl(other.ts, 5, 3))

export { B };
>B : Symbol(B, Decl(other.ts, 2, 13), Decl(other.ts, 6, 8))

=== main.ts ===
import { A, B } from "./other";
>A : Symbol(A, Decl(main.ts, 0, 8))
>B : Symbol(B, Decl(main.ts, 0, 11))

A();
>A : Symbol(A, Decl(main.ts, 0, 8))

export const C = B;
>C : Symbol(C, Decl(main.ts, 4, 12))
>B : Symbol(B, Decl(main.ts, 0, 11))

35 changes: 35 additions & 0 deletions tests/baselines/reference/typeValueMerge1.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//// [tests/cases/conformance/externalModules/typeValueMerge1.ts] ////

=== other.ts ===
export type A = string;
>A : string

function A() {}
>A : () => void

export { A };
>A : () => void

export type B = string;
>B : string

var B = 10;
>B : number
>10 : 10

export { B };
>B : number

=== main.ts ===
import { A, B } from "./other";
>A : () => void
>B : number

A();
>A() : void
>A : () => void

export const C = B;
>C : number
>B : number

17 changes: 17 additions & 0 deletions tests/cases/conformance/externalModules/typeValueMerge1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @noEmit: true

// @Filename: other.ts
export type A = string;
function A() {}
export { A };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this resolves to a value in this situation so it's kinda equivalent to:

export type A = string;
export function A() {}

and this was always~ allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that in the past this was considered to be ambiguous and one could get an error when writing code like this ("Individual declarations in merged declaration 'B' must be all exported or all local"). In the referenced issue it was observed that the variant with exported function declaration didn't report an error (at least back in 2016 :P). @DanielRosenwasser even stated that it should error. However, since the behavior was changed in 4.9 by #50853 I think that the proper resolution nowadays is to accept the new behavior and just commit those tests.


export type B = string;
var B = 10;
export { B };

// @Filename: main.ts
import { A, B } from "./other";

A();

export const C = B;