file_path
stringlengths
3
280
file_language
stringclasses
66 values
content
stringlengths
1
1.04M
repo_name
stringlengths
5
92
repo_stars
int64
0
154k
repo_description
stringlengths
0
402
repo_primary_language
stringclasses
108 values
developer_username
stringlengths
1
25
developer_name
stringlengths
0
30
developer_company
stringlengths
0
82
crates/swc_ecma_parser/tests/tsc/unionTypeReduction.ts
TypeScript
interface I2 { (): number; (q): boolean; } interface I3 { (): number; } var i2: I2, i3: I3; var e1: I2 | I3; var e2 = i2 || i3; // Type of e2 immediately reduced to I3 var r1 = e1(); // Type of e1 reduced to I3 upon accessing property or signature var r2 = e2();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/unionTypeReduction2.ts
TypeScript
// @strict: true function f1(x: { f(): void }, y: { f(x?: string): void }) { let z = !!true ? x : y; // { f(x?: string): void } z.f(); z.f('hello'); } function f2(x: { f(x: string | undefined): void }, y: { f(x?: string): void }) { let z = !!true ? x : y; // { f(x?: string): void } z.f(); z.f('hello'); } function f3(x: () => void, y: (x?: string) => void) { let f = !!true ? x : y; // (x?: string) => void f(); f('hello'); } function f4(x: (x: string | undefined) => void, y: (x?: string) => void) { let f = !!true ? x : y; // (x?: string) => void f(); f('hello'); } function f5(x: (x: string | undefined) => void, y: (x?: 'hello') => void) { let f = !!true ? x : y; // (x?: 'hello') => void f(); f('hello'); } function f6(x: (x: 'hello' | undefined) => void, y: (x?: string) => void) { let f = !!true ? x : y; // (x: 'hello' | undefined) => void f(); // Error f('hello'); } type A = { f(): void; } type B = { f(x?: string): void; g(): void; } function f11(a: A, b: B) { let z = !!true ? a : b; // A | B z.f(); z.f('hello'); } // Repro from #35414 interface ReturnVal { something(): void; } const k: ReturnVal = { something() { } } declare const val: ReturnVal; function run(options: { something?(b?: string): void }) { const something = options.something ?? val.something; something(''); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/unionTypeWithIndexSignature.ts
TypeScript
// @target: esnext // @strict: true type Two = { foo: { bar: true }, baz: true } | { [s: string]: string }; declare var u: Two u.foo = 'bye' u.baz = 'hi' type Three = { foo: number } | { [s: string]: string } | { [s: string]: boolean }; declare var v: Three v.foo = false type Missing = { foo: number, bar: true } | { [s: string]: string } | { foo: boolean } declare var m: Missing m.foo = 'hi' m.bar type RO = { foo: number } | { readonly [s: string]: string } declare var ro: RO ro.foo = 'not allowed' type Num = { '0': string } | { [n: number]: number } declare var num: Num num[0] = 1 num['0'] = 'ok' const sym = Symbol() type Both = { s: number, '0': number, [sym]: boolean } | { [n: number]: number, [s: string]: string | number } declare var both: Both both['s'] = 'ok' both[0] = 1 both[1] = 0 // not ok both[0] = 'not ok' both[sym] = 'not ok'
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/unionTypesAssignability.ts
TypeScript
var unionNumberString: number | string; class C { } class D extends C { foo1() { } } class E extends C { foo2() { } } var unionDE: D | E; var num: number; var str: string; var c: C; var d: D; var e: E; // A union type U is assignable to a type T if each type in U is assignable to T c = d; c = e; c = unionDE; // ok d = d; d = e; d = unionDE; // error e is not assignable to d e = d; e = e; e = unionDE; // error d is not assignable to e num = num; num = str; num = unionNumberString; // error string is not assignable to number str = num; str = str; str = unionNumberString; // error since number is not assignable to string // A type T is assignable to a union type U if T is assignable to any type in U d = c; e = c; unionDE = c; // error since C is not assinable to either D or E d = d; e = d; unionDE = d; // ok d = e; e = e; unionDE = e; // ok num = num; str = num; unionNumberString = num; // ok num = str; str = str; unionNumberString = str; // ok // Any var anyVar: any; anyVar = unionDE; anyVar = unionNumberString; unionDE = anyVar; unionNumberString = anyVar; // null unionDE = null; unionNumberString = null; // undefined unionDE = undefined; unionNumberString = undefined; // type parameters function foo<T, U>(t: T, u: U) { t = u; // error u = t; // error var x : T | U; x = t; // ok x = u; // ok x = undefined; t = x; // error U not assignable to T u = x; // error T not assignable to U }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/unionsOfTupleTypes1.ts
TypeScript
// @strict: true type T1 = [string, number]; type T2 = [boolean] | [string, number]; type T3 = [string, ...number[]]; type T4 = [boolean] | [string, ...number[]]; type T10 = T1[0]; // string type T11 = T1[1]; // number type T12 = T1[2]; // undefined type T1N = T1[number]; // string | number type T20 = T2[0]; // string | boolean type T21 = T2[1]; // number | undefined type T22 = T2[2]; // undefined type T2N = T2[number]; // string | number | boolean type T30 = T3[0]; // string type T31 = T3[1]; // number type T32 = T3[2]; // number type T3N = T3[number]; // string | number type T40 = T4[0]; // string | boolean type T41 = T4[1]; // number | undefined type T42 = T4[2]; // number | undefined type T4N = T4[number]; // string | number | boolean function f1(t1: T1, t2: T2, t3: T3, t4: T4, x: number) { let [d10, d11, d12] = t1; // string, number let [d20, d21, d22] = t2; // string | boolean, number | undefined let [d30, d31, d32] = t3; // string, number, number let [d40, d41, d42] = t4; // string | boolean, number | undefined, number | undefined [d10, d11, d12] = t1; [d20, d21, d22] = t2; [d30, d31, d32] = t3; [d40, d41, d42] = t4; let t10 = t1[0]; // string let t11 = t1[1]; // number let t12 = t1[2]; // undefined let t1x = t1[x]; // string | number let t20 = t2[0]; // string | boolean let t21 = t2[1]; // number | undefined let t22 = t2[2]; // undefined let t2x = t2[x]; // string | number | boolean let t30 = t3[0]; // string let t31 = t3[1]; // number let t32 = t3[2]; // number let t3x = t3[x]; // string | number let t40 = t4[0]; // string | boolean let t41 = t4[1]; // number | undefined let t42 = t4[2]; // number | undefined let t4x = t4[x]; // string | number | boolean t1[1] = 42; t2[1] = 42; t3[1] = 42; t4[1] = 42; } // Repro from #27543 type Unioned = [string] | [string, number]; const ex: Unioned = ["hi"] as Unioned; const [x, y] = ex;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/uniqueSymbols.ts
TypeScript
// @target: esnext // @lib: esnext // @declaration: false // @useDefineForClassFields: false // declarations with call initializer const constCall = Symbol(); let letCall = Symbol(); var varCall = Symbol(); // ambient declaration with type declare const constType: unique symbol; // declaration with type and call initializer const constTypeAndCall: unique symbol = Symbol(); // declaration from initializer const constInitToConstCall = constCall; const constInitToLetCall = letCall; const constInitToVarCall = varCall; const constInitToConstDeclAmbient = constType; let letInitToConstCall = constCall; let letInitToLetCall = letCall; let letInitToVarCall = varCall; let letInitToConstDeclAmbient = constType; var varInitToConstCall = constCall; var varInitToLetCall = letCall; var varInitToVarCall = varCall; var varInitToConstDeclAmbient = constType; // declaration from initializer with type query const constInitToConstCallWithTypeQuery: typeof constCall = constCall; const constInitToConstDeclAmbientWithTypeQuery: typeof constType = constType; // assignment from any // https://github.com/Microsoft/TypeScript/issues/29108 const fromAny: unique symbol = {} as any; // function return inference function funcReturnConstCall() { return constCall; } function funcReturnLetCall() { return letCall; } function funcReturnVarCall() { return varCall; } // function return value with type query function funcReturnConstCallWithTypeQuery(): typeof constCall { return constCall; } // generator function yield inference function* genFuncYieldConstCall() { yield constCall; } function* genFuncYieldLetCall() { yield letCall; } function* genFuncYieldVarCall() { yield varCall; } // generator function yield with return type query function* genFuncYieldConstCallWithTypeQuery(): IterableIterator<typeof constCall> { yield constCall; } // async function return inference async function asyncFuncReturnConstCall() { return constCall; } async function asyncFuncReturnLetCall() { return letCall; } async function asyncFuncReturnVarCall() { return varCall; } // async generator function yield inference async function* asyncGenFuncYieldConstCall() { yield constCall; } async function* asyncGenFuncYieldLetCall() { yield letCall; } async function* asyncGenFuncYieldVarCall() { yield varCall; } // classes class C { static readonly readonlyStaticCall = Symbol(); static readonly readonlyStaticType: unique symbol; static readonly readonlyStaticTypeAndCall: unique symbol = Symbol(); static readwriteStaticCall = Symbol(); readonly readonlyCall = Symbol(); readwriteCall = Symbol(); } declare const c: C; const constInitToCReadonlyStaticCall = C.readonlyStaticCall; const constInitToCReadonlyStaticType = C.readonlyStaticType; const constInitToCReadonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; const constInitToCReadwriteStaticCall = C.readwriteStaticCall; const constInitToCReadonlyStaticCallWithTypeQuery: typeof C.readonlyStaticCall = C.readonlyStaticCall; const constInitToCReadonlyStaticTypeWithTypeQuery: typeof C.readonlyStaticType = C.readonlyStaticType; const constInitToCReadonlyStaticTypeAndCallWithTypeQuery: typeof C.readonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; const constInitToCReadwriteStaticCallWithTypeQuery: typeof C.readwriteStaticCall = C.readwriteStaticCall; const constInitToCReadonlyCall = c.readonlyCall; const constInitToCReadwriteCall = c.readwriteCall; const constInitToCReadonlyCallWithTypeQuery: typeof c.readonlyCall = c.readonlyCall; const constInitToCReadwriteCallWithTypeQuery: typeof c.readwriteCall = c.readwriteCall; const constInitToCReadonlyCallWithIndexedAccess: C["readonlyCall"] = c.readonlyCall; const constInitToCReadwriteCallWithIndexedAccess: C["readwriteCall"] = c.readwriteCall; // interfaces interface I { readonly readonlyType: unique symbol; } declare const i: I; const constInitToIReadonlyType = i.readonlyType; const constInitToIReadonlyTypeWithTypeQuery: typeof i.readonlyType = i.readonlyType; const constInitToIReadonlyTypeWithIndexedAccess: I["readonlyType"] = i.readonlyType; // type literals type L = { readonly readonlyType: unique symbol; nested: { readonly readonlyNestedType: unique symbol; } }; declare const l: L; const constInitToLReadonlyType = l.readonlyType; const constInitToLReadonlyNestedType = l.nested.readonlyNestedType; const constInitToLReadonlyTypeWithTypeQuery: typeof l.readonlyType = l.readonlyType; const constInitToLReadonlyNestedTypeWithTypeQuery: typeof l.nested.readonlyNestedType = l.nested.readonlyNestedType; const constInitToLReadonlyTypeWithIndexedAccess: L["readonlyType"] = l.readonlyType; const constInitToLReadonlyNestedTypeWithIndexedAccess: L["nested"]["readonlyNestedType"] = l.nested.readonlyNestedType; // type argument inference const promiseForConstCall = Promise.resolve(constCall); const arrayOfConstCall = [constCall]; // unique symbol widening in expressions declare const s: unique symbol; declare namespace N { const s: unique symbol; } declare const o: { [s]: "a", [N.s]: "b" }; declare function f<T>(x: T): T; declare function g(x: typeof s): void; declare function g(x: typeof N.s): void; // widening positions // argument inference f(s); f(N.s); f(N["s"]); // array literal elements [s]; [N.s]; [N["s"]]; // property assignments/methods const o2 = { a: s, b: N.s, c: N["s"], method1() { return s; }, async method2() { return s; }, async * method3() { yield s; }, * method4() { yield s; }, method5(p = s) { return p; }, }; // property initializers class C0 { static readonly a = s; static readonly b = N.s; static readonly c = N["s"]; static d = s; static e = N.s; static f = N["s"]; readonly a = s; readonly b = N.s; readonly c = N["s"]; d = s; e = N.s; f = N["s"]; method1() { return s; } async method2() { return s; } async * method3() { yield s; } * method4() { yield s; } method5(p = s) { return p; } } // non-widening positions // element access o[s]; o[N.s]; o[N["s"]]; // arguments (no-inference) f<typeof s>(s); f<typeof N.s>(N.s); f<typeof N.s>(N["s"]); g(s); g(N.s); g(N["s"]); // falsy expressions s || ""; N.s || ""; N["s"] || ""; // conditionals Math.random() * 2 ? s : "a"; Math.random() * 2 ? N.s : "a"; Math.random() * 2 ? N["s"] : "a"; // computed property names ({ [s]: "a", [N.s]: "b", }); class C1 { static [s]: "a"; static [N.s]: "b"; [s]: "a"; [N.s]: "b"; } // contextual types interface Context { method1(): typeof s; method2(): Promise<typeof s>; method3(): AsyncIterableIterator<typeof s>; method4(): IterableIterator<typeof s>; method5(p?: typeof s): typeof s; } const o3: Context = { method1() { return s; // return type should not widen due to contextual type }, async method2() { return s; // return type should not widen due to contextual type }, async * method3() { yield s; // yield type should not widen due to contextual type }, * method4() { yield s; // yield type should not widen due to contextual type }, method5(p = s) { // parameter should not widen due to contextual type return p; }, }; // allowed when not emitting declarations const o4 = { method1(p: typeof s): typeof s { return p; }, method2(p: I["readonlyType"]): I["readonlyType"] { return p; } }; const ce0 = class { method1(p: typeof s): typeof s { return p; } method2(p: I["readonlyType"]): I["readonlyType"] { return p; } }; function funcInferredReturnType(obj: { method(p: typeof s): void }) { return obj; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/uniqueSymbolsDeclarations.ts
TypeScript
// @target: esnext // @lib: esnext // @declaration: true // @useDefineForClassFields: false // declarations with call initializer const constCall = Symbol(); let letCall = Symbol(); var varCall = Symbol(); // ambient declaration with type declare const constType: unique symbol; // declaration with type and call initializer const constTypeAndCall: unique symbol = Symbol(); // declaration from initializer const constInitToConstCall = constCall; const constInitToLetCall = letCall; const constInitToVarCall = varCall; const constInitToConstDeclAmbient = constType; let letInitToConstCall = constCall; let letInitToLetCall = letCall; let letInitToVarCall = varCall; let letInitToConstDeclAmbient = constType; var varInitToConstCall = constCall; var varInitToLetCall = letCall; var varInitToVarCall = varCall; var varInitToConstDeclAmbient = constType; // declaration from initializer with type query const constInitToConstCallWithTypeQuery: typeof constCall = constCall; const constInitToConstDeclAmbientWithTypeQuery: typeof constType = constType; // function return inference function funcReturnConstCall() { return constCall; } function funcReturnLetCall() { return letCall; } function funcReturnVarCall() { return varCall; } // function return value with type query function funcReturnConstCallWithTypeQuery(): typeof constCall { return constCall; } // generator function yield inference function* genFuncYieldConstCall() { yield constCall; } function* genFuncYieldLetCall() { yield letCall; } function* genFuncYieldVarCall() { yield varCall; } // generator function yield with return type query function* genFuncYieldConstCallWithTypeQuery(): IterableIterator<typeof constCall> { yield constCall; } // async function return inference async function asyncFuncReturnConstCall() { return constCall; } async function asyncFuncReturnLetCall() { return letCall; } async function asyncFuncReturnVarCall() { return varCall; } // async generator function yield inference async function* asyncGenFuncYieldConstCall() { yield constCall; } async function* asyncGenFuncYieldLetCall() { yield letCall; } async function* asyncGenFuncYieldVarCall() { yield varCall; } // classes class C { static readonly readonlyStaticCall = Symbol(); static readonly readonlyStaticType: unique symbol; static readonly readonlyStaticTypeAndCall: unique symbol = Symbol(); static readwriteStaticCall = Symbol(); readonly readonlyCall = Symbol(); readwriteCall = Symbol(); } declare const c: C; const constInitToCReadonlyStaticCall = C.readonlyStaticCall; const constInitToCReadonlyStaticType = C.readonlyStaticType; const constInitToCReadonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; const constInitToCReadwriteStaticCall = C.readwriteStaticCall; const constInitToCReadonlyStaticCallWithTypeQuery: typeof C.readonlyStaticCall = C.readonlyStaticCall; const constInitToCReadonlyStaticTypeWithTypeQuery: typeof C.readonlyStaticType = C.readonlyStaticType; const constInitToCReadonlyStaticTypeAndCallWithTypeQuery: typeof C.readonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; const constInitToCReadwriteStaticCallWithTypeQuery: typeof C.readwriteStaticCall = C.readwriteStaticCall; const constInitToCReadonlyCall = c.readonlyCall; const constInitToCReadwriteCall = c.readwriteCall; const constInitToCReadonlyCallWithTypeQuery: typeof c.readonlyCall = c.readonlyCall; const constInitToCReadwriteCallWithTypeQuery: typeof c.readwriteCall = c.readwriteCall; const constInitToCReadonlyCallWithIndexedAccess: C["readonlyCall"] = c.readonlyCall; const constInitToCReadwriteCallWithIndexedAccess: C["readwriteCall"] = c.readwriteCall; // interfaces interface I { readonly readonlyType: unique symbol; } declare const i: I; const constInitToIReadonlyType = i.readonlyType; const constInitToIReadonlyTypeWithTypeQuery: typeof i.readonlyType = i.readonlyType; const constInitToIReadonlyTypeWithIndexedAccess: I["readonlyType"] = i.readonlyType; // type literals type L = { readonly readonlyType: unique symbol; nested: { readonly readonlyNestedType: unique symbol; } }; declare const l: L; const constInitToLReadonlyType = l.readonlyType; const constInitToLReadonlyNestedType = l.nested.readonlyNestedType; const constInitToLReadonlyTypeWithTypeQuery: typeof l.readonlyType = l.readonlyType; const constInitToLReadonlyNestedTypeWithTypeQuery: typeof l.nested.readonlyNestedType = l.nested.readonlyNestedType; const constInitToLReadonlyTypeWithIndexedAccess: L["readonlyType"] = l.readonlyType; const constInitToLReadonlyNestedTypeWithIndexedAccess: L["nested"]["readonlyNestedType"] = l.nested.readonlyNestedType; // type argument inference const promiseForConstCall = Promise.resolve(constCall); const arrayOfConstCall = [constCall]; // unique symbol widening in expressions declare const s: unique symbol; declare namespace N { const s: unique symbol; } declare const o: { [s]: "a", [N.s]: "b" }; declare function f<T>(x: T): T; declare function g(x: typeof s): void; declare function g(x: typeof N.s): void; // widening positions // argument inference f(s); f(N.s); f(N["s"]); // array literal elements [s]; [N.s]; [N["s"]]; // property assignments/methods const o2 = { a: s, b: N.s, c: N["s"], method1() { return s; }, async method2() { return s; }, async * method3() { yield s; }, * method4() { yield s; }, method5(p = s) { return p; } }; // property initializers class C0 { static readonly a = s; static readonly b = N.s; static readonly c = N["s"]; static d = s; static e = N.s; static f = N["s"]; readonly a = s; readonly b = N.s; readonly c = N["s"]; d = s; e = N.s; f = N["s"]; method1() { return s; } async method2() { return s; } async * method3() { yield s; } * method4() { yield s; } method5(p = s) { return p; } } // non-widening positions // element access o[s]; o[N.s]; o[N["s"]]; // arguments (no-inference) f<typeof s>(s); f<typeof N.s>(N.s); f<typeof N.s>(N["s"]); g(s); g(N.s); g(N["s"]); // falsy expressions s || ""; N.s || ""; N["s"] || ""; // conditionals Math.random() * 2 ? s : "a"; Math.random() * 2 ? N.s : "a"; Math.random() * 2 ? N["s"] : "a"; // computed property names ({ [s]: "a", [N.s]: "b", }); class C1 { static [s]: "a"; static [N.s]: "b"; [s]: "a"; [N.s]: "b"; } // contextual types interface Context { method1(): typeof s; method2(): Promise<typeof s>; method3(): AsyncIterableIterator<typeof s>; method4(): IterableIterator<typeof s>; method5(p?: typeof s): typeof s; } const o4: Context = { method1() { return s; // return type should not widen due to contextual type }, async method2() { return s; // return type should not widen due to contextual type }, async * method3() { yield s; // yield type should not widen due to contextual type }, * method4() { yield s; // yield type should not widen due to contextual type }, method5(p = s) { // parameter should not widen due to contextual type return p; } };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/uniqueSymbolsDeclarationsErrors.ts
TypeScript
// @target: esnext // @lib: esnext // @module: commonjs // @declaration: true // @useDefineForClassFields: false declare const s: unique symbol; interface I { readonly readonlyType: unique symbol; } // not allowed when emitting declarations export const obj = { method1(p: typeof s): typeof s { return p; }, method2(p: I["readonlyType"]): I["readonlyType"] { return p; } }; export const classExpression = class { method1(p: typeof s): typeof s { return p; } method2(p: I["readonlyType"]): I["readonlyType"] { return p; } }; export function funcInferredReturnType(obj: { method(p: typeof s): void }) { return obj; } export interface InterfaceWithPrivateNamedProperties { [s]: any; } export interface InterfaceWithPrivateNamedMethods { [s](): any; } export type TypeLiteralWithPrivateNamedProperties = { [s]: any; } export type TypeLiteralWithPrivateNamedMethods = { [s](): any; } export class ClassWithPrivateNamedProperties { [s]: any; static [s]: any; } export class ClassWithPrivateNamedMethods { [s]() {} static [s]() {} } export class ClassWithPrivateNamedAccessors { get [s](): any { return undefined; } set [s](v: any) { } static get [s](): any { return undefined; } static set [s](v: any) { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/uniqueSymbolsDeclarationsInJs.ts
TypeScript
// @target: esnext // @lib: esnext // @declaration: true // @allowJs: true // @checkJs: true // @filename: uniqueSymbolsDeclarationsInJs.js // @outFile: uniqueSymbolsDeclarationsInJs-out.js // @useDefineForClassFields: false // classes class C { /** * @readonly */ static readonlyStaticCall = Symbol(); /** * @type {unique symbol} * @readonly */ static readonlyStaticType; /** * @type {unique symbol} * @readonly */ static readonlyStaticTypeAndCall = Symbol(); static readwriteStaticCall = Symbol(); /** * @readonly */ readonlyCall = Symbol(); readwriteCall = Symbol(); } /** @type {unique symbol} */ const a = Symbol();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/uniqueSymbolsDeclarationsInJsErrors.ts
TypeScript
// @target: esnext // @lib: esnext // @declaration: true // @allowJs: true // @checkJs: true // @filename: uniqueSymbolsDeclarationsInJsErrors.js // @outFile: uniqueSymbolsDeclarationsInJsErrors-out.js // @useDefineForClassFields: false class C { /** * @type {unique symbol} */ static readwriteStaticType; /** * @type {unique symbol} * @readonly */ static readonlyType; /** * @type {unique symbol} */ static readwriteType; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/unknownControlFlow.ts
TypeScript
// @strict: true // @declaration: true type T01 = {} & string; // {} & string type T02 = {} & 'a'; // 'a' type T03 = {} & object; // object type T04 = {} & { x: number }; // { x: number } type T05 = {} & null; // never type T06 = {} & undefined; // never type T07 = undefined & void; // undefined type T10 = string & {}; // Specially preserved type T11 = number & {}; // Specially preserved type T12 = bigint & {}; // Specially preserved type ThisNode = {}; type ThatNode = {}; type ThisOrThatNode = ThisNode | ThatNode; function f01(u: unknown) { let x1: {} = u; // Error let x2: {} | null | undefined = u; let x3: {} | { x: string } | null | undefined = u; let x4: ThisOrThatNode | null | undefined = u; } function f10(x: unknown) { if (x) { x; // {} } else { x; // unknown } if (!x) { x; // unknown } else { x; // {} } } function f11<T>(x: T) { if (x) { x; // T & {} } else { x; // T } if (!x) { x; // T } else { x; // T & {} } } function f12<T extends {}>(x: T) { if (x) { x; // T } else { x; // T } } function f20(x: unknown) { if (x !== undefined) { x; // {} | null } else { x; // undefined } if (x !== null) { x; // {} | undefined } else { x; // null } if (x !== undefined && x !== null) { x; // {} } else { x; // null | undefined } if (x != undefined) { x; // {} } else { x; // null | undefined } if (x != null) { x; // {} } else { x; // null | undefined } } function f21<T>(x: T) { if (x !== undefined) { x; // T & ({} | null) } else { x; // T } if (x !== null) { x; // T & ({} | undefined) } else { x; // T } if (x !== undefined && x !== null) { x; // T & {} } else { x; // T } if (x != undefined) { x; // T & {} } else { x; // T } if (x != null) { x; // T & {} } else { x; // T } } function f22<T extends {} | undefined>(x: T) { if (x !== undefined) { x; // T & {} } else { x; // T } if (x !== null) { x; // T } else { x; // T } if (x !== undefined && x !== null) { x; // T & {} } else { x; // T } if (x != undefined) { x; // T & {} } else { x; // T } if (x != null) { x; // T & {} } else { x; // T } } function f23<T>(x: T | undefined | null) { if (x !== undefined) { x; // T & {} | null } if (x !== null) { x; // T & {} | undefined } if (x != undefined) { x; // T & {} } if (x != null) { x; // T & {} } } function f30(x: {}) { if (typeof x === "object") { x; // object } } function f31<T>(x: T) { if (typeof x === "object") { x; // T & object | T & null } if (x && typeof x === "object") { x; // T & object } if (typeof x === "object" && x) { x; // T & object } } function f32<T extends {} | undefined>(x: T) { if (typeof x === "object") { x; // T & object } } function possiblyNull<T>(x: T) { return !!true ? x : null; // T | null } function possiblyUndefined<T>(x: T) { return !!true ? x : undefined; // T | undefined } function possiblyNullOrUndefined<T>(x: T) { return possiblyUndefined(possiblyNull(x)); // T | null | undefined } function ensureNotNull<T>(x: T) { if (x === null) throw Error(); return x; // T & ({} | undefined) } function ensureNotUndefined<T>(x: T) { if (x === undefined) throw Error(); return x; // T & ({} | null) } function ensureNotNullOrUndefined<T>(x: T) { return ensureNotUndefined(ensureNotNull(x)); // T & {} } function f40(a: string | undefined, b: number | null | undefined) { let a1 = ensureNotNullOrUndefined(a); // string let b1 = ensureNotNullOrUndefined(b); // number } type QQ<T> = NonNullable<NonNullable<NonNullable<T>>>; function f41<T>(a: T) { let a1 = ensureNotUndefined(ensureNotNull(a)); // T & {} let a2 = ensureNotNull(ensureNotUndefined(a)); // T & {} let a3 = ensureNotNull(ensureNotNull(a)); // T & {} | T & undefined let a4 = ensureNotUndefined(ensureNotUndefined(a)); // T & {} | T & null let a5 = ensureNotNullOrUndefined(ensureNotNullOrUndefined(a)); // T & {} let a6 = ensureNotNull(possiblyNullOrUndefined(a)); // T & {} | undefined let a7 = ensureNotUndefined(possiblyNullOrUndefined(a)); // T & {} | null let a8 = ensureNotNull(possiblyUndefined(a)); // T & {} | undefined let a9 = ensureNotUndefined(possiblyNull(a)); // T & {} | null } // Repro from #48468 function deepEquals<T>(a: T, b: T): boolean { if (typeof a !== 'object' || typeof b !== 'object' || !a || !b) { return false; } if (Array.isArray(a) || Array.isArray(b)) { return false; } if (Object.keys(a).length !== Object.keys(b).length) { // Error here return false; } return true; } // Repro from #49386 function foo<T>(x: T | null) { let y = x; if (y !== null) { y; } } // We allow an unconstrained object of a generic type `T` to be indexed by a key of type `keyof T` // without a check that the object is non-undefined and non-null. This is safe because `keyof T` // is `never` (meaning no possible keys) for any `T` that includes `undefined` or `null`. function ff1<T>(t: T, k: keyof T) { t[k]; } function ff2<T>(t: T & {}, k: keyof T) { t[k]; } function ff3<T>(t: T, k: keyof (T & {})) { t[k]; // Error } function ff4<T>(t: T & {}, k: keyof (T & {})) { t[k]; } ff1(null, 'foo'); // Error ff2(null, 'foo'); // Error ff3(null, 'foo'); ff4(null, 'foo'); // Error // Repro from #49681 type Foo = { [key: string]: unknown }; type NullableFoo = Foo | undefined; type Bar<T extends NullableFoo> = NonNullable<T>[string]; // Generics and intersections with {} function fx0<T>(value: T & ({} | null)) { if (value === 42) { value; // T & {} } else { value; // T & ({} | null) } } function fx1<T extends unknown>(value: T & ({} | null)) { if (value === 42) { value; // T & {} } else { value; // T & ({} | null) } } function fx2<T extends {}>(value: T & ({} | null)) { if (value === 42) { value; // T & {} } else { value; // T & ({} | null) } } function fx3<T extends {} | undefined>(value: T & ({} | null)) { if (value === 42) { value; // T & {} } else { value; // T & ({} | null) } } function fx4<T extends {} | null>(value: T & ({} | null)) { if (value === 42) { value; // T & {} } else { value; // T & ({} | null) } } function fx5<T extends {} | null | undefined>(value: T & ({} | null)) { if (value === 42) { value; // T & {} } else { value; // T & ({} | null) } } // Double-equals narrowing function fx10(x: string | number, y: number) { if (x == y) { x; // string | number } else { x; // string | number } if (x != y) { x; // string | number } else { x; // string | number } } // Repros from #50706 function SendBlob(encoding: unknown) { if (encoding !== undefined && encoding !== 'utf8') { throw new Error('encoding'); } encoding; }; function doSomething1<T extends unknown>(value: T): T { if (value === undefined) { return value; } if (value === 42) { throw Error('Meaning of life value'); } return value; } function doSomething2(value: unknown): void { if (value === undefined) { return; } if (value === 42) { value; } } // Repro from #51009 type TypeA = { A: 'A', B: 'B', } type TypeB = { A: 'A', B: 'B', C: 'C', } type R<T extends keyof TypeA> = T extends keyof TypeB ? [TypeA[T], TypeB[T]] : never; type R2<T extends PropertyKey> = T extends keyof TypeA ? T extends keyof TypeB ? [TypeA[T], TypeB[T]] : never : never; // Repro from #51041 type AB = "A" | "B"; function x<T_AB extends AB>(x: T_AB & undefined, y: any) { let r2: never = y as T_AB & undefined; } // Repro from #51538 type Left = 'left'; type Right = 'right' & { right: 'right' }; type Either = Left | Right; function assertNever(v: never): never { throw new Error('never'); } function fx20(value: Either) { if (value === 'left') { const foo: 'left' = value; } else if (value === 'right') { const bar: 'right' = value; } else { assertNever(value); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/unknownType1.ts
TypeScript
// @strict: true // In an intersection everything absorbs unknown type T00 = unknown & null; // null type T01 = unknown & undefined; // undefined type T02 = unknown & null & undefined; // never type T03 = unknown & string; // string type T04 = unknown & string[]; // string[] type T05 = unknown & unknown; // unknown type T06 = unknown & any; // any // In a union an unknown absorbs everything type T10 = unknown | null; // unknown type T11 = unknown | undefined; // unknown type T12 = unknown | null | undefined; // unknown type T13 = unknown | string; // unknown type T14 = unknown | string[]; // unknown type T15 = unknown | unknown; // unknown type T16 = unknown | any; // any // Type variable and unknown in union and intersection type T20<T> = T & {}; // T & {} type T21<T> = T | {}; // T | {} type T22<T> = T & unknown; // T type T23<T> = T | unknown; // unknown // unknown in conditional types type T30<T> = unknown extends T ? true : false; // Deferred type T31<T> = T extends unknown ? true : false; // Deferred (so it distributes) type T32<T> = never extends T ? true : false; // true type T33<T> = T extends never ? true : false; // Deferred type T35<T> = T extends unknown ? { x: T } : false; type T36 = T35<string | number>; // { x: string } | { x: number } type T37 = T35<any>; // { x: any } type T38 = T35<unknown>; // { x: unknown } // keyof unknown type T40 = keyof any; // string | number | symbol type T41 = keyof unknown; // never // Only equality operators are allowed with unknown function f10(x: unknown) { x == 5; x !== 10; x >= 0; // Error x.foo; // Error x[10]; // Error x(); // Error x + 1; // Error x * 2; // Error -x; // Error +x; // Error } // No property accesses, element accesses, or function calls function f11(x: unknown) { x.foo; // Error x[5]; // Error x(); // Error new x(); // Error } // typeof, instanceof, and user defined type predicates declare function isFunction(x: unknown): x is Function; function f20(x: unknown) { if (typeof x === "string" || typeof x === "number") { x; // string | number } if (x instanceof Error) { x; // Error } if (isFunction(x)) { x; // Function } } // Homomorphic mapped type over unknown type T50<T> = { [P in keyof T]: number }; type T51 = T50<any>; // { [x: string]: number } type T52 = T50<unknown>; // {} // Anything is assignable to unknown function f21<T>(pAny: any, pNever: never, pT: T) { let x: unknown; x = 123; x = "hello"; x = [1, 2, 3]; x = new Error(); x = x; x = pAny; x = pNever; x = pT; } // unknown assignable only to itself and any function f22(x: unknown) { let v1: any = x; let v2: unknown = x; let v3: object = x; // Error let v4: string = x; // Error let v5: string[] = x; // Error let v6: {} = x; // Error let v7: {} | null | undefined = x; // Error } // Type parameter 'T extends unknown' not related to object function f23<T extends unknown>(x: T) { let y: object = x; // Error } // Anything fresh but primitive assignable to { [x: string]: unknown } function f24(x: { [x: string]: unknown }) { x = {}; x = { a: 5 }; x = [1, 2, 3]; // Error x = 123; // Error } // Locals of type unknown always considered initialized function f25() { let x: unknown; let y = x; } // Spread of unknown causes result to be unknown function f26(x: {}, y: unknown, z: any) { let o1 = { a: 42, ...x }; // { a: number } let o2 = { a: 42, ...x, ...y }; // unknown let o3 = { a: 42, ...x, ...y, ...z }; // any let o4 = { a: 42, ...z }; // any } // Functions with unknown return type don't need return expressions function f27(): unknown { } // Rest type cannot be created from unknown function f28(x: unknown) { let { ...a } = x; // Error } // Class properties of type unknown don't need definite assignment class C1 { a: string; // Error b: unknown; c: any; } // Type parameter with explicit 'unknown' constraint not assignable to '{}' function f30<T, U extends unknown>(t: T, u: U) { let x: {} = t; let y: {} = u; } // Repro from #26796 type Test1 = [unknown] extends [{}] ? true : false; // false type IsDefinitelyDefined<T extends unknown> = [T] extends [{}] ? true : false; type Test2 = IsDefinitelyDefined<unknown>; // false function oops<T extends unknown>(arg: T): {} { return arg; // Error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/unknownType2.ts
TypeScript
// @strict: true type isUnknown<T> = unknown extends T ? true : false; type isTrue<T extends true> = T; type SomeResponse = 'yes' | 'no' | 'idk'; let validate: (x: unknown) => SomeResponse = x => (x === 'yes' || x === 'no') ? x : 'idk'; // No error const u: unknown = undefined; declare const symb: unique symbol; declare const symbNonUnique: symbol; if (u === 5) { const y = u.toString(10); } if (u === true || u === false) { const someBool: boolean = u; } if (u === undefined) { const undef: undefined = u; } if (u === null) { const someNull: null = u; } if (u === symb) { const symbolAlias: typeof symb = u; } if (!(u === 42)) { type A = isTrue<isUnknown<typeof u>> } if (u !== 42) { type B = isTrue<isUnknown<typeof u>> } if (u == 42) { type C = isTrue<isUnknown<typeof u>> } if (u == true) { type D = isTrue<isUnknown<typeof u>> } if (u == Object) { type E = isTrue<isUnknown<typeof u>> } declare const aString: string; declare const aBoolean: boolean; declare const aNumber: number; declare const anObject: object; declare const anObjectLiteral: { x: number }; declare const aUnion: { x: number } | { y: string }; declare const anIntersection: { x: number } & { y: string }; declare const aFunction: () => number; if (u === aString) { let uString: string = u; } if (u === aBoolean) { let uString: boolean = u; } if (u === aNumber) { let uNumber: number = u; } if (u === anObject) { let uObject: object = u; } if (u === anObjectLiteral) { let uObjectLiteral: object = u; } if (u === aUnion) { type unionDoesNotNarrow = isTrue<isUnknown<typeof u>> } if (u === anIntersection) { type intersectionDoesNotNarrow = isTrue<isUnknown<typeof u>> } if (u === aFunction) { let uFunction: object = u; } enum NumberEnum { A, B, C } enum StringEnum { A = "A", B = "B", C = "C" } if (u === NumberEnum || u === StringEnum) { let enumObj: object = u; } if (u === NumberEnum.A) { let a: NumberEnum.A = u } if (u === StringEnum.B) { let b: StringEnum.B = u } function switchTestEnum(x: unknown) { switch (x) { case StringEnum.A: const a: StringEnum.A = x; break; case StringEnum.B: const b: StringEnum.B = x; break; case StringEnum.C: const c: StringEnum.C = x; break; } type End = isTrue<isUnknown<typeof x>> } function switchTestCollectEnum(x: unknown) { switch (x) { case StringEnum.A: const a: StringEnum.A = x; case StringEnum.B: const b: StringEnum.A | StringEnum.B = x; case StringEnum.C: const c: StringEnum.A | StringEnum.B | StringEnum.C = x; const all: StringEnum = x; return; } type End = isTrue<isUnknown<typeof x>> } function switchTestLiterals(x: unknown) { switch (x) { case 1: const one: 1 = x; break; case 2: const two: 2 = x; break; case 3: const three: 3 = x; break; case true: const t: true = x; break; case false: const f: false = x; break; case "A": const a: "A" = x; break; case undefined: const undef: undefined = x; break; case null: const llun: null = x; break; case symb: const anotherSymbol: typeof symb = x; break; case symbNonUnique: const nonUniqueSymbol: symbol = x; break; } type End = isTrue<isUnknown<typeof x>> } function switchTestObjects(x: unknown, y: () => void, z: { prop: number }) { switch (x) { case true: case false: const bool: boolean = x; break; case y: const obj1: object = x; break; case z: const obj2: object = x; break; } type End = isTrue<isUnknown<typeof x>> } function switchResponse(x: unknown): SomeResponse { switch (x) { case 'yes': case 'no': case 'idk': return x; default: throw new Error('unknown response'); } // Arguably this should be never. type End = isTrue<isUnknown<typeof x>> } function switchResponseWrong(x: unknown): SomeResponse { switch (x) { case 'yes': case 'no': case 'maybe': return x; // error default: throw new Error('Can you repeat the question?'); } // Arguably this should be never. type End = isTrue<isUnknown<typeof x>> } // Repro from #33483 function f2(x: unknown): string | undefined { if (x !== undefined && typeof x !== 'string') { throw new Error(); } return x; } function notNotEquals(u: unknown) { if (u !== NumberEnum) { } else { const o: object = u; } if (u !== NumberEnum.A) { } else { const a: NumberEnum.A = u; } if (u !== NumberEnum.A && u !== NumberEnum.B && u !== StringEnum.A) { } else { const aOrB: NumberEnum.A | NumberEnum.B | StringEnum.A = u; } // equivalent to if (!(u === NumberEnum.A || u === NumberEnum.B || u === StringEnum.A)) { } else { const aOrB: NumberEnum.A | NumberEnum.B | StringEnum.A = u; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/untypedModuleImport_allowJs.ts
TypeScript
// @noImplicitReferences: true // @currentDirectory: / // @allowJs: true // @maxNodeModuleJsDepth: 1 // Same as untypedModuleImport.ts but with --allowJs, so the package will actually be typed. // @filename: /node_modules/foo/index.js exports.default = { bar() { return 0; } } // @filename: /a.ts import foo from "foo"; foo.bar();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/useObjectValuesAndEntries1.ts
TypeScript
// @target: es5 // @lib: es5,es2017.object var o = { a: 1, b: 2 }; for (var x of Object.values(o)) { let y = x; } var entries = Object.entries(o); // [string, number][] var values = Object.values(o); // number[] var entries1 = Object.entries(1); // [string, any][] var values1 = Object.values(1); // any[] var entries2 = Object.entries({ a: true, b: 2 }); // [string, number|boolean][] var values2 = Object.values({ a: true, b: 2 }); // (number|boolean)[] var entries3 = Object.entries({}); // [string, {}][] var values3 = Object.values({}); // {}[] var a = ["a", "b", "c"]; var entries4 = Object.entries(a); // [string, string][] var values4 = Object.values(a); // string[] enum E { A, B } var entries5 = Object.entries(E); // [string, any][] var values5 = Object.values(E); // any[] interface I { } var i: I = {}; var entries6 = Object.entries(i); // [string, any][] var values6 = Object.values(i); // any[]
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/useObjectValuesAndEntries2.ts
TypeScript
// @target: es5 // @lib: es5 var o = { a: 1, b: 2 }; for (var x of Object.values(o)) { let y = x; } var entries = Object.entries(o);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/useObjectValuesAndEntries3.ts
TypeScript
// @target: es6 var o = { a: 1, b: 2 }; for (var x of Object.values(o)) { let y = x; } var entries = Object.entries(o);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/useObjectValuesAndEntries4.ts
TypeScript
// @target: es6 // @lib: es2017 var o = { a: 1, b: 2 }; for (var x of Object.values(o)) { let y = x; } var entries = Object.entries(o);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usePromiseFinally.ts
TypeScript
// @target: es5 // @lib: es6,es2018 let promise1 = new Promise(function(resolve, reject) {}) .finally(function() {});
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/useRegexpGroups.ts
TypeScript
// @target: es5 // @lib: es6,es2018 let re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/u; let result = re.exec("2015-01-02"); let date = result[0]; let year1 = result.groups.year; let year2 = result[1]; let month1 = result.groups.month; let month2 = result[2]; let day1 = result.groups.day; let day2 = result[3]; let foo = "foo".match(/(?<bar>foo)/)!.groups.foo;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/useSharedArrayBuffer1.ts
TypeScript
// @target: es5 // @lib: es5,es2017.sharedmemory var foge = new SharedArrayBuffer(1024); var bar = foge.slice(1, 10); var len = foge.byteLength;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/useSharedArrayBuffer2.ts
TypeScript
// @target: es5 // @lib: es5 var foge = new SharedArrayBuffer(1024); var bar = foge.slice(1, 10); var len = foge.byteLength;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/useSharedArrayBuffer3.ts
TypeScript
// @target: es6 var foge = new SharedArrayBuffer(1024); var bar = foge.slice(1, 10); var len = foge.byteLength;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/useSharedArrayBuffer4.ts
TypeScript
// @target: es6 // @lib: es2017 var foge = new SharedArrayBuffer(1024); var bar = foge.slice(1, 10); var species = foge[Symbol.species]; var stringTag = foge[Symbol.toStringTag]; var len = foge.byteLength;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/useSharedArrayBuffer5.ts
TypeScript
// @target: es5 // @lib: es6,es2017.sharedmemory var foge = new SharedArrayBuffer(1024); var species = foge[Symbol.species]; var stringTag = foge[Symbol.toStringTag];
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/useSharedArrayBuffer6.ts
TypeScript
// @target: es5 // @lib: es6,es2017.sharedmemory var foge = new SharedArrayBuffer(1024); foge.length; // should error var length = SharedArrayBuffer.length;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarations.1.ts
TypeScript
// @target: esnext,es2022,es2017,es2015,es5 // @module: esnext // @lib: esnext // @noTypesAndSymbols: true using d1 = { [Symbol.dispose]() {} }; function f() { using d2 = { [Symbol.dispose]() {} }; } async function af() { using d3 = { [Symbol.dispose]() {} }; await null; } function * g() { using d4 = { [Symbol.dispose]() {} }; yield; } async function * ag() { using d5 = { [Symbol.dispose]() {} }; yield; await null; } const a = () => { using d6 = { [Symbol.dispose]() {} }; } class C1 { a = () => { using d7 = { [Symbol.dispose]() {} }; } constructor() { using d8 = { [Symbol.dispose]() {} }; } static { using d9 = { [Symbol.dispose]() {} }; } m() { using d10 = { [Symbol.dispose]() {} }; } get x() { using d11 = { [Symbol.dispose]() {} }; return 0; } set x(v) { using d12 = { [Symbol.dispose]() {} }; } async am() { using d13 = { [Symbol.dispose]() {} }; await null; } * g() { using d14 = { [Symbol.dispose]() {} }; yield; } async * ag() { using d15 = { [Symbol.dispose]() {} }; yield; await null; } } class C2 extends C1 { constructor() { using d16 = { [Symbol.dispose]() {} }; super(); } } class C3 extends C1 { y = 1; constructor() { using d17 = { [Symbol.dispose]() {} }; super(); } } namespace N { using d18 = { [Symbol.dispose]() {} }; } { using d19 = { [Symbol.dispose]() {} }; } switch (Math.random()) { case 0: using d20 = { [Symbol.dispose]() {} }; break; case 1: using d21 = { [Symbol.dispose]() {} }; break; } if (true) switch (0) { case 0: using d22 = { [Symbol.dispose]() {} }; break; } try { using d23 = { [Symbol.dispose]() {} }; } catch { using d24 = { [Symbol.dispose]() {} }; } finally { using d25 = { [Symbol.dispose]() {} }; } if (true) { using d26 = { [Symbol.dispose]() {} }; } else { using d27 = { [Symbol.dispose]() {} }; } while (true) { using d28 = { [Symbol.dispose]() {} }; break; } do { using d29 = { [Symbol.dispose]() {} }; break; } while (true); for (;;) { using d30 = { [Symbol.dispose]() {} }; break; } for (const x in {}) { using d31 = { [Symbol.dispose]() {} }; } for (const x of []) { using d32 = { [Symbol.dispose]() {} }; } export {};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarations.11.ts
TypeScript
// @target: es5 // @module: esnext // @lib: esnext // @noTypesAndSymbols: true class A {} class C1 extends A { constructor() { using x = null; super(); } } class C2 extends A { constructor() { super(); using x = null; } } class C3 extends A { y = 1; constructor() { using x = null; super(); } } class C4 extends A { constructor(public y: number) { using x = null; super(); } } class C5 extends A { z = 1; constructor(public y: number) { using x = null; super(); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarations.12.ts
TypeScript
// @target: es2018 // @module: esnext // @lib: esnext // @noTypesAndSymbols: true // @useDefineForClassFields: * class C1 { constructor() {} } class C2 extends C1 { y = 1; constructor() { super(); using d17 = { [Symbol.dispose]() {} }; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarations.14.ts
TypeScript
// @target: esnext // @module: esnext // @lib: esnext // @noTypesAndSymbols: true using x = {};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarations.15.ts
TypeScript
// @target: esnext // @module: esnext // @lib: esnext // @noTypesAndSymbols: true // @noUnusedLocals: true export {}; using _ = { [Symbol.dispose]() {} };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarations.2.ts
TypeScript
// @target: esnext,es2022,es2017,es2015,es5 // @module: esnext // @lib: esnext // @noTypesAndSymbols: true { using d1 = { [Symbol.dispose]() {} }, d2 = { [Symbol.dispose]() {} }; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarations.3.ts
TypeScript
// @target: esnext,es2022,es2017,es2015,es5 // @module: esnext // @lib: esnext // @noTypesAndSymbols: true { using d1 = { [Symbol.dispose]() {} }, d2 = null, d3 = undefined, d4 = { [Symbol.dispose]() {} }; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarations.4.ts
TypeScript
// @target: esnext // @module: esnext // @lib: esnext // @noTypesAndSymbols: true { using [a] = null; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarations.9.ts
TypeScript
// @target: esnext // @module: esnext // @lib: es2022 // @noTypesAndSymbols: true { using a = null; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsDeclarationEmit.1.ts
TypeScript
// @target: esnext // @module: esnext // @declaration: true // @noTypesAndSymbols: true using r1 = { [Symbol.dispose]() {} }; export { r1 }; await using r2 = { async [Symbol.asyncDispose]() {} }; export { r2 };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsDeclarationEmit.2.ts
TypeScript
// @target: esnext // @module: esnext // @declaration: true // @noTypesAndSymbols: true using r1 = { [Symbol.dispose]() {} }; export type R1 = typeof r1; await using r2 = { async [Symbol.asyncDispose]() {} }; export type R2 = typeof r2;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsInFor.ts
TypeScript
// @target: esnext,es2022,es2017,es2015,es5 // @module: esnext // @lib: esnext // @noTypesAndSymbols: true for (using d1 = { [Symbol.dispose]() {} }, d2 = null, d3 = undefined;;) { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsInForAwaitOf.ts
TypeScript
// @target: esnext,es2022,es2017,es2015,es5 // @module: esnext // @lib: esnext // @noTypesAndSymbols: true async function main() { for await (using d1 of [{ [Symbol.dispose]() {} }, null, undefined]) { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsInForOf.1.ts
TypeScript
// @target: esnext,es2022,es2017,es2015,es5 // @module: esnext // @lib: esnext // @noTypesAndSymbols: true for (using d1 of [{ [Symbol.dispose]() {} }, null, undefined]) { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsNamedEvaluationDecoratorsAndClassFields.ts
TypeScript
// @target: es2018 // @module: esnext // @lib: esnext // @noTypesAndSymbols: true export {}; declare var dec: any; using C1 = class { static [Symbol.dispose]() {} }; using C2 = class { static x = 1; static [Symbol.dispose]() {} }; using C3 = @dec class { static [Symbol.dispose]() {} }; using C4 = @dec class { static x = 1; static [Symbol.dispose]() {} };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsTopLevelOfModule.1.ts
TypeScript
// @target: es2022 // @lib: esnext,dom // @module: commonjs,system,esnext,amd // @noTypesAndSymbols: true // @noEmitHelpers: true export const x = 1; export { y }; using z = { [Symbol.dispose]() {} }; const y = 2; export const w = 3; export default 4; console.log(w, x, y, z);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsTopLevelOfModule.2.ts
TypeScript
// @target: es2022 // @lib: esnext,dom // @module: commonjs,amd // @noTypesAndSymbols: true // @noEmitHelpers: true using z = { [Symbol.dispose]() {} }; const y = 2; console.log(y, z); export = 4;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsTopLevelOfModule.3.ts
TypeScript
// @target: es2022 // @lib: esnext,dom // @module: commonjs,system,esnext,amd // @noTypesAndSymbols: true // @noEmitHelpers: true export { y }; using z = { [Symbol.dispose]() {} }; if (false) { var y = 1; } function f() { console.log(y, z); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithESClassDecorators.1.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: false // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; using before = null; @dec class C { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithESClassDecorators.10.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: false // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; @dec export default class { } using after = null;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithESClassDecorators.11.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: false // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; @dec class C { } export { C }; using after = null;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithESClassDecorators.12.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: false // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; @dec class C { } export { C as D }; using after = null;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithESClassDecorators.2.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: false // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; using before = null; @dec export class C { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithESClassDecorators.3.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: false // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; using before = null; @dec export default class C { } void C;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithESClassDecorators.4.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: false // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; using before = null; @dec export default class { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithESClassDecorators.5.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: false // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; using before = null; @dec class C { } export { C };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithESClassDecorators.6.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: false // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; using before = null; @dec class C { } export { C as D };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithESClassDecorators.7.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: false // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; @dec class C { } using after = null;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithESClassDecorators.8.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: false // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; @dec export class C { } using after = null;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithESClassDecorators.9.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: false // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; @dec export default class C { } void C; using after = null;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithImportHelpers.ts
TypeScript
// @target: es2022 // @module: esnext // @lib: esnext // @importHelpers: true // @noTypesAndSymbols: true export {}; { using a = null; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithLegacyClassDecorators.1.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: true // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; using before = null; @dec class C { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithLegacyClassDecorators.10.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: true // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; @dec export default class { } using after = null;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithLegacyClassDecorators.11.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: true // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; @dec class C { } export { C }; using after = null;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithLegacyClassDecorators.12.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: true // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; @dec class C { } export { C as D }; using after = null;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithLegacyClassDecorators.2.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: true // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; using before = null; @dec export class C { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithLegacyClassDecorators.3.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: true // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; using before = null; @dec export default class C { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithLegacyClassDecorators.4.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: true // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; using before = null; @dec export default class { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithLegacyClassDecorators.5.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: true // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; using before = null; @dec class C { } export { C };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithLegacyClassDecorators.6.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: true // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; using before = null; @dec class C { } export { C as D };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithLegacyClassDecorators.7.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: true // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; @dec class C { } using after = null;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithLegacyClassDecorators.8.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: true // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; @dec export class C { } using after = null;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/usingDeclarationsWithLegacyClassDecorators.9.ts
TypeScript
// @target: esnext,es2015,es5 // @module: commonjs,system,esnext // @lib: esnext // @experimentalDecorators: true // @noTypesAndSymbols: true // @noEmitHelpers: true export {}; declare var dec: any; @dec export default class C { } using after = null;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/validBooleanAssignments.ts
TypeScript
var x = true; var a: any = x; var b: Object = x; var c: Boolean = x; var d: boolean = x;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/validEnumAssignments.ts
TypeScript
enum E { A, B } var n: number; var a: any; var e: E; n = e; n = E.A; a = n; a = e; a = E.A; e = e; e = E.A; e = E.B; e = n; e = null; e = undefined; e = 1; e = 1.; e = 1.0; e = -1;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/validMultipleVariableDeclarations.ts
TypeScript
// all expected to be valid var x: number; var x = 2; if (true) { var x = 3; for (var x = 0; ;) { } } var x = <number>undefined; // new declaration space, making redeclaring x as a string valid function declSpace() { var x = 'this is a string'; } interface Point { x: number; y: number; } var p: Point; var p = { x: 1, y: 2 }; var p: Point = { x: 0, y: undefined }; var p = { x: 1, y: <number>undefined }; var p: { x: number; y: number; } = { x: 1, y: 2 }; var p = <{ x: number; y: number; }>{ x: 0, y: undefined }; var p: typeof p; var fn = function (s: string) { return 42; } var fn = (s: string) => 3; var fn: (s: string) => number; var fn: { (s: string): number }; var fn = <(s: string) => number> null; var fn: typeof fn; var a: string[]; var a = ['a', 'b'] var a = <string[]>[]; var a: string[] = []; var a = new Array<string>(); var a: typeof a;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/validNullAssignments.ts
TypeScript
var a: number = null; var b: boolean = null; var c: string = null; var d: void = null; var e: typeof undefined = null; e = null; // ok enum E { A } E.A = null; // error class C { foo: string } var f: C; f = null; // ok C = null; // error interface I { foo: string } var g: I; g = null; // ok I = null; // error module M { export var x = 1; } M = null; // error var h: { f(): void } = null; function i<T>(a: T) { a = null; } i = null; // error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/validNumberAssignments.ts
TypeScript
var x = 1; var a: any = x; var b: Object = x; var c: number = x; enum E { A }; var d: E = x; var e = E.A; e = x;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/validStringAssignments.ts
TypeScript
var x = ''; var a: any = x; var b: Object = x; var c: string = x; var d: String = x;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/validUndefinedAssignments.ts
TypeScript
var x: typeof undefined; var a: number = x; var b: boolean = x; var c: string = x; var d: void = x; var e: typeof undefined = x; e = x; // should work class C { foo: string } var f: C; f = x; interface I { foo: string } var g: I; g = x; var h: { f(): void } = x; function i<T>(a: T) { a = x; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/validUndefinedValues.ts
TypeScript
var x: typeof undefined; x = undefined;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/validVoidAssignments.ts
TypeScript
var x: void; var y: any; var z: void; y = x; x = y; x = z;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/validVoidValues.ts
TypeScript
var x: void; x = undefined; x = null;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/valuesMergingAcrossModules.ts
TypeScript
// @Filename: a.ts function A() {} export { A }; // @Filename: b.ts import { A } from "./a"; type A = 0; export { A }; // @Filename: c.ts import { A } from "./b"; namespace A { export const displayName = "A"; } A(); A.displayName;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/varRequireFromJavascript.ts
TypeScript
// @allowJs: true // @checkJs: true // @strict: true // @noEmit: true // @Filename: ex.js export class Crunch { /** @param {number} n */ constructor(n) { this.n = n } m() { return this.n } } // @Filename: use.js var ex = require('./ex') // values work var crunch = new ex.Crunch(1); crunch.n // types work /** * @param {ex.Crunch} wrap */ function f(wrap) { wrap.n }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/varRequireFromTypescript.ts
TypeScript
// @allowJs: true // @checkJs: true // @strict: true // @noEmit: true // @Filename: ex.d.ts export type Greatest = { day: 1 } export class Crunch { n: number m(): number constructor(n: number) } // @Filename: use.js var ex = require('./ex') // values work var crunch = new ex.Crunch(1); crunch.n // types work /** * @param {ex.Greatest} greatest * @param {ex.Crunch} wrap */ function f(greatest, wrap) { greatest.day wrap.n }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/variadicTuples1.ts
TypeScript
// @strict: true // @declaration: true // Variadics in tuple types type TV0<T extends unknown[]> = [string, ...T]; type TV1<T extends unknown[]> = [string, ...T, number]; type TV2<T extends unknown[]> = [string, ...T, number, ...T]; type TV3<T extends unknown[]> = [string, ...T, ...number[], ...T]; // Normalization type TN1 = TV1<[boolean, string]>; type TN2 = TV1<[]>; type TN3 = TV1<[boolean?]>; type TN4 = TV1<string[]>; type TN5 = TV1<[boolean] | [symbol, symbol]>; type TN6 = TV1<any>; type TN7 = TV1<never>; // Variadics in array literals function tup2<T extends unknown[], U extends unknown[]>(t: [...T], u: [...U]) { return [1, ...t, 2, ...u, 3] as const; } const t2 = tup2(['hello'], [10, true]); function concat<T extends unknown[], U extends unknown[]>(t: [...T], u: [...U]): [...T, ...U] { return [...t, ...u]; } declare const sa: string[]; const tc1 = concat([], []); const tc2 = concat(['hello'], [42]); const tc3 = concat([1, 2, 3], sa); const tc4 = concat(sa, [1, 2, 3]); // Ideally would be [...string[], number, number, number] function concat2<T extends readonly unknown[], U extends readonly unknown[]>(t: T, u: U) { return [...t, ...u]; // (T[number] | U[number])[] } const tc5 = concat2([1, 2, 3] as const, [4, 5, 6] as const); // (1 | 2 | 3 | 4 | 5 | 6)[] // Spread arguments declare function foo1(a: number, b: string, c: boolean, ...d: number[]): void; function foo2(t1: [number, string], t2: [boolean], a1: number[]) { foo1(1, 'abc', true, 42, 43, 44); foo1(...t1, true, 42, 43, 44); foo1(...t1, ...t2, 42, 43, 44); foo1(...t1, ...t2, ...a1); foo1(...t1); // Error foo1(...t1, 45); // Error } declare function foo3<T extends unknown[]>(x: number, ...args: [...T, number]): T; function foo4<U extends unknown[]>(u: U) { foo3(1, 2); foo3(1, 'hello', true, 2); foo3(1, ...u, 'hi', 2); foo3(1); } // Contextual typing of array literals declare function ft1<T extends unknown[]>(t: T): T; declare function ft2<T extends unknown[]>(t: T): readonly [...T]; declare function ft3<T extends unknown[]>(t: [...T]): T; declare function ft4<T extends unknown[]>(t: [...T]): readonly [...T]; ft1(['hello', 42]); // (string | number)[] ft2(['hello', 42]); // readonly (string | number)[] ft3(['hello', 42]); // [string, number] ft4(['hello', 42]); // readonly [string, number] // Indexing variadic tuple types function f0<T extends unknown[]>(t: [string, ...T], n: number) { const a = t[0]; // string const b = t[1]; // [string, ...T][1] const c = t[2]; // [string, ...T][2] const d = t[n]; // [string, ...T][number] } function f1<T extends unknown[]>(t: [string, ...T, number], n: number) { const a = t[0]; // string const b = t[1]; // number | T[number] const c = t[2]; // [string, ...T, number][2] const d = t[n]; // [string, ...T, number][number] } // Destructuring variadic tuple types function f2<T extends unknown[]>(t: [string, ...T]) { let [...ax] = t; // [string, ...T] let [b1, ...bx] = t; // string, [...T] let [c1, c2, ...cx] = t; // string, [string, ...T][1], T[number][] } function f3<T extends unknown[]>(t: [string, ...T, number]) { let [...ax] = t; // [string, ...T, number] let [b1, ...bx] = t; // string, [...T, number] let [c1, c2, ...cx] = t; // string, number | T[number], (number | T[number])[] } // Mapped types applied to variadic tuple types type Arrayify<T> = { [P in keyof T]: T[P][] }; type TM1<U extends unknown[]> = Arrayify<readonly [string, number?, ...U, ...boolean[]]>; // [string[], (number | undefined)[]?, Arrayify<U>, ...boolean[][]] type TP1<T extends unknown[]> = Partial<[string, ...T, number]>; // [string?, Partial<T>, number?] type TP2<T extends unknown[]> = Partial<[string, ...T, ...number[]]>; // [string?, Partial<T>, ...(number | undefined)[]] // Reverse mapping through mapped type applied to variadic tuple type declare function fm1<T extends unknown[]>(t: Arrayify<[string, number, ...T]>): T; let tm1 = fm1([['abc'], [42], [true], ['def']]); // [boolean, string] // Spread of readonly array-like infers mutable array-like declare function fx1<T extends unknown[]>(a: string, ...args: T): T; function gx1<U extends unknown[], V extends readonly unknown[]>(u: U, v: V) { fx1('abc'); // [] fx1('abc', ...u); // U fx1('abc', ...v); // [...V] fx1<U>('abc', ...u); // U fx1<V>('abc', ...v); // Error } declare function fx2<T extends readonly unknown[]>(a: string, ...args: T): T; function gx2<U extends unknown[], V extends readonly unknown[]>(u: U, v: V) { fx2('abc'); // [] fx2('abc', ...u); // U fx2('abc', ...v); // [...V] fx2<U>('abc', ...u); // U fx2<V>('abc', ...v); // V } // Relations involving variadic tuple types function f10<T extends string[], U extends T>(x: [string, ...unknown[]], y: [string, ...T], z: [string, ...U]) { x = y; x = z; y = x; // Error y = z; z = x; // Error z = y; // Error } // For a generic type T, [...T] is assignable to T, T is assignable to readonly [...T], and T is assignable // to [...T] when T is constrained to a mutable array or tuple type. function f11<T extends unknown[]>(t: T, m: [...T], r: readonly [...T]) { t = m; t = r; // Error m = t; m = r; // Error r = t; r = m; } function f12<T extends readonly unknown[]>(t: T, m: [...T], r: readonly [...T]) { t = m; t = r; // Error m = t; // Error m = r; // Error r = t; r = m; } function f13<T extends string[], U extends T>(t0: T, t1: [...T], t2: [...U]) { t0 = t1; t0 = t2; t1 = t0; t1 = t2; t2 = t0; // Error t2 = t1; // Error } function f14<T extends readonly string[], U extends T>(t0: T, t1: [...T], t2: [...U]) { t0 = t1; t0 = t2; t1 = t0; // Error t1 = t2; t2 = t0; // Error t2 = t1; // Error } function f15<T extends string[], U extends T>(k0: keyof T, k1: keyof [...T], k2: keyof [...U], k3: keyof [1, 2, ...T]) { k0 = 'length'; k1 = 'length'; k2 = 'length'; k0 = 'slice'; k1 = 'slice'; k2 = 'slice'; k3 = '0'; k3 = '1'; k3 = '2'; // Error } // Constraints of variadic tuple types function ft16<T extends [unknown]>(x: [unknown, unknown], y: [...T, ...T]) { x = y; } function ft17<T extends [] | [unknown]>(x: [unknown, unknown], y: [...T, ...T]) { x = y; } function ft18<T extends unknown[]>(x: [unknown, unknown], y: [...T, ...T]) { x = y; } // Inference between variadic tuple types type First<T extends readonly unknown[]> = T extends readonly [unknown, ...unknown[]] ? T[0] : T[0] | undefined; type DropFirst<T extends readonly unknown[]> = T extends readonly [unknown?, ...infer U] ? U : [...T]; type Last<T extends readonly unknown[]> = T extends readonly [...unknown[], infer U] ? U : T extends readonly [unknown, ...unknown[]] ? T[number] : T[number] | undefined; type DropLast<T extends readonly unknown[]> = T extends readonly [...infer U, unknown] ? U : [...T]; type T00 = First<[number, symbol, string]>; type T01 = First<[symbol, string]>; type T02 = First<[string]>; type T03 = First<[number, symbol, ...string[]]>; type T04 = First<[symbol, ...string[]]>; type T05 = First<[string?]>; type T06 = First<string[]>; type T07 = First<[]>; type T08 = First<any>; type T09 = First<never>; type T10 = DropFirst<[number, symbol, string]>; type T11 = DropFirst<[symbol, string]>; type T12 = DropFirst<[string]>; type T13 = DropFirst<[number, symbol, ...string[]]>; type T14 = DropFirst<[symbol, ...string[]]>; type T15 = DropFirst<[string?]>; type T16 = DropFirst<string[]>; type T17 = DropFirst<[]>; type T18 = DropFirst<any>; type T19 = DropFirst<never>; type T20 = Last<[number, symbol, string]>; type T21 = Last<[symbol, string]>; type T22 = Last<[string]>; type T23 = Last<[number, symbol, ...string[]]>; type T24 = Last<[symbol, ...string[]]>; type T25 = Last<[string?]>; type T26 = Last<string[]>; type T27 = Last<[]>; type T28 = Last<any>; type T29 = Last<never>; type T30 = DropLast<[number, symbol, string]>; type T31 = DropLast<[symbol, string]>; type T32 = DropLast<[string]>; type T33 = DropLast<[number, symbol, ...string[]]>; type T34 = DropLast<[symbol, ...string[]]>; type T35 = DropLast<[string?]>; type T36 = DropLast<string[]>; type T37 = DropLast<[]>; // unknown[], maybe should be [] type T38 = DropLast<any>; type T39 = DropLast<never>; type R00 = First<readonly [number, symbol, string]>; type R01 = First<readonly [symbol, string]>; type R02 = First<readonly [string]>; type R03 = First<readonly [number, symbol, ...string[]]>; type R04 = First<readonly [symbol, ...string[]]>; type R05 = First<readonly string[]>; type R06 = First<readonly []>; type R10 = DropFirst<readonly [number, symbol, string]>; type R11 = DropFirst<readonly [symbol, string]>; type R12 = DropFirst<readonly [string]>; type R13 = DropFirst<readonly [number, symbol, ...string[]]>; type R14 = DropFirst<readonly [symbol, ...string[]]>; type R15 = DropFirst<readonly string[]>; type R16 = DropFirst<readonly []>; type R20 = Last<readonly [number, symbol, string]>; type R21 = Last<readonly [symbol, string]>; type R22 = Last<readonly [string]>; type R23 = Last<readonly [number, symbol, ...string[]]>; type R24 = Last<readonly [symbol, ...string[]]>; type R25 = Last<readonly string[]>; type R26 = Last<readonly []>; type R30 = DropLast<readonly [number, symbol, string]>; type R31 = DropLast<readonly [symbol, string]>; type R32 = DropLast<readonly [string]>; type R33 = DropLast<readonly [number, symbol, ...string[]]>; type R34 = DropLast<readonly [symbol, ...string[]]>; type R35 = DropLast<readonly string[]>; type R36 = DropLast<readonly []>; // Inference to [...T, ...U] with implied arity for T function curry<T extends unknown[], U extends unknown[], R>(f: (...args: [...T, ...U]) => R, ...a: T) { return (...b: U) => f(...a, ...b); } const fn1 = (a: number, b: string, c: boolean, d: string[]) => 0; const c0 = curry(fn1); // (a: number, b: string, c: boolean, d: string[]) => number const c1 = curry(fn1, 1); // (b: string, c: boolean, d: string[]) => number const c2 = curry(fn1, 1, 'abc'); // (c: boolean, d: string[]) => number const c3 = curry(fn1, 1, 'abc', true); // (d: string[]) => number const c4 = curry(fn1, 1, 'abc', true, ['x', 'y']); // () => number const fn2 = (x: number, b: boolean, ...args: string[]) => 0; const c10 = curry(fn2); // (x: number, b: boolean, ...args: string[]) => number const c11 = curry(fn2, 1); // (b: boolean, ...args: string[]) => number const c12 = curry(fn2, 1, true); // (...args: string[]) => number const c13 = curry(fn2, 1, true, 'abc', 'def'); // (...args: string[]) => number const fn3 = (...args: string[]) => 0; const c20 = curry(fn3); // (...args: string[]) => number const c21 = curry(fn3, 'abc', 'def'); // (...args: string[]) => number const c22 = curry(fn3, ...sa); // (...args: string[]) => number // No inference to [...T, ...U] when there is no implied arity function curry2<T extends unknown[], U extends unknown[], R>(f: (...args: [...T, ...U]) => R, t: [...T], u: [...U]) { return f(...t, ...u); } declare function fn10(a: string, b: number, c: boolean): string[]; curry2(fn10, ['hello', 42], [true]); curry2(fn10, ['hello'], [42, true]); // Inference to [...T] has higher priority than inference to [...T, number?] declare function ft<T extends unknown[]>(t1: [...T], t2: [...T, number?]): T; ft([1, 2, 3], [1, 2, 3]); ft([1, 2], [1, 2, 3]); ft(['a', 'b'], ['c', 'd']) ft(['a', 'b'], ['c', 'd', 42]) // Last argument is contextually typed declare function call<T extends unknown[], R>(...args: [...T, (...args: T) => R]): [T, R]; call('hello', 32, (a, b) => 42); call(...sa, (...x) => 42); // No inference to ending optional elements (except with identical structure) declare function f20<T extends unknown[] = []>(args: [...T, number?]): T; function f21<U extends string[]>(args: [...U, number?]) { let v1 = f20(args); // U let v2 = f20(["foo", "bar"]); // [string] let v3 = f20(["foo", 42]); // [string] } declare function f22<T extends unknown[] = []>(args: [...T, number]): T; declare function f22<T extends unknown[] = []>(args: [...T]): T; function f23<U extends string[]>(args: [...U, number]) { let v1 = f22(args); // U let v2 = f22(["foo", "bar"]); // [string, string] let v3 = f22(["foo", 42]); // [string] } // Repro from #39327 interface Desc<A extends unknown[], T> { readonly f: (...args: A) => T; bind<T extends unknown[], U extends unknown[], R>(this: Desc<[...T, ...U], R>, ...args: T): Desc<[...U], R>; } declare const a: Desc<[string, number, boolean], object>; const b = a.bind("", 1); // Desc<[boolean], object> // Repro from #39607 declare function getUser(id: string, options?: { x?: string }): string; declare function getOrgUser(id: string, orgId: number, options?: { y?: number, z?: boolean }): void; function callApi<T extends unknown[] = [], U = void>(method: (...args: [...T, object]) => U) { return (...args: [...T]) => method(...args, {}); } callApi(getUser); callApi(getOrgUser); // Repro from #40235 type Numbers = number[]; type Unbounded = [...Numbers, boolean]; const data: Unbounded = [false, false]; // Error type U1 = [string, ...Numbers, boolean]; type U2 = [...[string, ...Numbers], boolean]; type U3 = [...[string, number], boolean]; // Repro from #53563 type ToStringLength1<T extends any[]> = `${T['length']}`; type ToStringLength2<T extends any[]> = `${[...T]['length']}`; type AnyArr = [...any];
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/variance.ts
TypeScript
// @strict: true // Test cases for parameter variances affected by conditional types. // Repro from #30047 interface Foo<T> { prop: T extends unknown ? true : false; } const foo = { prop: true } as const; const x: Foo<1> = foo; const y: Foo<number> = foo; const z: Foo<number> = x; // Repro from #30118 class Bar<T extends string> { private static instance: Bar<string>[] = []; cast(_name: ([T] extends [string] ? string : string)) { } pushThis() { Bar.instance.push(this); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/verbatimModuleSyntaxCompat.ts
TypeScript
// @verbatimModuleSyntax: true // @isolatedModules: true // @preserveValueImports: true // @importsNotUsedAsValues: error // @module: system // @noEmit: true // @noTypesAndSymbols: true export {};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/verbatimModuleSyntaxConstEnum.ts
TypeScript
// @verbatimModuleSyntax: true // @module: esnext export const enum E { A = 1, }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/verbatimModuleSyntaxConstEnumUsage.ts
TypeScript
// @module: esnext // @verbatimModuleSyntax: true // @filename: foo.ts export enum Foo { a = 1, b, c, } // @filename: bar.ts import {Foo} from './foo.js'; export enum Bar { a = Foo.a, c = Foo.c, e = 5, }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/verbatimModuleSyntaxInternalImportEquals.ts
TypeScript
// @verbatimModuleSyntax: true // @module: esnext export {}; import f1 = NonExistent; namespace Foo { export const foo = 1; export type T = any; } import f2 = Foo.foo; import f3 = Foo.T;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/verbatimModuleSyntaxNoElisionCJS.ts
TypeScript
// @verbatimModuleSyntax: true // @target: esnext // @module: commonjs // @moduleResolution: node // @Filename: /a.ts interface I {} export = I; // @Filename: /b.ts import I = require("./a"); // @Filename: /c.ts interface I {} namespace I { export const x = 1; } export = I; // @Filename: /d.ts import I = require("./c"); import type J = require("./c"); export = J; // @Filename: /e.d.ts interface I {} export = I; // @Filename: /f.ts import type I = require("./e"); const I = {}; export = I; // @Filename: /z.ts // test harness is weird if the last file includs a require >:(
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/verbatimModuleSyntaxNoElisionESM.ts
TypeScript
// @verbatimModuleSyntax: true // @module: esnext // @moduleResolution: node // @Filename: /a.ts export const a = 0; export type A = typeof a; export class AClass {} // @Filename: /b.ts import { a, A, AClass } from "./a"; import type { a as aValue, A as AType } from "./a"; import { type A as AType2 } from "./a"; export { A }; export { A as A2 } from "./a"; export type { A as A3 } from "./a"; export { type A as A4 } from "./a"; export type { AClass } from "./a"; // @Filename: /c.ts import { AClass } from "./b"; // @Filename: /main4.ts export default 1; // ok // @Filename: /main5.ts export default class C {} // ok // @Filename: /main6.ts interface I {} export default I; // error // @Filename: /main7.ts import type C from "./main5"; export default C; // error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/verbatimModuleSyntaxRestrictionsCJS.ts
TypeScript
// @verbatimModuleSyntax: true // @target: esnext // @module: commonjs // @moduleResolution: node // @esModuleInterop: true // @Filename: /decl.d.ts declare function esmy(): void; export default esmy; export declare function funciton(): void; // @Filename: /ambient.d.ts declare module "ambient" { const _default: number; export default _default; } // @Filename: /main.ts import esmy from "./decl"; // error import * as esmy2 from "./decl"; // error import { funciton } from "./decl"; // error import type { funciton as funciton2 } from "./decl"; // ok I guess? import("./decl"); // error type T = typeof import("./decl"); // ok export {}; // error export const x = 1; // error export interface I {} // ok export type { T }; // ok export namespace JustTypes { export type T = number; } export namespace Values { // error export const x = 1; } export default interface Default {} // sketchy, but ok // @Filename: /main2.ts export interface I {} export = { x: 1 }; // @Filename: /main3.ts namespace ns { export const x = 1; export interface I {} } export = ns; // @Filename: /main4.ts export default 1; // error // @Filename: /main5.ts export default class C {} // error // @Filename: /main6.ts interface I {} export default I; // error // @Filename: /main7.ts import type esmy from "./decl"; export default esmy; // error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/verbatimModuleSyntaxRestrictionsESM.ts
TypeScript
// @verbatimModuleSyntax: true // @target: esnext // @module: esnext // @moduleResolution: node // @esModuleInterop: true, false // @Filename: /decl.d.ts declare class CJSy {} export = CJSy; // @Filename: /ambient.d.ts declare module "ambient" { const _export: number; export = _export; } // @Filename: /types.ts interface Typey {} export type { Typey }; // @Filename: /main.ts import CJSy = require("./decl"); // error import type CJSy2 = require("./decl"); // ok I guess? import CJSy3 from "./decl"; // ok in esModuleInterop import * as types from "./types"; // ok CJSy; // @Filename: /ns.ts export namespace ns { export enum A {} }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/voidOperatorWithAnyOtherType.ts
TypeScript
// void operator on any type var ANY: any; var ANY1; var ANY2: any[] = ["", ""]; var obj: () => {} var obj1 = {x:"",y:1}; function foo(): any { var a; return a; } class A { public a: any; static foo() { var a; return a; } } module M { export var n: any; } var objA = new A(); // any type var var ResultIsAny1 = void ANY1; var ResultIsAny2 = void ANY2; var ResultIsAny3 = void A; var ResultIsAny4 = void M; var ResultIsAny5 = void obj; var ResultIsAny6 = void obj1; // any type literal var ResultIsAny7 = void undefined; var ResultIsAny8 = void null; // any type expressions var ResultIsAny9 = void ANY2[0] var ResultIsAny10 = void obj1.x; var ResultIsAny11 = void obj1.y; var ResultIsAny12 = void objA.a; var ResultIsAny13 = void M.n; var ResultIsAny14 = void foo(); var ResultIsAny15 = void A.foo(); var ResultIsAny16 = void (ANY + ANY1); var ResultIsAny17 = void (null + undefined); var ResultIsAny18 = void (null + null); var ResultIsAny19 = void (undefined + undefined); // multiple void operators var ResultIsAny20 = void void ANY; var ResultIsAny21 = void void void (ANY + ANY1); // miss assignment operators void ANY; void ANY1; void ANY2[0]; void ANY, ANY1; void objA.a; void M.n;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/voidOperatorWithBooleanType.ts
TypeScript
// void operator on boolean type var BOOLEAN: boolean; function foo(): boolean { return true; } class A { public a: boolean; static foo() { return false; } } module M { export var n: boolean; } var objA = new A(); // boolean type var var ResultIsAny1 = void BOOLEAN; // boolean type literal var ResultIsAny2 = void true; var ResultIsAny3 = void { x: true, y: false }; // boolean type expressions var ResultIsAny4 = void objA.a; var ResultIsAny5 = void M.n; var ResultIsAny6 = void foo(); var ResultIsAny7 = void A.foo(); // multiple void operator var ResultIsAny8 = void void BOOLEAN; // miss assignment operators void true; void BOOLEAN; void foo(); void true, false; void objA.a; void M.n;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/voidOperatorWithEnumType.ts
TypeScript
// void operator on enum type enum ENUM { }; enum ENUM1 { A, B, "" }; // enum type var var ResultIsAny1 = void ENUM; var ResultIsAny2 = void ENUM1; // enum type expressions var ResultIsAny3 = void ENUM1["A"]; var ResultIsAny4 = void (ENUM[0] + ENUM1["B"]); // multiple void operators var ResultIsAny5 = void void ENUM; var ResultIsAny6 = void void void (ENUM[0] + ENUM1.B); // miss assignment operators void ENUM; void ENUM1; void ENUM1["B"]; void ENUM, ENUM1;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/voidOperatorWithNumberType.ts
TypeScript
// void operator on number type var NUMBER: number; var NUMBER1: number[] = [1, 2]; function foo(): number { return 1; } class A { public a: number; static foo() { return 1; } } module M { export var n: number; } var objA = new A(); // number type var var ResultIsAny1 = void NUMBER; var ResultIsAny2 = void NUMBER1; // number type literal var ResultIsAny3 = void 1; var ResultIsAny4 = void { x: 1, y: 2}; var ResultIsAny5 = void { x: 1, y: (n: number) => { return n; } }; // number type expressions var ResultIsAny6 = void objA.a; var ResultIsAny7 = void M.n; var ResultIsAny8 = void NUMBER1[0]; var ResultIsAny9 = void foo(); var ResultIsAny10 = void A.foo(); var ResultIsAny11 = void (NUMBER + NUMBER); // multiple void operators var ResultIsAny12 = void void NUMBER; var ResultIsAny13 = void void void (NUMBER + NUMBER); // miss assignment operators void 1; void NUMBER; void NUMBER1; void foo(); void objA.a; void M.n; void objA.a, M.n;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/voidOperatorWithStringType.ts
TypeScript
// void operator on string type var STRING: string; var STRING1: string[] = ["", "abc"]; function foo(): string { return "abc"; } class A { public a: string; static foo() { return ""; } } module M { export var n: string; } var objA = new A(); // string type var var ResultIsAny1 = void STRING; var ResultIsAny2 = void STRING1; // string type literal var ResultIsAny3 = void ""; var ResultIsAny4 = void { x: "", y: "" }; var ResultIsAny5 = void { x: "", y: (s: string) => { return s; } }; // string type expressions var ResultIsAny6 = void objA.a; var ResultIsAny7 = void M.n; var ResultIsAny8 = void STRING1[0]; var ResultIsAny9 = void foo(); var ResultIsAny10 = void A.foo(); var ResultIsAny11 = void (STRING + STRING); var ResultIsAny12 = void STRING.charAt(0); // multiple void operators var ResultIsAny13 = void void STRING; var ResultIsAny14 = void void void (STRING + STRING); // miss assignment operators void ""; void STRING; void STRING1; void foo(); void objA.a,M.n;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/voidParamAssignmentCompatibility.ts
TypeScript
// @strict: true declare function g(a: void): void; let gg: () => void = g; interface Obj<T> { method(value: T): void; } declare const o: Obj<void>; gg = o.method;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/weakTypesAndLiterals01.ts
TypeScript
// @strict: true // @declaration: true // @emitDeclarationOnly: true type WeakTypes = | { optional?: true; } | { toLowerCase?(): string } | { toUpperCase?(): string, otherOptionalProp?: number }; type LiteralsOrWeakTypes = | "A" | "B" | WeakTypes; declare let aOrB: "A" | "B"; const f = (arg: LiteralsOrWeakTypes) => { if (arg === "A") { return arg; } else { return arg; } } const g = (arg: WeakTypes) => { if (arg === "A") { return arg; } else { return arg; } } const h = (arg: LiteralsOrWeakTypes) => { if (arg === aOrB) { return arg; } else { return arg; } } const i = (arg: WeakTypes) => { if (arg === aOrB) { return arg; } else { return arg; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/whileBreakStatements.ts
TypeScript
// @allowUnusedLabels: true // @allowUnreachableCode: true while(true) { break; } ONE: while (true) { break ONE; } TWO: THREE: while (true) { break THREE; } FOUR: while (true) { FIVE: while (true) { break FOUR; } } while (true) { SIX: while (true) break SIX; } SEVEN: while (true) while (true) while (true) break SEVEN; EIGHT: while (true) { var fn = function () { } break EIGHT; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University