-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
DanielRosenwasser
merged 1 commit into
microsoft:main
from
Andarist:tests/value-type-merge
Aug 16, 2023
Merged
Changes from all commits
Commits
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
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)) | ||
|
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,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
17
tests/cases/conformance/externalModules/typeValueMerge1.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,17 @@ | ||
// @noEmit: true | ||
|
||
// @Filename: other.ts | ||
export type A = string; | ||
function A() {} | ||
export { A }; | ||
|
||
export type B = string; | ||
var B = 10; | ||
export { B }; | ||
|
||
// @Filename: main.ts | ||
import { A, B } from "./other"; | ||
|
||
A(); | ||
|
||
export const C = B; |
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.
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.
this resolves to a value in this situation so it's kinda equivalent to:
and this was always~ allowed.
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.
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.