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/computedPropertyNamesContextualType1_ES6.ts | TypeScript | // @target: es6
interface I {
[s: string]: (x: string) => number;
[s: number]: (x: any) => number; // Doesn't get hit
}
var o: I = {
["" + 0](y) { return y.length; },
["" + 1]: y => y.length
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesContextualType2_ES5.ts | TypeScript | // @target: es5
interface I {
[s: string]: (x: any) => number; // Doesn't get hit
[s: number]: (x: string) => number;
}
var o: I = {
[+"foo"](y) { return y.length; },
[+"bar"]: y => y.length
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesContextualType2_ES6.ts | TypeScript | // @target: es6
interface I {
[s: string]: (x: any) => number; // Doesn't get hit
[s: number]: (x: string) => number;
}
var o: I = {
[+"foo"](y) { return y.length; },
[+"bar"]: y => y.length
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesContextualType3_ES5.ts | TypeScript | // @target: es5
interface I {
[s: string]: (x: string) => number;
}
var o: I = {
[+"foo"](y) { return y.length; },
[+"bar"]: y => y.length
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesContextualType3_ES6.ts | TypeScript | // @target: es6
interface I {
[s: string]: (x: string) => number;
}
var o: I = {
[+"foo"](y) { return y.length; },
[+"bar"]: y => y.length
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesContextualType4_ES5.ts | TypeScript | // @target: es5
interface I {
[s: string]: any;
[s: number]: any;
}
var o: I = {
[""+"foo"]: "",
[""+"bar"]: 0
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesContextualType4_ES6.ts | TypeScript | // @target: es6
interface I {
[s: string]: any;
[s: number]: any;
}
var o: I = {
[""+"foo"]: "",
[""+"bar"]: 0
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesContextualType5_ES5.ts | TypeScript | // @target: es5
interface I {
[s: string]: any;
[s: number]: any;
}
var o: I = {
[+"foo"]: "",
[+"bar"]: 0
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesContextualType5_ES6.ts | TypeScript | // @target: es6
interface I {
[s: string]: any;
[s: number]: any;
}
var o: I = {
[+"foo"]: "",
[+"bar"]: 0
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesContextualType6_ES5.ts | TypeScript | // @target: es5
interface I<T> {
[s: string]: T;
}
declare function foo<T>(obj: I<T>): T
foo({
p: "",
0: () => { },
["hi" + "bye"]: true,
[0 + 1]: 0,
[+"hi"]: [0]
}); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesContextualType6_ES6.ts | TypeScript | // @target: es6
interface I<T> {
[s: string]: T;
}
declare function foo<T>(obj: I<T>): T
foo({
p: "",
0: () => { },
["hi" + "bye"]: true,
[0 + 1]: 0,
[+"hi"]: [0]
}); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesContextualType7_ES5.ts | TypeScript | // @target: es5
interface I<T> {
[n: number]: T;
}
interface J<T> {
[s: string]: T;
}
declare function foo<T>(obj: I<T>): T;
declare function g<T>(obj: J<T>): T;
foo({
0: () => { },
["hi" + "bye"]: true,
[0 + 1]: 0,
[+"hi"]: [0]
});
g({ p: "" });
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesContextualType7_ES6.ts | TypeScript | // @target: es6
interface I<T> {
[n: number]: T;
}
interface J<T> {
[s: string]: T;
}
declare function foo<T>(obj: I<T>): T;
declare function g<T>(obj: J<T>): T;
foo({
0: () => { },
["hi" + "bye"]: true,
[0 + 1]: 0,
[+"hi"]: [0]
});
g({ p: "" });
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesContextualType8_ES5.ts | TypeScript | // @target: es5
interface I {
[s: string]: boolean;
[s: number]: boolean;
}
var o: I = {
[""+"foo"]: "",
[""+"bar"]: 0
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesContextualType8_ES6.ts | TypeScript | // @target: es6
interface I {
[s: string]: boolean;
[s: number]: boolean;
}
var o: I = {
[""+"foo"]: "",
[""+"bar"]: 0
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesContextualType9_ES5.ts | TypeScript | // @target: es5
interface I {
[s: string]: boolean;
[s: number]: boolean;
}
var o: I = {
[+"foo"]: "",
[+"bar"]: 0
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesContextualType9_ES6.ts | TypeScript | // @target: es6
interface I {
[s: string]: boolean;
[s: number]: boolean;
}
var o: I = {
[+"foo"]: "",
[+"bar"]: 0
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesDeclarationEmit1_ES5.ts | TypeScript | // @target: es5
// @declaration: true
class C {
["" + ""]() { }
get ["" + ""]() { return 0; }
set ["" + ""](x) { }
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesDeclarationEmit1_ES6.ts | TypeScript | // @target: es6
// @declaration: true
class C {
["" + ""]() { }
get ["" + ""]() { return 0; }
set ["" + ""](x) { }
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesDeclarationEmit2_ES5.ts | TypeScript | // @target: es5
// @declaration: true
class C {
static ["" + ""]() { }
static get ["" + ""]() { return 0; }
static set ["" + ""](x) { }
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesDeclarationEmit2_ES6.ts | TypeScript | // @target: es6
// @declaration: true
class C {
static ["" + ""]() { }
static get ["" + ""]() { return 0; }
static set ["" + ""](x) { }
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesDeclarationEmit5_ES5.ts | TypeScript | // @target: es5
// @declaration: true
var v = {
["" + ""]: 0,
["" + ""]() { },
get ["" + ""]() { return 0; },
set ["" + ""](x) { }
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesDeclarationEmit5_ES6.ts | TypeScript | // @target: es6
// @declaration: true
var v = {
["" + ""]: 0,
["" + ""]() { },
get ["" + ""]() { return 0; },
set ["" + ""](x) { }
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesDeclarationEmit6_ES5.ts | TypeScript | // @target: es5
// @declaration: true
var v = {
[-1]: {},
[+1]: {},
[~1]: {},
[!1]: {}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesDeclarationEmit6_ES6.ts | TypeScript | // @target: es6
// @declaration: true
var v = {
[-1]: {},
[+1]: {},
[~1]: {},
[!1]: {}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesSourceMap1_ES5.ts | TypeScript | // @target: es5
// @sourceMap: true
class C {
["hello"]() {
debugger;
}
get ["goodbye"]() {
return 0;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesSourceMap1_ES6.ts | TypeScript | // @target: es6
// @sourceMap: true
class C {
["hello"]() {
debugger;
}
get ["goodbye"]() {
return 0;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesSourceMap2_ES5.ts | TypeScript | // @target: es5
// @sourceMap: true
var v = {
["hello"]() {
debugger;
},
get ["goodbye"]() {
return 0;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesSourceMap2_ES6.ts | TypeScript | // @target: es6
// @sourceMap: true
var v = {
["hello"]() {
debugger;
},
get ["goodbye"]() {
return 0;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/computedPropertyNamesWithStaticProperty.ts | TypeScript | // @target: es6
class C1 {
static staticProp = 10;
get [C1.staticProp]() {
return "hello";
}
set [C1.staticProp](x: string) {
var y = x;
}
[C1.staticProp]() { }
}
(class C2 {
static staticProp = 10;
get [C2.staticProp]() {
return "hello";
}
set [C2.staticProp](x: string) {
var y = x;
}
[C2.staticProp]() { }
})
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/conditionalOperatorConditionIsBooleanType.ts | TypeScript | //Cond ? Expr1 : Expr2, Cond is of boolean type, Expr1 and Expr2 have the same type
var condBoolean: boolean;
var exprAny1: any;
var exprBoolean1: boolean;
var exprNumber1: number;
var exprString1: string;
var exprIsObject1: Object;
var exprAny2: any;
var exprBoolean2: boolean;
var exprNumber2: number;
var exprString2: string;
var exprIsObject2: Object;
//Cond is a boolean type variable
condBoolean ? exprAny1 : exprAny2;
condBoolean ? exprBoolean1 : exprBoolean2;
condBoolean ? exprNumber1 : exprNumber2;
condBoolean ? exprString1 : exprString2;
condBoolean ? exprIsObject1 : exprIsObject2;
condBoolean ? exprString1 : exprBoolean1; // union
//Cond is a boolean type literal
true ? exprAny1 : exprAny2;
false ? exprBoolean1 : exprBoolean2;
true ? exprNumber1 : exprNumber2;
false ? exprString1 : exprString2;
true ? exprIsObject1 : exprIsObject2;
true ? exprString1 : exprBoolean1; // union
//Cond is a boolean type expression
!true ? exprAny1 : exprAny2;
typeof "123" == "string" ? exprBoolean1 : exprBoolean2;
2 > 1 ? exprNumber1 : exprNumber2;
null === undefined ? exprString1 : exprString2;
true || false ? exprIsObject1 : exprIsObject2;
null === undefined ? exprString1 : exprBoolean1; // union
//Results shoud be same as Expr1 and Expr2
var resultIsAny1 = condBoolean ? exprAny1 : exprAny2;
var resultIsBoolean1 = condBoolean ? exprBoolean1 : exprBoolean2;
var resultIsNumber1 = condBoolean ? exprNumber1 : exprNumber2;
var resultIsString1 = condBoolean ? exprString1 : exprString2;
var resultIsObject1 = condBoolean ? exprIsObject1 : exprIsObject2;
var resultIsStringOrBoolean1 = condBoolean ? exprString1 : exprBoolean1; // union
var resultIsAny2 = true ? exprAny1 : exprAny2;
var resultIsBoolean2 = false ? exprBoolean1 : exprBoolean2;
var resultIsNumber2 = true ? exprNumber1 : exprNumber2;
var resultIsString2 = false ? exprString1 : exprString2;
var resultIsObject2 = true ? exprIsObject1 : exprIsObject2;
var resultIsStringOrBoolean2 = true ? exprString1 : exprBoolean1; // union
var resultIsStringOrBoolean3 = false ? exprString1 : exprBoolean1; // union
var resultIsAny3 = !true ? exprAny1 : exprAny2;
var resultIsBoolean3 = typeof "123" == "string" ? exprBoolean1 : exprBoolean2;
var resultIsNumber3 = 2 > 1 ? exprNumber1 : exprNumber2;
var resultIsString3 = null === undefined ? exprString1 : exprString2;
var resultIsObject3 = true || false ? exprIsObject1 : exprIsObject2;
var resultIsStringOrBoolean4 = typeof "123" === "string" ? exprString1 : exprBoolean1; // union
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/conditionalOperatorConditionIsNumberType.ts | TypeScript | //Cond ? Expr1 : Expr2, Cond is of number type, Expr1 and Expr2 have the same type
var condNumber: number;
var exprAny1: any;
var exprBoolean1: boolean;
var exprNumber1: number;
var exprString1: string;
var exprIsObject1: Object;
var exprAny2: any;
var exprBoolean2: boolean;
var exprNumber2: number;
var exprString2: string;
var exprIsObject2: Object;
//Cond is a number type variable
condNumber ? exprAny1 : exprAny2;
condNumber ? exprBoolean1 : exprBoolean2;
condNumber ? exprNumber1 : exprNumber2;
condNumber ? exprString1 : exprString2;
condNumber ? exprIsObject1 : exprIsObject2;
condNumber ? exprString1 : exprBoolean1; // Union
//Cond is a number type literal
1 ? exprAny1 : exprAny2;
0 ? exprBoolean1 : exprBoolean2;
0.123456789 ? exprNumber1 : exprNumber2;
- 10000000000000 ? exprString1 : exprString2;
1000000000000 ? exprIsObject1 : exprIsObject2;
10000 ? exprString1 : exprBoolean1; // Union
//Cond is a number type expression
function foo() { return 1 };
var array = [1, 2, 3];
1 * 0 ? exprAny1 : exprAny2;
1 + 1 ? exprBoolean1 : exprBoolean2;
"string".length ? exprNumber1 : exprNumber2;
foo() ? exprString1 : exprString2;
foo() / array[1] ? exprIsObject1 : exprIsObject2;
foo() ? exprString1 : exprBoolean1; // Union
//Results shoud be same as Expr1 and Expr2
var resultIsAny1 = condNumber ? exprAny1 : exprAny2;
var resultIsBoolean1 = condNumber ? exprBoolean1 : exprBoolean2;
var resultIsNumber1 = condNumber ? exprNumber1 : exprNumber2;
var resultIsString1 = condNumber ? exprString1 : exprString2;
var resultIsObject1 = condNumber ? exprIsObject1 : exprIsObject2;
var resultIsStringOrBoolean1 = condNumber ? exprString1 : exprBoolean1; // Union
var resultIsAny2 = 1 ? exprAny1 : exprAny2;
var resultIsBoolean2 = 0 ? exprBoolean1 : exprBoolean2;
var resultIsNumber2 = 0.123456789 ? exprNumber1 : exprNumber2;
var resultIsString2 = - 10000000000000 ? exprString1 : exprString2;
var resultIsObject2 = 1000000000000 ? exprIsObject1 : exprIsObject2;
var resultIsStringOrBoolean2 = 10000 ? exprString1 : exprBoolean1; // Union
var resultIsAny3 = 1 * 0 ? exprAny1 : exprAny2;
var resultIsBoolean3 = 1 + 1 ? exprBoolean1 : exprBoolean2;
var resultIsNumber3 = "string".length ? exprNumber1 : exprNumber2;
var resultIsString3 = foo() ? exprString1 : exprString2;
var resultIsObject3 = foo() / array[1] ? exprIsObject1 : exprIsObject2;
var resultIsStringOrBoolean3 = foo() / array[1] ? exprString1 : exprBoolean1; // Union | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/conditionalOperatorConditoinIsAnyType.ts | TypeScript | //Cond ? Expr1 : Expr2, Cond is of any type, Expr1 and Expr2 have the same type
var condAny: any;
var x: any;
var exprAny1: any;
var exprBoolean1: boolean;
var exprNumber1: number;
var exprString1: string;
var exprIsObject1: Object;
var exprAny2: any;
var exprBoolean2: boolean;
var exprNumber2: number;
var exprString2: string;
var exprIsObject2: Object;
//Cond is an any type variable
condAny ? exprAny1 : exprAny2;
condAny ? exprBoolean1 : exprBoolean2;
condAny ? exprNumber1 : exprNumber2;
condAny ? exprString1 : exprString2;
condAny ? exprIsObject1 : exprIsObject2;
condAny ? exprString1 : exprBoolean1; // union
//Cond is an any type literal
null ? exprAny1 : exprAny2;
null ? exprBoolean1 : exprBoolean2;
undefined ? exprNumber1 : exprNumber2;
[null, undefined] ? exprString1 : exprString2;
[null, undefined] ? exprIsObject1 : exprIsObject2;
undefined ? exprString1 : exprBoolean1; // union
//Cond is an any type expression
x.doSomeThing() ? exprAny1 : exprAny2;
x("x") ? exprBoolean1 : exprBoolean2;
x(x) ? exprNumber1 : exprNumber2;
x("x") ? exprString1 : exprString2;
x.doSomeThing() ? exprIsObject1 : exprIsObject2;
x.doSomeThing() ? exprString1 : exprBoolean1; // union
//Results shoud be same as Expr1 and Expr2
var resultIsAny1 = condAny ? exprAny1 : exprAny2;
var resultIsBoolean1 = condAny ? exprBoolean1 : exprBoolean2;
var resultIsNumber1 = condAny ? exprNumber1 : exprNumber2;
var resultIsString1 = condAny ? exprString1 : exprString2;
var resultIsObject1 = condAny ? exprIsObject1 : exprIsObject2;
var resultIsStringOrBoolean1 = condAny ? exprString1 : exprBoolean1; // union
var resultIsAny2 = null ? exprAny1 : exprAny2;
var resultIsBoolean2 = null ? exprBoolean1 : exprBoolean2;
var resultIsNumber2 = undefined ? exprNumber1 : exprNumber2;
var resultIsString2 = [null, undefined] ? exprString1 : exprString2;
var resultIsObject2 = [null, undefined] ? exprIsObject1 : exprIsObject2;
var resultIsStringOrBoolean2 = null ? exprString1 : exprBoolean1; // union
var resultIsStringOrBoolean3 = undefined ? exprString1 : exprBoolean1; // union
var resultIsStringOrBoolean4 = [null, undefined] ? exprString1 : exprBoolean1; // union
var resultIsAny3 = x.doSomeThing() ? exprAny1 : exprAny2;
var resultIsBoolean3 = x("x") ? exprBoolean1 : exprBoolean2;
var resultIsNumber3 = x(x) ? exprNumber1 : exprNumber2;
var resultIsString3 = x("x") ? exprString1 : exprString2;
var resultIsObject3 = x.doSomeThing() ? exprIsObject1 : exprIsObject2;
var resultIsStringOrBoolean5 = x.doSomeThing() ? exprString1 : exprBoolean1; // union | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/conditionalOperatorConditoinIsStringType.ts | TypeScript | //Cond ? Expr1 : Expr2, Cond is of string type, Expr1 and Expr2 have the same type
var condString: string;
var exprAny1: any;
var exprBoolean1: boolean;
var exprNumber1: number;
var exprString1: string;
var exprIsObject1: Object;
var exprAny2: any;
var exprBoolean2: boolean;
var exprNumber2: number;
var exprString2: string;
var exprIsObject2: Object;
//Cond is a string type variable
condString ? exprAny1 : exprAny2;
condString ? exprBoolean1 : exprBoolean2;
condString ? exprNumber1 : exprNumber2;
condString ? exprString1 : exprString2;
condString ? exprIsObject1 : exprIsObject2;
condString ? exprString1 : exprBoolean1; // union
//Cond is a string type literal
"" ? exprAny1 : exprAny2;
"string" ? exprBoolean1 : exprBoolean2;
'c' ? exprNumber1 : exprNumber2;
'string' ? exprString1 : exprString2;
" " ? exprIsObject1 : exprIsObject2;
"hello " ? exprString1 : exprBoolean1; // union
//Cond is a string type expression
function foo() { return "string" };
var array = ["1", "2", "3"];
typeof condString ? exprAny1 : exprAny2;
condString.toUpperCase ? exprBoolean1 : exprBoolean2;
condString + "string" ? exprNumber1 : exprNumber2;
foo() ? exprString1 : exprString2;
array[1] ? exprIsObject1 : exprIsObject2;
foo() ? exprString1 : exprBoolean1; // union
//Results shoud be same as Expr1 and Expr2
var resultIsAny1 = condString ? exprAny1 : exprAny2;
var resultIsBoolean1 = condString ? exprBoolean1 : exprBoolean2;
var resultIsNumber1 = condString ? exprNumber1 : exprNumber2;
var resultIsString1 = condString ? exprString1 : exprString2;
var resultIsObject1 = condString ? exprIsObject1 : exprIsObject2;
var resultIsStringOrBoolean1 = condString ? exprString1 : exprBoolean1; // union
var resultIsAny2 = "" ? exprAny1 : exprAny2;
var resultIsBoolean2 = "string" ? exprBoolean1 : exprBoolean2;
var resultIsNumber2 = 'c' ? exprNumber1 : exprNumber2;
var resultIsString2 = 'string' ? exprString1 : exprString2;
var resultIsObject2 = " " ? exprIsObject1 : exprIsObject2;
var resultIsStringOrBoolean2 = "hello" ? exprString1 : exprBoolean1; // union
var resultIsAny3 = typeof condString ? exprAny1 : exprAny2;
var resultIsBoolean3 = condString.toUpperCase ? exprBoolean1 : exprBoolean2;
var resultIsNumber3 = condString + "string" ? exprNumber1 : exprNumber2;
var resultIsString3 = foo() ? exprString1 : exprString2;
var resultIsObject3 = array[1] ? exprIsObject1 : exprIsObject2;
var resultIsStringOrBoolean3 = typeof condString ? exprString1 : exprBoolean1; // union
var resultIsStringOrBoolean4 = condString.toUpperCase ? exprString1 : exprBoolean1; // union | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/conditionalOperatorWithIdenticalBCT.ts | TypeScript | //Cond ? Expr1 : Expr2, Expr1 and Expr2 have identical best common type
class X { propertyX: any; propertyX1: number; propertyX2: string };
class A extends X { propertyA: number };
class B extends X { propertyB: string };
var x: X;
var a: A;
var b: B;
//Cond ? Expr1 : Expr2, Expr1 is supertype
//Be Not contextually typed
true ? x : a;
var result1 = true ? x : a;
//Expr1 and Expr2 are literals
true ? {} : 1;
true ? { a: 1 } : { a: 2, b: 'string' };
var result2 = true ? {} : 1;
var result3 = true ? { a: 1 } : { a: 2, b: 'string' };
//Contextually typed
var resultIsX1: X = true ? x : a;
var result4: (t: A) => any = true ? (m) => m.propertyX : (n) => n.propertyA;
//Cond ? Expr1 : Expr2, Expr2 is supertype
//Be Not contextually typed
true ? a : x;
var result5 = true ? a : x;
//Expr1 and Expr2 are literals
true ? 1 : {};
true ? { a: 2, b: 'string' } : { a: 1 };
var result6 = true ? 1 : {};
var result7 = true ? { a: 2, b: 'string' } : { a: 1 };
//Contextually typed
var resultIsX2: X = true ? x : a;
var result8: (t: A) => any = true ? (m) => m.propertyA : (n) => n.propertyX;
//Result = Cond ? Expr1 : Expr2, Result is supertype
//Contextually typed
var resultIsX3: X = true ? a : b;
var result10: (t: X) => any = true ? (m) => m.propertyX1 : (n) => n.propertyX2;
//Expr1 and Expr2 are literals
var result11: any = true ? 1 : 'string';
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/conditionalOperatorWithoutIdenticalBCT.ts | TypeScript | //Cond ? Expr1 : Expr2, Expr1 and Expr2 have no identical best common type
class X { propertyX: any; propertyX1: number; propertyX2: string };
class A extends X { propertyA: number };
class B extends X { propertyB: string };
var x: X;
var a: A;
var b: B;
// No errors anymore, uses union types
true ? a : b;
var result1 = true ? a : b;
//Be contextually typed and and bct is not identical, results in errors that union type is not assignable to target
var result2: A = true ? a : b;
var result3: B = true ? a : b;
var result31: A | B = true ? a : b;
var result4: (t: X) => number = true ? (m) => m.propertyX1 : (n) => n.propertyX2;
var result5: (t: X) => string = true ? (m) => m.propertyX1 : (n) => n.propertyX2;
var result6: (t: X) => boolean = true ? (m) => m.propertyX1 : (n) => n.propertyX2;
var result61: (t: X) => number| string = true ? (m) => m.propertyX1 : (n) => n.propertyX2;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/conditionalTypes1.ts | TypeScript | // @strict: true
// @declaration: true
type T00 = Exclude<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "b" | "d"
type T01 = Extract<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "a" | "c"
type T02 = Exclude<string | number | (() => void), Function>; // string | number
type T03 = Extract<string | number | (() => void), Function>; // () => void
type T04 = NonNullable<string | number | undefined>; // string | number
type T05 = NonNullable<(() => string) | string[] | null | undefined>; // (() => string) | string[]
function f1<T>(x: T, y: NonNullable<T>) {
x = y;
y = x; // Error
}
function f2<T extends string | undefined>(x: T, y: NonNullable<T>) {
x = y;
y = x; // Error
let s1: string = x; // Error
let s2: string = y;
}
function f3<T>(x: Partial<T>[keyof T], y: NonNullable<Partial<T>[keyof T]>) {
x = y;
y = x; // Error
}
function f4<T extends { x: string | undefined }>(x: T["x"], y: NonNullable<T["x"]>) {
x = y;
y = x; // Error
let s1: string = x; // Error
let s2: string = y;
}
type Options = { k: "a", a: number } | { k: "b", b: string } | { k: "c", c: boolean };
type T10 = Exclude<Options, { k: "a" | "b" }>; // { k: "c", c: boolean }
type T11 = Extract<Options, { k: "a" | "b" }>; // { k: "a", a: number } | { k: "b", b: string }
type T12 = Exclude<Options, { k: "a" } | { k: "b" }>; // { k: "c", c: boolean }
type T13 = Extract<Options, { k: "a" } | { k: "b" }>; // { k: "a", a: number } | { k: "b", b: string }
type T14 = Exclude<Options, { q: "a" }>; // Options
type T15 = Extract<Options, { q: "a" }>; // never
declare function f5<T extends Options, K extends string>(p: K): Extract<T, { k: K }>;
let x0 = f5("a"); // { k: "a", a: number }
type OptionsOfKind<K extends Options["k"]> = Extract<Options, { k: K }>;
type T16 = OptionsOfKind<"a" | "b">; // { k: "a", a: number } | { k: "b", b: string }
type Select<T, K extends keyof T, V extends T[K]> = Extract<T, { [P in K]: V }>;
type T17 = Select<Options, "k", "a" | "b">; // // { k: "a", a: number } | { k: "b", b: string }
type TypeName<T> =
T extends string ? "string" :
T extends number ? "number" :
T extends boolean ? "boolean" :
T extends undefined ? "undefined" :
T extends Function ? "function" :
"object";
type T20 = TypeName<string | (() => void)>; // "string" | "function"
type T21 = TypeName<any>; // "string" | "number" | "boolean" | "undefined" | "function" | "object"
type T22 = TypeName<never>; // never
type T23 = TypeName<{}>; // "object"
type KnockoutObservable<T> = { object: T };
type KnockoutObservableArray<T> = { array: T };
type KnockedOut<T> = T extends any[] ? KnockoutObservableArray<T[number]> : KnockoutObservable<T>;
type KnockedOutObj<T> = {
[P in keyof T]: KnockedOut<T[P]>;
}
interface Item {
id: number;
name: string;
subitems: string[];
}
type KOItem = KnockedOutObj<Item>;
interface Part {
id: number;
name: string;
subparts: Part[];
updatePart(newName: string): void;
}
type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T];
type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;
type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
type T30 = FunctionProperties<Part>;
type T31 = NonFunctionProperties<Part>;
function f7<T>(x: T, y: FunctionProperties<T>, z: NonFunctionProperties<T>) {
x = y; // Error
x = z; // Error
y = x;
y = z; // Error
z = x;
z = y; // Error
}
function f8<T>(x: keyof T, y: FunctionPropertyNames<T>, z: NonFunctionPropertyNames<T>) {
x = y;
x = z;
y = x; // Error
y = z; // Error
z = x; // Error
z = y; // Error
}
type DeepReadonly<T> =
T extends any[] ? DeepReadonlyArray<T[number]> :
T extends object ? DeepReadonlyObject<T> :
T;
interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> {}
type DeepReadonlyObject<T> = {
readonly [P in NonFunctionPropertyNames<T>]: DeepReadonly<T[P]>;
};
function f10(part: DeepReadonly<Part>) {
let name: string = part.name;
let id: number = part.subparts[0].id;
part.id = part.id; // Error
part.subparts[0] = part.subparts[0]; // Error
part.subparts[0].id = part.subparts[0].id; // Error
part.updatePart("hello"); // Error
}
type ZeroOf<T extends number | string | boolean> = T extends number ? 0 : T extends string ? "" : false;
function zeroOf<T extends number | string | boolean>(value: T) {
return <ZeroOf<T>>(typeof value === "number" ? 0 : typeof value === "string" ? "" : false);
}
function f20<T extends string>(n: number, b: boolean, x: number | boolean, y: T) {
zeroOf(5); // 0
zeroOf("hello"); // ""
zeroOf(true); // false
zeroOf(n); // 0
zeroOf(b); // False
zeroOf(x); // 0 | false
zeroOf(y); // ZeroOf<T>
}
function f21<T extends number | string>(x: T, y: ZeroOf<T>) {
let z1: number | string = y;
let z2: 0 | "" = y;
x = y; // Error
y = x; // Error
}
type T35<T extends { a: string, b: number }> = T[];
type T36<T> = T extends { a: string } ? T extends { b: number } ? T35<T> : never : never;
type T37<T> = T extends { b: number } ? T extends { a: string } ? T35<T> : never : never;
type T38<T> = [T] extends [{ a: string }] ? [T] extends [{ b: number }] ? T35<T> : never : never;
type Extends<T, U> = T extends U ? true : false;
type If<C extends boolean, T, F> = C extends true ? T : F;
type Not<C extends boolean> = If<C, false, true>;
type And<A extends boolean, B extends boolean> = If<A, B, false>;
type Or<A extends boolean, B extends boolean> = If<A, true, B>;
type IsString<T> = Extends<T, string>;
type Q1 = IsString<number>; // false
type Q2 = IsString<"abc">; // true
type Q3 = IsString<any>; // boolean
type Q4 = IsString<never>; // never
type N1 = Not<false>; // true
type N2 = Not<true>; // false
type N3 = Not<boolean>; // boolean
type A1 = And<false, false>; // false
type A2 = And<false, true>; // false
type A3 = And<true, false>; // false
type A4 = And<true, true>; // true
type A5 = And<boolean, false>; // false
type A6 = And<false, boolean>; // false
type A7 = And<boolean, true>; // boolean
type A8 = And<true, boolean>; // boolean
type A9 = And<boolean, boolean>; // boolean
type O1 = Or<false, false>; // false
type O2 = Or<false, true>; // true
type O3 = Or<true, false>; // true
type O4 = Or<true, true>; // true
type O5 = Or<boolean, false>; // boolean
type O6 = Or<false, boolean>; // boolean
type O7 = Or<boolean, true>; // true
type O8 = Or<true, boolean>; // true
type O9 = Or<boolean, boolean>; // boolean
type T40 = never extends never ? true : false; // true
type T41 = number extends never ? true : false; // false
type T42 = never extends number ? true : false; // true
type IsNever<T> = [T] extends [never] ? true : false;
type T50 = IsNever<never>; // true
type T51 = IsNever<number>; // false
type T52 = IsNever<any>; // false
function f22<T>(x: T extends (infer U)[] ? U[] : never) {
let e = x[0]; // {}
}
function f23<T extends string[]>(x: T extends (infer U)[] ? U[] : never) {
let e = x[0]; // string
}
// Repros from #21664
type Eq<T, U> = T extends U ? U extends T ? true : false : false;
type T60 = Eq<true, true>; // true
type T61 = Eq<true, false>; // false
type T62 = Eq<false, true>; // false
type T63 = Eq<false, false>; // true
type Eq1<T, U> = Eq<T, U> extends false ? false : true;
type T70 = Eq1<true, true>; // true
type T71 = Eq1<true, false>; // false
type T72 = Eq1<false, true>; // false
type T73 = Eq1<false, false>; // true
type Eq2<T, U> = Eq<T, U> extends true ? true : false;
type T80 = Eq2<true, true>; // true
type T81 = Eq2<true, false>; // false
type T82 = Eq2<false, true>; // false
type T83 = Eq2<false, false>; // true
// Repro from #21756
type Foo<T> = T extends string ? boolean : number;
type Bar<T> = T extends string ? boolean : number;
const convert = <U>(value: Foo<U>): Bar<U> => value;
type Baz<T> = Foo<T>;
const convert2 = <T>(value: Foo<T>): Baz<T> => value;
function f31<T>() {
type T1 = T extends string ? boolean : number;
type T2 = T extends string ? boolean : number;
var x: T1;
var x: T2;
}
function f32<T, U>() {
type T1 = T & U extends string ? boolean : number;
type T2 = Foo<T & U>;
var z: T1;
var z: T2; // Error, T2 is distributive, T1 isn't
}
function f33<T, U>() {
type T1 = Foo<T & U>;
type T2 = Bar<T & U>;
var z: T1;
var z: T2;
}
// Repro from #21823
type T90<T> = T extends 0 ? 0 : () => 0;
type T91<T> = T extends 0 ? 0 : () => 0;
const f40 = <U>(a: T90<U>): T91<U> => a;
const f41 = <U>(a: T91<U>): T90<U> => a;
type T92<T> = T extends () => 0 ? () => 1 : () => 2;
type T93<T> = T extends () => 0 ? () => 1 : () => 2;
const f42 = <U>(a: T92<U>): T93<U> => a;
const f43 = <U>(a: T93<U>): T92<U> => a;
type T94<T> = T extends string ? true : 42;
type T95<T> = T extends string ? boolean : number;
const f44 = <U>(value: T94<U>): T95<U> => value;
const f45 = <U>(value: T95<U>): T94<U> => value; // Error
// Repro from #21863
function f50() {
type Eq<T, U> = T extends U ? U extends T ? true : false : false;
type If<S, T, U> = S extends false ? U : T;
type Omit<T extends object> = { [P in keyof T]: If<Eq<T[P], never>, never, P>; }[keyof T];
type Omit2<T extends object, U = never> = { [P in keyof T]: If<Eq<T[P], U>, never, P>; }[keyof T];
type A = Omit<{ a: void; b: never; }>; // 'a'
type B = Omit2<{ a: void; b: never; }>; // 'a'
}
// Repro from #21862
type OldDiff<T extends keyof any, U extends keyof any> = (
& { [P in T]: P; }
& { [P in U]: never; }
& { [x: string]: never; }
)[T];
type NewDiff<T, U> = T extends U ? never : T;
interface A {
a: 'a';
}
interface B1 extends A {
b: 'b';
c: OldDiff<keyof this, keyof A>;
}
interface B2 extends A {
b: 'b';
c: NewDiff<keyof this, keyof A>;
}
type c1 = B1['c']; // 'c' | 'b'
type c2 = B2['c']; // 'c' | 'b'
// Repro from #21929
type NonFooKeys1<T extends object> = OldDiff<keyof T, 'foo'>;
type NonFooKeys2<T extends object> = Exclude<keyof T, 'foo'>;
type Test1 = NonFooKeys1<{foo: 1, bar: 2, baz: 3}>; // "bar" | "baz"
type Test2 = NonFooKeys2<{foo: 1, bar: 2, baz: 3}>; // "bar" | "baz"
// Repro from #21729
interface Foo2 { foo: string; }
interface Bar2 { bar: string; }
type FooBar = Foo2 | Bar2;
declare interface ExtractFooBar<FB extends FooBar> { }
type Extracted<Struct> = {
[K in keyof Struct]: Struct[K] extends FooBar ? ExtractFooBar<Struct[K]> : Struct[K];
}
// Repro from #22985
type RecursivePartial<T> = {
[P in keyof T]?: T[P] extends Array<any> ? {[index: number]: RecursivePartial<T[P][0]>} :
T[P] extends object ? RecursivePartial<T[P]> : T[P];
};
declare function assign<T>(o: T, a: RecursivePartial<T>): void;
var a = {o: 1, b: 2, c: [{a: 1, c: '213'}]}
assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}})
// Repros from #23843
type Weird1 = (<U extends boolean>(a: U) => never) extends
(<U extends true>(a: U) => never) ? never : never;
type Weird2 = (<U extends boolean>(a: U) => U) extends
(<U extends true>(a: U) => infer T) ? T : never;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/conditionalTypes2.ts | TypeScript | // @strict: true
// @declaration: true
interface Covariant<T> {
foo: T extends string ? T : number;
}
interface Contravariant<T> {
foo: T extends string ? keyof T : number;
}
interface Invariant<T> {
foo: T extends string ? keyof T : T;
}
function f1<A, B extends A>(a: Covariant<A>, b: Covariant<B>) {
a = b;
b = a; // Error
}
function f2<A, B extends A>(a: Contravariant<A>, b: Contravariant<B>) {
a = b; // Error
b = a;
}
function f3<A, B extends A>(a: Invariant<A>, b: Invariant<B>) {
a = b; // Error
b = a; // Error
}
// Extract<T, Function> is a T that is known to be a Function
function isFunction<T>(value: T): value is Extract<T, Function> {
return typeof value === "function";
}
function getFunction<T>(item: T) {
if (isFunction(item)) {
return item;
}
throw new Error();
}
function f10<T>(x: T) {
if (isFunction(x)) {
const f: Function = x;
const t: T = x;
}
}
function f11(x: string | (() => string) | undefined) {
if (isFunction(x)) {
x();
}
}
function f12(x: string | (() => string) | undefined) {
const f = getFunction(x); // () => string
f();
}
type Foo = { foo: string };
type Bar = { bar: string };
declare function fooBar(x: { foo: string, bar: string }): void;
declare function fooBat(x: { foo: string, bat: string }): void;
type Extract2<T, U, V> = T extends U ? T extends V ? T : never : never;
function f20<T>(x: Extract<Extract<T, Foo>, Bar>, y: Extract<T, Foo & Bar>, z: Extract2<T, Foo, Bar>) {
fooBar(x);
fooBar(y);
fooBar(z);
}
function f21<T>(x: Extract<Extract<T, Foo>, Bar>, y: Extract<T, Foo & Bar>, z: Extract2<T, Foo, Bar>) {
fooBat(x); // Error
fooBat(y); // Error
fooBat(z); // Error
}
// Repros from #22860
class Opt<T> {
toVector(): Vector<T> {
return <any>undefined;
}
}
interface Seq<T> {
tail(): Opt<Seq<T>>;
}
class Vector<T> implements Seq<T> {
tail(): Opt<Vector<T>> {
return <any>undefined;
}
partition2<U extends T>(predicate:(v:T)=>v is U): [Vector<U>,Vector<Exclude<T, U>>];
partition2(predicate:(x:T)=>boolean): [Vector<T>,Vector<T>];
partition2<U extends T>(predicate:(v:T)=>boolean): [Vector<U>,Vector<any>] {
return <any>undefined;
}
}
interface A1<T> {
bat: B1<A1<T>>;
}
interface B1<T> extends A1<T> {
bat: B1<B1<T>>;
boom: T extends any ? true : true
}
// Repro from #22899
declare function toString1(value: object | Function): string ;
declare function toString2(value: Function): string ;
function foo<T>(value: T) {
if (isFunction(value)) {
toString1(value);
toString2(value);
}
}
// Repro from #23052
type A<T, V, E> =
T extends object
? { [Q in { [P in keyof T]: T[P] extends V ? P : P; }[keyof T]]: A<T[Q], V, E>; }
: T extends V ? T : never;
type B<T, V> =
T extends object
? { [Q in { [P in keyof T]: T[P] extends V ? P : P; }[keyof T]]: B<T[Q], V>; }
: T extends V ? T : never;
type C<T, V, E> =
{ [Q in { [P in keyof T]: T[P] extends V ? P : P; }[keyof T]]: C<T[Q], V, E>; };
// Repro from #23100
type A2<T, V, E> =
T extends object ? T extends any[] ? T : { [Q in keyof T]: A2<T[Q], V, E>; } : T;
type B2<T, V> =
T extends object ? T extends any[] ? T : { [Q in keyof T]: B2<T[Q], V>; } : T;
type C2<T, V, E> =
T extends object ? { [Q in keyof T]: C2<T[Q], V, E>; } : T;
// Repro from #28654
type MaybeTrue<T extends { b: boolean }> = true extends T["b"] ? "yes" : "no";
type T0 = MaybeTrue<{ b: never }> // "no"
type T1 = MaybeTrue<{ b: false }>; // "no"
type T2 = MaybeTrue<{ b: true }>; // "yes"
type T3 = MaybeTrue<{ b: boolean }>; // "yes"
// Repro from #28824
type Union = 'a' | 'b';
type Product<A extends Union, B> = { f1: A, f2: B};
type ProductUnion = Product<'a', 0> | Product<'b', 1>;
// {a: "b"; b: "a"}
type UnionComplement = {
[K in Union]: Exclude<Union, K>
};
type UCA = UnionComplement['a'];
type UCB = UnionComplement['b'];
// {a: "a"; b: "b"}
type UnionComplementComplement = {
[K in Union]: Exclude<Union, Exclude<Union, K>>
};
type UCCA = UnionComplementComplement['a'];
type UCCB = UnionComplementComplement['b'];
// {a: Product<'b', 1>; b: Product<'a', 0>}
type ProductComplement = {
[K in Union]: Exclude<ProductUnion, { f1: K }>
};
type PCA = ProductComplement['a'];
type PCB = ProductComplement['b'];
// {a: Product<'a', 0>; b: Product<'b', 1>}
type ProductComplementComplement = {
[K in Union]: Exclude<ProductUnion, Exclude<ProductUnion, { f1: K }>>
};
type PCCA = ProductComplementComplement['a'];
type PCCB = ProductComplementComplement['b'];
// Repro from #31326
type Hmm<T, U extends T> = U extends T ? { [K in keyof U]: number } : never;
type What = Hmm<{}, { a: string }>
const w: What = { a: 4 };
// Repro from #33568
declare function save(_response: IRootResponse<string>): void;
exportCommand(save);
declare function exportCommand<TResponse>(functionToCall: IExportCallback<TResponse>): void;
interface IExportCallback<TResponse> {
(response: IRootResponse<TResponse>): void;
}
type IRootResponse<TResponse> =
TResponse extends IRecord ? IRecordResponse<TResponse> : IResponse<TResponse>;
interface IRecord {
readonly Id: string;
}
declare type IRecordResponse<T extends IRecord> = IResponse<T> & {
sendRecord(): void;
};
declare type IResponse<T> = {
sendValue(name: keyof GetAllPropertiesOfType<T, string>): void;
};
declare type GetPropertyNamesOfType<T, RestrictToType> = {
[PropertyName in Extract<keyof T, string>]: T[PropertyName] extends RestrictToType ? PropertyName : never
}[Extract<keyof T, string>];
declare type GetAllPropertiesOfType<T, RestrictToType> = Pick<
T,
GetPropertyNamesOfType<Required<T>, RestrictToType>
>;
// Repro from #33568
declare function ff(x: Foo3<string>): void;
declare function gg<T>(f: (x: Foo3<T>) => void): void;
type Foo3<T> = T extends number ? { n: T } : { x: T };
gg(ff);
// Repro from #41613
type Wat<K extends string> = { x: { y: 0, z: 1 } } extends { x: { [P in K]: 0 } } ? true : false;
type Huh = Wat<"y">; // true
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/conditionalTypesExcessProperties.ts | TypeScript | type Something<T> = { test: string } & (T extends object ? {
arg: T
} : {
arg?: undefined
});
function testFunc2<A extends object>(a: A, sa: Something<A>) {
sa = { test: 'hi', arg: a }; // not excess (but currently still not assignable)
sa = { test: 'bye', arg: a, arr: a } // excess
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/conflictingCommonJSES2015Exports.ts | TypeScript | // @checkJs: true
// @allowJS: true
// @noEmit: true
// @Filename: bug24934.js
export function abc(a, b, c) { return 5; }
module.exports = { abc };
// @Filename: use.js
import { abc } from './bug24934';
abc(1, 2, 3);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constEnum1.ts | TypeScript | // @declaration: true
// An enum declaration that specifies a const modifier is a constant enum declaration.
// In a constant enum declaration, all members must have constant values and
// it is an error for a member declaration to specify an expression that isn't classified as a constant enum expression.
const enum E {
a = 10,
b = a,
c = (a+1),
e,
d = ~e,
f = a << 2 >> 1,
g = a << 2 >>> 1,
h = a | b
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constEnum2.ts | TypeScript | // @declaration: true
// An enum declaration that specifies a const modifier is a constant enum declaration.
// In a constant enum declaration, all members must have constant values and
// it is an error for a member declaration to specify an expression that isn't classified as a constant enum expression.
// Error : not a constant enum expression
const CONST = 9000 % 2;
const enum D {
d = 10,
e = 199 * Math.floor(Math.random() * 1000),
f = d - (100 * Math.floor(Math.random() % 8)),
g = CONST,
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constEnum3.ts | TypeScript | const enum TestType { foo, bar }
type TestTypeStr = keyof typeof TestType;
function f1(f: TestType) { }
function f2(f: TestTypeStr) { }
f1(TestType.foo)
f1(TestType.bar)
f2('foo')
f2('bar')
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constEnum4.ts | TypeScript | if (1)
const enum A { }
else if (2)
const enum B { }
else
const enum C { }
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constEnumNoObjectPrototypePropertyAccess.ts | TypeScript | // @strict: true
// @noEmit: true
// https://github.com/microsoft/TypeScript/issues/55421
const enum Bebra {}
console.log(Bebra.constructor)
console.log(Bebra.hasOwnProperty)
console.log(Bebra.isPrototypeOf)
console.log(Bebra.propertyIsEnumerable)
console.log(Bebra.toLocaleString)
console.log(Bebra.toString)
console.log(Bebra.valueOf)
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constEnumPropertyAccess1.ts | TypeScript | // @declaration: true
// @target: es6
// constant enum declarations are completely erased in the emitted JavaScript code.
// it is an error to reference a constant enum object in any other context
// than a property access that selects one of the enum's members
const enum G {
A = 1,
B = 2,
C = A + B,
D = A * 2
}
var o: {
[idx: number]: boolean
} = {
1: true
};
var a = G.A;
var a1 = G["A"];
var g = o[G.A];
class C {
[G.A]() { }
get [G.B]() {
return true;
}
set [G.B](x: number) { }
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constEnumPropertyAccess2.ts | TypeScript | // @declaration: true
// constant enum declarations are completely erased in the emitted JavaScript code.
// it is an error to reference a constant enum object in any other context
// than a property access that selects one of the enum's members
const enum G {
A = 1,
B = 2,
C = A + B,
D = A * 2
}
// Error from referring constant enum in any other context than a property access
var z = G;
var z1 = G[G.A];
var g: G;
g = "string";
function foo(x: G) { }
G.B = 3;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constEnumPropertyAccess3.ts | TypeScript | const enum E {
A = ~1,
B = -1,
C = ~(1 + 1),
D = -(1 + 2),
E = 1 - 10,
}
E.A.toString();
E.B.toString();
E.C.toString();
E.D.toString();
E["A"].toString();
E["B"].toString();
E["C"].toString();
E["D"].toString();
E["E"].toString();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constLocalsInFunctionExpressions.ts | TypeScript | declare function getStringOrNumber(): string | number;
function f1() {
const x = getStringOrNumber();
if (typeof x === "string") {
const f = () => x.length;
}
}
function f2() {
const x = getStringOrNumber();
if (typeof x !== "string") {
return;
}
const f = () => x.length;
}
function f3() {
const x = getStringOrNumber();
if (typeof x === "string") {
const f = function() { return x.length; };
}
}
function f4() {
const x = getStringOrNumber();
if (typeof x !== "string") {
return;
}
const f = function() { return x.length; };
}
function f5() {
const x = getStringOrNumber();
if (typeof x === "string") {
const f = () => () => x.length;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constraintSatisfactionWithAny.ts | TypeScript | // any is not a valid type argument unless there is no constraint, or the constraint is any
function foo<T extends String>(x: T): T { return null; }
function foo2<T extends { x: number }>(x: T): T { return null; }
//function foo3<T extends T[]>(x: T): T { return null; }
function foo4<T extends <T>(x: T) => void>(x: T): T { return null; }
var a;
foo(a);
foo2(a);
//foo3(a);
foo4(a);
var b: number;
foo<any>(b);
foo2<any>(b);
//foo3<any>(b);
foo4<any>(b);
//function foo5<T extends String, U extends T>(x: T, y: U): T { return null; }
//foo5(a, a);
//foo5<any, any>(b, b);
class C<T extends String> {
constructor(public x: T) { }
}
var c1 = new C(a);
var c2 = new C<any>(b);
class C2<T extends { x: number }> {
constructor(public x: T) { }
}
var c3 = new C2(a);
var c4 = new C2<any>(b);
//class C3<T extends T[]> {
// constructor(public x: T) { }
//}
//var c5 = new C3(a);
//var c6 = new C3<any>(b);
class C4<T extends <T>(x:T) => T> {
constructor(public x: T) { }
}
var c7 = new C4(a);
var c8 = new C4<any>(b);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constraintSatisfactionWithAny2.ts | TypeScript | // errors expected for type parameter cannot be referenced in the constraints of the same list
// any is not a valid type argument unless there is no constraint, or the constraint is any
declare function foo<Z, T extends <U>(x: U) => Z>(y: T): Z;
var a: any;
foo(a);
foo<any, any>(a); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constraintSatisfactionWithEmptyObject.ts | TypeScript | // valid uses of a basic object constraint, no errors expected
// Object constraint
function foo<T extends Object>(x: T) { }
var r = foo({});
var a = {};
var r = foo({});
class C<T extends Object> {
constructor(public x: T) { }
}
var r2 = new C({});
interface I<T extends Object> {
x: T;
}
var i: I<{}>;
// {} constraint
function foo2<T extends {}>(x: T) { }
var r = foo2({});
var a = {};
var r = foo2({});
class C2<T extends {}> {
constructor(public x: T) { }
}
var r2 = new C2({});
interface I2<T extends {}> {
x: T;
}
var i2: I2<{}>;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructBigint.ts | TypeScript | // @target: esnext
// @lib: esnext
// @strict: true
BigInt(1);
BigInt(1n);
BigInt("0");
BigInt(false);
BigInt(Symbol());
BigInt({ e: 1, m: 1 })
BigInt(null);
BigInt(undefined)
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructSignatureAssignabilityInInheritance.ts | TypeScript | // Checking basic subtype relations with construct signatures
module ConstructSignature {
interface Base { // T
// M's
new (x: number): void; // BUG 842221
new (x: number, y: number): number;
}
// S's
interface I extends Base {
// N's
new (x: number): number; // satisfies subtype for both of base's call signatures
new (x: number, y: number): boolean; // so this one hides the base type member that is identical modulo return types
}
interface Base2 { // T
// M's
new (x: number): number;
}
// S's
interface I2 extends Base2 {
// N's
new (x: number): string; // error because return types don't match
}
// S's
interface I3 extends Base2 {
// N's
new <T>(x: T): string; // ok, adds a new call signature
}
}
module MemberWithConstructSignature {
interface Base { // T
// M's
a: new (x: number) => void;
a2: new (x: number, y: number) => void;
a3: new <T>(x: T) => void;
}
var b: Base;
var r = new b.a(1);
// S's
interface I extends Base {
// N's
a: new (x: number) => number; // ok because base returns void
a2: new (x: number, y: number) => boolean; // ok because base returns void
a3: new <T>(x: T) => string; // ok because base returns void
}
interface Base2 { // T
// M's
a: new (x: number) => number;
a2: new <T>(x: T) => T;
}
// S's
interface I2 extends Base2 {
// N's
a: new (x: number) => string; // error because base returns non-void;
}
// S's
interface I3 extends Base2 {
// N's
a2: new <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/constructSignatureAssignabilityInInheritance2.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: new (x: number) => number[];
a2: new (x: number) => string[];
a3: new (x: number) => void;
a4: new (x: string, y: number) => string;
a5: new (x: (arg: string) => number) => string;
a6: new (x: (arg: Base) => Derived) => Base;
a7: new (x: (arg: Base) => Derived) => (r: Base) => Derived;
a8: new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived;
a9: new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived;
a10: new (...x: Derived[]) => Derived;
a11: new (x: { foo: string }, y: { foo: string; bar: string }) => Base;
a12: new (x: Array<Base>, y: Array<Derived2>) => Array<Derived>;
a13: new (x: Array<Base>, y: Array<Derived>) => Array<Derived>;
a14: new (x: { a: string; b: number }) => Object;
a15: {
new (x: number): number[];
new (x: string): string[];
};
a16: {
new <T extends Derived>(x: T): number[];
new <U extends Base>(x: U): number[];
};
a17: {
new (x: new (a: number) => number): number[];
new (x: new (a: string) => string): string[];
};
a18: {
new (x: {
new (a: number): number;
new (a: string): string;
}): any[];
new (x: {
new (a: boolean): boolean;
new (a: Date): Date;
}): any[];
};
}
// S's
interface I extends A {
// N's
a: new <T>(x: T) => T[]; // ok, instantiation of N is a subtype of M, T is number
a2: new <T>(x: T) => string[]; // ok
a3: new <T>(x: T) => T; // ok since Base returns void
a4: new <T, U>(x: T, y: U) => T; // ok, instantiation of N is a subtype of M, T is string, U is number
a5: new <T, U>(x: (arg: T) => U) => T; // ok, U is in a parameter position so inferences can be made
a6: new <T extends Base, U extends Derived>(x: (arg: T) => U) => T; // ok, same as a5 but with object type hierarchy
a7: new <T extends Base, U extends Derived>(x: (arg: T) => U) => (r: T) => U; // ok
a8: new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U; // ok
a9: new <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: new <T extends Derived>(...x: T[]) => T; // ok
a11: new <T extends Base>(x: T, y: T) => T; // ok
a12: new <T extends Array<Base>>(x: Array<Base>, y: T) => Array<Derived>; // ok, less specific parameter type
a13: new <T extends Array<Derived>>(x: Array<Base>, y: T) => T; // ok, T = Array<Derived>, satisfies constraint, contextual signature instantiation succeeds
a14: new <T, U>(x: { a: T; b: U }) => T; // ok
a15: new <T>(x: T) => T[]; // ok
a16: new <T extends Base>(x: T) => number[]; // ok
a17: new <T>(x: new (a: T) => T) => T[]; // ok
a18: new <T>(x: new (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/constructSignatureAssignabilityInInheritance3.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: new (x: number) => string[];
a7: new (x: (arg: Base) => Derived) => (r: Base) => Derived2;
a8: new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived;
a10: new (...x: Base[]) => Base;
a11: new (x: { foo: string }, y: { foo: string; bar: string }) => Base;
a12: new (x: Array<Base>, y: Array<Derived2>) => Array<Derived>;
a14: {
new (x: number): number[];
new (x: string): string[];
};
a15: new (x: { a: string; b: number }) => number;
a16: {
// type of parameter is overload set which means we can't do inference based on this type
new (x: {
new (a: number): number;
new (a?: number): number;
}): number[];
new (x: {
new (a: boolean): boolean;
new (a?: boolean): boolean;
}): boolean[];
};
}
interface I extends A {
a2: new <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: new (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: new <T extends Base, U extends Derived, V extends Derived2>(x: (arg: T) => U) => (r: T) => V;
}
interface I4 extends A {
a8: new <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: new <T extends Derived>(...x: T[]) => T; // valid, parameter covariance works even after contextual signature instantiation
}
interface I4C extends A {
a11: new <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: new <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: new <T>(x: { a: T; b: T }) => T; // error, T is {} which isn't an acceptable return type
}
interface I7 extends A {
a15: new <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: new <T>(x: new (a: T) => T) => T[];
}
}
module WithGenericSignaturesInBaseType {
// base type has generic call signature
interface B {
a2: new <T>(x: T) => T[];
}
interface I6 extends B {
a2: new <T>(x: T) => string[]; // error
}
// base type has generic call signature
interface C {
a2: new <T>(x: T) => string[];
}
interface I7 extends C {
a2: new <T>(x: T) => T[]; // error
}
// base type has a generic call signature with overloads
interface D {
a14: {
new <T extends Derived>(x: T): number[];
new <U extends Base>(x: U): number[];
};
}
interface I8 extends D {
a14: new <T extends Base>(x: T) => number[];
}
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructSignatureAssignabilityInInheritance4.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: new <T>(x: T) => T[];
a2: new <T>(x: T) => string[];
a3: new <T>(x: T) => void;
a4: new <T, U>(x: T, y: U) => string;
a5: new <T, U>(x: (arg: T) => U) => T;
a6: new <T extends Base>(x: (arg: T) => Derived) => T;
a11: new <T>(x: { foo: T }, y: { foo: T; bar: T }) => Base;
a15: new <T>(x: { a: T; b: T }) => T[];
a16: new <T extends Base>(x: { a: T; b: T }) => T[];
a17: {
new <T extends Base>(x: T): T[];
new <U extends Derived>(x: U): U[];
};
a18: {
new <T extends Derived>(x: T): number[];
new <U extends Base>(x: U): number[];
};
a19: {
new <T extends Derived>(x: new (a: T) => T): T[];
new <U extends Base>(x: new (a: U) => U): U[];
};
a20: {
new (x: {
new <T extends Derived>(a: T): T;
new <U extends Base>(a: U): U;
}): any[];
new (x: {
new <T extends Base>(a: T): T;
new <U extends Derived2>(a: U): U;
}): any[];
};
}
// S's
interface I extends A {
// N's
a: new <T>(x: T) => T[]; // ok, instantiation of N is a subtype of M, T is number
a2: new <T>(x: T) => string[]; // ok
a3: new <T>(x: T) => T; // ok since Base returns void
a4: new <T, U>(x: T, y: U) => string; // ok, instantiation of N is a subtype of M, T is string, U is number
a5: new <T, U>(x: (arg: T) => U) => T; // ok, U is in a parameter position so inferences can be made
a6: new <T extends Base, U extends Derived>(x: (arg: T) => U) => T; // ok, same as a5 but with object type hierarchy
a11: new <T, U>(x: { foo: T }, y: { foo: U; bar: U }) => Base; // ok
a15: new <U, V>(x: { a: U; b: V; }) => U[]; // ok, T = U, T = V
a16: new <T>(x: { a: T; b: T }) => T[]; // ok, more general parameter type
a17: new <T extends Base>(x: T) => T[]; // ok, more general parameter type
a18: new <T extends Base>(x: T) => number[]; // ok, more general parameter type
a19: new <T extends Base>(x: new (a: T) => T) => T[]; // ok
a20: new (x: new <T extends Base>(a: T) => T) => any[]; // ok
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructSignatureAssignabilityInInheritance5.ts | TypeScript | // checking subtype relations for function types as it relates to contextual signature instantiation
// same as subtypingWithConstructSignatures2 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: new (x: number) => number[];
a2: new (x: number) => string[];
a3: new (x: number) => void;
a4: new (x: string, y: number) => string;
a5: new (x: (arg: string) => number) => string;
a6: new (x: (arg: Base) => Derived) => Base;
a7: new (x: (arg: Base) => Derived) => (r: Base) => Derived;
a8: new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived;
a9: new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived;
a10: new (...x: Derived[]) => Derived;
a11: new (x: { foo: string }, y: { foo: string; bar: string }) => Base;
a12: new (x: Array<Base>, y: Array<Derived2>) => Array<Derived>;
a13: new (x: Array<Base>, y: Array<Derived>) => Array<Derived>;
a14: new (x: { a: string; b: number }) => Object;
}
interface B extends A {
a: new <T>(x: T) => T[];
}
// S's
interface I extends B {
// N's
a: new <T>(x: T) => T[]; // ok, instantiation of N is a subtype of M, T is number
a2: new <T>(x: T) => string[]; // ok
a3: new <T>(x: T) => T; // ok since Base returns void
a4: new <T, U>(x: T, y: U) => T; // ok, instantiation of N is a subtype of M, T is string, U is number
a5: new <T, U>(x: (arg: T) => U) => T; // ok, U is in a parameter position so inferences can be made
a6: new <T extends Base, U extends Derived>(x: (arg: T) => U) => T; // ok, same as a5 but with object type hierarchy
a7: new <T extends Base, U extends Derived>(x: (arg: T) => U) => (r: T) => U; // ok
a8: new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U; // ok
a9: new <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: new <T extends Derived>(...x: T[]) => T; // ok
a11: new <T extends Base>(x: T, y: T) => T; // ok
a12: new <T extends Array<Base>>(x: Array<Base>, y: T) => Array<Derived>; // ok, less specific parameter type
a13: new <T extends Array<Derived>>(x: Array<Base>, y: T) => T; // ok, T = Array<Derived>, satisfies constraint, contextual signature instantiation succeeds
a14: new <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/constructSignatureAssignabilityInInheritance6.ts | TypeScript | // checking subtype relations for function types as it relates to contextual signature instantiation
// same as subtypingWithConstructSignatures4 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: new <T>(x: T) => T[];
a2: new <T>(x: T) => string[];
a3: new <T>(x: T) => void;
a4: new <T, U>(x: T, y: U) => string;
a5: new <T, U>(x: (arg: T) => U) => T;
a6: new <T extends Base>(x: (arg: T) => Derived) => T;
a11: new <T>(x: { foo: T }, y: { foo: T; bar: T }) => Base;
a15: new <T>(x: { a: T; b: T }) => T[];
a16: new <T extends Base>(x: { a: T; b: T }) => T[];
}
// S's
interface I<T> extends A {
a: new (x: T) => T[];
}
interface I2<T> extends A {
a2: new (x: T) => string[];
}
interface I3<T> extends A {
a3: new (x: T) => T;
}
interface I4<T> extends A {
a4: new <U>(x: T, y: U) => string;
}
interface I5<T> extends A {
a5: new <U>(x: (arg: T) => U) => T;
}
interface I7<T> extends A {
a11: new <U>(x: { foo: T }, y: { foo: U; bar: U }) => Base;
}
interface I9<T> extends A {
a16: new (x: { a: T; b: T }) => T[];
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructSignatureWithAccessibilityModifiersOnParameters.ts | TypeScript | // Parameter properties are only valid in constructor definitions, not even in other forms of construct signatures
class C {
constructor(public x, private y) { }
}
class C2 {
constructor(public x) { }
}
class C3 {
constructor(private x) { }
}
interface I {
new (public x);
}
interface I2 {
new (private x);
}
var a: {
new (public x);
}
var b: {
new (private x);
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructSignatureWithAccessibilityModifiersOnParameters2.ts | TypeScript | // Parameter properties are not valid in overloads of constructors
class C {
constructor(public x, private y);
constructor(public x, private y) { }
}
class C2 {
constructor(private x);
constructor(public x) { }
}
class C3 {
constructor(private x);
constructor(private y) { }
}
interface I {
new (public x);
new (public x);
}
interface I2 {
new (private x);
new (private x);
}
var a: {
new (public x);
new (public y);
}
var b: {
new (private x);
new (private y);
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructSignaturesWithIdenticalOverloads.ts | TypeScript | // Duplicate overloads of construct signatures should generate errors
class C {
constructor(x: number, y: string);
constructor(x: number, y: string); // error
constructor(x: number) { }
}
var r1 = new C(1, '');
class C2<T> {
constructor(x: T, y: string);
constructor(x: T, y: string); // error
constructor(x: T) { }
}
var r2 = new C2(1, '');
interface I {
new (x: number, y: string): C;
new (x: number, y: string): C; // error
}
var i: I;
var r3 = new i(1, '');
interface I2<T> {
new (x: T, y: string): C2<T>;
new (x: T, y: string): C2<T>; // error
new <T>(x: T, y: string): C2<T>;
new <T>(x: T, y: string): C2<T>; // error
}
var i2: I2<number>;
var r4 = new i2(1, '');
var a: {
new (x: number, y: string): C;
new (x: number, y: string): C; // error
}
var r5 = new a(1, '');
var b: {
new <T>(x: T, y: string): C2<T>;
new <T>(x: T, y: string): C2<T>; // error
}
var r6 = new b(1, ''); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructSignaturesWithOverloads.ts | TypeScript | // No errors expected for basic overloads of construct signatures
class C {
constructor(x: number, y?: string);
constructor(x: number, y: string);
constructor(x: number) { }
}
var r1 = new C(1, '');
class C2<T> {
constructor(x: T, y?: string);
constructor(x: T, y: string);
constructor(x: T) { }
}
var r2 = new C2(1, '');
interface I {
new(x: number, y?: string): C;
new(x: number, y: string): C;
}
var i: I;
var r3 = new i(1, '');
interface I2<T> {
new (x: T, y?: string): C2<T>;
new (x: T, y: string): C2<T>;
new <T>(x: T, y?: string): C2<T>;
new <T>(x: T, y: string): C2<T>;
}
var i2: I2<number>;
var r4 = new i2(1, '');
var a: {
new(x: number, y?: string): C;
new(x: number, y: string): C;
}
var r5 = new a(1, '');
var b: {
new<T>(x: T, y?: string): C2<T>;
new<T>(x: T, y: string): C2<T>;
}
var r6 = new b(1, ''); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructSignaturesWithOverloads2.ts | TypeScript | // No errors expected for basic overloads of construct signatures with merged declarations
// clodules
class C {
constructor(x: number, y?: string);
constructor(x: number, y: string);
constructor(x: number) { }
}
module C {
export var x = 1;
}
var r1 = new C(1, '');
class C2<T> {
constructor(x: T, y?: string);
constructor(x: T, y: string);
constructor(x: T) { }
}
module C2 {
export var x = 1;
}
var r2 = new C2(1, '');
// merged interfaces
interface I {
new (x: number, y?: string): C;
new (x: number, y: string): C;
}
interface I<T> {
new (x: T, y?: number): C2<T>;
new (x: T, y: number): C2<T>;
}
var i2: I<number>;
var r4 = new i2(1, '');
var r5 = new i2(1, 1); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructSignaturesWithOverloadsThatDifferOnlyByReturnType.ts | TypeScript | // Error for construct signature overloads to differ only by return type
class C {
constructor(x: number) { }
}
class C2<T> {
constructor(x: T, y?: string) { }
}
interface I {
new(x: number, y: string): C;
new(x: number, y: string): C2<number>; // error
}
interface I2<T> {
new (x: T, y: string): C2<number>;
new (x: T, y: string): C; // error
new <T>(x: T, y: string): C2<T>;
new <T>(x: T, y: string): C; // error
}
var a: {
new (x: number, y: string): C2<number>;
new (x: number, y: string): C; // error
}
var b: {
new <T>(x: T, y: string): C2<T>;
new <T>(x: T, y: string): C; // error
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorFunctionMergeWithClass.ts | TypeScript | // @allowJs: true
// @noEmit: true
// @checkJs: true
// @Filename: file1.js
var SomeClass = function () {
this.otherProp = 0;
};
new SomeClass();
// @Filename: file2.js
class SomeClass { }
SomeClass.prop = 0
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorFunctionMethodTypeParameters.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @filename: constructorFunctionMethodTypeParameters.js
/**
* @template {string} T
* @param {T} t
*/
function Cls(t) {
this.t = t;
}
/**
* @template {string} V
* @param {T} t
* @param {V} v
* @return {V}
*/
Cls.prototype.topLevelComment = function (t, v) {
return v
};
Cls.prototype.nestedComment =
/**
* @template {string} U
* @param {T} t
* @param {U} u
* @return {T}
*/
function (t, u) {
return t
};
var c = new Cls('a');
const s = c.topLevelComment('a', 'b');
const t = c.nestedComment('a', 'b');
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorFunctionTypeIsAssignableToBaseType.ts | TypeScript | class Base {
static foo: {
bar: Object;
}
}
class Derived extends Base {
// ok
static foo: {
bar: number;
}
}
class Derived2 extends Base {
// ok, use assignability here
static foo: {
bar: any;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorFunctionTypeIsAssignableToBaseType2.ts | TypeScript | // the constructor function itself does not need to be a subtype of the base type constructor function
class Base {
static foo: {
bar: Object;
}
constructor(x: Object) {
}
}
class Derived extends Base {
// ok
static foo: {
bar: number;
}
constructor(x: number) {
super(x);
}
}
class Derived2 extends Base {
static foo: {
bar: number;
}
// ok, not enforcing assignability relation on this
constructor(x: any) {
super(x);
return 1;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorFunctions.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @filename: index.js
function C1() {
if (!(this instanceof C1)) return new C1();
this.x = 1;
}
const c1_v1 = C1();
const c1_v2 = new C1();
var C2 = function () {
if (!(this instanceof C2)) return new C2();
this.x = 1;
};
const c2_v1 = C2();
const c2_v2 = new C2();
/** @class */
function C3() {
if (!(this instanceof C3)) return new C3();
};
const c3_v1 = C3(); // error: @class tag requires 'new'
const c3_v2 = new C3();
/** @class */
var C4 = function () {
if (!(this instanceof C4)) return new C4();
};
const c4_v1 = C4(); // error: @class tag requires 'new'
const c4_v2 = new C4();
var c5_v1;
c5_v1 = function f() { };
new c5_v1();
var c5_v2;
c5_v2 = class { };
new c5_v2();
/** @class */
function C6() {
this.functions = [x => x, x => x + 1, x => x - 1]
};
var c6_v1 = new C6();
/**
* @constructor
* @param {number} num
*/
function C7(num) {}
var c7_v1 = new C7();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorFunctions2.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @module: commonjs
// @filename: node.d.ts
declare function require(id: string): any;
declare var module: any, exports: any;
// @filename: index.js
const A = require("./other");
const a = new A().id;
const B = function() { this.id = 1; }
B.prototype.m = function() { this.x = 2; }
const b = new B();
b.id;
b.x;
// @filename: other.js
function A() { this.id = 1; }
module.exports = A; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorFunctions3.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @noImplicitAny: true
// @Filename: a.js
function Instance() {
this.i = 'simple'
}
var i = new Instance();
Instance;
i;
function StaticToo() {
this.i = 'more complex'
}
StaticToo.property = 'yep'
var s = new StaticToo();
s;
StaticToo;
// Both!
function A () {
this.x = 1
/** @type {1} */
this.second = 1
}
/** @param {number} n */
A.prototype.z = function f(n) {
return n + this.x
}
/** @param {number} m */
A.t = function g(m) {
return m + 1
}
var a = new A()
a.z(3)
A.t(2)
a.second = 1
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorFunctionsStrict.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @strict: true
// @noImplicitThis: false
// @Filename: a.js
/** @param {number} x */
function C(x) {
this.x = x
}
C.prototype.m = function() {
this.y = 12
}
var c = new C(1)
c.x = undefined // should error
c.y = undefined // ok
/** @param {number} x */
function A(x) {
if (!(this instanceof A)) {
return new A(x)
}
this.x = x
}
var k = A(1)
var j = new A(2)
k.x === j.x
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorHasPrototypeProperty.ts | TypeScript | module NonGeneric {
class C {
foo: string;
}
class D extends C {
bar: string;
}
var r = C.prototype;
r.foo;
var r2 = D.prototype;
r2.bar;
}
module Generic {
class C<T,U> {
foo: T;
bar: U;
}
class D<T,U> extends C<T,U> {
baz: T;
bing: U;
}
var r = C.prototype; // C<any, any>
var ra = r.foo; // any
var r2 = D.prototype; // D<any, any>
var rb = r2.baz; // any
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorImplementationWithDefaultValues.ts | TypeScript | class C {
constructor(x);
constructor(x = 1) {
var y = x;
}
}
class D<T> {
constructor(x);
constructor(x:T = null) {
var y = x;
}
}
class E<T extends Date> {
constructor(x);
constructor(x: T = null) {
var y = x;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorImplementationWithDefaultValues2.ts | TypeScript | class C {
constructor(x);
constructor(public x: string = 1) { // error
var y = x;
}
}
class D<T, U> {
constructor(x: T, y: U);
constructor(x: T = 1, public y: U = x) { // error
var z = x;
}
}
class E<T extends Date> {
constructor(x);
constructor(x: T = new Date()) { // error
var y = x;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorNameInObjectLiteralAccessor.ts | TypeScript | // @target: esnext
const c1 = {
get constructor() { return },
set constructor(value) {}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorOverloadsWithDefaultValues.ts | TypeScript | class C {
foo: string;
constructor(x = 1); // error
constructor() {
}
}
class D<T> {
foo: string;
constructor(x = 1); // error
constructor() {
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorOverloadsWithOptionalParameters.ts | TypeScript | class C {
foo: string;
constructor(x?, y?: any[]);
constructor() {
}
}
class D<T> {
foo: string;
constructor(x?, y?: any[]);
constructor() {
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorParameterProperties.ts | TypeScript | class C {
y: string;
constructor(private x: string, protected z: string) { }
}
var c: C;
var r = c.y;
var r2 = c.x; // error
var r3 = c.z; // error
class D<T> {
y: T;
constructor(a: T, private x: T, protected z: T) { }
}
var d: D<string>;
var r = d.y;
var r2 = d.x; // error
var r3 = d.a; // error
var r4 = d.z; // error
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorParameterProperties2.ts | TypeScript | class C {
y: number;
constructor(y: number) { } // ok
}
var c: C;
var r = c.y;
class D {
y: number;
constructor(public y: number) { } // error
}
var d: D;
var r2 = d.y;
class E {
y: number;
constructor(private y: number) { } // error
}
var e: E;
var r3 = e.y; // error
class F {
y: number;
constructor(protected y: number) { } // error
}
var f: F;
var r4 = f.y; // error
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorParameterShadowsOuterScopes.ts | TypeScript | // Initializer expressions for instance member variables are evaluated in the scope of the class constructor
// body but are not permitted to reference parameters or local variables of the constructor.
// This effectively means that entities from outer scopes by the same name as a constructor parameter or
// local variable are inaccessible in initializer expressions for instance member variables
var x = 1;
class C {
b = x; // error, evaluated in scope of constructor, cannot reference x
constructor(x: string) {
x = 2; // error, x is string
}
}
var y = 1;
class D {
b = y; // error, evaluated in scope of constructor, cannot reference y
constructor(x: string) {
var y = "";
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorParameterShadowsOuterScopes2.ts | TypeScript | // @target: esnext
// @useDefineForClassFields: true
// With useDefineForClassFields: true and ESNext target, initializer
// expressions for property declarations are evaluated in the scope of
// the class body and are permitted to reference parameters or local
// variables of the constructor. This is different from classic
// Typescript behaviour, with useDefineForClassFields: false. There,
// initialisers of property declarations are evaluated in the scope of
// the constructor body.
// Note that when class fields are accepted in the ECMAScript
// standard, the target will become that year's ES20xx
var x = 1;
class C {
b = x; // ok
constructor(x: string) {
}
}
var y = 1;
class D {
b = y; // ok
constructor(x: string) {
var y = "";
}
}
class E {
b = z; // not ok
constructor(z: string) {
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorTagOnClassConstructor.ts | TypeScript | // @allowJs: true
// @noEmit: true
// @checkJs: true
// @Filename: bug27025.js
export class Alpha { }
export class Beta {
/**
* @constructor
*/
constructor() {
}
}
const arr = [Alpha, Beta];
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorTagOnNestedBinaryExpression.ts | TypeScript | // @allowjs: true
// @noemit: true
// @Filename: constructorTagOnNestedBinaryExpression.js
// Fixes #35021
/** @constructor */
a = b = function c () {
console.log(this)
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorTagOnObjectLiteralMethod.ts | TypeScript | // @noEmit: true
// @Filename: example.js
// @allowJs: true
// @checkJs: true
// @noImplicitAny: true
const obj = {
/** @constructor */
Foo() { this.bar = "bar" }
};
(new obj.Foo()).bar
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorTagWithThisTag.ts | TypeScript | // @allowJs: true
// @noEmit: true
// @checkJs: true
// @Filename: classthisboth.js
/**
* @class
* @this {{ e: number, m: number }}
* this-tag should win, both 'e' and 'm' should be defined.
*/
function C() {
this.e = this.m + 1
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorWithAssignableReturnExpression.ts | TypeScript | // a class constructor may return an expression, it must be assignable to the class instance type to be valid
class C {
constructor() {
return 1;
}
}
class D {
x: number;
constructor() {
return 1; // error
}
}
class E {
x: number;
constructor() {
return { x: 1 };
}
}
class F<T> {
x: T;
constructor() {
return { x: 1 }; // error
}
}
class G<T> {
x: T;
constructor() {
return { x: <T>null };
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/constructorWithExpressionLessReturn.ts | TypeScript | class C {
constructor() {
return;
}
}
class D {
x: number;
constructor() {
return;
}
}
class E {
constructor(public x: number) {
return;
}
}
class F<T> {
constructor(public x: T) {
return;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextualIntersectionType.ts | TypeScript | var x: { a: (s: string) => string } & { b: (n: number) => number };
x = {
a: s => s,
b: n => n
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextualSignatureInstantiation.ts | TypeScript | // TypeScript Spec, section 4.12.2:
// If e is an expression of a function type that contains exactly one generic call signature and no other members,
// and T is a function type with exactly one non - generic call signature and no other members, then any inferences
// made for type parameters referenced by the parameters of T's call signature are fixed, and e's type is changed
// to a function type with e's call signature instantiated in the context of T's call signature (section 3.8.5).
declare function foo<T>(cb: (x: number, y: string) => T): T;
declare function bar<T, U, V>(x: T, y: U, cb: (x: T, y: U) => V): V;
declare function baz<T, U>(x: T, y: T, cb: (x: T, y: T) => U): U;
declare function g<T>(x: T, y: T): T;
declare function h<T, U>(x: T, y: U): T[] | U[];
var a: number;
var a = bar(1, 1, g); // Should be number
var a = baz(1, 1, g); // Should be number
var b: number | string;
var b = foo(g); // Error, number and string are disjoint types
var b = bar(1, "one", g); // Error, number and string are disjoint types
var b = bar("one", 1, g); // Error, number and string are disjoint types
var b = baz(b, b, g); // Should be number | string
var d: number[] | string[];
var d = foo(h); // Should be number[] | string[]
var d = bar(1, "one", h); // Should be number[] | string[]
var d = bar("one", 1, h); // Should be number[] | string[]
var d = baz(d, d, g); // Should be number[] | string[]
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextualThisType.ts | TypeScript | interface X {
a: (p: this) => this;
}
interface Y extends X {
}
var x: Y = {
a(p) {
return p;
}
}
var y = x.a(x);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextualThisTypeInJavascript.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: context.js
const obj = {
prop: 2,
method() {
this;
this.prop;
this.method;
this.unknown; // ok, obj has a string indexer
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextualTypeFromJSDoc.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @filename: index.js
// @target: esnext
/** @type {Array<[string, {x?:number, y?:number}]>} */
const arr = [
['a', { x: 1 }],
['b', { y: 2 }]
];
/** @return {Array<[string, {x?:number, y?:number}]>} */
function f() {
return [
['a', { x: 1 }],
['b', { y: 2 }]
];
}
class C {
/** @param {Array<[string, {x?:number, y?:number}]>} value */
set x(value) { }
get x() {
return [
['a', { x: 1 }],
['b', { y: 2 }]
];
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextualTypeTupleEnd.ts | TypeScript | // @strict: true
// @noEmit: true
type Funcs = [...((arg: number) => void)[], (arg: string) => void];
declare function num(x: number): void;
declare function str(x: string): void;
declare function f1(...args: Funcs): void;
f1(); // Error
f1(x => str(x));
f1(x => num(x), x => str(x));
f1(x => num(x), x => num(x), x => str(x));
const a0: Funcs = []; // Error
const a1: Funcs = [x => str(x)];
const a2: Funcs = [x => num(x), x => str(x)];
const a3: Funcs = [x => num(x), x => num(x), x => str(x)];
// Repro from #43122
export type Selector<State> = (state: State) => unknown;
export type SelectorTuple<State> = Selector<State>[];
export type ExampleState = {
foo: "foo";
bar: 42;
};
export function createSelector<S extends SelectorTuple<ExampleState>>(...selectors: [...selectors: S, f: (x: any) => any]) {
console.log(selectors);
}
createSelector(
x => x.foo,
x => x.bar,
() => 42
);
// Repro from #43122
declare function example(...args: [...((n: number) => void)[], (x: any) => void]): void
example(
x => x.foo, // Error
x => x.bar, // Error
x => x.baz,
);
// Repro from #52846
declare function test(...args: [...((arg: number) => void)[], (arg: string) => void]): void;
test(a => a, b => b, c => c);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextualTypeWithTuple.ts | TypeScript | // no error
var numStrTuple: [number, string] = [5, "hello"];
var numStrTuple2: [number, string] = [5, "foo", true];
var numStrBoolTuple: [number, string, boolean] = [5, "foo", true];
var objNumTuple: [{ a: string }, number] = [{ a: "world" }, 5];
var strTupleTuple: [string, [number, {}]] = ["bar", [5, { x: 1, y: 1 }]];
class C { }
class D { }
var unionTuple: [C, string | number] = [new C(), "foo"];
var unionTuple1: [C, string | number] = [new C(), "foo"];
var unionTuple2: [C, string | number, D] = [new C(), "foo", new D()];
var unionTuple3: [number, string| number] = [10, "foo"];
numStrTuple = numStrTuple2;
numStrTuple = numStrBoolTuple;
// error
objNumTuple = [ {}, 5];
numStrBoolTuple = numStrTuple;
var strStrTuple: [string, string] = ["foo", "bar", 5];
unionTuple = unionTuple1;
unionTuple = unionTuple2;
unionTuple2 = unionTuple;
numStrTuple = unionTuple3;
// repro from #29311
type test1 = [...number[]]
type fixed1 = test1 & { length: 2 }
let var1: fixed1 = [0, 0]
// #52551
type EmptyTuple = []
interface MyEmptyTuple extends EmptyTuple { extraInfo?: any; }
const withExtra: MyEmptyTuple = []
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextualTypeWithUnionTypeCallSignatures.ts | TypeScript | //When used as a contextual type, a union type U has those members that are present in any of
// its constituent types, with types that are unions of the respective members in the constituent types.
// Let S be the set of types in U that have call signatures.
// If S is not empty and the sets of call signatures of the types in S are identical ignoring return types,
// U has the same set of call signatures, but with return types that are unions of the return types of the respective call signatures from each type in S.
interface IWithNoCallSignatures {
foo: string;
}
interface IWithCallSignatures {
(a: number): string;
}
interface IWithCallSignatures2 {
(a: number): number;
}
interface IWithCallSignatures3 {
(b: string): number;
}
interface IWithCallSignatures4 {
(a: number): string;
(a: string, b: number): number;
}
// With no call signature | callSignatures
var x: IWithNoCallSignatures | IWithCallSignatures = a => a.toString();
// With call signatures with different return type
var x2: IWithCallSignatures | IWithCallSignatures2 = a => a.toString(); // Like iWithCallSignatures
var x2: IWithCallSignatures | IWithCallSignatures2 = a => a; // Like iWithCallSignatures2
// With call signatures of mismatching parameter type
var x3: IWithCallSignatures | IWithCallSignatures3 = a => /*here a should be any*/ a.toString();
// With call signature count mismatch
var x4: IWithCallSignatures | IWithCallSignatures4 = a => /*here a should be any*/ a.toString(); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextualTypeWithUnionTypeIndexSignatures.ts | TypeScript | //When used as a contextual type, a union type U has those members that are present in any of
// its constituent types, with types that are unions of the respective members in the constituent types.
interface SomeType {
(a: number): number;
}
interface SomeType2 {
(a: number): string;
}
interface IWithNoStringIndexSignature {
foo: string;
}
interface IWithNoNumberIndexSignature {
0: string;
}
interface IWithStringIndexSignature1 {
[a: string]: SomeType;
}
interface IWithStringIndexSignature2 {
[a: string]: SomeType2;
}
interface IWithNumberIndexSignature1 {
[a: number]: SomeType;
}
interface IWithNumberIndexSignature2 {
[a: number]: SomeType2;
}
// When an object literal is contextually typed by a type that includes a string index signature,
// the resulting type of the object literal includes a string index signature with the union type of
// the types of the properties declared in the object literal, or the Undefined type if the object literal
// is empty.Likewise, when an object literal is contextually typed by a type that includes a numeric index
// signature, the resulting type of the object literal includes a numeric index signature with the union type
// of the types of the numerically named properties(section 3.7.4) declared in the object literal,
// or the Undefined type if the object literal declares no numerically named properties.
// Let S be the set of types in U that has a string index signature.
// If S is not empty, U has a string index signature of a union type of
// the types of the string index signatures from each type in S.
var x: IWithNoStringIndexSignature | IWithStringIndexSignature1 = { z: a => a }; // a should be number
var x: IWithNoStringIndexSignature | IWithStringIndexSignature1 = { foo: a => a }; // a should be number (because of index signature of IWithStringIndexSignature1)
var x: IWithNoStringIndexSignature | IWithStringIndexSignature1 = { foo: "hello" };
var x2: IWithStringIndexSignature1 | IWithStringIndexSignature2 = { z: a => a.toString() }; // a should be number
var x2: IWithStringIndexSignature1 | IWithStringIndexSignature2 = { z: a => a }; // a should be number
// Let S be the set of types in U that has a numeric index signature.
// If S is not empty, U has a numeric index signature of a union type of
// the types of the numeric index signatures from each type in S.
var x3: IWithNoNumberIndexSignature | IWithNumberIndexSignature1 = { 1: a => a }; // a should be number
var x3: IWithNoNumberIndexSignature | IWithNumberIndexSignature1 = { 0: a => a }; // a should be number (because of index signature of IWithNumberIndexSignature1)
var x3: IWithNoNumberIndexSignature | IWithNumberIndexSignature1 = { 0: "hello" };
var x4: IWithNumberIndexSignature1 | IWithNumberIndexSignature2 = { 1: a => a.toString() }; // a should be number
var x4: IWithNumberIndexSignature1 | IWithNumberIndexSignature2 = { 1: a => a }; // a should be number | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextualTypeWithUnionTypeMembers.ts | TypeScript | //When used as a contextual type, a union type U has those members that are present in any of
// its constituent types, with types that are unions of the respective members in the constituent types.
interface I1<T> {
commonMethodType(a: string): string;
commonPropertyType: string;
commonMethodWithTypeParameter(a: T): T;
methodOnlyInI1(a: string): string;
propertyOnlyInI1: string;
}
interface I2<T> {
commonMethodType(a: string): string;
commonPropertyType: string;
commonMethodWithTypeParameter(a: T): T;
methodOnlyInI2(a: string): string;
propertyOnlyInI2: string;
}
// Let S be the set of types in U that has a property P.
// If S is not empty, U has a property P of a union type of the types of P from each type in S.
var i1: I1<number>;
var i2: I2<number>;
var i1Ori2: I1<number> | I2<number> = i1;
var i1Ori2: I1<number> | I2<number> = i2;
var i1Ori2: I1<number> | I2<number> = { // Like i1
commonPropertyType: "hello",
commonMethodType: a=> a,
commonMethodWithTypeParameter: a => a,
methodOnlyInI1: a => a,
propertyOnlyInI1: "Hello",
};
var i1Ori2: I1<number> | I2<number> = { // Like i2
commonPropertyType: "hello",
commonMethodType: a=> a,
commonMethodWithTypeParameter: a => a,
methodOnlyInI2: a => a,
propertyOnlyInI2: "Hello",
};
var i1Ori2: I1<number> | I2<number> = { // Like i1 and i2 both
commonPropertyType: "hello",
commonMethodType: a=> a,
commonMethodWithTypeParameter: a => a,
methodOnlyInI1: a => a,
propertyOnlyInI1: "Hello",
methodOnlyInI2: a => a,
propertyOnlyInI2: "Hello",
};
var arrayI1OrI2: Array<I1<number> | I2<number>> = [i1, i2, { // Like i1
commonPropertyType: "hello",
commonMethodType: a=> a,
commonMethodWithTypeParameter: a => a,
methodOnlyInI1: a => a,
propertyOnlyInI1: "Hello",
},
{ // Like i2
commonPropertyType: "hello",
commonMethodType: a=> a,
commonMethodWithTypeParameter: a => a,
methodOnlyInI2: a => a,
propertyOnlyInI2: "Hello",
}, { // Like i1 and i2 both
commonPropertyType: "hello",
commonMethodType: a=> a,
commonMethodWithTypeParameter: a => a,
methodOnlyInI1: a => a,
propertyOnlyInI1: "Hello",
methodOnlyInI2: a => a,
propertyOnlyInI2: "Hello",
}];
interface I11 {
commonMethodDifferentReturnType(a: string, b: number): string;
commonPropertyDifferentType: string;
}
interface I21 {
commonMethodDifferentReturnType(a: string, b: number): number;
commonPropertyDifferentType: number;
}
var i11: I11;
var i21: I21;
var i11Ori21: I11 | I21 = i11;
var i11Ori21: I11 | I21 = i21;
var i11Ori21: I11 | I21 = {
// Like i1
commonMethodDifferentReturnType: (a, b) => {
var z = a.charAt(b);
return z;
},
commonPropertyDifferentType: "hello",
};
var i11Ori21: I11 | I21 = {
// Like i2
commonMethodDifferentReturnType: (a, b) => {
var z = a.charCodeAt(b);
return z;
},
commonPropertyDifferentType: 10,
};
var arrayOrI11OrI21: Array<I11 | I21> = [i11, i21, i11 || i21, {
// Like i1
commonMethodDifferentReturnType: (a, b) => {
var z = a.charAt(b);
return z;
},
commonPropertyDifferentType: "hello",
}, {
// Like i2
commonMethodDifferentReturnType: (a, b) => {
var z = a.charCodeAt(b);
return z;
},
commonPropertyDifferentType: 10,
}]; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextualTypeWithUnionTypeObjectLiteral.ts | TypeScript | var str: string;
var num: number;
var strOrNumber: string | number = str || num;
var objStr: { prop: string };
var objNum: { prop: number };
var objStrOrNum1: { prop: string } | { prop: number } = objStr || objNum;
var objStrOrNum2: { prop: string | number } = objStr || objNum;
// Below is error because :
// Spec says:
// S is a union type and each constituent type of S is assignable to T.
// T is a union type and S is assignable to at least one constituent type of T.
// In case of objStrOrNum3, the S is not union Type but object Literal so we go to next step.
// Since T is union Type we only allow the assignment of either object with property of type string or object with property of type number but do not allow object with property of type string | number
var objStrOrNum3: { prop: string } | { prop: number } = {
prop: strOrNumber
};
var objStrOrNum4: { prop: string | number } = {
prop: strOrNumber
};
var objStrOrNum5: { prop: string; anotherP: string; } | { prop: number } = { prop: strOrNumber };
var objStrOrNum6: { prop: string; anotherP: string; } | { prop: number } = {
prop: strOrNumber,
anotherP: str
};
var objStrOrNum7: { prop: string; anotherP: string; } | { prop: number; anotherP1: number } = {
prop: strOrNumber,
anotherP: str
};
var objStrOrNum8: { prop: string; anotherP: string; } | { prop: number; anotherP1: number } = {
prop: strOrNumber,
anotherP: str,
anotherP1: num
};
interface I11 {
commonMethodDifferentReturnType(a: string, b: number): string;
}
interface I21 {
commonMethodDifferentReturnType(a: string, b: number): number;
}
var i11: I11;
var i21: I21;
var i11Ori21: I11 | I21 = i11;
var i11Ori21: I11 | I21 = i21;
var i11Ori21: I11 | I21 = { // Like i1
commonMethodDifferentReturnType: (a, b) => {
var z = a.charAt(b);
return z;
},
};
var i11Ori21: I11 | I21 = { // Like i2
commonMethodDifferentReturnType: (a, b) => {
var z = a.charCodeAt(b);
return z;
},
};
var strOrNumber: string | number;
var i11Ori21: I11 | I21 = { // Like i1 and i2 both
commonMethodDifferentReturnType: (a, b) => strOrNumber,
}; | 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.