Skip to content

Commit

Permalink
more test
Browse files Browse the repository at this point in the history
  • Loading branch information
CPunisher committed Jan 12, 2025
1 parent a0c9e23 commit 26c6534
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
58 changes: 58 additions & 0 deletions crates/swc_typescript/tests/fixture/symbol-properties.snap
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 | };
`----
```
56 changes: 56 additions & 0 deletions crates/swc_typescript/tests/fixture/symbol-properties.ts
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 => {},
};
}

0 comments on commit 26c6534

Please sign in to comment.