-
Notifications
You must be signed in to change notification settings - Fork 893
Allow global Symbol computed names during pseudochecker object literal serialization #3297
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
Open
Andarist
wants to merge
2
commits into
microsoft:main
Choose a base branch
from
Andarist:fix/id-definitely-symbol-methods
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
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
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
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
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
25 changes: 25 additions & 0 deletions
25
testdata/baselines/reference/compiler/declarationEmitComputedPropertyGlobalSymbol1.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,25 @@ | ||
| //// [tests/cases/compiler/declarationEmitComputedPropertyGlobalSymbol1.ts] //// | ||
|
|
||
| //// [declarationEmitComputedPropertyGlobalSymbol1.ts] | ||
| export const symbolNamed = { | ||
| [Symbol.toStringTag]: "demo", | ||
| [Symbol.iterator](): IterableIterator<number> { | ||
| return [1, 2, 3][Symbol.iterator](); | ||
| }, | ||
| } as const; | ||
|
|
||
|
|
||
| //// [declarationEmitComputedPropertyGlobalSymbol1.js] | ||
| export const symbolNamed = { | ||
| [Symbol.toStringTag]: "demo", | ||
| [Symbol.iterator]() { | ||
| return [1, 2, 3][Symbol.iterator](); | ||
| }, | ||
| }; | ||
|
|
||
|
|
||
| //// [declarationEmitComputedPropertyGlobalSymbol1.d.ts] | ||
| export declare const symbolNamed: { | ||
| readonly [Symbol.toStringTag]: "demo"; | ||
| readonly [Symbol.iterator]: () => IterableIterator<number>; | ||
| }; |
28 changes: 28 additions & 0 deletions
28
testdata/baselines/reference/compiler/declarationEmitComputedPropertyGlobalSymbol1.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,28 @@ | ||
| //// [tests/cases/compiler/declarationEmitComputedPropertyGlobalSymbol1.ts] //// | ||
|
|
||
| === declarationEmitComputedPropertyGlobalSymbol1.ts === | ||
| export const symbolNamed = { | ||
| >symbolNamed : Symbol(symbolNamed, Decl(declarationEmitComputedPropertyGlobalSymbol1.ts, 0, 12)) | ||
|
|
||
| [Symbol.toStringTag]: "demo", | ||
| >[Symbol.toStringTag] : Symbol([Symbol.toStringTag], Decl(declarationEmitComputedPropertyGlobalSymbol1.ts, 0, 28)) | ||
| >Symbol.toStringTag : Symbol(SymbolConstructor.toStringTag, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) | ||
| >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) | ||
| >toStringTag : Symbol(SymbolConstructor.toStringTag, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) | ||
|
|
||
| [Symbol.iterator](): IterableIterator<number> { | ||
| >[Symbol.iterator] : Symbol([Symbol.iterator], Decl(declarationEmitComputedPropertyGlobalSymbol1.ts, 1, 33)) | ||
| >Symbol.iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --)) | ||
| >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) | ||
| >iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --)) | ||
| >IterableIterator : Symbol(IterableIterator, Decl(lib.es2015.iterable.d.ts, --, --)) | ||
|
|
||
| return [1, 2, 3][Symbol.iterator](); | ||
| >Symbol.iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --)) | ||
| >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) | ||
| >iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --)) | ||
|
|
||
| }, | ||
| } as const; | ||
| >const : Symbol(const) | ||
|
|
35 changes: 35 additions & 0 deletions
35
testdata/baselines/reference/compiler/declarationEmitComputedPropertyGlobalSymbol1.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,35 @@ | ||
| //// [tests/cases/compiler/declarationEmitComputedPropertyGlobalSymbol1.ts] //// | ||
|
|
||
| === declarationEmitComputedPropertyGlobalSymbol1.ts === | ||
| export const symbolNamed = { | ||
| >symbolNamed : { readonly [Symbol.toStringTag]: "demo"; readonly [Symbol.iterator]: () => IterableIterator<number>; } | ||
| >{ [Symbol.toStringTag]: "demo", [Symbol.iterator](): IterableIterator<number> { return [1, 2, 3][Symbol.iterator](); },} as const : { readonly [Symbol.toStringTag]: "demo"; readonly [Symbol.iterator]: () => IterableIterator<number>; } | ||
| >{ [Symbol.toStringTag]: "demo", [Symbol.iterator](): IterableIterator<number> { return [1, 2, 3][Symbol.iterator](); },} : { readonly [Symbol.toStringTag]: "demo"; readonly [Symbol.iterator]: () => IterableIterator<number>; } | ||
|
|
||
| [Symbol.toStringTag]: "demo", | ||
| >[Symbol.toStringTag] : "demo" | ||
| >Symbol.toStringTag : unique symbol | ||
| >Symbol : SymbolConstructor | ||
| >toStringTag : unique symbol | ||
| >"demo" : "demo" | ||
|
|
||
| [Symbol.iterator](): IterableIterator<number> { | ||
| >[Symbol.iterator] : () => IterableIterator<number> | ||
| >Symbol.iterator : unique symbol | ||
| >Symbol : SymbolConstructor | ||
| >iterator : unique symbol | ||
|
|
||
| return [1, 2, 3][Symbol.iterator](); | ||
| >[1, 2, 3][Symbol.iterator]() : ArrayIterator<number> | ||
| >[1, 2, 3][Symbol.iterator] : () => ArrayIterator<number> | ||
| >[1, 2, 3] : number[] | ||
| >1 : 1 | ||
| >2 : 2 | ||
| >3 : 3 | ||
| >Symbol.iterator : unique symbol | ||
| >Symbol : SymbolConstructor | ||
| >iterator : unique symbol | ||
|
|
||
| }, | ||
| } as const; | ||
|
|
15 changes: 15 additions & 0 deletions
15
...data/baselines/reference/compiler/declarationEmitComputedPropertyGlobalSymbol2.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,15 @@ | ||
| declarationEmitComputedPropertyGlobalSymbol2.ts(4,16): error TS9013: Expression type can't be inferred with --isolatedDeclarations. | ||
|
|
||
|
|
||
| ==== declarationEmitComputedPropertyGlobalSymbol2.ts (1 errors) ==== | ||
| export const symbolNamed = { | ||
| [Symbol.toStringTag]: "demo", | ||
| [Symbol.iterator]() { | ||
| return [1, 2, 3][Symbol.iterator](); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Strada, this reports a slightly different error (TS playground):
|
||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| !!! error TS9013: Expression type can't be inferred with --isolatedDeclarations. | ||
| !!! related TS9034 declarationEmitComputedPropertyGlobalSymbol2.ts:3:5: Add a return type to the method | ||
| !!! related TS9035 declarationEmitComputedPropertyGlobalSymbol2.ts:4:16: Add satisfies and a type assertion to this expression (satisfies T as T) to make the type explicit. | ||
| }, | ||
| } as const; | ||
|
|
||
25 changes: 25 additions & 0 deletions
25
testdata/baselines/reference/compiler/declarationEmitComputedPropertyGlobalSymbol2.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,25 @@ | ||
| //// [tests/cases/compiler/declarationEmitComputedPropertyGlobalSymbol2.ts] //// | ||
|
|
||
| //// [declarationEmitComputedPropertyGlobalSymbol2.ts] | ||
| export const symbolNamed = { | ||
| [Symbol.toStringTag]: "demo", | ||
| [Symbol.iterator]() { | ||
| return [1, 2, 3][Symbol.iterator](); | ||
| }, | ||
| } as const; | ||
|
|
||
|
|
||
| //// [declarationEmitComputedPropertyGlobalSymbol2.js] | ||
| export const symbolNamed = { | ||
| [Symbol.toStringTag]: "demo", | ||
| [Symbol.iterator]() { | ||
| return [1, 2, 3][Symbol.iterator](); | ||
| }, | ||
| }; | ||
|
|
||
|
|
||
| //// [declarationEmitComputedPropertyGlobalSymbol2.d.ts] | ||
| export declare const symbolNamed: { | ||
| readonly [Symbol.toStringTag]: "demo"; | ||
| readonly [Symbol.iterator]: () => ArrayIterator<number>; | ||
| }; |
27 changes: 27 additions & 0 deletions
27
testdata/baselines/reference/compiler/declarationEmitComputedPropertyGlobalSymbol2.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,27 @@ | ||
| //// [tests/cases/compiler/declarationEmitComputedPropertyGlobalSymbol2.ts] //// | ||
|
|
||
| === declarationEmitComputedPropertyGlobalSymbol2.ts === | ||
| export const symbolNamed = { | ||
| >symbolNamed : Symbol(symbolNamed, Decl(declarationEmitComputedPropertyGlobalSymbol2.ts, 0, 12)) | ||
|
|
||
| [Symbol.toStringTag]: "demo", | ||
| >[Symbol.toStringTag] : Symbol([Symbol.toStringTag], Decl(declarationEmitComputedPropertyGlobalSymbol2.ts, 0, 28)) | ||
| >Symbol.toStringTag : Symbol(SymbolConstructor.toStringTag, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) | ||
| >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) | ||
| >toStringTag : Symbol(SymbolConstructor.toStringTag, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) | ||
|
|
||
| [Symbol.iterator]() { | ||
| >[Symbol.iterator] : Symbol([Symbol.iterator], Decl(declarationEmitComputedPropertyGlobalSymbol2.ts, 1, 33)) | ||
| >Symbol.iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --)) | ||
| >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) | ||
| >iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --)) | ||
|
|
||
| return [1, 2, 3][Symbol.iterator](); | ||
| >Symbol.iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --)) | ||
| >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) | ||
| >iterator : Symbol(SymbolConstructor.iterator, Decl(lib.es2015.iterable.d.ts, --, --)) | ||
|
|
||
| }, | ||
| } as const; | ||
| >const : Symbol(const) | ||
|
|
35 changes: 35 additions & 0 deletions
35
testdata/baselines/reference/compiler/declarationEmitComputedPropertyGlobalSymbol2.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,35 @@ | ||
| //// [tests/cases/compiler/declarationEmitComputedPropertyGlobalSymbol2.ts] //// | ||
|
|
||
| === declarationEmitComputedPropertyGlobalSymbol2.ts === | ||
| export const symbolNamed = { | ||
| >symbolNamed : { readonly [Symbol.toStringTag]: "demo"; readonly [Symbol.iterator]: () => ArrayIterator<number>; } | ||
| >{ [Symbol.toStringTag]: "demo", [Symbol.iterator]() { return [1, 2, 3][Symbol.iterator](); },} as const : { readonly [Symbol.toStringTag]: "demo"; readonly [Symbol.iterator]: () => ArrayIterator<number>; } | ||
| >{ [Symbol.toStringTag]: "demo", [Symbol.iterator]() { return [1, 2, 3][Symbol.iterator](); },} : { readonly [Symbol.toStringTag]: "demo"; readonly [Symbol.iterator]: () => ArrayIterator<number>; } | ||
|
|
||
| [Symbol.toStringTag]: "demo", | ||
| >[Symbol.toStringTag] : "demo" | ||
| >Symbol.toStringTag : unique symbol | ||
| >Symbol : SymbolConstructor | ||
| >toStringTag : unique symbol | ||
| >"demo" : "demo" | ||
|
|
||
| [Symbol.iterator]() { | ||
| >[Symbol.iterator] : () => ArrayIterator<number> | ||
| >Symbol.iterator : unique symbol | ||
| >Symbol : SymbolConstructor | ||
| >iterator : unique symbol | ||
|
|
||
| return [1, 2, 3][Symbol.iterator](); | ||
| >[1, 2, 3][Symbol.iterator]() : ArrayIterator<number> | ||
| >[1, 2, 3][Symbol.iterator] : () => ArrayIterator<number> | ||
| >[1, 2, 3] : number[] | ||
| >1 : 1 | ||
| >2 : 2 | ||
| >3 : 3 | ||
| >Symbol.iterator : unique symbol | ||
| >Symbol : SymbolConstructor | ||
| >iterator : unique symbol | ||
|
|
||
| }, | ||
| } as const; | ||
|
|
10 changes: 10 additions & 0 deletions
10
testdata/tests/cases/compiler/declarationEmitComputedPropertyGlobalSymbol1.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,10 @@ | ||
| // @declaration: true | ||
| // @isolatedDeclarations: true | ||
| // @target: es2015 | ||
|
|
||
| export const symbolNamed = { | ||
| [Symbol.toStringTag]: "demo", | ||
| [Symbol.iterator](): IterableIterator<number> { | ||
| return [1, 2, 3][Symbol.iterator](); | ||
| }, | ||
| } as const; |
10 changes: 10 additions & 0 deletions
10
testdata/tests/cases/compiler/declarationEmitComputedPropertyGlobalSymbol2.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,10 @@ | ||
| // @declaration: true | ||
| // @isolatedDeclarations: true | ||
| // @target: es2015 | ||
|
|
||
| export const symbolNamed = { | ||
| [Symbol.toStringTag]: "demo", | ||
| [Symbol.iterator]() { | ||
| return [1, 2, 3][Symbol.iterator](); | ||
| }, | ||
| } as const; |
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.
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 super fond of coupling the pseudochecker with a checker's method like this but this is kinda the earliest moment at which this thing can be checked without doubling the work somewhere else.
I tried putting this in the nodebuilder but that had its own issues and was allowing all computed properties in the pseudochecker, just so the nodebuilder could reject them
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.
cc @weswigham
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'd go so far as to say it's a bad idea that goes against the premise of the ID pseudochecker. The functionality needs to be implementable without a full check to be consistent with ID's goals.
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.
Fortunately, it seems like
isDefinitelyReferenceToGlobalSymbolObjectseems like it's not too bad to implement an equivalent outside the checker? You just need the binder's reference resolver instead.