-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix resolving entity name of namespace member after alias is merged with type #53387
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
2 commits
Select commit
Hold shift + click to select a range
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
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/exportTypeMergedWithExportStarAsNamespace.js
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,32 @@ | ||
//// [tests/cases/conformance/externalModules/exportTypeMergedWithExportStarAsNamespace.ts] //// | ||
|
||
//// [usage.ts] | ||
import { Something } from "./prelude" | ||
export const myValue: Something<string> = Something.of("abc") | ||
export type MyType = Something.SubType<string> | ||
|
||
//// [Something.ts] | ||
export type Something<A> = { value: A } | ||
export type SubType<A> = { value: A } | ||
export declare function of<A>(value: A): Something<A> | ||
|
||
//// [prelude.ts] | ||
import * as S from "./Something" | ||
export * as Something from "./Something" | ||
export type Something<A> = S.Something<A> | ||
|
||
|
||
//// [Something.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//// [prelude.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Something = void 0; | ||
exports.Something = require("./Something"); | ||
//// [usage.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.myValue = void 0; | ||
var prelude_1 = require("./prelude"); | ||
exports.myValue = prelude_1.Something.of("abc"); |
51 changes: 51 additions & 0 deletions
51
tests/baselines/reference/exportTypeMergedWithExportStarAsNamespace.symbols
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,51 @@ | ||
=== tests/cases/conformance/externalModules/usage.ts === | ||
import { Something } from "./prelude" | ||
>Something : Symbol(Something, Decl(usage.ts, 0, 8)) | ||
|
||
export const myValue: Something<string> = Something.of("abc") | ||
>myValue : Symbol(myValue, Decl(usage.ts, 1, 12)) | ||
>Something : Symbol(Something, Decl(usage.ts, 0, 8)) | ||
>Something.of : Symbol(of, Decl(Something.ts, 1, 37)) | ||
>Something : Symbol(Something, Decl(usage.ts, 0, 8)) | ||
>of : Symbol(of, Decl(Something.ts, 1, 37)) | ||
|
||
export type MyType = Something.SubType<string> | ||
>MyType : Symbol(MyType, Decl(usage.ts, 1, 61)) | ||
>Something : Symbol(Something, Decl(usage.ts, 0, 8)) | ||
>SubType : Symbol(SubType, Decl(Something.ts, 0, 39)) | ||
|
||
=== tests/cases/conformance/externalModules/Something.ts === | ||
export type Something<A> = { value: A } | ||
>Something : Symbol(Something, Decl(Something.ts, 0, 0)) | ||
>A : Symbol(A, Decl(Something.ts, 0, 22)) | ||
>value : Symbol(value, Decl(Something.ts, 0, 28)) | ||
>A : Symbol(A, Decl(Something.ts, 0, 22)) | ||
|
||
export type SubType<A> = { value: A } | ||
>SubType : Symbol(SubType, Decl(Something.ts, 0, 39)) | ||
>A : Symbol(A, Decl(Something.ts, 1, 20)) | ||
>value : Symbol(value, Decl(Something.ts, 1, 26)) | ||
>A : Symbol(A, Decl(Something.ts, 1, 20)) | ||
|
||
export declare function of<A>(value: A): Something<A> | ||
>of : Symbol(of, Decl(Something.ts, 1, 37)) | ||
>A : Symbol(A, Decl(Something.ts, 2, 27)) | ||
>value : Symbol(value, Decl(Something.ts, 2, 30)) | ||
>A : Symbol(A, Decl(Something.ts, 2, 27)) | ||
>Something : Symbol(Something, Decl(Something.ts, 0, 0)) | ||
>A : Symbol(A, Decl(Something.ts, 2, 27)) | ||
|
||
=== tests/cases/conformance/externalModules/prelude.ts === | ||
import * as S from "./Something" | ||
>S : Symbol(S, Decl(prelude.ts, 0, 6)) | ||
|
||
export * as Something from "./Something" | ||
>Something : Symbol(Something, Decl(prelude.ts, 1, 6), Decl(prelude.ts, 1, 40)) | ||
|
||
export type Something<A> = S.Something<A> | ||
>Something : Symbol(Something, Decl(prelude.ts, 1, 6), Decl(prelude.ts, 1, 40)) | ||
>A : Symbol(A, Decl(prelude.ts, 2, 22)) | ||
>S : Symbol(S, Decl(prelude.ts, 0, 6)) | ||
>Something : Symbol(S.Something, Decl(Something.ts, 0, 0)) | ||
>A : Symbol(A, Decl(prelude.ts, 2, 22)) | ||
|
40 changes: 40 additions & 0 deletions
40
tests/baselines/reference/exportTypeMergedWithExportStarAsNamespace.types
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 @@ | ||
=== tests/cases/conformance/externalModules/usage.ts === | ||
import { Something } from "./prelude" | ||
>Something : typeof import("tests/cases/conformance/externalModules/Something") | ||
|
||
export const myValue: Something<string> = Something.of("abc") | ||
>myValue : Something<string> | ||
>Something.of("abc") : import("tests/cases/conformance/externalModules/Something").Something<string> | ||
>Something.of : <A>(value: A) => import("tests/cases/conformance/externalModules/Something").Something<A> | ||
>Something : typeof import("tests/cases/conformance/externalModules/Something") | ||
>of : <A>(value: A) => import("tests/cases/conformance/externalModules/Something").Something<A> | ||
>"abc" : "abc" | ||
|
||
export type MyType = Something.SubType<string> | ||
>MyType : { value: string; } | ||
>Something : any | ||
|
||
=== tests/cases/conformance/externalModules/Something.ts === | ||
export type Something<A> = { value: A } | ||
>Something : Something<A> | ||
>value : A | ||
|
||
export type SubType<A> = { value: A } | ||
>SubType : SubType<A> | ||
>value : A | ||
|
||
export declare function of<A>(value: A): Something<A> | ||
>of : <A>(value: A) => Something<A> | ||
>value : A | ||
|
||
=== tests/cases/conformance/externalModules/prelude.ts === | ||
import * as S from "./Something" | ||
>S : typeof S | ||
|
||
export * as Something from "./Something" | ||
>Something : typeof S | ||
|
||
export type Something<A> = S.Something<A> | ||
>Something : Something<A> | ||
>S : any | ||
|
14 changes: 14 additions & 0 deletions
14
tests/cases/conformance/externalModules/exportTypeMergedWithExportStarAsNamespace.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,14 @@ | ||
// @Filename: usage.ts | ||
import { Something } from "./prelude" | ||
export const myValue: Something<string> = Something.of("abc") | ||
export type MyType = Something.SubType<string> | ||
|
||
// @Filename: Something.ts | ||
export type Something<A> = { value: A } | ||
export type SubType<A> = { value: A } | ||
export declare function of<A>(value: A): Something<A> | ||
|
||
// @Filename: prelude.ts | ||
import * as S from "./Something" | ||
export * as Something from "./Something" | ||
export type Something<A> = S.Something<A> |
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.
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.
Can this be simplified to just calling
resolveSymbol
in the originalsymbol = ...
expression RHS above?I feel like I fixed a bug like this recently that did something similar. That and there's
getExportSymbolOfValueSymbolIfExported
which I think is related and does some of this chain of calls. (I think we're somewhat inconsistent about it.)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.
No, because then we would fail to look up the property on the original value of
namespace
, which could very well be the one that has the export—it’s just not in this case. You could make a (somewhat more contrived) test where the alias points to a type and the local declaration is the namespace containing the export we’re looking for.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.
I think this also needs another condition, like
since if that symbol exists in the original non-alias namespace (just with not the target meanings we're looking for), it should probably still block lookup in the alias target... right?
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.
I’m not sure it should, but it’s worth noting that this scenario you describe would be a merge error. In the test given, the non-alias symbol meaning is the type alias
Something<A>
—not a namespace at all. If we change it to be a namespace and try to reason about which of the two namespaces we want to pull from: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.
Are you sure you can't manage a similar shape in JS that we don't technically error on though? Something like
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.
In that example, we basically seem to ignore the
module.exports.Something
assignment, both before and after this change. But just imagine that the double-namespace example I gave was not an error, and our emit did something that would make the runtime merge work as expected. If that were possible, then the following would be true:Saying that the local should block the alias would be predicated on the runtime merge not working, but there’s already a top-level error for that.
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.
Yeah, I guess that's true; JS merges already let weird things with totally undefined behavior happen anyway, so it's not really important how they influence this.