-
Notifications
You must be signed in to change notification settings - Fork 12.9k
fix typeof import("path").Foo.#private
#48763
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
Closed
Closed
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
14 changes: 14 additions & 0 deletions
14
tests/baselines/reference/privateNameInTypeQueryImport.errors.txt
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 @@ | ||
tests/cases/conformance/classes/members/privateNames/main.ts(3,43): error TS2694: Namespace '"tests/cases/conformance/classes/members/privateNames/lib".Bar' has no exported member '#m'. | ||
|
||
|
||
==== tests/cases/conformance/classes/members/privateNames/main.ts (1 errors) ==== | ||
export class Foo { | ||
static #m = 1; | ||
static #f(x: typeof import("./lib").Bar.#m) {} | ||
~~ | ||
!!! error TS2694: Namespace '"tests/cases/conformance/classes/members/privateNames/lib".Bar' has no exported member '#m'. | ||
} | ||
|
||
==== tests/cases/conformance/classes/members/privateNames/lib.ts (0 errors) ==== | ||
export { Foo as Bar } from "./main"; | ||
|
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,19 @@ | ||
//// [tests/cases/conformance/classes/members/privateNames/privateNameInTypeQueryImport.ts] //// | ||
|
||
//// [main.ts] | ||
export class Foo { | ||
static #m = 1; | ||
static #f(x: typeof import("./lib").Bar.#m) {} | ||
} | ||
|
||
//// [lib.ts] | ||
export { Foo as Bar } from "./main"; | ||
|
||
|
||
//// [lib.js] | ||
export { Foo as Bar } from "./main"; | ||
//// [main.js] | ||
export class Foo { | ||
static #m = 1; | ||
static #f(x) { } | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/privateNameInTypeQueryImport.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,18 @@ | ||
=== tests/cases/conformance/classes/members/privateNames/main.ts === | ||
export class Foo { | ||
>Foo : Symbol(Foo, Decl(main.ts, 0, 0)) | ||
|
||
static #m = 1; | ||
>#m : Symbol(Foo.#m, Decl(main.ts, 0, 18)) | ||
|
||
static #f(x: typeof import("./lib").Bar.#m) {} | ||
>#f : Symbol(Foo.#f, Decl(main.ts, 1, 16)) | ||
>x : Symbol(x, Decl(main.ts, 2, 12)) | ||
>Bar : Symbol(Bar, Decl(lib.ts, 0, 8)) | ||
} | ||
|
||
=== tests/cases/conformance/classes/members/privateNames/lib.ts === | ||
export { Foo as Bar } from "./main"; | ||
>Foo : Symbol(Foo, Decl(main.ts, 0, 0)) | ||
>Bar : Symbol(Bar, Decl(lib.ts, 0, 8)) | ||
|
19 changes: 19 additions & 0 deletions
19
tests/baselines/reference/privateNameInTypeQueryImport.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,19 @@ | ||
=== tests/cases/conformance/classes/members/privateNames/main.ts === | ||
export class Foo { | ||
>Foo : Foo | ||
|
||
static #m = 1; | ||
>#m : number | ||
>1 : 1 | ||
|
||
static #f(x: typeof import("./lib").Bar.#m) {} | ||
>#f : (x: any) => void | ||
>x : any | ||
>Bar : any | ||
} | ||
|
||
=== tests/cases/conformance/classes/members/privateNames/lib.ts === | ||
export { Foo as Bar } from "./main"; | ||
>Foo : typeof import("tests/cases/conformance/classes/members/privateNames/main").Foo | ||
>Bar : typeof import("tests/cases/conformance/classes/members/privateNames/main").Foo | ||
|
11 changes: 11 additions & 0 deletions
11
tests/cases/conformance/classes/members/privateNames/privateNameInTypeQueryImport.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,11 @@ | ||
// @strict: true | ||
// @target: esnext | ||
|
||
// @filename: main.ts | ||
export class Foo { | ||
static #m = 1; | ||
static #f(x: typeof import("./lib").Bar.#m) {} | ||
} | ||
|
||
// @filename: lib.ts | ||
export { Foo as Bar } from "./main"; |
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.
This error seems to be wrong, since
Bar
isFoo
and thus it has the#m
static field.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 can't tell if it's completely correct or not.
In this PR, I convert SyntaxError into TypeError.
Maybe it should be counted as "external" access.
Originally posted by @bradzacher in babel/babel#14454 (comment)
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 will try to add more test cases to determine which case is more reasonable and self-consistent.
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 a comparable way to test this would be to stick
private
onto the non-#
one and see what happens.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 didn't manage to do it.
At first I tried to alias
type Bar = typeof import("./lib").Bar
, then I found I cannot useBar.#m
.typeof import("./lib").Bar.#m
does not imply(typeof import("./lib").Bar).#m
.it means
typeof (import("./lib").Bar.#m)
.What do you think 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.
For
private
, I just meant to write something like:Where the static thing is "private" via TS, not via ECMAScript's private identifiers. I was replying on my phone so couldn't write it myself, sorry about 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.
Regarding the precedence, that's #19707 (mentioned in #48640). All of this is getting really hairy and inconsistent, though.
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.
The AST should be changed. This PR is blocked by #48640.