-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
crates/swc_typescript/tests/fixture/symbol-properties.snap
This file contains 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,58 @@ | ||
```==================== .D.TS ==================== | ||
// Correct | ||
export declare const foo: { | ||
[Symbol.iterator]: () => void; | ||
[Symbol.asyncIterator]: () => Promise<void>; | ||
[globalThis.Symbol.iterator]: () => void; | ||
[Symbol.toStringTag]: string; | ||
}; | ||
export declare abstract class Foo { | ||
[Symbol.iterator](): void; | ||
[Symbol.asyncIterator](): Promise<void>; | ||
[globalThis.Symbol.iterator](): void; | ||
get [Symbol.toStringTag](): string; | ||
} | ||
// Incorrect | ||
export declare namespace Foo { | ||
const foo: { | ||
}; | ||
} | ||
export declare function bar(Symbol: { | ||
}, globalThis: { | ||
}): { | ||
}; | ||
==================== Errors ==================== | ||
x TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. | ||
,-[$DIR/tests/fixture/symbol-properties.ts:46:1] | ||
45 | export const foo = { | ||
46 | [Symbol.iterator]: (): void => {}, | ||
: ^^^^^^^^^^^^^^^^^ | ||
47 | [globalThis.Symbol.iterator]: (): void => {}, | ||
`---- | ||
x TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. | ||
,-[$DIR/tests/fixture/symbol-properties.ts:47:1] | ||
46 | [Symbol.iterator]: (): void => {}, | ||
47 | [globalThis.Symbol.iterator]: (): void => {}, | ||
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
48 | }; | ||
`---- | ||
x TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. | ||
,-[$DIR/tests/fixture/symbol-properties.ts:53:1] | ||
52 | return { | ||
53 | [Symbol.iterator]: (): void => {}, | ||
: ^^^^^^^^^^^^^^^^^ | ||
54 | [globalThis.Symbol.iterator]: (): void => {}, | ||
`---- | ||
x TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations. | ||
,-[$DIR/tests/fixture/symbol-properties.ts:54:1] | ||
53 | [Symbol.iterator]: (): void => {}, | ||
54 | [globalThis.Symbol.iterator]: (): void => {}, | ||
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
55 | }; | ||
`---- | ||
``` |
This file contains 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,56 @@ | ||
// Correct | ||
export const foo = { | ||
[Symbol.iterator]: (): void => {}, | ||
[Symbol.asyncIterator]: async (): Promise<void> => {}, | ||
[globalThis.Symbol.iterator]: (): void => {}, | ||
get [Symbol.toStringTag]() { | ||
return "foo"; | ||
}, | ||
}; | ||
|
||
export abstract class Foo { | ||
[Symbol.iterator](): void {} | ||
async [Symbol.asyncIterator](): Promise<void> {} | ||
[globalThis.Symbol.iterator](): void {} | ||
get [Symbol.toStringTag]() { | ||
return "Foo"; | ||
} | ||
} | ||
|
||
// OK because these are not exported | ||
|
||
namespace Foo { | ||
const Symbol = {}; | ||
const globalThis = {}; | ||
|
||
export const foo = { | ||
[Symbol.iterator]: (): void => {}, | ||
[globalThis.Symbol.iterator]: (): void => {}, | ||
}; | ||
} | ||
|
||
function bar(Symbol: {}, globalThis: {}) { | ||
return { | ||
[Symbol.iterator]: (): void => {}, | ||
[globalThis.Symbol.iterator]: (): void => {}, | ||
}; | ||
} | ||
|
||
// Incorrect | ||
|
||
export namespace Foo { | ||
const Symbol = {}; | ||
const globalThis = {}; | ||
|
||
export const foo = { | ||
[Symbol.iterator]: (): void => {}, | ||
[globalThis.Symbol.iterator]: (): void => {}, | ||
}; | ||
} | ||
|
||
export function bar(Symbol: {}, globalThis: {}) { | ||
return { | ||
[Symbol.iterator]: (): void => {}, | ||
[globalThis.Symbol.iterator]: (): void => {}, | ||
}; | ||
} |