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/awaitUsingDeclarations.3.ts | TypeScript | // @target: esnext,es2022,es2017,es2015,es5
// @module: esnext
// @lib: esnext
// @noTypesAndSymbols: true
{
await using d1 = { async [Symbol.asyncDispose]() {} },
d2 = null,
d3 = undefined,
d4 = { [Symbol.dispose]() {} };
}
export {}; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/awaitUsingDeclarations.9.ts | TypeScript | // @target: esnext
// @module: esnext
// @lib: es2022
// @noTypesAndSymbols: true
{
await using a = null;
}
export {}; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/awaitUsingDeclarationsInFor.ts | TypeScript | // @target: esnext,es2022,es2017,es2015,es5
// @module: esnext
// @lib: esnext
// @noTypesAndSymbols: true
async function main() {
for (await using d1 = { [Symbol.dispose]() {} },
d2 = { async [Symbol.asyncDispose]() {} },
d3 = null,
d4 = undefined;;) {
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/awaitUsingDeclarationsInForAwaitOf.2.ts | TypeScript | // @target: esnext
// @module: esnext
// @lib: esnext
// @noTypesAndSymbols: true
// https://github.com/microsoft/TypeScript/issues/55555
async function test() {
for await (await using of of of) {};
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/awaitUsingDeclarationsInForAwaitOf.ts | TypeScript | // @target: esnext,es2022,es2017,es2015,es5
// @module: esnext
// @lib: esnext
// @noTypesAndSymbols: true
async function main() {
for await (await using d1 of [{ async [Symbol.asyncDispose]() {} }, { [Symbol.dispose]() {} }, null, undefined]) {
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/awaitUsingDeclarationsInForOf.1.ts | TypeScript | // @target: esnext,es2022,es2017,es2015,es5
// @module: esnext
// @lib: esnext
// @noTypesAndSymbols: true
async function main() {
for (await using d1 of [{ async [Symbol.asyncDispose]() {} }, { [Symbol.dispose]() {} }, null, undefined]) {
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/awaitUsingDeclarationsInForOf.2.ts | TypeScript | // @target: esnext
// @module: esnext
// @lib: esnext
// @noTypesAndSymbols: true
async function main() {
for (await using of of []) {
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/awaitUsingDeclarationsInForOf.4.ts | TypeScript | // @target: esnext
// @module: esnext
// @lib: esnext
// @noTypesAndSymbols: true
// https://github.com/microsoft/TypeScript/issues/55555
{
for (await using of of of) {};
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/awaitUsingDeclarationsTopLevelOfModule.1.ts | TypeScript | // @target: es2022
// @lib: esnext,dom
// @module: system,esnext
// @noTypesAndSymbols: true
// @noEmitHelpers: true
export const x = 1;
export { y };
await using z = { async [Symbol.asyncDispose]() {} };
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/awaitUsingDeclarationsWithImportHelpers.ts | TypeScript | // @target: es2022
// @module: esnext
// @lib: esnext
// @importHelpers: true
// @noTypesAndSymbols: true
export {};
async function f() {
await using a = null;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/await_unaryExpression_es2017.ts | TypeScript | // @target: es2017
async function bar() {
!await 42; // OK
}
async function bar1() {
+await 42; // OK
}
async function bar3() {
-await 42; // OK
}
async function bar4() {
~await 42; // OK
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/await_unaryExpression_es2017_1.ts | TypeScript | // @target: es2017
async function bar() {
!await 42; // OK
}
async function bar1() {
delete await 42; // OK
}
async function bar2() {
delete await 42; // OK
}
async function bar3() {
void await 42;
}
async function bar4() {
+await 42;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/await_unaryExpression_es2017_2.ts | TypeScript | // @target: es2017
async function bar1() {
delete await 42;
}
async function bar2() {
delete await 42;
}
async function bar3() {
void await 42;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/await_unaryExpression_es6.ts | TypeScript | // @target: es6
async function bar() {
!await 42; // OK
}
async function bar1() {
+await 42; // OK
}
async function bar3() {
-await 42; // OK
}
async function bar4() {
~await 42; // OK
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/await_unaryExpression_es6_1.ts | TypeScript | // @target: es6
async function bar() {
!await 42; // OK
}
async function bar1() {
delete await 42; // OK
}
async function bar2() {
delete await 42; // OK
}
async function bar3() {
void await 42;
}
async function bar4() {
+await 42;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/await_unaryExpression_es6_2.ts | TypeScript | // @target: es6
async function bar1() {
delete await 42;
}
async function bar2() {
delete await 42;
}
async function bar3() {
void await 42;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/bestCommonTypeOfConditionalExpressions.ts | TypeScript | // conditional expressions return the best common type of the branches plus contextual type (using the first candidate if multiple BCTs exist)
// no errors expected here
var a: { x: number; y?: number };
var b: { x: number; z?: number };
class Base { foo: string; }
class Derived extends Base { bar: string; }
class Derived2 extends Base { baz: string; }
var base: Base;
var derived: Derived;
var derived2: Derived2;
var r = true ? 1 : 2;
var r3 = true ? 1 : {};
var r4 = true ? a : b; // typeof a
var r5 = true ? b : a; // typeof b
var r6 = true ? (x: number) => { } : (x: Object) => { }; // returns number => void
var r7: (x: Object) => void = true ? (x: number) => { } : (x: Object) => { };
var r8 = true ? (x: Object) => { } : (x: number) => { }; // returns Object => void
var r10: Base = true ? derived : derived2; // no error since we use the contextual type in BCT
var r11 = true ? base : derived2;
function foo5<T, U>(t: T, u: U): Object {
return true ? t : u; // BCT is Object
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/bestCommonTypeOfConditionalExpressions2.ts | TypeScript | // conditional expressions return the best common type of the branches plus contextual type (using the first candidate if multiple BCTs exist)
// these are errors
class Base { foo: string; }
class Derived extends Base { bar: string; }
class Derived2 extends Base { baz: string; }
var base: Base;
var derived: Derived;
var derived2: Derived2;
var r2 = true ? 1 : '';
var r9 = true ? derived : derived2;
function foo<T, U>(t: T, u: U) {
return true ? t : u;
}
function foo2<T extends U, U>(t: T, u: U) { // Error for referencing own type parameter
return true ? t : u; // Ok because BCT(T, U) = U
}
function foo3<T extends U, U extends V, V>(t: T, u: U) {
return true ? t : u;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/bestCommonTypeOfTuple.ts | TypeScript | function f1(x: number): string { return "foo"; }
function f2(x: number): number { return 10; }
function f3(x: number): boolean { return true; }
enum E1 { one }
enum E2 { two }
var t1: [(x: number) => string, (x: number) => number];
var t2: [E1, E2];
var t3: [number, any];
var t4: [E1, E2, number];
// no error
t1 = [f1, f2];
t2 = [E1.one, E2.two];
t3 = [5, undefined];
t4 = [E1.one, E2.two, 20];
var e1 = t1[2]; // {}
var e2 = t2[2]; // {}
var e3 = t3[2]; // any
var e4 = t4[3]; // number | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/bestCommonTypeOfTuple2.ts | TypeScript | interface base { }
interface base1 { i }
class C implements base { c }
class D implements base { d }
class E implements base { e }
class F extends C { f }
class C1 implements base1 { i = "foo"; c }
class D1 extends C1 { i = "bar"; d }
var t1: [C, base];
var t2: [C, D];
var t3: [C1, D1];
var t4: [base1, C1];
var t5: [C1, F]
var e11 = t1[4]; // base
var e21 = t2[4]; // {}
var e31 = t3[4]; // C1
var e41 = t4[2]; // base1
var e51 = t5[2]; // {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/bigintMissingES2019.ts | TypeScript | // @target: es2019
// @lib: dom,es2019
declare function test<A, B extends A>(): void;
test<{t?: string}, object>();
test<{t?: string}, bigint>();
// no error when bigint is used even when ES2020 lib is not present
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/bigintMissingES2020.ts | TypeScript | // @target: es2020
// @lib: dom,es2017
declare function test<A, B extends A>(): void;
test<{t?: string}, object>();
test<{t?: string}, bigint>();
// no error when bigint is used even when ES2020 lib is not present
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/bigintMissingESNext.ts | TypeScript | // @target: esnext
// @lib: dom,es2017
declare function test<A, B extends A>(): void;
test<{t?: string}, object>();
test<{t?: string}, bigint>();
// no error when bigint is used even when ES2020 lib is not present
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/binaryIntegerLiteral.ts | TypeScript | // @target: es5
var bin1 = 0b11010;
var bin2 = 0B11010;
var bin3 = 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111;
var bin4 = 0B111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101001010100000010111110001111111111;
var obj1 = {
0b11010: "Hello",
a: bin1,
bin1,
b: 0b11010,
0B111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101001010100000010111110001111111111: true,
}
var obj2 = {
0B11010: "World",
a: bin2,
bin2,
b: 0B11010,
0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: false,
}
obj1[0b11010]; // string
obj1[26]; // string
obj1["26"]; // string
obj1["0b11010"]; // any
obj1["a"]; // number
obj1["b"]; // number
obj1["bin1"]; // number
obj1["Infinity"]; // boolean
obj2[0B11010]; // string
obj2[26]; // string
obj2["26"]; // string
obj2["0B11010"]; // any
obj2["a"]; // number
obj2["b"]; // number
obj2["bin2"]; // number
obj2[9.671406556917009e+24]; // boolean
obj2["9.671406556917009e+24"]; // boolean
obj2["Infinity"]; // any
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/binaryIntegerLiteralES6.ts | TypeScript | // @target: es6
var bin1 = 0b11010;
var bin2 = 0B11010;
var bin3 = 0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111;
var bin4 = 0B111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101001010100000010111110001111111111;
var obj1 = {
0b11010: "Hello",
a: bin1,
bin1,
b: 0b11010,
0B111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101001010100000010111110001111111111: true,
}
var obj2 = {
0B11010: "World",
a: bin2,
bin2,
b: 0B11010,
0B11111111111111111111111111111111111111111111111101001010100000010111110001111111111: false,
}
obj1[0b11010]; // string
obj1[26]; // string
obj1["26"]; // string
obj1["0b11010"]; // any
obj1["a"]; // number
obj1["b"]; // number
obj1["bin1"]; // number
obj1["Infinity"]; // boolean
obj2[0B11010]; // string
obj2[26]; // string
obj2["26"]; // string
obj2["0B11010"]; // any
obj2["a"]; // number
obj2["b"]; // number
obj2["bin2"]; // number
obj2[9.671406556917009e+24]; // boolean
obj2["9.671406556917009e+24"]; // boolean
obj2["Infinity"]; // any
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/binderUninitializedModuleExportsAssignment.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: loop.js
var loop1 = loop2;
var loop2 = loop1;
module.exports = loop2;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/bitwiseNotOperatorWithBooleanType.ts | TypeScript | // @allowUnreachableCode: true
// ~ 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 ResultIsNumber1 = ~BOOLEAN;
// boolean type literal
var ResultIsNumber2 = ~true;
var ResultIsNumber3 = ~{ x: true, y: false };
// boolean type expressions
var ResultIsNumber4 = ~objA.a;
var ResultIsNumber5 = ~M.n;
var ResultIsNumber6 = ~foo();
var ResultIsNumber7 = ~A.foo();
// multiple ~ operators
var ResultIsNumber8 = ~~BOOLEAN;
// miss assignment operators
~true;
~BOOLEAN;
~foo();
~true, false;
~objA.a;
~M.n; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/bitwiseNotOperatorWithEnumType.ts | TypeScript | // @allowUnreachableCode: true
// ~ operator on enum type
enum ENUM1 { A, B, "" };
// enum type var
var ResultIsNumber1 = ~ENUM1;
// enum type expressions
var ResultIsNumber2 = ~ENUM1["A"];
var ResultIsNumber3 = ~(ENUM1.A + ENUM1["B"]);
// multiple ~ operators
var ResultIsNumber4 = ~~~(ENUM1["A"] + ENUM1.B);
// miss assignment operators
~ENUM1;
~ENUM1["A"];
~ENUM1.A, ~ENUM1["B"]; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/bitwiseNotOperatorWithNumberType.ts | TypeScript | // @allowUnreachableCode: true
// ~ 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 ResultIsNumber1 = ~NUMBER;
var ResultIsNumber2 = ~NUMBER1;
// number type literal
var ResultIsNumber3 = ~1;
var ResultIsNumber4 = ~{ x: 1, y: 2};
var ResultIsNumber5 = ~{ x: 1, y: (n: number) => { return n; } };
// number type expressions
var ResultIsNumber6 = ~objA.a;
var ResultIsNumber7 = ~M.n;
var ResultIsNumber8 = ~NUMBER1[0];
var ResultIsNumber9 = ~foo();
var ResultIsNumber10 = ~A.foo();
var ResultIsNumber11 = ~(NUMBER + NUMBER);
// multiple ~ operators
var ResultIsNumber12 = ~~NUMBER;
var ResultIsNumber13 = ~~~(NUMBER + NUMBER);
// miss assignment operators
~NUMBER;
~NUMBER1;
~foo();
~objA.a;
~M.n;
~objA.a, M.n; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/bitwiseNotOperatorWithStringType.ts | TypeScript | // @allowUnreachableCode: true
// ~ 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 ResultIsNumber1 = ~STRING;
var ResultIsNumber2 = ~STRING1;
// string type literal
var ResultIsNumber3 = ~"";
var ResultIsNumber4 = ~{ x: "", y: "" };
var ResultIsNumber5 = ~{ x: "", y: (s: string) => { return s; } };
// string type expressions
var ResultIsNumber6 = ~objA.a;
var ResultIsNumber7 = ~M.n;
var ResultIsNumber8 = ~STRING1[0];
var ResultIsNumber9 = ~foo();
var ResultIsNumber10 = ~A.foo();
var ResultIsNumber11 = ~(STRING + STRING);
var ResultIsNumber12 = ~STRING.charAt(0);
// multiple ~ operators
var ResultIsNumber13 = ~~STRING;
var ResultIsNumber14 = ~~~(STRING + STRING);
//miss assignment operators
~STRING;
~STRING1;
~foo();
~objA.a,M.n; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/bivariantInferences.ts | TypeScript | // @strict: true
// Repro from #27337
interface Array<T> {
equalsShallow<T>(this: ReadonlyArray<T>, other: ReadonlyArray<T>): boolean;
}
declare const a: (string | number)[] | null[] | undefined[] | {}[];
declare const b: (string | number)[] | null[] | undefined[] | {}[];
let x = a.equalsShallow(b);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/boolInsteadOfBoolean.ts | TypeScript | var x: bool;
var a: boolean = x;
x = a; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/booleanLiteralTypes1.ts | TypeScript | type A1 = true | false;
type A2 = false | true;
function f1() {
var a: A1;
var a: A2;
var a: true | false;
var a: false | true;
}
function f2(a: true | false, b: boolean) {
a = b;
b = a;
}
function f3(a: true | false, b: true | false) {
var x = a || b;
var x = a && b;
var x = !a;
}
function f4(t: true, f: false) {
var x1 = t && f;
var x2 = f && t;
var x3 = t || f;
var x4 = f || t;
var x5 = !t;
var x6 = !f;
}
declare function g(x: true): string;
declare function g(x: false): boolean;
declare function g(x: boolean): number;
function f5(b: boolean) {
var z1 = g(true);
var z2 = g(false);
var z3 = g(b);
}
function assertNever(x: never): never {
throw new Error("Unexpected value");
}
function f10(x: true | false) {
switch (x) {
case true: return "true";
case false: return "false";
}
}
function f11(x: true | false) {
switch (x) {
case true: return "true";
case false: return "false";
}
return assertNever(x);
}
function f12(x: true | false) {
if (x) {
x;
}
else {
x;
}
}
function f13(x: true | false) {
if (x === true) {
x;
}
else {
x;
}
}
type Item =
{ kind: true, a: string } |
{ kind: false, b: string };
function f20(x: Item) {
switch (x.kind) {
case true: return x.a;
case false: return x.b;
}
}
function f21(x: Item) {
switch (x.kind) {
case true: return x.a;
case false: return x.b;
}
return assertNever(x);
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/booleanLiteralTypes2.ts | TypeScript | // @strictNullChecks: true
type A1 = true | false;
type A2 = false | true;
function f1() {
var a: A1;
var a: A2;
var a: true | false;
var a: false | true;
}
function f2(a: true | false, b: boolean) {
a = b;
b = a;
}
function f3(a: true | false, b: true | false) {
var x = a || b;
var x = a && b;
var x = !a;
}
function f4(t: true, f: false) {
var x1 = t && f;
var x2 = f && t;
var x3 = t || f;
var x4 = f || t;
var x5 = !t;
var x6 = !f;
}
declare function g(x: true): string;
declare function g(x: false): boolean;
declare function g(x: boolean): number;
function f5(b: boolean) {
var z1 = g(true);
var z2 = g(false);
var z3 = g(b);
}
function assertNever(x: never): never {
throw new Error("Unexpected value");
}
function f10(x: true | false) {
switch (x) {
case true: return "true";
case false: return "false";
}
}
function f11(x: true | false) {
switch (x) {
case true: return "true";
case false: return "false";
}
return assertNever(x);
}
function f12(x: true | false) {
if (x) {
x;
}
else {
x;
}
}
function f13(x: true | false) {
if (x === true) {
x;
}
else {
x;
}
}
type Item =
{ kind: true, a: string } |
{ kind: false, b: string };
function f20(x: Item) {
switch (x.kind) {
case true: return x.a;
case false: return x.b;
}
}
function f21(x: Item) {
switch (x.kind) {
case true: return x.a;
case false: return x.b;
}
return assertNever(x);
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/booleanPropertyAccess.ts | TypeScript | var x = true;
var a = x.toString();
var b = x['toString'](); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/bundlerSyntaxRestrictions.ts | TypeScript | // @moduleResolution: bundler
// @module: esnext, preserve
// @checkJs: true
// @allowJs: true
// @outDir: out
// @Filename: /node_modules/@types/node/index.d.ts
declare var require: (...args: any[]) => any;
// @Filename: /ambient.d.ts
declare module "fs" {
export function readFileSync(path: string, encoding?: string): string;
}
declare module "path" {
import fs = require("fs"); // ok
namespace path {
export const sep: string;
}
export = path; // ok
}
// @Filename: /mainJs.js
import {} from "./a";
import("./a");
const _ = require("./a");
_.a; // any
// @Filename: /main.ts
import {} from "./a";
import _ = require("./a"); // Error in esnext
export = {}; // Error
export {};
// @Filename: /a.ts
export const a = "a";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callChain.2.ts | TypeScript | // @strict: false
declare const o1: undefined | (() => number);
o1?.();
declare const o2: undefined | { b: () => number };
o2?.b();
declare const o3: { b: (() => { c: string }) | undefined };
o3.b?.().c;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callChain.3.ts | TypeScript | // @strict: true
declare function absorb<T>(): T;
declare const a: { m?<T>(obj: {x: T}): T } | undefined;
const n1: number = a?.m?.({x: 12 }); // should be an error (`undefined` is not assignable to `number`)
const n2: number = a?.m?.({x: absorb()}); // likewise
const n3: number | undefined = a?.m?.({x: 12}); // should be ok
const n4: number | undefined = a?.m?.({x: absorb()}); // likewise
// Also a test showing `!` vs `?` for good measure
let t1 = a?.m?.({x: 12});
t1 = a!.m!({x: 12}); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callChain.ts | TypeScript | // @strict: true
declare const o1: undefined | ((...args: any[]) => number);
o1?.();
o1?.(1);
o1?.(...[1, 2]);
o1?.(1, ...[2, 3], 4);
declare const o2: undefined | { b: (...args: any[]) => number };
o2?.b();
o2?.b(1);
o2?.b(...[1, 2]);
o2?.b(1, ...[2, 3], 4);
o2?.["b"]();
o2?.["b"](1);
o2?.["b"](...[1, 2]);
o2?.["b"](1, ...[2, 3], 4);
declare const o3: { b: ((...args: any[]) => { c: string }) | undefined };
o3.b?.().c;
o3.b?.(1).c;
o3.b?.(...[1, 2]).c;
o3.b?.(1, ...[2, 3], 4).c;
o3.b?.()["c"];
o3.b?.(1)["c"];
o3.b?.(...[1, 2])["c"];
o3.b?.(1, ...[2, 3], 4)["c"];
o3["b"]?.().c;
o3["b"]?.(1).c;
o3["b"]?.(...[1, 2]).c;
o3["b"]?.(1, ...[2, 3], 4).c;
declare const o4: undefined | (<T>(f: (a: T) => T) => T);
declare function incr(x: number): number;
const v: number | undefined = o4?.(incr);
// GH#33744
declare const o5: <T>() => undefined | (() => void);
o5<number>()?.();
// GH#36031
o2?.b()!.toString;
o2?.b()!.toString!; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callChainInference.ts | TypeScript | // @strict: true
// Repro from #42404
interface Y {
foo<T>(this: T, arg: keyof T): void;
a: number;
b: string;
}
declare const value: Y | undefined;
if (value) {
value?.foo("a");
}
value?.foo("a");
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callChainWithSuper.ts | TypeScript | // @target: *,-es3
// @strict: true
// @noTypesAndSymbols: true
// GH#34952
class Base { method?() {} }
class Derived extends Base {
method1() { return super.method?.(); }
method2() { return super["method"]?.(); }
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callGenericFunctionWithIncorrectNumberOfTypeArguments.ts | TypeScript | // type parameter lists must exactly match type argument lists
// all of these invocations are errors
function f<T, U>(x: T, y: U): T { return null; }
var r1 = f<number>(1, '');
var r1b = f<number, string, number>(1, '');
var f2 = <T, U>(x: T, y: U): T => { return null; }
var r2 = f2<number>(1, '');
var r2b = f2<number, string, number>(1, '');
var f3: { <T, U>(x: T, y: U): T; }
var r3 = f3<number>(1, '');
var r3b = f3<number, string, number>(1, '');
class C {
f<T, U>(x: T, y: U): T {
return null;
}
}
var r4 = (new C()).f<number>(1, '');
var r4b = (new C()).f<number, string, number>(1, '');
interface I {
f<T, U>(x: T, y: U): T;
}
var i: I;
var r5 = i.f<number>(1, '');
var r5b = i.f<number, string, number>(1, '');
class C2<T, U> {
f(x: T, y: U): T {
return null;
}
}
var r6 = (new C2()).f<number>(1, '');
var r6b = (new C2()).f<number, string, number>(1, '');
interface I2<T, U> {
f(x: T, y: U): T;
}
var i2: I2<number, string>;
var r7 = i2.f<number>(1, '');
var r7b = i2.f<number, string, number>(1, ''); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callGenericFunctionWithZeroTypeArguments.ts | TypeScript | // valid invocations of generic functions with no explicit type arguments provided
function f<T>(x: T): T { return null; }
var r = f(1);
var f2 = <T>(x: T): T => { return null; }
var r2 = f2(1);
var f3: { <T>(x: T): T; }
var r3 = f3(1);
class C {
f<T>(x: T): T {
return null;
}
}
var r4 = (new C()).f(1);
interface I {
f<T>(x: T): T;
}
var i: I;
var r5 = i.f(1);
class C2<T> {
f(x: T): T {
return null;
}
}
var r6 = (new C2()).f(1);
interface I2<T> {
f(x: T): T;
}
var i2: I2<number>;
var r7 = i2.f(1); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callNonGenericFunctionWithTypeArguments.ts | TypeScript | // it is always illegal to provide type arguments to a non-generic function
// all invocations here are illegal
function f(x: number) { return null; }
var r = f<string>(1);
var f2 = (x: number) => { return null; }
var r2 = f2<string>(1);
var f3: { (x: number): any; }
var r3 = f3<string>(1);
class C {
f(x: number) {
return null;
}
}
var r4 = (new C()).f<string>(1);
interface I {
f(x: number): any;
}
var i: I;
var r5 = i.f<string>(1);
class C2 {
f(x: number) {
return null;
}
}
var r6 = (new C2()).f<string>(1);
interface I2 {
f(x: number);
}
var i2: I2;
var r7 = i2.f<string>(1);
var a;
var r8 = a<number>();
var a2: any;
var r8 = a2<number>(); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callOfPropertylessConstructorFunction.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: callOfPropertylessConstructorFunction.js
/**
* @constructor
*/
function Dependency(j) {
return j
}
Dependency({})
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callOverload.ts | TypeScript | declare function fn(x: any): void;
declare function takeTwo(x: any, y: any): void;
declare function withRest(a: any, ...args: Array<any>): void;
var n: number[];
fn(1) // no error
fn(1, 2, 3, 4)
takeTwo(1, 2, 3, 4)
withRest('a', ...n); // no error
withRest();
withRest(...n); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callSignatureAssignabilityInInheritance.ts | TypeScript | module CallSignature {
interface Base { // T
// M's
(x: number): void;
(x: number, y: number): void;
}
// S's
interface I extends Base {
// N's
(x: number): number; // ok because base returns void
(x: number, y: number): boolean; // ok because base returns void
<T>(x: T): string; // ok because base returns void
}
interface Base2 { // T
// M's
(x: number): number;
}
// S's
interface I2 extends Base2 {
// N's
(x: number): string; // error because base returns non-void;
}
// S's
interface I3 extends Base2 {
// N's
<T>(x: T): string; // ok, adds a new call signature
}
}
module MemberWithCallSignature {
interface Base { // T
// M's
a: (x: number) => void;
a2: (x: number, y: number) => void;
a3: <T>(x: T) => void;
}
// S's
interface I extends Base {
// N's
a: (x: number) => number; // ok because base returns void
a2: (x: number, y: number) => boolean; // ok because base returns void
a3: <T>(x: T) => string; // ok because base returns void
}
interface Base2 { // T
// M's
a: (x: number) => number;
a2: <T>(x: T) => T;
}
// S's
interface I2 extends Base2 {
// N's
a: (x: number) => string; // error because base returns non-void;
}
// S's
interface I3 extends Base2 {
// N's
a2: <T>(x: T) => string; // error because base returns non-void;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callSignatureAssignabilityInInheritance2.ts | TypeScript | // checking subtype relations for function types as it relates to contextual signature instantiation
class Base { foo: string; }
class Derived extends Base { bar: string; }
class Derived2 extends Derived { baz: string; }
class OtherDerived extends Base { bing: string; }
interface A { // T
// M's
a: (x: number) => number[];
a2: (x: number) => string[];
a3: (x: number) => void;
a4: (x: string, y: number) => string;
a5: (x: (arg: string) => number) => string;
a6: (x: (arg: Base) => Derived) => Base;
a7: (x: (arg: Base) => Derived) => (r: Base) => Derived;
a8: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived;
a9: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived;
a10: (...x: Derived[]) => Derived;
a11: (x: { foo: string }, y: { foo: string; bar: string }) => Base;
a12: (x: Array<Base>, y: Array<Derived2>) => Array<Derived>;
a13: (x: Array<Base>, y: Array<Derived>) => Array<Derived>;
a14: (x: { a: string; b: number }) => Object;
a15: {
(x: number): number[];
(x: string): string[];
};
a16: {
<T extends Derived>(x: T): number[];
<U extends Base>(x: U): number[];
};
a17: {
(x: (a: number) => number): number[];
(x: (a: string) => string): string[];
};
a18: {
(x: {
(a: number): number;
(a: string): string;
}): any[];
(x: {
(a: boolean): boolean;
(a: Date): Date;
}): any[];
};
}
// S's
interface I extends A {
// N's
a: <T>(x: T) => T[]; // ok, instantiation of N is a subtype of M, T is number
a2: <T>(x: T) => string[]; // ok
a3: <T>(x: T) => T; // ok since Base returns void
a4: <T, U>(x: T, y: U) => T; // ok, instantiation of N is a subtype of M, T is string, U is number
a5: <T, U>(x: (arg: T) => U) => T; // ok, U is in a parameter position so inferences can be made
a6: <T extends Base, U extends Derived>(x: (arg: T) => U) => T; // ok, same as a5 but with object type hierarchy
a7: <T extends Base, U extends Derived>(x: (arg: T) => U) => (r: T) => U; // ok
a8: <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U; // ok
a9: <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: string; bing: number }) => U) => (r: T) => U; // ok, same as a8 with compatible object literal
a10: <T extends Derived>(...x: T[]) => T; // ok
a11: <T extends Base>(x: T, y: T) => T; // ok
a12: <T extends Array<Base>>(x: Array<Base>, y: T) => Array<Derived>; // ok, less specific parameter type
a13: <T extends Array<Derived>>(x: Array<Base>, y: T) => T; // ok, T = Array<Derived>, satisfies constraint, contextual signature instantiation succeeds
a14: <T, U>(x: { a: T; b: U }) => T; // ok
a15: <T>(x: T) => T[]; // ok
a16: <T extends Base>(x: T) => number[]; // ok
a17: <T>(x: (a: T) => T) => T[]; // ok
a18: <T>(x: (a: T) => T) => T[]; // ok, no inferences for T but assignable to any
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callSignatureAssignabilityInInheritance3.ts | TypeScript | // checking subtype relations for function types as it relates to contextual signature instantiation
// error cases
module Errors {
class Base { foo: string; }
class Derived extends Base { bar: string; }
class Derived2 extends Derived { baz: string; }
class OtherDerived extends Base { bing: string; }
module WithNonGenericSignaturesInBaseType {
// base type with non-generic call signatures
interface A {
a2: (x: number) => string[];
a7: (x: (arg: Base) => Derived) => (r: Base) => Derived2;
a8: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived;
a10: (...x: Base[]) => Base;
a11: (x: { foo: string }, y: { foo: string; bar: string }) => Base;
a12: (x: Array<Base>, y: Array<Derived2>) => Array<Derived>;
a14: {
(x: number): number[];
(x: string): string[];
};
a15: (x: { a: string; b: number }) => number;
a16: {
// type of parameter is overload set which means we can't do inference based on this type
(x: {
(a: number): number;
(a?: number): number;
}): number[];
(x: {
(a: boolean): boolean;
(a?: boolean): boolean;
}): boolean[];
};
a17: {
(x: {
<T extends Derived>(a: T): T;
<T extends Base>(a: T): T;
}): any[];
(x: {
<T extends Derived2>(a: T): T;
<T extends Base>(a: T): T;
}): any[];
};
}
interface I extends A {
a2: <T, U>(x: T) => U[]; // error, contextual signature instantiation doesn't relate return types so U is {}, not a subtype of string[]
}
interface I2<T, U> extends A {
a2: (x: T) => U[]; // error, no contextual signature instantiation since I2.a2 is not generic
}
interface I3 extends A {
// valid, no inferences for V so it defaults to Derived2
a7: <T extends Base, U extends Derived, V extends Derived2>(x: (arg: T) => U) => (r: T) => V;
}
interface I4 extends A {
a8: <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U; // error, type mismatch
}
interface I4B extends A {
a10: <T extends Derived>(...x: T[]) => T; // valid, parameter covariance works even after contextual signature instantiation
}
interface I4C extends A {
a11: <T extends Derived>(x: T, y: T) => T; // valid, even though x is a Base, parameter covariance works even after contextual signature instantiation
}
interface I4E extends A {
a12: <T extends Array<Derived2>>(x: Array<Base>, y: Array<Base>) => T; // valid, no inferences for T, defaults to Array<Derived2>
}
interface I6 extends A {
a15: <T>(x: { a: T; b: T }) => T; // error, T is {} which isn't an acceptable return type
}
interface I7 extends A {
a15: <T extends Base>(x: { a: T; b: T }) => number; // error, T defaults to Base, which is not compatible with number or string
}
interface I8 extends A {
// ok, we relate each signature of a16 to b16, and within that, we make inferences from two different signatures in the respective A.a16 signature
a16: <T>(x: (a: T) => T) => T[];
}
interface I9 extends A {
a17: <T>(x: (a: T) => T) => any[]; // valid, target is more constrained than source, so it is safe in the traditional constraint-contravariant fashion
}
}
module WithGenericSignaturesInBaseType {
// base type has generic call signature
interface B {
a2: <T>(x: T) => T[];
}
interface I6 extends B {
a2: <T>(x: T) => string[]; // error
}
// base type has generic call signature
interface C {
a2: <T>(x: T) => string[];
}
interface I7 extends C {
a2: <T>(x: T) => T[]; // error
}
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callSignatureAssignabilityInInheritance4.ts | TypeScript | // checking subtype relations for function types as it relates to contextual signature instantiation
class Base { foo: string; }
class Derived extends Base { bar: string; }
class Derived2 extends Derived { baz: string; }
class OtherDerived extends Base { bing: string; }
interface A { // T
// M's
a: <T>(x: T) => T[];
a2: <T>(x: T) => string[];
a3: <T>(x: T) => void;
a4: <T,U>(x: T, y: U) => string;
a5: <T,U>(x: (arg: T) => U) => T;
a6: <T extends Base>(x: (arg: T) => Derived) => T;
a11: <T>(x: { foo: T }, y: { foo: T; bar: T }) => Base;
a15: <T>(x: { a: T; b: T }) => T[];
a16: <T extends Base>(x: { a: T; b: T }) => T[];
a17: {
<T extends Derived>(x: (a: T) => T): T[];
<T extends Base>(x: (a: T) => T): T[];
};
a18: {
(x: {
<T extends Derived>(a: T): T;
<T extends Base>(a: T): T;
}): any[];
(x: {
<T extends Derived2>(a: T): T;
<T extends Base>(a: T): T;
}): any[];
};
}
// S's
interface I extends A {
// N's
a: <T>(x: T) => T[]; // ok, instantiation of N is a subtype of M, T is number
a2: <T>(x: T) => string[]; // ok
a3: <T>(x: T) => T; // ok since Base returns void
a4: <T, U>(x: T, y: U) => string; // ok, instantiation of N is a subtype of M, T is string, U is number
a5: <T, U>(x: (arg: T) => U) => T; // ok, U is in a parameter position so inferences can be made
a6: <T extends Base, U extends Derived>(x: (arg: T) => U) => T; // ok, same as a5 but with object type hierarchy
a11: <T, U>(x: { foo: T }, y: { foo: U; bar: U }) => Base; // ok
a15: <U, V>(x: { a: U; b: V; }) => U[]; // ok, T = U, T = V
a16: <T>(x: { a: T; b: T }) => T[]; // ok, more general parameter type
a17: <T>(x: (a: T) => T) => T[]; // ok
a18: (x: <T>(a: T) => T) => any[]; // ok
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callSignatureAssignabilityInInheritance5.ts | TypeScript | // checking subtype relations for function types as it relates to contextual signature instantiation
// same as subtypingWithCallSignatures2 just with an extra level of indirection in the inheritance chain
class Base { foo: string; }
class Derived extends Base { bar: string; }
class Derived2 extends Derived { baz: string; }
class OtherDerived extends Base { bing: string; }
interface A { // T
// M's
a: (x: number) => number[];
a2: (x: number) => string[];
a3: (x: number) => void;
a4: (x: string, y: number) => string;
a5: (x: (arg: string) => number) => string;
a6: (x: (arg: Base) => Derived) => Base;
a7: (x: (arg: Base) => Derived) => (r: Base) => Derived;
a8: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived;
a9: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived;
a10: (...x: Derived[]) => Derived;
a11: (x: { foo: string }, y: { foo: string; bar: string }) => Base;
a12: (x: Array<Base>, y: Array<Derived2>) => Array<Derived>;
a13: (x: Array<Base>, y: Array<Derived>) => Array<Derived>;
a14: (x: { a: string; b: number }) => Object;
}
interface B extends A {
a: <T>(x: T) => T[];
}
// S's
interface I extends B {
// N's
a: <T>(x: T) => T[]; // ok, instantiation of N is a subtype of M, T is number
a2: <T>(x: T) => string[]; // ok
a3: <T>(x: T) => T; // ok since Base returns void
a4: <T, U>(x: T, y: U) => T; // ok, instantiation of N is a subtype of M, T is string, U is number
a5: <T, U>(x: (arg: T) => U) => T; // ok, U is in a parameter position so inferences can be made
a6: <T extends Base, U extends Derived>(x: (arg: T) => U) => T; // ok, same as a5 but with object type hierarchy
a7: <T extends Base, U extends Derived>(x: (arg: T) => U) => (r: T) => U; // ok
a8: <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U; // ok
a9: <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: string; bing: number }) => U) => (r: T) => U; // ok, same as a8 with compatible object literal
a10: <T extends Derived>(...x: T[]) => T; // ok
a11: <T extends Base>(x: T, y: T) => T; // ok
a12: <T extends Array<Base>>(x: Array<Base>, y: T) => Array<Derived>; // ok, less specific parameter type
a13: <T extends Array<Derived>>(x: Array<Base>, y: T) => T; // ok, T = Array<Derived>, satisfies constraint, contextual signature instantiation succeeds
a14: <T, U>(x: { a: T; b: U }) => T; // ok
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callSignatureAssignabilityInInheritance6.ts | TypeScript | // checking subtype relations for function types as it relates to contextual signature instantiation
// same as subtypingWithCallSignatures4 but using class type parameters instead of generic signatures
// all are errors
class Base { foo: string; }
class Derived extends Base { bar: string; }
class Derived2 extends Derived { baz: string; }
class OtherDerived extends Base { bing: string; }
interface A { // T
// M's
a: <T>(x: T) => T[];
a2: <T>(x: T) => string[];
a3: <T>(x: T) => void;
a4: <T,U>(x: T, y: U) => string;
a5: <T,U>(x: (arg: T) => U) => T;
a6: <T extends Base>(x: (arg: T) => Derived) => T;
a11: <T>(x: { foo: T }, y: { foo: T; bar: T }) => Base;
a15: <T>(x: { a: T; b: T }) => T[];
a16: <T extends Base>(x: { a: T; b: T }) => T[];
}
// S's
interface I<T> extends A {
a: (x: T) => T[];
}
interface I2<T> extends A {
a2: (x: T) => string[];
}
interface I3<T> extends A {
a3: (x: T) => T;
}
interface I4<T> extends A {
a4: <U>(x: T, y: U) => string;
}
interface I5<T> extends A {
a5: <U>(x: (arg: T) => U) => T;
}
interface I7<T> extends A {
a11: <U>(x: { foo: T }, y: { foo: U; bar: U }) => Base;
}
interface I9<T> extends A {
a16: (x: { a: T; b: T }) => T[];
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callSignatureWithoutAnnotationsOrBody.ts | TypeScript | // Call signatures without a return type annotation and function body return 'any'
function foo(x) { }
var r = foo(1); // void since there's a body
interface I {
();
f();
}
var i: I;
var r2 = i();
var r3 = i.f();
var a: {
();
f();
};
var r4 = a();
var r5 = a.f(); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callSignatureWithoutReturnTypeAnnotationInference.ts | TypeScript | // @allowUnreachableCode: true
// Call signatures without a return type should infer one from the function body (if present)
// Simple types
function foo(x) {
return 1;
}
var r = foo(1);
function foo2(x) {
return foo(x);
}
var r2 = foo2(1);
function foo3() {
return foo3();
}
var r3 = foo3();
function foo4<T>(x: T) {
return x;
}
var r4 = foo4(1);
function foo5(x) {
if (true) {
return 1;
} else {
return 2;
}
}
var r5 = foo5(1);
function foo6(x) {
try {
}
catch (e) {
return [];
}
finally {
return [];
}
}
var r6 = foo6(1);
function foo7(x) {
return typeof x;
}
var r7 = foo7(1);
// object types
function foo8(x: number) {
return { x: x };
}
var r8 = foo8(1);
interface I {
foo: string;
}
function foo9(x: number) {
var i: I;
return i;
}
var r9 = foo9(1);
class C {
foo: string;
}
function foo10(x: number) {
var c: C;
return c;
}
var r10 = foo10(1);
module M {
export var x = 1;
export class C { foo: string }
}
function foo11() {
return M;
}
var r11 = foo11();
// merged declarations
interface I2 {
x: number;
}
interface I2 {
y: number;
}
function foo12() {
var i2: I2;
return i2;
}
var r12 = foo12();
function m1() { return 1; }
module m1 { export var y = 2; }
function foo13() {
return m1;
}
var r13 = foo13();
class c1 {
foo: string;
constructor(x) { }
}
module c1 {
export var x = 1;
}
function foo14() {
return c1;
}
var r14 = foo14();
enum e1 { A }
module e1 { export var y = 1; }
function foo15() {
return e1;
}
var r15 = foo15(); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callSignaturesThatDifferOnlyByReturnType.ts | TypeScript | // Each pair of signatures in these types has a signature that should cause an error.
// Overloads, generic or not, that differ only by return type are an error.
interface I {
(x): number;
(x): void; // error
<T>(x: T): number;
<T>(x: T): string; // error
}
interface I2 {
<T>(x: T): number;
<T>(x: T): string; // error
}
interface I3<T> {
(x: T): number;
(x: T): string; // error
}
var a: {
(x, y): Object;
(x, y): any; // error
}
var a2: {
<T>(x: T): number;
<T>(x: T): string; // error
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callSignaturesThatDifferOnlyByReturnType2.ts | TypeScript | // Normally it is an error to have multiple overloads which differ only by return type in a single type declaration.
// Here the multiple overloads come from multiple bases.
interface I<T> {
foo(x: number): T;
}
interface A extends I<number>, I<string> { }
var x: A;
// BUG 822524
var r = x.foo(1); // no error
var r2 = x.foo(''); // error
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callSignaturesThatDifferOnlyByReturnType3.ts | TypeScript | // Normally it is an error to have multiple overloads with identical signatures in a single type declaration.
// Here the multiple overloads come from multiple merged declarations.
interface I {
(x: string): string;
}
interface I {
(x: string): number;
}
interface I2<T> {
(x: string): string;
}
interface I2<T> {
(x: string): number;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callSignaturesWithAccessibilityModifiersOnParameters.ts | TypeScript | // Call signature parameters do not allow accessibility modifiers
function foo(public x, private y) { }
var f = function foo(public x, private y) { }
var f2 = function (public x, private y) { }
var f3 = (x, private y) => { }
var f4 = <T>(public x: T, y: T) => { }
function foo2(private x: string, public y: number) { }
var f5 = function foo(private x: string, public y: number) { }
var f6 = function (private x: string, public y: number) { }
var f7 = (private x: string, public y: number) => { }
var f8 = <T>(private x: T, public y: T) => { }
class C {
foo(public x, private y) { }
foo2(public x: number, private y: string) { }
foo3<T>(public x: T, private y: T) { }
}
interface I {
(private x, public y);
(private x: string, public y: number);
foo(private x, public y);
foo(public x: number, y: string);
foo3<T>(x: T, private y: T);
}
var a: {
foo(public x, private y);
foo2(private x: number, public y: string);
};
var b = {
foo(public x, y) { },
a: function foo(x: number, private y: string) { },
b: <T>(public x: T, private y: T) => { }
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callSignaturesWithDuplicateParameters.ts | TypeScript | // Duplicate parameter names are always an error
function foo(x, x) { }
var f = function foo(x, x) { }
var f2 = function (x, x) { }
var f3 = (x, x) => { }
var f4 = <T>(x: T, x: T) => { }
function foo2(x: string, x: number) { }
var f5 = function foo(x: string, x: number) { }
var f6 = function (x: string, x: number) { }
var f7 = (x: string, x: number) => { }
var f8 = <T>(x: T, y: T) => { }
class C {
foo(x, x) { }
foo2(x: number, x: string) { }
foo3<T>(x: T, x: T) { }
}
interface I {
(x, x);
(x: string, x: number);
foo(x, x);
foo(x: number, x: string);
foo3<T>(x: T, x: T);
}
var a: {
foo(x, x);
foo2(x: number, x: string);
};
var b = {
foo(x, x) { },
a: function foo(x: number, x: string) { },
b: <T>(x: T, x: T) => { }
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callSignaturesWithOptionalParameters.ts | TypeScript | // Optional parameters should be valid in all the below casts
function foo(x?: number) { }
var f = function foo(x?: number) { }
var f2 = (x: number, y?: number) => { }
foo(1);
foo();
f(1);
f();
f2(1);
f2(1, 2);
class C {
foo(x?: number) { }
}
var c: C;
c.foo();
c.foo(1);
interface I {
(x?: number);
foo(x: number, y?: number);
}
var i: I;
i();
i(1);
i.foo(1);
i.foo(1, 2);
var a: {
(x?: number);
foo(x?: number);
}
a();
a(1);
a.foo();
a.foo(1);
var b = {
foo(x?: number) { },
a: function foo(x: number, y?: number) { },
b: (x?: number) => { }
}
b.foo();
b.foo(1);
b.a(1);
b.a(1, 2);
b.b();
b.b(1);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callSignaturesWithOptionalParameters2.ts | TypeScript | // Optional parameters should be valid in all the below casts
function foo(x?: number);
function foo(x?: number) { }
foo(1);
foo();
function foo2(x: number);
function foo2(x: number, y?: number);
function foo2(x: number, y?: number) { }
foo2(1);
foo2(1, 2);
class C {
foo(x?: number);
foo(x?: number) { }
foo2(x: number);
foo2(x: number, y?: number);
foo2(x: number, y?: number) { }
}
var c: C;
c.foo();
c.foo(1);
c.foo2(1);
c.foo2(1, 2);
interface I {
(x?: number);
(x?: number, y?: number);
foo(x: number, y?: number);
foo(x: number, y?: number, z?: number);
}
var i: I;
i();
i(1);
i(1, 2);
i.foo(1);
i.foo(1, 2);
i.foo(1, 2, 3);
var a: {
(x?: number);
(x?: number, y?: number);
foo(x: number, y?: number);
foo(x: number, y?: number, z?: number);
}
a();
a(1);
a(1, 2);
a.foo(1);
a.foo(1, 2);
a.foo(1, 2, 3); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callSignaturesWithParameterInitializers.ts | TypeScript | // Optional parameters allow initializers only in implementation signatures
function foo(x = 1) { }
var f = function foo(x = 1) { }
var f2 = (x: number, y = 1) => { }
foo(1);
foo();
f(1);
f();
f2(1);
f2(1, 2);
class C {
foo(x = 1) { }
}
var c: C;
c.foo();
c.foo(1);
// these are errors
interface I {
(x = 1);
foo(x: number, y = 1);
}
var i: I;
i();
i(1);
i.foo(1);
i.foo(1, 2);
// these are errors
var a: {
(x = 1);
foo(x = 1);
}
a();
a(1);
a.foo();
a.foo(1);
var b = {
foo(x = 1) { },
a: function foo(x: number, y = 1) { },
b: (x = 1) => { }
}
b.foo();
b.foo(1);
b.a(1);
b.a(1, 2);
b.b();
b.b(1);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callWithMissingVoid.ts | TypeScript | // @strict: true
// From #4260
class X<T> {
f(t: T) {
return { a: t };
}
}
declare const x: X<void>;
x.f() // no error because f expects void
declare const xUnion: X<void | number>;
xUnion.f(42) // no error because f accepts number
xUnion.f() // no error because f accepts void
declare const xAny: X<any>;
xAny.f() // error, any still expects an argument
declare const xUnknown: X<unknown>;
xUnknown.f() // error, unknown still expects an argument
declare const xNever: X<never>;
xNever.f() // error, never still expects an argument
// Promise has previously been updated to work without arguments, but to show this fixes the issue too.
class MyPromise<X> {
constructor(executor: (resolve: (value: X) => void) => void) {
}
}
new MyPromise<void>(resolve => resolve()); // no error
new MyPromise<void | number>(resolve => resolve()); // no error
new MyPromise<any>(resolve => resolve()); // error, `any` arguments cannot be omitted
new MyPromise<unknown>(resolve => resolve()); // error, `unknown` arguments cannot be omitted
new MyPromise<never>(resolve => resolve()); // error, `never` arguments cannot be omitted
// Multiple parameters
function a(x: number, y: string, z: void): void {
}
a(4, "hello"); // ok
a(4, "hello", void 0); // ok
a(4); // not ok
function b(x: number, y: string, z: void, what: number): void {
}
b(4, "hello", void 0, 2); // ok
b(4, "hello"); // not ok
b(4, "hello", void 0); // not ok
b(4); // not ok
function c(x: number | void, y: void, z: void | string | number): void {
}
c(3, void 0, void 0); // ok
c(3, void 0); // ok
c(3); // ok
c(); // ok
// Spread Parameters
declare function call<TS extends unknown[]>(
handler: (...args: TS) => unknown,
...args: TS): void;
call((x: number, y: number) => x + y) // error
call((x: number, y: number) => x + y, 4, 2) // ok
call((x: number, y: void) => x, 4, void 0) // ok
call((x: number, y: void) => x, 4) // ok
call((x: void, y: void) => 42) // ok
call((x: number | void, y: number | void) => 42) // ok
call((x: number | void, y: number | void) => 42, 4) // ok
call((x: number | void, y: number | void) => 42, 4, 2) // ok
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callWithMissingVoidUndefinedUnknownAnyInJs.ts | TypeScript | // @strict: *
// @checkJS: true
// @allowJS: true
// @noEmit: true
// @filename: defs.d.ts
declare function f1(p: void): void;
declare function f2(p: undefined): void;
declare function f3(p: unknown): void;
declare function f4(p: any): void;
interface I<T> { m(p: T): void; }
declare const o1: I<void>;
declare const o2: I<undefined>;
declare const o3: I<unknown>;
declare const o4: I<any>;
// @filename: jsfile.js
// current behavior: treat trailing `void` as optional
f1();
o1.m();
// new behavior: treat 'undefined', 'unknown', and 'any' as optional in non-strict mode
f2();
f3();
f4();
o2.m();
o3.m();
o4.m();
// @filename: tsfile.ts
// current behavior: treat trailing `void` as optional
f1();
o1.m();
// no change in behavior
f2();
f3();
f4();
o2.m();
o3.m();
o4.m();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callWithSpread.ts | TypeScript | interface X {
foo(x: number, y: number, ...z: string[]): X;
}
function foo(x: number, y: number, ...z: string[]) {
}
var a: string[];
var z: number[];
var obj: X;
var xa: X[];
foo(1, 2, "abc");
foo(1, 2, ...a);
foo(1, 2, ...a, "abc");
obj.foo(1, 2, "abc");
obj.foo(1, 2, ...a);
obj.foo(1, 2, ...a, "abc");
obj.foo(1, 2, ...a).foo(1, 2, "abc");
obj.foo(1, 2, ...a).foo(1, 2, ...a);
obj.foo(1, 2, ...a).foo(1, 2, ...a, "abc");
(obj.foo)(1, 2, "abc");
(obj.foo)(1, 2, ...a);
(obj.foo)(1, 2, ...a, "abc");
((obj.foo)(1, 2, ...a).foo)(1, 2, "abc");
((obj.foo)(1, 2, ...a).foo)(1, 2, ...a);
((obj.foo)(1, 2, ...a).foo)(1, 2, ...a, "abc");
xa[1].foo(1, 2, "abc");
xa[1].foo(1, 2, ...a);
xa[1].foo(1, 2, ...a, "abc");
(<Function>xa[1].foo)(...[1, 2, "abc"]);
class C {
constructor(x: number, y: number, ...z: string[]) {
this.foo(x, y);
this.foo(x, y, ...z);
}
foo(x: number, y: number, ...z: string[]) {
}
}
class D extends C {
constructor() {
super(1, 2);
super(1, 2, ...a);
}
foo() {
super.foo(1, 2);
super.foo(1, 2, ...a);
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callWithSpread2.ts | TypeScript | declare function all(a?: number, b?: number): void;
declare function weird(a?: number | string, b?: number | string): void;
declare function prefix(s: string, a?: number, b?: number): void;
declare function rest(s: string, a?: number, b?: number, ...rest: number[]): void;
declare function normal(s: string): void;
declare function thunk(): string;
declare function prefix2(s: string, n: number, a?: number, b?: number): void;
declare var ns: number[];
declare var mixed: (number | string)[];
declare var tuple: [number, string];
// good
all(...ns)
weird(...ns)
weird(...mixed)
weird(...tuple)
prefix("a", ...ns)
rest("d", ...ns)
// extra arguments
normal("g", ...ns)
thunk(...ns)
// bad
all(...mixed)
all(...tuple)
prefix("b", ...mixed)
prefix("c", ...tuple)
rest("e", ...mixed)
rest("f", ...tuple)
prefix(...ns) // required parameters are required
prefix(...mixed)
prefix(...tuple)
prefix2("g", ...ns);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callWithSpread3.ts | TypeScript | declare const s2: [string, string];
declare const s3: [string, string, string];
declare const s2_: [string, string, ...string[]];
declare const s_: string[];
declare const n_: number[];
declare const s2n_: [string, string, ...number[]];
declare function fs2(a: string, b: string): void;
declare function fs2_(a: string, b: string, ...c: string[]): void;
declare function fs2n_(a: string, b: string, ...c: number[]): void;
declare function fs5(a: string, b: string, c: string, d: string, e: string): void;
// error
fs2('a', ...s2); // error on ...s2
fs2('a', 'b', 'c', ...s2); // error on 'c' and ...s2
fs2('a', 'b', ...s2, 'c'); // error on ...s2 and 'c'
fs2('a', 'b', 'c', ...s2, 'd'); // error on 'c', ...s2 and 'd'
fs2(...s2, 'a'); // error on 'a'
fs2(...s3); // error on ...s3
fs2_(...s_); // error on ...s_
fs2_(...s2n_); // error on ...s2n_
fs2_(...s_, ...s_); // error on ...s_
fs2_(...s_, ...s_, ...s_); // error on ...s_
// fs2n_(...s2, ...s_); // FIXME: should be a type error
fs2n_(...s2_); // error on ...s2_
// ok
fs2_(...s2_);
fs2_(...s2_, ...s_);
fs2_(...s2_, ...s2_);
fs2_(...s_, ...s2_);
fs2n_(...s2n_);
fs2n_(...s2);
// fs2n_(...s2, ...n_); // FIXME: should compile
fs5(...s2, "foo", ...s2);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callWithSpread4.ts | TypeScript | // @strict: true
// @target: esnext
type R = { a: number }
type W = { b: number }
type RW = { a: number, b: number }
declare const pli: {
(s1: R, s2: RW, s3: RW, s4: RW, s5: W): Promise<void>;
(streams: ReadonlyArray<R | W | RW>): Promise<void>;
(s1: R, s2: RW | W, ...streams: Array<RW | W>): Promise<void>;
}
declare var writes: W
declare var reads: R
declare var tr: W
declare var gun: RW[]
declare var gz: RW[]
declare var fun: (inp: any) => AsyncGenerator<string, void, unknown>
pli(
reads,
...gun,
tr,
fun,
...gz,
writes
);
declare function test(x: any, y: () => string): string | undefined;
declare var anys: any[]
test(...anys)
pli(...[reads, writes, writes] as const)
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callWithSpread5.ts | TypeScript | declare const x: number
declare const nnnu: [number, number, number?]
declare const nntnnnt: [number, number] | [number, number, number]
declare function fn(a: number, b: number, bb: number, ...c: number[]): number
fn(...nnnu, x)
fn(...nntnnnt, x)
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callWithSpreadES6.ts | TypeScript | // @target: ES6
interface X {
foo(x: number, y: number, ...z: string[]);
}
function foo(x: number, y: number, ...z: string[]) {
}
var a: string[];
var z: number[];
var obj: X;
var xa: X[];
foo(1, 2, "abc");
foo(1, 2, ...a);
foo(1, 2, ...a, "abc");
obj.foo(1, 2, "abc");
obj.foo(1, 2, ...a);
obj.foo(1, 2, ...a, "abc");
(obj.foo)(1, 2, "abc");
(obj.foo)(1, 2, ...a);
(obj.foo)(1, 2, ...a, "abc");
xa[1].foo(1, 2, "abc");
xa[1].foo(1, 2, ...a);
xa[1].foo(1, 2, ...a, "abc");
(<Function>xa[1].foo)(...[1, 2, "abc"]);
class C {
constructor(x: number, y: number, ...z: string[]) {
this.foo(x, y);
this.foo(x, y, ...z);
}
foo(x: number, y: number, ...z: string[]) {
}
}
class D extends C {
constructor() {
super(1, 2);
super(1, 2, ...a);
}
foo() {
super.foo(1, 2);
super.foo(1, 2, ...a);
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callbackCrossModule.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: mod1.js
/** @callback Con - some kind of continuation
* @param {object | undefined} error
* @return {any} I don't even know what this should return
*/
module.exports = C
function C() {
this.p = 1
}
// @Filename: use.js
/** @param {import('./mod1').Con} k */
function f(k) {
if (1 === 2 - 1) {
// I guess basic math works!
}
return k({ ok: true})
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callbackOnConstructor.ts | TypeScript | // @filename: callbackOnConstructor.js
// @checkJs: true
// @outdir: dist
// @declaration: true
export class Preferences {
assignability = "no"
/**
* @callback ValueGetter_2
* @param {string} name
* @returns {boolean|number|string|undefined}
*/
constructor() {}
}
/** @type {ValueGetter_2} */
var ooscope2 = s => s.length > 0
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callbackTag1.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: cb.js
/** @callback Sid
* @param {string} s
* @returns {string} What were you expecting
*/
var x = 1
/** @type {Sid} smallId */
var sid = s => s + "!";
/** @type {NoReturn} */
var noreturn = obj => void obj.title
/**
* @callback NoReturn
* @param {{ e: number, m: number, title: string }} s - Knee deep, shores, etc
*/
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callbackTag2.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: cb.js
/** @template T
* @callback Id
* @param {T} t
* @returns {T} Maybe just return 120 and cast it?
*/
var x = 1
/** @type {Id<string>} I actually wanted to write `const "120"` */
var one_twenty = s => "120";
/** @template S
* @callback SharedId
* @param {S} ego
* @return {S}
*/
class SharedClass {
constructor() {
/** @type {SharedId<S>} */
this.id;
}
}
/** @type {SharedId<number>} */
var outside = n => n + 1;
/** @type {Final<{ fantasy }, { heroes }>} */
var noreturn = (barts, tidus, noctis) => "cecil"
/**
* @template V,X
* @callback Final
* @param {V} barts - "Barts"
* @param {X} tidus - Titus
* @param {X & V} noctis - "Prince Noctis Lucius Caelum"
* @return {"cecil" | "zidane"}
*/
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callbackTag3.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: cb.js
/** @callback Miracle
* @returns {string} What were you expecting
*/
/** @type {Miracle} smallId */
var sid = () => "!";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callbackTag4.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @strict: true
// @noEmit: true
// @filename: ./a.js
/**
* @callback C
* @this {{ a: string, b: number }}
* @param {string} a
* @param {number} b
* @returns {boolean}
*/
/** @type {C} */
const cb = function (a, b) {
this
return true
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callbackTagNamespace.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: namespaced.js
/**
* @callback NS.Nested.Inner
* @param {Object} space - spaaaaaaaaace
* @param {Object} peace - peaaaaaaaaace
* @return {string | number}
*/
var x = 1;
/** @type {NS.Nested.Inner} */
function f(space, peace) {
return '1'
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callbackTagNestedParameter.ts | TypeScript | // @emitDeclarationOnly: true
// @declaration: true
// @allowJs: true
// @checkJs: true
// @Filename: cb_nested.js
/**
* @callback WorksWithPeopleCallback
* @param {Object} person
* @param {string} person.name
* @param {number} [person.age]
* @returns {void}
*/
/**
* For each person, calls your callback.
* @param {WorksWithPeopleCallback} callback
* @returns {void}
*/
function eachPerson(callback) {
callback({ name: "Empty" });
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/callbackTagVariadicType.ts | TypeScript | // @declaration: true
// @outDir: bin/
// @checkJs: true
// @Filename: callbackTagVariadicType.js
/**
* @callback Foo
* @param {...string} args
* @returns {number}
*/
/** @type {Foo} */
export const x = () => 1
var res = x('a', 'b')
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/castingTuple.ts | TypeScript | interface I { }
class A { a = 10; }
class C implements I { c };
class D implements I { d };
class E extends A { e };
class F extends A { f };
enum E1 { one }
enum E2 { one }
// no error
var numStrTuple: [number, string] = [5, "foo"];
var emptyObjTuple = <[{}, {}]>numStrTuple;
var numStrBoolTuple = <[number, string, boolean]>numStrTuple;
var shorter = numStrBoolTuple as [number, string]
var longer = numStrTuple as [number, string, boolean]
var classCDTuple: [C, D] = [new C(), new D()];
var interfaceIITuple = <[I, I]>classCDTuple;
var classCDATuple = <[C, D, A]>classCDTuple;
var eleFromCDA1 = classCDATuple[2]; // A
var eleFromCDA2 = classCDATuple[5]; // C | D | A
var t10: [E1, E2] = [E1.one, E2.one];
var t11 = <[number, number]>t10;
var array1 = <{}[]>emptyObjTuple;
var unionTuple: [C, string | number] = [new C(), "foo"];
var unionTuple2: [C, string | number, D] = [new C(), "foo", new D()];
var unionTuple3: [number, string| number] = [10, "foo"];
var unionTuple4 = <[number, number]>unionTuple3;
// error
var t3 = <[number, number]>numStrTuple;
var t9 = <[A, I]>classCDTuple;
var array1 = <number[]>numStrTuple;
t4[2] = 10;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/chained.ts | TypeScript | // @Filename: /a.ts
class A { a!: string }
export type { A as B };
export type Z = A;
// @Filename: /b.ts
import { Z as Y } from './a';
export { B as C } from './a';
// @Filename: /c.ts
import type { C } from './b';
export { C as D };
// @Filename: /d.ts
import { D } from './c';
new D();
const d: D = {};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/chained2.ts | TypeScript | // @Filename: /a.ts
class A { a!: string }
export type { A as default };
// @Filename: /b.ts
import A from './a';
import type { default as B } from './a';
export { A, B };
// @Filename: /c.ts
import * as types from './b';
export { types as default };
// @Filename: /d.ts
import types from './c';
new types.A();
new types.B();
const a: types.A = {};
const b: types.B = {};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/chainedPrototypeAssignment.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @noImplicitAny: true
// @Filename: types.d.ts
declare function require(name: string): any;
declare var exports: any;
// @Filename: mod.js
/// <reference path='./types.d.ts'/>
var A = function A() {
this.a = 1
}
var B = function B() {
this.b = 2
}
exports.A = A
exports.B = B
A.prototype = B.prototype = {
/** @param {number} n */
m(n) {
return n + 1
}
}
// @Filename: use.js
/// <reference path='./types.d.ts'/>
var mod = require('./mod');
var a = new mod.A()
var b = new mod.B()
a.m('nope')
b.m('not really')
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/checkExportsObjectAssignProperty.ts | TypeScript | // @allowJs: true
// @noEmit: true
// @strict: true
// @checkJs: true
// @filename: mod1.js
Object.defineProperty(exports, "thing", { value: 42, writable: true });
Object.defineProperty(exports, "readonlyProp", { value: "Smith", writable: false });
Object.defineProperty(exports, "rwAccessors", { get() { return 98122 }, set(_) { /*ignore*/ } });
Object.defineProperty(exports, "readonlyAccessor", { get() { return 21.75 } });
Object.defineProperty(exports, "setonlyAccessor", {
/** @param {string} str */
set(str) {
this.rwAccessors = Number(str)
}
});
// @filename: mod2.js
Object.defineProperty(module.exports, "thing", { value: "yes", writable: true });
Object.defineProperty(module.exports, "readonlyProp", { value: "Smith", writable: false });
Object.defineProperty(module.exports, "rwAccessors", { get() { return 98122 }, set(_) { /*ignore*/ } });
Object.defineProperty(module.exports, "readonlyAccessor", { get() { return 21.75 } });
Object.defineProperty(module.exports, "setonlyAccessor", {
/** @param {string} str */
set(str) {
this.rwAccessors = Number(str)
}
});
// @filename: index.js
/**
* @type {number}
*/
const q = require("./mod1").thing;
/**
* @type {string}
*/
const u = require("./mod2").thing;
// @filename: validator.ts
import "./";
import m1 = require("./mod1");
m1.thing;
m1.readonlyProp;
m1.rwAccessors;
m1.readonlyAccessor;
m1.setonlyAccessor;
// allowed assignments
m1.thing = 10;
m1.rwAccessors = 11;
m1.setonlyAccessor = "yes";
// disallowed assignments
m1.readonlyProp = "name";
m1.readonlyAccessor = 12;
m1.thing = "no";
m1.rwAccessors = "no";
m1.setonlyAccessor = 0;
import m2 = require("./mod2");
m2.thing;
m2.readonlyProp;
m2.rwAccessors;
m2.readonlyAccessor;
m2.setonlyAccessor;
// allowed assignments
m2.thing = "ok";
m2.rwAccessors = 11;
m2.setonlyAccessor = "yes";
// disallowed assignments
m2.readonlyProp = "name";
m2.readonlyAccessor = 12;
m2.thing = 0;
m2.rwAccessors = "no";
m2.setonlyAccessor = 0;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/checkExportsObjectAssignPrototypeProperty.ts | TypeScript | // @allowJs: true
// @noEmit: true
// @strict: true
// @checkJs: true
// @filename: mod1.js
/**
* @constructor
* @param {string} name
*/
function Person(name) {
this.name = name;
}
Person.prototype.describe = function () {
return "Person called " + this.name;
};
Object.defineProperty(Person.prototype, "thing", { value: 42, writable: true });
Object.defineProperty(Person.prototype, "readonlyProp", { value: "Smith", writable: false });
Object.defineProperty(Person.prototype, "rwAccessors", { get() { return 98122 }, set(_) { /*ignore*/ } });
Object.defineProperty(Person.prototype, "readonlyAccessor", { get() { return 21.75 } });
Object.defineProperty(Person.prototype, "setonlyAccessor", {
/** @param {string} str */
set(str) {
this.rwAccessors = Number(str)
}
});
module.exports = Person;
// @filename: validator.ts
import "./";
import Person = require("./mod1");
const m1 = new Person("Name")
m1.thing;
m1.readonlyProp;
m1.rwAccessors;
m1.readonlyAccessor;
m1.setonlyAccessor;
// allowed assignments
m1.thing = 10;
m1.rwAccessors = 11;
m1.setonlyAccessor = "yes";
// disallowed assignments
m1.readonlyProp = "name";
m1.readonlyAccessor = 12;
m1.thing = "no";
m1.rwAccessors = "no";
m1.setonlyAccessor = 0;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/checkJsdocOnEndOfFile.ts | TypeScript | // @outFile: output.js
// @allowJs: true
// @checkJs: true
// @Filename: eof.js
/**
* @typedef {Array<bad>} Should have error here
*/
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/checkJsdocOptionalParamOrder.ts | TypeScript | // @allowJS: true
// @suppressOutputPathCheck: true
// @filename: 0.js
// @ts-check
/**
* @param {number} a
* @param {number} [b]
* @param {number} c
*/
function foo(a, b, c) {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/checkJsdocParamOnVariableDeclaredFunctionExpression.ts | TypeScript | // @allowJS: true
// @suppressOutputPathCheck: true
// @filename: 0.js
// @ts-check
/**
* @param {number=} n
* @param {string} [s]
*/
var x = function foo(n, s) {}
var y;
/**
* @param {boolean!} b
*/
y = function bar(b) {}
/**
* @param {string} s
*/
var one = function (s) { }, two = function (untyped) { };
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/checkJsdocParamTag1.ts | TypeScript | // @allowJS: true
// @suppressOutputPathCheck: true
// @filename: 0.js
// @ts-check
/**
* @param {number=} n
* @param {string} [s]
*/
function foo(n, s) {}
foo();
foo(1);
foo(1, "hi"); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/checkJsdocReturnTag1.ts | TypeScript | // @allowJs: true
// @outFile: dummy.js
// @filename: returns.js
// @ts-check
/**
* @returns {string} This comment is not currently exposed
*/
function f() {
return "hello";
}
/**
* @returns {string=} This comment is not currently exposed
*/
function f1() {
return "hello world";
}
/**
* @returns {string|number} This comment is not currently exposed
*/
function f2() {
return 5 || "hello";
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/checkJsdocReturnTag2.ts | TypeScript | // @allowJs: true
// @outFile: dummy.js
// @filename: returns.js
// @ts-check
/**
* @returns {string} This comment is not currently exposed
*/
function f() {
return 5;
}
/**
* @returns {string | number} This comment is not currently exposed
*/
function f1() {
return 5 || true;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/checkJsdocSatisfiesTag1.ts | TypeScript | // @noEmit: true
// @allowJS: true
// @checkJs: true
// @filename: /a.js
/**
* @typedef {Object} T1
* @property {number} a
*/
/**
* @typedef {Object} T2
* @property {"a" | "b"} a
*/
/**
* @typedef {(x: string) => string} T3
*/
/**
* @typedef {Object} T4
* @property {string} a
*/
const t1 = /** @satisfies {T1} */ ({ a: 1 });
const t2 = /** @satisfies {T1} */ ({ a: 1, b: 1 });
const t3 = /** @satisfies {T1} */ ({});
/** @type {T2} */
const t4 = /** @satisfies {T2} */ ({ a: "a" });
/** @type {(m: string) => string} */
const t5 = /** @satisfies {T3} */((m) => m.substring(0));
const t6 = /** @satisfies {[number, number]} */ ([1, 2]);
const t7 = /** @satisfies {T4} */ ({ a: 'test' });
const t8 = /** @satisfies {T4} */ ({ a: 'test', b: 'test' });
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/checkJsdocSatisfiesTag10.ts | TypeScript | // @noEmit: true
// @allowJS: true
// @checkJs: true
// @filename: /a.js
/** @typedef {"a" | "b" | "c" | "d"} Keys */
const p = /** @satisfies {Partial<Record<Keys, unknown>>} */ ({
a: 0,
b: "hello",
x: 8 // Should error, 'x' isn't in 'Keys'
});
// Should be OK -- retain info that a is number and b is string
let a = p.a.toFixed();
let b = p.b.substring(1);
// Should error even though 'd' is in 'Keys'
let d = p.d;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/checkJsdocSatisfiesTag11.ts | TypeScript | // @noEmit: true
// @allowJS: true
// @checkJs: true
// @filename: /a.js
/**
* @typedef {Object} T1
* @property {number} a
*/
/**
* @typedef {Object} T2
* @property {number} a
*/
/**
* @satisfies {T1}
* @satisfies {T2}
*/
const t1 = { a: 1 };
/**
* @satisfies {number}
*/
const t2 = /** @satisfies {number} */ (1);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/checkJsdocSatisfiesTag12.ts | TypeScript | // @noEmit: true
// @allowJS: true
// @checkJs: true
// @filename: /a.js
/**
* @typedef {Object} T1
* @property {number} a
*/
/**
* @typedef {Object} T2
* @property {string} a
*/
/**
* @typedef {Object} T3
* @property {"a" | "b"} a
*/
/**
* @satisfies {T1}
*/
const t1 = { a: 1 };
/**
* @satisfies {T1}
*/
const t2 = { a: 1, b: 1 };
/**
* @satisfies {T1}
*/
const t3 = {};
/**
* @satisfies {Array.<number, number>}
*/
const t4 = [1, 2];
/**
* @satisfies {T2}
*/
const t5 = { a: 'test' };
/**
* @satisfies {T2}
*/
const t6 = { a: 'test', b: 'test' };
/**
* @satisfies {T3}
*/
const t7 = { a: "a" };
/** @satisfies {string} */ const t8 = (1);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/checkJsdocSatisfiesTag13.ts | TypeScript | // @noEmit: true
// @allowJS: true
// @checkJs: true
// @filename: /a.js
/** @satisfies {{ f: (x: string) => string }} */
const t1 = { f: s => s.toLowerCase() }; // should work
/** @satisfies {{ f: (x: string) => string }} */
const t2 = { g: "oops" }; // should error
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/checkJsdocSatisfiesTag14.ts | TypeScript | // @noEmit: true
// @allowJS: true
// @checkJs: true
// @filename: /a.js
/**
* @typedef {Object} T1
* @property {number} a
*/
/**
* @satisfies T1
*/
const t1 = { a: 1 };
const t2 = /** @satisfies T1 */ ({ a: 1 });
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/checkJsdocSatisfiesTag2.ts | TypeScript | // @noEmit: true
// @allowJS: true
// @checkJs: true
// @filename: /a.js
/** @typedef {Object.<string, (n: number) => boolean>} Predicates */
const p = /** @satisfies {Predicates} */ ({
isEven: n => n % 2 === 0,
isOdd: n => n % 2 === 1
});
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/checkJsdocSatisfiesTag3.ts | TypeScript | // @strict: true
// @noEmit: true
// @allowJS: true
// @checkJs: true
// @filename: /a.js
/** @type {{ f(s: string): void } & Record<string, unknown> }} */
let obj = /** @satisfies {{ g(s: string): void } & Record<string, unknown>} */ ({
f(s) { }, // "incorrect" implicit any on 's'
g(s) { }
});
// This needs to not crash (outer node is not expression)
/** @satisfies {{ f(s: string): void }} */ ({ f(x) { } })
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/checkJsdocSatisfiesTag4.ts | TypeScript | // @noEmit: true
// @module: esnext
// @allowJS: true
// @checkJs: true
// @filename: /a.js
/**
* @typedef {Object} Foo
* @property {number} a
*/
export default /** @satisfies {Foo} */ ({});
// @filename: /b.js
/**
* @typedef {Object} Foo
* @property {number} a
*/
export default /** @satisfies {Foo} */ ({ a: 1 }); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.