-
Notifications
You must be signed in to change notification settings - Fork 13k
Fix unique symbol declaration emit and add baseline test #62379
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
Akshit222
wants to merge
13
commits into
microsoft:main
Choose a base branch
from
Akshit222:fix-unique-symbol-dts
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.
+407
−3
Open
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
422bdb0
Fix unique symbol .d.ts generation and add baseline test
Akshit222 638c34f
chore: format code
Akshit222 270aaee
fix(compiler): remove unused export and unnecessary @internal from is…
Akshit222 dca1f36
fix(compiler): enable declaration emit for uniqueSymbolReassignment t…
Akshit222 5db0560
Fix formatting for emitter.ts (LF line endings)
Akshit222 89fd4f0
test(compiler): remove stray baselines and add correct uniqueSymbolRe…
Akshit222 9e6554f
Delete tests/cases/compiler/uniqueSymbolReassignment.d.ts
Akshit222 38c02bf
Merge branch 'main' into fix-unique-symbol-dts
Akshit222 b43965c
fix(declarations): emit ypeof for exported unique symbols
Akshit222 294e6cb
fix(tests): correct @filename header in unique symbol test
Akshit222 89a0bf6
format(declarations): fix formatting
Akshit222 16dfb5a
Update baselines for uniqueSymbolReassignment test (unique symbol typ…
Akshit222 9f540f2
Merge branch 'main' into fix-unique-symbol-dts
Akshit222 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
38 changes: 38 additions & 0 deletions
38
tests/baselines/reference/uniqueSymbolReassignment.d.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,38 @@ | ||
//// [tests/cases/compiler/uniqueSymbolReassignment.d.ts] //// | ||
|
||
=== uniqueSymbolReassignment.d.ts === | ||
declare function myFunction(): void; | ||
>myFunction : Symbol(myFunction, Decl(uniqueSymbolReassignment.d.ts, 0, 0), Decl(uniqueSymbolReassignment.d.ts, 0, 36)) | ||
|
||
declare namespace myFunction { | ||
>myFunction : Symbol(myFunction, Decl(uniqueSymbolReassignment.d.ts, 0, 0), Decl(uniqueSymbolReassignment.d.ts, 0, 36)) | ||
|
||
const mySymbol: unique symbol; | ||
>mySymbol : Symbol(mySymbol, Decl(uniqueSymbolReassignment.d.ts, 2, 9)) | ||
|
||
const anotherUnique: unique symbol; | ||
>anotherUnique : Symbol(anotherUnique, Decl(uniqueSymbolReassignment.d.ts, 3, 9)) | ||
|
||
var nonUnique1: typeof nonUniqueSymbol1; | ||
>nonUnique1 : Symbol(nonUnique1, Decl(uniqueSymbolReassignment.d.ts, 4, 7)) | ||
>nonUniqueSymbol1 : Symbol(nonUniqueSymbol1, Decl(uniqueSymbolReassignment.d.ts, 9, 13)) | ||
|
||
var nonUnique2: typeof nonUniqueSymbol2; | ||
>nonUnique2 : Symbol(nonUnique2, Decl(uniqueSymbolReassignment.d.ts, 5, 7)) | ||
>nonUniqueSymbol2 : Symbol(nonUniqueSymbol2, Decl(uniqueSymbolReassignment.d.ts, 10, 13)) | ||
|
||
var normalVar: string; | ||
>normalVar : Symbol(normalVar, Decl(uniqueSymbolReassignment.d.ts, 6, 7)) | ||
|
||
var symbolName: string; | ||
>symbolName : Symbol(symbolName, Decl(uniqueSymbolReassignment.d.ts, 7, 7)) | ||
} | ||
declare const nonUniqueSymbol1: unique symbol; | ||
>nonUniqueSymbol1 : Symbol(nonUniqueSymbol1, Decl(uniqueSymbolReassignment.d.ts, 9, 13)) | ||
|
||
declare const nonUniqueSymbol2: unique symbol; | ||
>nonUniqueSymbol2 : Symbol(nonUniqueSymbol2, Decl(uniqueSymbolReassignment.d.ts, 10, 13)) | ||
|
||
export { myFunction }; | ||
>myFunction : Symbol(myFunction, Decl(uniqueSymbolReassignment.d.ts, 11, 8)) | ||
|
51 changes: 51 additions & 0 deletions
51
tests/baselines/reference/uniqueSymbolReassignment.d.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,51 @@ | ||
//// [tests/cases/compiler/uniqueSymbolReassignment.d.ts] //// | ||
|
||
=== uniqueSymbolReassignment.d.ts === | ||
declare function myFunction(): void; | ||
>myFunction : typeof myFunction | ||
> : ^^^^^^^^^^^^^^^^^ | ||
|
||
declare namespace myFunction { | ||
>myFunction : typeof myFunction | ||
> : ^^^^^^^^^^^^^^^^^ | ||
|
||
const mySymbol: unique symbol; | ||
>mySymbol : unique symbol | ||
> : ^^^^^^^^^^^^^ | ||
|
||
const anotherUnique: unique symbol; | ||
>anotherUnique : unique symbol | ||
> : ^^^^^^^^^^^^^ | ||
|
||
var nonUnique1: typeof nonUniqueSymbol1; | ||
>nonUnique1 : unique symbol | ||
> : ^^^^^^^^^^^^^ | ||
>nonUniqueSymbol1 : unique symbol | ||
> : ^^^^^^^^^^^^^ | ||
|
||
var nonUnique2: typeof nonUniqueSymbol2; | ||
>nonUnique2 : unique symbol | ||
> : ^^^^^^^^^^^^^ | ||
>nonUniqueSymbol2 : unique symbol | ||
> : ^^^^^^^^^^^^^ | ||
|
||
var normalVar: string; | ||
>normalVar : string | ||
> : ^^^^^^ | ||
|
||
var symbolName: string; | ||
>symbolName : string | ||
> : ^^^^^^ | ||
} | ||
declare const nonUniqueSymbol1: unique symbol; | ||
>nonUniqueSymbol1 : unique symbol | ||
> : ^^^^^^^^^^^^^ | ||
|
||
declare const nonUniqueSymbol2: unique symbol; | ||
>nonUniqueSymbol2 : unique symbol | ||
> : ^^^^^^^^^^^^^ | ||
|
||
export { myFunction }; | ||
>myFunction : typeof myFunction | ||
> : ^^^^^^^^^^^^^^^^^ | ||
|
48 changes: 48 additions & 0 deletions
48
tests/baselines/reference/uniqueSymbolReassignment.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,48 @@ | ||
uniqueSymbolReassignment.ts(2,18): error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later. | ||
uniqueSymbolReassignment.ts(7,23): error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later. | ||
uniqueSymbolReassignment.ts(19,26): error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later. | ||
uniqueSymbolReassignment.ts(20,26): error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later. | ||
|
||
|
||
==== uniqueSymbolReassignment.ts (4 errors) ==== | ||
// This is a unique symbol (const + Symbol()) | ||
const mySymbol = Symbol('Symbols.mySymbol'); | ||
~~~~~~ | ||
!!! error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later. | ||
Akshit222 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
const Symbols = { | ||
mySymbol | ||
} as const; | ||
|
||
const anotherUnique = Symbol('symbols.anotherUnique'); | ||
~~~~~~ | ||
!!! error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later. | ||
const Symbols2 = { | ||
anotherUnique | ||
} as const; | ||
|
||
function myFunction() {} | ||
|
||
// Attach the unique ones | ||
myFunction.mySymbol = Symbols.mySymbol; | ||
myFunction.anotherUnique = Symbols2.anotherUnique; | ||
|
||
// Non-unique symbols (regular Symbol() without const) | ||
const nonUniqueSymbol1 = Symbol('nonUnique1'); | ||
~~~~~~ | ||
!!! error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later. | ||
const nonUniqueSymbol2 = Symbol('nonUnique2'); | ||
~~~~~~ | ||
!!! error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later. | ||
|
||
// Plain text variables (not symbols at all) | ||
const normalVar = "not a symbol"; | ||
const symbolName = "this contains symbol but is not one"; | ||
|
||
// Attach those as well | ||
myFunction.nonUnique1 = nonUniqueSymbol1; | ||
myFunction.nonUnique2 = nonUniqueSymbol2; | ||
myFunction.normalVar = normalVar; | ||
myFunction.symbolName = symbolName; | ||
|
||
export { myFunction }; | ||
|
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,78 @@ | ||
//// [tests/cases/compiler/uniqueSymbolReassignment.ts] //// | ||
|
||
//// [uniqueSymbolReassignment.ts] | ||
// This is a unique symbol (const + Symbol()) | ||
const mySymbol = Symbol('Symbols.mySymbol'); | ||
const Symbols = { | ||
mySymbol | ||
} as const; | ||
|
||
const anotherUnique = Symbol('symbols.anotherUnique'); | ||
const Symbols2 = { | ||
anotherUnique | ||
} as const; | ||
|
||
function myFunction() {} | ||
|
||
// Attach the unique ones | ||
myFunction.mySymbol = Symbols.mySymbol; | ||
myFunction.anotherUnique = Symbols2.anotherUnique; | ||
|
||
// Non-unique symbols (regular Symbol() without const) | ||
const nonUniqueSymbol1 = Symbol('nonUnique1'); | ||
const nonUniqueSymbol2 = Symbol('nonUnique2'); | ||
|
||
// Plain text variables (not symbols at all) | ||
const normalVar = "not a symbol"; | ||
const symbolName = "this contains symbol but is not one"; | ||
|
||
// Attach those as well | ||
myFunction.nonUnique1 = nonUniqueSymbol1; | ||
myFunction.nonUnique2 = nonUniqueSymbol2; | ||
myFunction.normalVar = normalVar; | ||
myFunction.symbolName = symbolName; | ||
|
||
export { myFunction }; | ||
|
||
|
||
//// [uniqueSymbolReassignment.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.myFunction = myFunction; | ||
// This is a unique symbol (const + Symbol()) | ||
var mySymbol = Symbol('Symbols.mySymbol'); | ||
var Symbols = { | ||
mySymbol: mySymbol | ||
}; | ||
var anotherUnique = Symbol('symbols.anotherUnique'); | ||
var Symbols2 = { | ||
anotherUnique: anotherUnique | ||
}; | ||
function myFunction() { } | ||
// Attach the unique ones | ||
myFunction.mySymbol = Symbols.mySymbol; | ||
myFunction.anotherUnique = Symbols2.anotherUnique; | ||
// Non-unique symbols (regular Symbol() without const) | ||
var nonUniqueSymbol1 = Symbol('nonUnique1'); | ||
var nonUniqueSymbol2 = Symbol('nonUnique2'); | ||
// Plain text variables (not symbols at all) | ||
var normalVar = "not a symbol"; | ||
var symbolName = "this contains symbol but is not one"; | ||
// Attach those as well | ||
myFunction.nonUnique1 = nonUniqueSymbol1; | ||
myFunction.nonUnique2 = nonUniqueSymbol2; | ||
myFunction.normalVar = normalVar; | ||
myFunction.symbolName = symbolName; | ||
|
||
|
||
//// [uniqueSymbolReassignment.d.ts] | ||
declare function myFunction(): void; | ||
declare namespace myFunction { | ||
var mySymbol: any; | ||
var anotherUnique: any; | ||
var nonUnique1: any; | ||
var nonUnique2: any; | ||
var normalVar: string; | ||
var symbolName: string; | ||
} | ||
export { myFunction }; |
90 changes: 90 additions & 0 deletions
90
tests/baselines/reference/uniqueSymbolReassignment.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,90 @@ | ||
//// [tests/cases/compiler/uniqueSymbolReassignment.ts] //// | ||
|
||
=== uniqueSymbolReassignment.ts === | ||
// This is a unique symbol (const + Symbol()) | ||
const mySymbol = Symbol('Symbols.mySymbol'); | ||
>mySymbol : Symbol(mySymbol, Decl(uniqueSymbolReassignment.ts, 1, 5)) | ||
|
||
const Symbols = { | ||
>Symbols : Symbol(Symbols, Decl(uniqueSymbolReassignment.ts, 2, 5)) | ||
|
||
mySymbol | ||
>mySymbol : Symbol(mySymbol, Decl(uniqueSymbolReassignment.ts, 2, 17)) | ||
|
||
} as const; | ||
>const : Symbol(const) | ||
|
||
const anotherUnique = Symbol('symbols.anotherUnique'); | ||
>anotherUnique : Symbol(anotherUnique, Decl(uniqueSymbolReassignment.ts, 6, 5)) | ||
|
||
const Symbols2 = { | ||
>Symbols2 : Symbol(Symbols2, Decl(uniqueSymbolReassignment.ts, 7, 5)) | ||
|
||
anotherUnique | ||
>anotherUnique : Symbol(anotherUnique, Decl(uniqueSymbolReassignment.ts, 7, 18)) | ||
|
||
} as const; | ||
>const : Symbol(const) | ||
|
||
function myFunction() {} | ||
>myFunction : Symbol(myFunction, Decl(uniqueSymbolReassignment.ts, 9, 11), Decl(uniqueSymbolReassignment.ts, 11, 24), Decl(uniqueSymbolReassignment.ts, 14, 39), Decl(uniqueSymbolReassignment.ts, 23, 57), Decl(uniqueSymbolReassignment.ts, 26, 41) ... and 2 more) | ||
|
||
// Attach the unique ones | ||
myFunction.mySymbol = Symbols.mySymbol; | ||
>myFunction.mySymbol : Symbol(myFunction.mySymbol, Decl(uniqueSymbolReassignment.ts, 11, 24)) | ||
>myFunction : Symbol(myFunction, Decl(uniqueSymbolReassignment.ts, 9, 11), Decl(uniqueSymbolReassignment.ts, 11, 24), Decl(uniqueSymbolReassignment.ts, 14, 39), Decl(uniqueSymbolReassignment.ts, 23, 57), Decl(uniqueSymbolReassignment.ts, 26, 41) ... and 2 more) | ||
>mySymbol : Symbol(myFunction.mySymbol, Decl(uniqueSymbolReassignment.ts, 11, 24)) | ||
>Symbols.mySymbol : Symbol(mySymbol, Decl(uniqueSymbolReassignment.ts, 2, 17)) | ||
>Symbols : Symbol(Symbols, Decl(uniqueSymbolReassignment.ts, 2, 5)) | ||
>mySymbol : Symbol(mySymbol, Decl(uniqueSymbolReassignment.ts, 2, 17)) | ||
|
||
myFunction.anotherUnique = Symbols2.anotherUnique; | ||
>myFunction.anotherUnique : Symbol(myFunction.anotherUnique, Decl(uniqueSymbolReassignment.ts, 14, 39)) | ||
>myFunction : Symbol(myFunction, Decl(uniqueSymbolReassignment.ts, 9, 11), Decl(uniqueSymbolReassignment.ts, 11, 24), Decl(uniqueSymbolReassignment.ts, 14, 39), Decl(uniqueSymbolReassignment.ts, 23, 57), Decl(uniqueSymbolReassignment.ts, 26, 41) ... and 2 more) | ||
>anotherUnique : Symbol(myFunction.anotherUnique, Decl(uniqueSymbolReassignment.ts, 14, 39)) | ||
>Symbols2.anotherUnique : Symbol(anotherUnique, Decl(uniqueSymbolReassignment.ts, 7, 18)) | ||
>Symbols2 : Symbol(Symbols2, Decl(uniqueSymbolReassignment.ts, 7, 5)) | ||
>anotherUnique : Symbol(anotherUnique, Decl(uniqueSymbolReassignment.ts, 7, 18)) | ||
|
||
// Non-unique symbols (regular Symbol() without const) | ||
const nonUniqueSymbol1 = Symbol('nonUnique1'); | ||
>nonUniqueSymbol1 : Symbol(nonUniqueSymbol1, Decl(uniqueSymbolReassignment.ts, 18, 5)) | ||
|
||
const nonUniqueSymbol2 = Symbol('nonUnique2'); | ||
>nonUniqueSymbol2 : Symbol(nonUniqueSymbol2, Decl(uniqueSymbolReassignment.ts, 19, 5)) | ||
|
||
// Plain text variables (not symbols at all) | ||
const normalVar = "not a symbol"; | ||
>normalVar : Symbol(normalVar, Decl(uniqueSymbolReassignment.ts, 22, 5)) | ||
|
||
const symbolName = "this contains symbol but is not one"; | ||
>symbolName : Symbol(symbolName, Decl(uniqueSymbolReassignment.ts, 23, 5)) | ||
|
||
// Attach those as well | ||
myFunction.nonUnique1 = nonUniqueSymbol1; | ||
>myFunction.nonUnique1 : Symbol(myFunction.nonUnique1, Decl(uniqueSymbolReassignment.ts, 23, 57)) | ||
>myFunction : Symbol(myFunction, Decl(uniqueSymbolReassignment.ts, 9, 11), Decl(uniqueSymbolReassignment.ts, 11, 24), Decl(uniqueSymbolReassignment.ts, 14, 39), Decl(uniqueSymbolReassignment.ts, 23, 57), Decl(uniqueSymbolReassignment.ts, 26, 41) ... and 2 more) | ||
>nonUnique1 : Symbol(myFunction.nonUnique1, Decl(uniqueSymbolReassignment.ts, 23, 57)) | ||
>nonUniqueSymbol1 : Symbol(nonUniqueSymbol1, Decl(uniqueSymbolReassignment.ts, 18, 5)) | ||
|
||
myFunction.nonUnique2 = nonUniqueSymbol2; | ||
>myFunction.nonUnique2 : Symbol(myFunction.nonUnique2, Decl(uniqueSymbolReassignment.ts, 26, 41)) | ||
>myFunction : Symbol(myFunction, Decl(uniqueSymbolReassignment.ts, 9, 11), Decl(uniqueSymbolReassignment.ts, 11, 24), Decl(uniqueSymbolReassignment.ts, 14, 39), Decl(uniqueSymbolReassignment.ts, 23, 57), Decl(uniqueSymbolReassignment.ts, 26, 41) ... and 2 more) | ||
>nonUnique2 : Symbol(myFunction.nonUnique2, Decl(uniqueSymbolReassignment.ts, 26, 41)) | ||
>nonUniqueSymbol2 : Symbol(nonUniqueSymbol2, Decl(uniqueSymbolReassignment.ts, 19, 5)) | ||
|
||
myFunction.normalVar = normalVar; | ||
>myFunction.normalVar : Symbol(myFunction.normalVar, Decl(uniqueSymbolReassignment.ts, 27, 41)) | ||
>myFunction : Symbol(myFunction, Decl(uniqueSymbolReassignment.ts, 9, 11), Decl(uniqueSymbolReassignment.ts, 11, 24), Decl(uniqueSymbolReassignment.ts, 14, 39), Decl(uniqueSymbolReassignment.ts, 23, 57), Decl(uniqueSymbolReassignment.ts, 26, 41) ... and 2 more) | ||
>normalVar : Symbol(myFunction.normalVar, Decl(uniqueSymbolReassignment.ts, 27, 41)) | ||
>normalVar : Symbol(normalVar, Decl(uniqueSymbolReassignment.ts, 22, 5)) | ||
|
||
myFunction.symbolName = symbolName; | ||
>myFunction.symbolName : Symbol(myFunction.symbolName, Decl(uniqueSymbolReassignment.ts, 28, 33)) | ||
>myFunction : Symbol(myFunction, Decl(uniqueSymbolReassignment.ts, 9, 11), Decl(uniqueSymbolReassignment.ts, 11, 24), Decl(uniqueSymbolReassignment.ts, 14, 39), Decl(uniqueSymbolReassignment.ts, 23, 57), Decl(uniqueSymbolReassignment.ts, 26, 41) ... and 2 more) | ||
>symbolName : Symbol(myFunction.symbolName, Decl(uniqueSymbolReassignment.ts, 28, 33)) | ||
>symbolName : Symbol(symbolName, Decl(uniqueSymbolReassignment.ts, 23, 5)) | ||
|
||
export { myFunction }; | ||
>myFunction : Symbol(myFunction, Decl(uniqueSymbolReassignment.ts, 31, 8)) | ||
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.