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/templateStringWithEmbeddedTypeOfOperator.ts
TypeScript
var x = `abc${ typeof "hi" }def`;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/templateStringWithEmbeddedTypeOfOperatorES6.ts
TypeScript
// @target: ES6 var x = `abc${ typeof "hi" }def`;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/templateStringWithEmbeddedUnaryPlus.ts
TypeScript
var x = `abc${ +Infinity }def`;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/templateStringWithEmbeddedUnaryPlusES6.ts
TypeScript
// @target: ES6 var x = `abc${ +Infinity }def`;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/templateStringWithEmbeddedYieldKeywordES6.ts
TypeScript
// @target: ES6 function* gen() { // Once this is supported, yield *must* be parenthesized. var x = `abc${ yield 10 }def`; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/templateStringWithEmptyLiteralPortions.ts
TypeScript
var a = ``; var b = `${ 0 }`; var c = `1${ 0 }`; var d = `${ 0 }2`; var e = `1${ 0 }2`; var f = `${ 0 }${ 0 }`; var g = `1${ 0 }${ 0 }`; var h = `${ 0 }2${ 0 }`; var i = `1${ 0 }2${ 0 }`; var j = `${ 0 }${ 0 }3`; var k = `1${ 0 }${ 0 }3`; var l = `${ 0 }2${ 0 }3`; var m = `1${ 0 }2${ 0 }3`;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/templateStringWithEmptyLiteralPortionsES6.ts
TypeScript
// @target: ES6 var a = ``; var b = `${ 0 }`; var c = `1${ 0 }`; var d = `${ 0 }2`; var e = `1${ 0 }2`; var f = `${ 0 }${ 0 }`; var g = `1${ 0 }${ 0 }`; var h = `${ 0 }2${ 0 }`; var i = `1${ 0 }2${ 0 }`; var j = `${ 0 }${ 0 }3`; var k = `1${ 0 }${ 0 }3`; var l = `${ 0 }2${ 0 }3`; var m = `1${ 0 }2${ 0 }3`;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/templateStringWithOpenCommentInStringPortion.ts
TypeScript
` /**head ${ 10 } // still middle ${ 20 } /* still tail `
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/templateStringWithOpenCommentInStringPortionES6.ts
TypeScript
// @target: ES6 ` /**head ${ 10 } // still middle ${ 20 } /* still tail `
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/templateStringWithPropertyAccess.ts
TypeScript
`abc${0}abc`.indexOf(`abc`);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/templateStringWithPropertyAccessES6.ts
TypeScript
// @target: ES6 `abc${0}abc`.indexOf(`abc`);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts
TypeScript
 `${function (x: number) { x = "bad"; } }`;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts
TypeScript
//@target: es6 `${function (x: number) { x = "bad"; } }`;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisAndSuperInStaticMembers1.ts
TypeScript
// @target: esnext, es2022, es2015 // @useDefineForClassFields: true // @noTypesAndSymbols: true declare class B { static a: any; static f(): number; a: number; f(): number; } class C extends B { static x: any = undefined!; static y1 = this.x; static y2 = this.x(); static y3 = this?.x(); static y4 = this[("x")](); static y5 = this?.[("x")](); static z1 = super.a; static z2 = super["a"]; static z3 = super.f(); static z4 = super["f"](); static z5 = super.a = 0; static z6 = super.a += 1; static z7 = (() => { super.a = 0; })(); static z8 = [super.a] = [0]; static z9 = [super.a = 0] = [0]; static z10 = [...super.a] = [0]; static z11 = { x: super.a } = { x: 0 }; static z12 = { x: super.a = 0 } = { x: 0 }; static z13 = { ...super.a } = { x: 0 }; static z14 = ++super.a; static z15 = --super.a; static z16 = ++super[("a")]; static z17 = super.a++; static z18 = super.a``; // these should be unaffected x = 1; y = this.x; z = super.f(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisAndSuperInStaticMembers2.ts
TypeScript
// @target: esnext, es2022, es2015 // @useDefineForClassFields: false // @noTypesAndSymbols: true declare class B { static a: any; static f(): number; a: number; f(): number; } class C extends B { static x: any = undefined!; static y1 = this.x; static y2 = this.x(); static y3 = this?.x(); static y4 = this[("x")](); static y5 = this?.[("x")](); static z1 = super.a; static z2 = super["a"]; static z3 = super.f(); static z4 = super["f"](); static z5 = super.a = 0; static z6 = super.a += 1; static z7 = (() => { super.a = 0; })(); static z8 = [super.a] = [0]; static z9 = [super.a = 0] = [0]; static z10 = [...super.a] = [0]; static z11 = { x: super.a } = { x: 0 }; static z12 = { x: super.a = 0 } = { x: 0 }; static z13 = { ...super.a } = { x: 0 }; static z14 = ++super.a; static z15 = --super.a; static z16 = ++super[("a")]; static z17 = super.a++; static z18 = super.a``; // these should be unaffected x = 1; y = this.x; z = super.f(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisAndSuperInStaticMembers3.ts
TypeScript
// @target: es5 // @useDefineForClassFields: true // @noTypesAndSymbols: true declare class B { static a: any; static f(): number; a: number; f(): number; } class C extends B { static x: any = undefined!; static y1 = this.x; static y2 = this.x(); static y3 = this?.x(); static y4 = this[("x")](); static y5 = this?.[("x")](); static z3 = super.f(); static z4 = super["f"](); // these should be unaffected x = 1; y = this.x; z = super.f(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisAndSuperInStaticMembers4.ts
TypeScript
// @target: es5 // @useDefineForClassFields: false // @noTypesAndSymbols: true declare class B { static a: any; static f(): number; a: number; f(): number; } class C extends B { static x: any = undefined!; static y1 = this.x; static y2 = this.x(); static y3 = this?.x(); static y4 = this[("x")](); static y5 = this?.[("x")](); static z3 = super.f(); static z4 = super["f"](); // these should be unaffected x = 1; y = this.x; z = super.f(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisInInstanceMemberInitializer.ts
TypeScript
class C { x = this; } class D<T> { x = this; y: T; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisInObjectLiterals.ts
TypeScript
// @noImplicitAny: true // @noImplicitThis: true class MyClass { t: number; fn() { type ContainingThis = this; //type of 'this' in an object literal is the containing scope's this var t = { x: this, y: this.t }; var t: { x: ContainingThis; y: number }; } } //type of 'this' in an object literal method is the type of the object literal var obj = { f() { return this.spaaace; } }; var obj: { f: () => any; };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisMethodCall.ts
TypeScript
// @strict: true // @target: es6 class C { method?() {} other() { this.method?.(); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisPropertyAssignment.ts
TypeScript
// @checkJs: true // @allowJs: true // @strict: true // @emitDeclarationOnly: true // @declaration: true // @Filename: a.js // This test is asserting that a single property/element access // on `this` is a special assignment declaration, but chaining // off that does not create additional declarations. I’m not sure // if it needs to be that way in JavaScript; the test simply // ensures no accidental changes were introduced while allowing // element access assignments to create declarations. this.x = {}; this.x.y = {}; this["y"] = {}; this["y"]["z"] = {}; /** @constructor */ function F() { this.a = {}; this.a.b = {}; this["b"] = {}; this["b"]["c"] = {}; } const f = new F(); f.a; f.b;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisPropertyAssignmentCircular.ts
TypeScript
// @allowJs: true // @checkJs: true // @declaration: true // @emitDeclarationOnly: true // @filename: thisPropertyAssignmentCircular.js export class Foo { constructor() { this.foo = "Hello"; } slicey() { this.foo = this.foo.slice(); } m() { this.foo } } /** @class */ function C() { this.x = 0; this.x = function() { this.x.toString(); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisPropertyAssignmentComputed.ts
TypeScript
// @allowjs: true // @checkjs: true // @noemit: true // @strict: true // @filename: thisPropertyAssignmentComputed.js this["a" + "b"] = 0
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisPropertyAssignmentInherited.ts
TypeScript
// @checkJs: true // @strict: true // @emitDeclarationOnly: true // @declaration: true // @Filename: thisPropertyAssignmentInherited.js export class Element { /** * @returns {String} */ get textContent() { return '' } set textContent(x) {} cloneNode() { return this} } export class HTMLElement extends Element {} export class TextElement extends HTMLElement { get innerHTML() { return this.textContent; } set innerHTML(html) { this.textContent = html; } toString() { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisPropertyOverridesAccessors.ts
TypeScript
// @target: esnext // @allowjs: true // @noemit: true // @checkjs: true // @Filename: foo.ts class Foo { get p() { return 1 } set p(value) { } } // @Filename: bar.js class Bar extends Foo { constructor() { super() this.p = 2 } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisPrototypeMethodCompoundAssignment.ts
TypeScript
// @strict: true // @noEmit: true Element.prototype.remove ??= function () { this.parentNode?.removeChild(this); };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisPrototypeMethodCompoundAssignmentJs.ts
TypeScript
// @strict: true // @noEmit: true // @checkJs: true // @allowJs: true // @filename: index.js Element.prototype.remove ??= function () { this.parentNode?.removeChild(this); }; /** * @this Node */ Element.prototype.remove ??= function () { this.parentNode?.removeChild(this); };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTag1.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @strict: true // @Filename: a.js /** @this {{ n: number }} Mount Holyoke Preparatory School * @param {string} s * @return {number} */ function f(s) { return this.n + s.length } const o = { f, n: 1 } o.f('hi')
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTag2.ts
TypeScript
// @target: esnext // @allowJs: true // @declaration: true // @emitDeclarationOnly: true // @filename: a.js /** @this {string} */ export function f1() {} /** @this */ export function f2() {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTag3.ts
TypeScript
// @allowJs: true // @checkJs: true // @noEmit: true // @filename: /a.js /** * @typedef {{fn(a: string): void}} T */ class C { /** * @this {T} * @param {string} a */ p = (a) => this.fn("" + a); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeAccessibility.ts
TypeScript
class MyClass { private p: number = 123; protected pp: number = 123; public ppp: number = 123; private static sp: number = 123; protected static spp: number = 123; public static sppp: number = 123; } interface MyClass { extension1(p: number): void; extension2(p: number): void; extension3(p: number): void; } class MyGenericClass<T> { private p: T; protected pp: T; public ppp: T; private static sp: number; protected static spp: number; public static sppp: number; } MyClass.prototype.extension1 = function (this: MyClass, p: number) { this.p = p; this.pp = p; this.ppp = p; MyClass.sp = p; MyClass.spp = p; MyClass.sppp = p; } MyClass.prototype.extension2 = function<T extends MyClass> (this: T, p: number) { this.p = p; this.pp = p; this.ppp = p; MyClass.sp = p; MyClass.spp = p; MyClass.sppp = p; } function extension3<T extends MyClass> (this: T, p: number) { this.p = p; this.pp = p; this.ppp = p; MyClass.sp = p; MyClass.spp = p; MyClass.sppp = p; } MyClass.prototype.extension3 = extension3; function extension4<T extends number>(this: MyGenericClass<T>, p: T) { this.p = p; this.pp = p; this.ppp = p; MyGenericClass.sp = p; MyGenericClass.spp = p; MyGenericClass.sppp = p; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeAndConstraints.ts
TypeScript
class A { self() { return this; } } function f<T extends A>(x: T) { function g<U extends T>(x: U) { x = x.self(); } x = x.self(); } class B<T extends A> { foo(x: T) { x = x.self(); } bar<U extends T>(x: U) { x = x.self(); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeErrors.ts
TypeScript
var x1: this; var x2: { a: this }; var x3: this[]; function f1(x: this): this { var y: this; return this; } interface I1 { a: { x: this }; b: { (): this }; c: { new (): this }; d: { [x: string]: this }; e: { f(x: this): this }; } class C1 { a: { x: this }; b: { (): this }; c: { new (): this }; d: { [x: string]: this }; e: { f(x: this): this }; } class C2 { static x: this; static y = <this>undefined; static foo(x: this): this { return undefined; } } namespace N1 { export var x: this; export var y = this; } class C3 { x1 = { g(x: this): this { return undefined; } } f() { function g(x: this): this { return undefined; } let x2 = { h(x: this): this { return undefined; } } } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeErrors2.ts
TypeScript
class Base { constructor(a: this) { } } class Generic<T> { } class Derived { n: number; constructor(public host: Generic<this>) { let self: this = this; this.n = 12; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeInAccessors.ts
TypeScript
// @noImplicitAny: true // @noImplicitThis: true // @target: es5 interface Foo { n: number; x: number; } const explicit = { n: 12, get x(this: Foo): number { return this.n; }, set x(this: Foo, n: number) { this.n = n; } } const copiedFromGetter = { n: 14, get x(this: Foo): number { return this.n; }, set x(n) { this.n = n; } } const copiedFromSetter = { n: 15, get x() { return this.n }, set x(this: Foo, n: number) { this.n = n; } } const copiedFromGetterUnannotated = { n: 16, get x(this: Foo) { return this.n }, set x(this, n) { this.n = n; } } class Explicit { n = 17; get x(this: Foo): number { return this.n; } set x(this: Foo, n: number) { this.n = n; } } class Contextual { n = 21; get x() { return this.n } // inside a class, so already correct }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeInAccessorsNegative.ts
TypeScript
// @noImplicitAny: true // @noImplicitThis: true // @target: es5 interface Foo { n: number; x: number; } interface Bar { wrong: "place" | "time" | "method" | "technique"; } const mismatch = { n: 13, get x(this: Foo) { return this.n; }, set x(this: Bar, n) { this.wrong = "method"; } } const contextual: Foo = { n: 16, get x() { return this.n; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeInBasePropertyAndDerivedContainerOfBase01.ts
TypeScript
// @declaration: true interface BoxOfFoo<T extends Foo> { item: T } interface Foo { self: this; } interface Bar extends Foo { other: BoxOfFoo<this>; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeInClasses.ts
TypeScript
class C1 { x: this; f(x: this): this { return undefined; } } class C2 { [x: string]: this; } interface Foo<T> { x: T; y: this; } class C3 { a: this[]; b: [this, this]; c: this | Date; d: this & Date; e: (((this))); f: (x: this) => this; g: new (x: this) => this; h: Foo<this>; i: Foo<this | (() => this)>; j: (x: any) => x is this; } declare class C4 { x: this; f(x: this): this; } class C5 { foo() { let f1 = (x: this): this => this; let f2 = (x: this) => this; let f3 = (x: this) => (y: this) => this; let f4 = (x: this) => { let g = (y: this) => { return () => this; } return g(this); } } bar() { let x1 = <this>undefined; let x2 = undefined as this; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeInFunctions.ts
TypeScript
// body checking class B { n: number; } class C { n: number; explicitThis(this: this, m: number): number { return this.n + m; } explicitC(this: C, m: number): number { return this.n + m; } explicitProperty(this: {n: number}, m: number): number { return this.n + m; } explicitVoid(this: void, m: number): number { return m + 1; } } class D extends C { } interface I { a: number; explicitVoid1(this: void): number; explicitVoid2(this: void): number; explicitStructural(this: {a: number}): number; explicitInterface(this: I): number; explicitThis(this: this): number; } function explicitStructural(this: { y: number }, x: number): number { return x + this.y; } function justThis(this: { y: number }): number { return this.y; } function implicitThis(n: number): number { return this.m + n + 12; } let impl: I = { a: 12, explicitVoid2: () => this.a, // ok, this: any because it refers to some outer object (window?) explicitVoid1() { return 12; }, explicitStructural() { return this.a; }, explicitInterface() { return this.a; }, explicitThis() { return this.a; }, } impl.explicitVoid1 = function () { return 12; }; impl.explicitVoid2 = () => 12; impl.explicitStructural = function() { return this.a; }; impl.explicitInterface = function() { return this.a; }; impl.explicitStructural = () => 12; impl.explicitInterface = () => 12; impl.explicitThis = function () { return this.a; }; // parameter checking let ok: {y: number, f: (this: { y: number }, x: number) => number} = { y: 12, f: explicitStructural }; let implicitAnyOk: {notSpecified: number, f: (x: number) => number} = { notSpecified: 12, f: implicitThis }; ok.f(13); implicitThis(12); implicitAnyOk.f(12); let c = new C(); let d = new D(); let ripped = c.explicitC; c.explicitC(12); c.explicitProperty(12); c.explicitThis(12); d.explicitC(12); d.explicitProperty(12); d.explicitThis(12); let reconstructed: { n: number, explicitThis(this: C, m: number): number, // note: this: this is not allowed in an object literal type. explicitC(this: C, m: number): number, explicitProperty: (this: {n : number}, m: number) => number, explicitVoid(this: void, m: number): number, } = { n: 12, explicitThis: c.explicitThis, explicitC: c.explicitC, explicitProperty: c.explicitProperty, explicitVoid: c.explicitVoid }; reconstructed.explicitThis(10); reconstructed.explicitProperty(11); let explicitVoid = reconstructed.explicitVoid; explicitVoid(12); // assignment checking let unboundToSpecified: (this: { y: number }, x: number) => number = x => x + this.y; // ok, this:any let specifiedToSpecified: (this: {y: number}, x: number) => number = explicitStructural; let anyToSpecified: (this: { y: number }, x: number) => number = function(x: number): number { return x + 12; }; let unspecifiedLambda: (x: number) => number = x => x + 12; let specifiedLambda: (this: void, x: number) => number = x => x + 12; let unspecifiedLambdaToSpecified: (this: {y: number}, x: number) => number = unspecifiedLambda; let specifiedLambdaToSpecified: (this: {y: number}, x: number) => number = specifiedLambda; let explicitCFunction: (this: C, m: number) => number; let explicitPropertyFunction: (this: {n: number}, m: number) => number; c.explicitC = explicitCFunction; c.explicitC = function(this: C, m: number) { return this.n + m }; c.explicitProperty = explicitPropertyFunction; c.explicitProperty = function(this: {n: number}, m: number) { return this.n + m }; c.explicitProperty = reconstructed.explicitProperty; // lambdas are assignable to anything c.explicitC = m => m; c.explicitThis = m => m; c.explicitProperty = m => m; // this inside lambdas refer to outer scope // the outer-scoped lambda at top-level is still just `any` c.explicitC = m => m + this.n; c.explicitThis = m => m + this.n; c.explicitProperty = m => m + this.n; //NOTE: this=C here, I guess? c.explicitThis = explicitCFunction; c.explicitThis = function(this: C, m: number) { return this.n + m }; // this:any compatibility c.explicitC = function(m) { return this.n + m }; c.explicitProperty = function(m) { return this.n + m }; c.explicitThis = function(m) { return this.n + m }; // this: contextual typing c.explicitThis = function(this, m) { return this.n + m }; // this: superclass compatibility c.explicitC = function(this: B, m: number) { return this.n + m }; // this:void compatibility c.explicitVoid = n => n; // class-based assignability class Base1 { x: number; public polymorphic(this: this): number { return this.x; } explicit(this: Base1): number { return this.x; } static explicitStatic(this: typeof Base1): number { return this.y; } static y: number; } class Derived1 extends Base1 { y: number } class Base2 { y: number polymorphic(this: this): number { return this.y; } explicit(this: Base1): number { return this.x; } } class Derived2 extends Base2 { x: number } let b1 = new Base1(); let b2 = new Base2(); let d1 = new Derived1(); let d2 = new Derived2(); d2.polymorphic = d1.polymorphic // ok, 'x' and 'y' in { x, y } d1.polymorphic = d2.polymorphic // ok, 'x' and 'y' in { x, y } // bivariance-allowed cases d1.polymorphic = b2.polymorphic // ok, 'y' in D: { x, y } d2.polymorphic = d1.explicit // ok, 'y' in { x, y } b1.polymorphic = d2.polymorphic // ok, 'x' and 'y' not in Base1: { x } b1.explicit = d2.polymorphic // ok, 'x' and 'y' not in Base1: { x } ////// use this-type for construction with new //// function InterfaceThis(this: I) { this.a = 12; } function LiteralTypeThis(this: {x: string}) { this.x = "ok"; } function AnyThis(this: any) { this.x = "ok"; } let interfaceThis = new InterfaceThis(); let literalTypeThis = new LiteralTypeThis(); let anyThis = new AnyThis(); //// type parameter inference //// declare var f: { (this: void, x: number): number, call<U>(this: (...argArray: any[]) => U, ...argArray: any[]): U; }; let n: number = f.call(12); function missingTypeIsImplicitAny(this, a: number) { return this.anything + a; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeInFunctions2.ts
TypeScript
// @noImplicitAny: true // @noImplicitThis: true interface IndexedWithThis { // this is a workaround for React init?: (this: this) => void; willDestroy?: (this: any) => void; [propName: string]: number | string | boolean | symbol | undefined | null | {} | ((this: any, ...args:any[]) => any); } interface IndexedWithoutThis { // this is what React would like to write (and what they write today) init?: () => void; willDestroy?: () => void; [propName: string]: any; } interface SimpleInterface { foo(n: string); bar(): number; } declare function extend1(args: IndexedWithThis): void; declare function extend2(args: IndexedWithoutThis): void; declare function simple(arg: SimpleInterface): void; extend1({ init() { this // this: IndexedWithThis because of contextual typing. // this.mine this.willDestroy }, mine: 12, foo() { this.url; // this: any because 'foo' matches the string indexer this.willDestroy; } }); extend2({ init() { this // this: IndexedWithoutThis because of contextual typing this.mine }, mine: 13, foo() { this // this: IndexedWithoutThis because of contextual typing this.mine } }); simple({ foo(n) { return n.length + this.bar(); }, bar() { return 14; } })
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeInFunctions3.ts
TypeScript
declare class Base { check<TProp extends this>(prop: TProp): boolean; } class Test extends Base { m() { this.check(this); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeInFunctions4.ts
TypeScript
type WrongObject = {value: number}; type CorrectObject = {name: string}; declare function isCorrect(obj: any): obj is CorrectObject declare function callsCallback(cb: (name: string)=>void) function problemFunction(this: CorrectObject | WrongObject): void { //check type if (!isCorrect(this)) return; callsCallback((name)=>{ this.name = name; //should not error type T = typeof this; }); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeInInterfaces.ts
TypeScript
interface I1 { x: this; f(x: this): this; } interface I2 { (x: this): this; new (x: this): this; [x: string]: this; } interface Foo<T> { x: T; y: this; } interface I3 { a: this[]; b: [this, this]; c: this | Date; d: this & Date; e: (((this))); f: (x: this) => this; g: new (x: this) => this; h: Foo<this>; i: Foo<this | (() => this)>; j: (x: any) => x is this; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeInObjectLiterals.ts
TypeScript
// @noImplicitAny: true // @noImplicitThis: true let o = { d: "bar", m() { return this.d.length; }, f: function() { return this.d.length; } } let mutuallyRecursive = { a: 100, start() { return this.passthrough(this.a); }, passthrough(n: number) { return this.sub1(n); }, sub1(n: number): number { if (n > 0) { return this.passthrough(n - 1); } return n; } } var i: number = mutuallyRecursive.start(); interface I { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; } var impl: I = mutuallyRecursive;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeInObjectLiterals2.ts
TypeScript
// @declaration: true // @strict: true // @target: es5 // In methods of an object literal with no contextual type, 'this' has the type // of the object literal. let obj1 = { a: 1, f() { return this.a; }, b: "hello", c: { g() { this.g(); } }, get d() { return this.a; }, get e() { return this.b; }, set e(value) { this.b = value; } }; // In methods of an object literal with a contextual type, 'this' has the // contextual type. type Point = { x: number; y: number; z?: number; moveBy(dx: number, dy: number, dz?: number): void; } let p1: Point = { x: 10, y: 20, moveBy(dx, dy, dz) { this.x += dx; this.y += dy; if (this.z && dz) { this.z += dz; } } }; let p2: Point | null = { x: 10, y: 20, moveBy(dx, dy, dz) { this.x += dx; this.y += dy; if (this.z && dz) { this.z += dz; } } }; let p3: Point | undefined = { x: 10, y: 20, moveBy(dx, dy, dz) { this.x += dx; this.y += dy; if (this.z && dz) { this.z += dz; } } }; let p4: Point | null | undefined = { x: 10, y: 20, moveBy(dx, dy, dz) { this.x += dx; this.y += dy; if (this.z && dz) { this.z += dz; } } }; declare function f1(p: Point): void; f1({ x: 10, y: 20, moveBy(dx, dy, dz) { this.x += dx; this.y += dy; if (this.z && dz) { this.z += dz; } } }); declare function f2(p: Point | null | undefined): void; f2({ x: 10, y: 20, moveBy(dx, dy, dz) { this.x += dx; this.y += dy; if (this.z && dz) { this.z += dz; } } }); // In methods of an object literal with a contextual type that includes some // ThisType<T>, 'this' is of type T. type ObjectDescriptor<D, M> = { data?: D; methods?: M & ThisType<D & M>; // Type of 'this' in methods is D & M } declare function makeObject<D, M>(desc: ObjectDescriptor<D, M>): D & M; let x1 = makeObject({ data: { x: 0, y: 0 }, methods: { moveBy(dx: number, dy: number) { this.x += dx; // Strongly typed this this.y += dy; // Strongly typed this } } }); // In methods contained in an object literal with a contextual type that includes // some ThisType<T>, 'this' is of type T. type ObjectDescriptor2<D, M> = ThisType<D & M> & { data?: D; methods?: M; } declare function makeObject2<D, M>(desc: ObjectDescriptor<D, M>): D & M; let x2 = makeObject2({ data: { x: 0, y: 0 }, methods: { moveBy(dx: number, dy: number) { this.x += dx; // Strongly typed this this.y += dy; // Strongly typed this } } }); // Check pattern similar to Object.defineProperty and Object.defineProperties type PropDesc<T> = { value?: T; get?(): T; set?(value: T): void; } type PropDescMap<T> = { [K in keyof T]: PropDesc<T[K]>; } declare function defineProp<T, K extends string, U>(obj: T, name: K, desc: PropDesc<U> & ThisType<T>): T & Record<K, U>; declare function defineProps<T, U>(obj: T, descs: PropDescMap<U> & ThisType<T>): T & U; let p10 = defineProp(p1, "foo", { value: 42 }); p10.foo = p10.foo + 1; let p11 = defineProp(p1, "bar", { get() { return this.x; }, set(value: number) { this.x = value; } }); p11.bar = p11.bar + 1; let p12 = defineProps(p1, { foo: { value: 42 }, bar: { get(): number { return this.x; }, set(value: number) { this.x = value; } } }); p12.foo = p12.foo + 1; p12.bar = p12.bar + 1; // Proof of concept for typing of Vue.js type Accessors<T> = { [K in keyof T]: (() => T[K]) | Computed<T[K]> }; type Dictionary<T> = { [x: string]: T } type Computed<T> = { get?(): T; set?(value: T): void; } type VueOptions<D, M, P> = ThisType<D & M & P> & { data?: D | (() => D); methods?: M; computed?: Accessors<P>; } declare const Vue: new <D, M, P>(options: VueOptions<D, M, P>) => D & M & P; let vue = new Vue({ data: () => ({ x: 1, y: 2 }), methods: { f(x: string) { return this.x; } }, computed: { test(): number { return this.x; }, hello: { get() { return "hi"; }, set(value: string) { } } } }); vue; vue.x; vue.f("abc"); vue.test; vue.hello;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeInTaggedTemplateCall.ts
TypeScript
// @target: esnext class Foo { static m<T>(this: new () => T, strings: TemplateStringsArray | string) { return new this() } } Foo.m`test`; (Foo.m)`test`;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeInTuples.ts
TypeScript
interface Array<T> { slice(): this; } let t: [number, string] = [42, "hello"]; let a = t.slice(); let b = t.slice(1); let c = t.slice(0, 1);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeInTypePredicate.ts
TypeScript
declare function filter<S>(f: (this: void, x: any) => x is S): S[]; const numbers = filter<number>((x): x is number => 'number' == typeof x)
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeOfConstructorFunctions.ts
TypeScript
// @Filename: thisTypeOfConstructorFunctions.js // @allowJs: true // @checkJs: true // @noEmit: true /** * @class * @template T * @param {T} t */ function Cp(t) { /** @type {this} */ this.dit = this this.y = t /** @return {this} */ this.m3 = () => this } Cp.prototype = { /** @return {this} */ m4() { this.z = this.y; return this } } /** * @class * @template T * @param {T} t */ function Cpp(t) { this.y = t } /** @return {this} */ Cpp.prototype.m2 = function () { this.z = this.y; return this } var cp = new Cp(1) var cpp = new Cpp(2) cp.dit /** @type {Cpp<number>} */ var cppn = cpp.m2() /** @type {Cp<number>} */ var cpn = cp.m3() /** @type {Cp<number>} */ var cpn = cp.m4()
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeOptionalCall.ts
TypeScript
// @strictNullChecks: true // @noImplicitAny: true // @noImplicitThis: true // @strictBindCallApply: false function maybeBind<T, A extends any[], R>(obj: T, fn: ((this: T, ...args: A) => R) | undefined): ((...args: A) => R) | undefined { return fn?.bind(obj); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/thisTypeSyntacticContext.ts
TypeScript
function f(this: { n: number }) { } const o: { n: number, test?: (this: { n: number }) => void } = { n: 1 } o.test = f o.test(); o!.test(); o.test!(); o.test!!!(); (o.test!)(); (o.test)();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/throwInEnclosingStatements.ts
TypeScript
// @allowUnreachableCode: true function fn(x) { throw x; } <T>(x: T) => { throw x; } var y: string; switch (y) { case 'a': throw y; default: throw y; } var z = 0; while (z < 10) { throw z; } for (var i = 0; ;) { throw i; } for (var idx in {}) { throw idx; } do { throw null; }while(true) var j = 0; while (j < 0) { throw j; } class C<T> { private value: T; biz() { throw this.value; } constructor() { throw this; } } var aa = { id:12, biz() { throw this; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/throwStatements.ts
TypeScript
// @allowUnreachableCode: true // all legal interface I { id: number; } class C implements I { id: number; } class D<T>{ source: T; recurse: D<T>; wrapped: D<D<T>> } function F(x: string): number { return 42; } module M { export class A { name: string; } export function F2(x: number): string { return x.toString(); } } var aNumber = 9.9; throw aNumber; var aString = 'this is a string'; throw aString; var aDate = new Date(12); throw aDate; var anObject = new Object(); throw anObject; var anAny = null; throw anAny; var anOtherAny = <any> new C(); throw anOtherAny; var anUndefined = undefined; throw anUndefined; var aClass = new C(); throw aClass; var aGenericClass = new D<string>(); throw aGenericClass; var anObjectLiteral = { id: 12 }; throw anObjectLiteral; var aFunction = F; throw aFunction; throw aFunction(''); var aLambda = (x) => 2; throw aLambda; throw aLambda(1); var aModule = M; throw aModule; throw typeof M; var aClassInModule = new M.A(); throw aClassInModule; var aFunctionInModule = M.F2; throw aFunctionInModule; // no initializer or annotation, so this is an 'any' var x; throw x; // literals throw 0.0; throw false; throw null; throw undefined; throw 'a string'; throw function () { return 'a string' }; throw <T>(x:T) => 42; throw { x: 12, y: 13 }; throw []; throw ['a', ['b']]; throw /[a-z]/; throw new Date(); throw new C(); throw new Object(); throw new D<number>();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/topLevelAmbientModule.ts
TypeScript
// @module: commonjs // @Filename: foo_0.ts declare module "foo" { export var x: number; } // @Filename: foo_1.ts /// <reference path="foo_0.ts"/> import foo = require("foo"); var z = foo.x + 10;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/topLevelAwait.2.ts
TypeScript
// @target: esnext // @module: es2022,esnext declare namespace foo { const await: any; } // await allowed in import=namespace when not a module import await = foo.await;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/topLevelAwait.3.ts
TypeScript
// @target: esnext // @module: es2022,esnext // @filename: index.d.ts // await keyword allowed as identifier in a declaration file export {}; declare const await: any; declare class C extends await {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/topLevelFileModule.ts
TypeScript
// @module: commonjs // @Filename: vs/foo_0.ts export var x: number; // @Filename: vs/fum.d.ts export declare var y: number; // @Filename: foo_1.ts import foo = require("./vs/foo_0"); import fum = require("./vs/fum"); var z = foo.x + fum.y;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/topLevelFileModuleMissing.ts
TypeScript
// @module: commonjs // @Filename: vs/foo_0.ts export var x: number; // @Filename: foo_1.ts import foo = require("vs/foo"); var z = foo.x + 10;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/topLevelModuleDeclarationAndFile.ts
TypeScript
// @module: commonjs // @Filename: vs/foo_0/index.ts export var x: number = 42; // @Filename: foo_1.ts declare module "vs/foo_0" { export var y: () => number; } // @Filename: foo_2.ts /// <reference path="foo_1.ts"/> import foo = require("vs/foo_0"); var z1 = foo.x + 10; // Should error, as declaration should win var z2 = foo.y() + 10; // Should resolve
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/topLevelThisAssignment.ts
TypeScript
// @outFile: output.js // @allowJs: true // @checkJs: true // @Filename: a.js this.a = 10; this.a; a; // @Filename: b.js this.a; a;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/topLevelVarHoistingCommonJS.ts
TypeScript
// @target: esnext // @module: commonjs // @noTypesAndSymbols: true declare var _: any; { var a = _; } if (_) { var b = _; } else { var c = _; } switch (_) { case _: var d = _; default: var e = _; } while (_) { var f = _; } do { var g = _; } while (_); for (var h = _; ;) { break; } for (; ;) { var m = _; break; } for (var n in _) break; for (_ in _) { var o = _; } for (var p of _) break; for (_ of _) { var u = _; } try { var v = _; } catch { var w = _; } label: { var x = _; break label; } // @ts-ignore with (_) { var y = _; } var z = _; export { a, b, c, d, e, f, g, h, m, n, o, p, u, v, w, x, y, z };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/topLevelVarHoistingSystem.ts
TypeScript
// @target: esnext // @module: system // @noTypesAndSymbols: true if (false) { var y = 1; } function f() { console.log(y); } export { y };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tryStatements.ts
TypeScript
function fn() { try { } catch { } try { } catch { try { } catch { try { } catch { } } try { } catch { } } try { } catch (x) { var x: any; } try { } finally { } try { } catch { } finally { } try { } catch (z) { } finally { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/ts-expect-error-js.ts
TypeScript
// @allowJs: true // @checkJs: true // @noEmit: true // @fileName: a.js // there should be a "Unused @ts-expect-error" error since js files are being checked // @ts-expect-error const a = 1;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/ts-expect-error-nocheck-js.ts
TypeScript
// @allowJs: true // @checkJs: false // @noEmit: true // @fileName: a.js // there should not be a "Unused @ts-expect-error" error since js files are not being checked // @ts-expect-error const a = 1;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/ts-expect-error-nocheck.ts
TypeScript
// @ts-nocheck // there should not be a "Unused @ts-expect-error" error due to the // @ts-nocheck // @ts-expect-error const a = 1;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/ts-expect-error.ts
TypeScript
// @ts-expect-error additional commenting var invalidCommentedFancySingle: number = 'nope'; /* @ts-expect-error additional commenting */ var invalidCommentedFancyMulti: number = 'nope'; // @ts-expect-error additional commenting var validCommentedFancySingle: string = 'nope'; /* @ts-expect-error additional commenting */ var validCommentedFancyMulti: string = 'nope'; // @ts-expect-error var invalidCommentedPlainSingle: number = 'nope'; /* @ts-expect-error */ var invalidCommentedPlainMulti: number = 'nope'; // @ts-expect-error var validCommentedPlainSingle: string = 'nope'; /* @ts-expect-error */ var validCommentedPlainMulti1: string = 'nope'; /* @ts-expect-error */ var validCommentedPlainMulti2: string = 'nope'; var invalidPlain: number = 'nope'; var validPlain: string = 'nope'; // @ts-expect-error (({ a: true } as const).a === false); // <-- compiles (as expected via comment) (({ a: true } as const).a === false); // Should error (({ a: true } as const).a === false); // error (({ a: true } as const).a === false); // error // @ts-expect-error: additional commenting with no whitespace var invalidCommentedFancySingle: number = 'nope'; /* @ts-expect-error: additional commenting with no whitespace */ var invalidCommentedFancyMulti: number = 'nope';
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/ts-ignore.ts
TypeScript
// @ts-ignore with additional commenting var invalidCommentedFancy: number = 'nope'; // @ts-ignore with additional commenting var validCommentedFancy: string = 'nope'; // @ts-ignore var invalidCommentedPlain: number = 'nope'; // @ts-ignore var validCommentedPlain: string = 'nope'; var invalidPlain: number = 'nope'; var validPlain: string = 'nope'; // @ts-ignore: with additional commenting var invalidCommentedFancy: number = 'nope'; // @ts-ignore: with additional commenting var validCommentedFancy: string = 'nope';
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsNoCheckForTypescript.ts
TypeScript
// @declaration: true // @filename: file.ts // @ts-nocheck export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment export interface Aleph { q: number; } export class Bet implements Aleph { q: string = "lol" // And so will this implements error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsNoCheckForTypescriptComments1.ts
TypeScript
// @declaration: true // @filename: file.ts // @ts-nocheck additional comments export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment export interface Aleph { q: number; } export class Bet implements Aleph { q: string = 'lol'; // And so will this implements error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsNoCheckForTypescriptComments2.ts
TypeScript
// @declaration: true // @filename: file.ts // @ts-nocheck: additional comments export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment export interface Aleph { q: number; } export class Bet implements Aleph { q: string = "lol" // And so will this implements error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeErrors.tsx
TypeScript (TSX)
// @jsx: preserve declare namespace JSX { interface Element { } interface IntrinsicElements { div: { text?: string; width?: number; } span: any; } } // Error, number is not assignable to string <div text={42} />; // Error, string is not assignable to number <div width={'foo'} />; // Error, number is not assignable to string var attribs = { text: 100 }; <div {...attribs} />; // No errors here <span foo='bar' bar={'foo'} />;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeResolution.tsx
TypeScript (TSX)
//@jsx: preserve declare namespace JSX { interface IntrinsicElements { x: { y: number; z: string; }; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeResolution1.tsx
TypeScript (TSX)
//@filename: file.tsx //@jsx: preserve declare module JSX { interface Element { } interface IntrinsicElements { test1: Attribs1; test2: { reqd: string }; var: { var: string }; } } interface Attribs1 { x?: number; s?: string; } // OK <test1 x={0} />; // OK <test1 />; // OK <test1 data-x={true} />; // OK <test2 reqd='true' />; // OK <test2 reqd={'true'} />; // OK // Errors <test1 x={'0'} />; // Error, '0' is not number <test1 y={0} />; // Error, no property "y" <test1 y="foo" />; // Error, no property "y" <test1 x="32" />; // Error, "32" is not number <test1 var="10" />; // Error, no 'var' property <test2 />; // Error, missing reqd <test2 reqd={10} />; // Error, reqd is not string // Should be OK <var var='var' />;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeResolution10.tsx
TypeScript (TSX)
//@jsx: preserve //@module: amd //@filename: react.d.ts declare module JSX { interface Element { } interface IntrinsicElements { } interface ElementAttributesProperty { props; } } //@filename: file.tsx export class MyComponent { render() { } props: { [s: string]: boolean; } } // Should be an error <MyComponent bar='world' />; // Should be OK <MyComponent bar={true} />; // Should be ok <MyComponent data-bar='hello' />;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeResolution11.tsx
TypeScript (TSX)
//@jsx: preserve //@module: amd //@filename: react.d.ts declare module JSX { interface Element { } interface IntrinsicElements { } interface ElementAttributesProperty { props; } interface IntrinsicAttributes { ref?: string; } } //@filename: file.tsx class MyComponent { render() { } props: { ref?: string; } } // Should be an OK var x = <MyComponent bar='world' />;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeResolution12.tsx
TypeScript (TSX)
//@jsx: preserve //@filename: react.d.ts declare module JSX { interface Element { } interface IntrinsicElements { } interface ElementAttributesProperty { props; } interface IntrinsicAttributes { ref?: string; } } //@filename: file.tsx declare class Component<P, S> { constructor(props?: P, context?: any); setState(f: (prevState: S, props: P) => S, callback?: () => any): void; setState(state: S, callback?: () => any): void; forceUpdate(callBack?: () => any): void; render(): JSX.Element; props: P; state: S; context: {}; } interface ComponentClass<P> { new (props?: P, context?: any): Component<P, any>; } declare module TestMod { interface TestClass extends ComponentClass<{reqd: any}> { } var Test: TestClass; } // Errors correctly const T = TestMod.Test; var t1 = <T />; // Should error var t2 = <TestMod.Test />;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeResolution13.tsx
TypeScript (TSX)
//@jsx: preserve //@filename: test.tsx function Test() { } <Test></Test>
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeResolution14.tsx
TypeScript (TSX)
//@jsx: preserve //@module: amd //@filename: react.d.ts declare module JSX { interface Element { } interface IntrinsicElements { div: any; } interface ElementAttributesProperty { prop: any } } //@filename: file.tsx interface IProps { primaryText: string, [propName: string]: string | number } function VerticalNavMenuItem(prop: IProps) { return <div>props.primaryText</div> } function VerticalNav() { return ( <div> <VerticalNavMenuItem primaryText={2} /> // error <VerticalNavMenuItem justRandomProp={2} primaryText={"hello"} /> // ok <VerticalNavMenuItem justRandomProp1={true} primaryText={"hello"} /> // error </div> ) }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeResolution15.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @noImplicitAny: true // @libFiles: react.d.ts,lib.d.ts import React = require('react'); class BigGreeter extends React.Component<{ }, {}> { render() { return <div>Default hi</div>; } greeting: string; } // Error let a = <BigGreeter prop1="hello" /> // OK let b = <BigGreeter ref={(input) => { this.textInput = input; }} /> let c = <BigGreeter data-extra="hi" />
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeResolution16.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts import React = require('react'); interface Address { street: string; country: string; } interface CanadianAddress extends Address { postalCode: string; } interface AmericanAddress extends Address { zipCode: string; } type Properties = CanadianAddress | AmericanAddress; export class AddressComp extends React.Component<Properties, void> { public render() { return null; } } let a = <AddressComp postalCode='T1B 0L3' street="vancouver" country="CA" />
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeResolution2.tsx
TypeScript (TSX)
//@filename: file.tsx //@jsx: preserve declare module JSX { interface Element { } interface IntrinsicElements { test1: Attribs1; } } interface Attribs1 { c1?: (x: string) => void; } // OK <test1 c1={(x) => x.length} />; // OK <test1 data-c1={(x) => x.leng} />; // OK // Errors <test1 c1={(x) => x.leng} />; // Error, no leng on 'string'
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeResolution3.tsx
TypeScript (TSX)
//@filename: file.tsx //@jsx: preserve declare module JSX { interface Element { } interface IntrinsicElements { test1: Attribs1; } } interface Attribs1 { x: string; y?: number; z?: string; } // OK var obj1 = { x: 'foo' }; <test1 {...obj1} /> // Error, x is not string var obj2 = { x: 32 }; <test1 {...obj2} /> // Error, x is missing var obj3 = { y: 32 }; <test1 {...obj3} /> // OK var obj4 = { x: 32, y: 32 }; <test1 {...obj4} x="ok" /> // Error var obj5 = { x: 32, y: 32 }; <test1 x="ok" {...obj5} /> // Ok var obj6 = { x: 'ok', y: 32, extra: 100 }; <test1 {...obj6} /> // OK (spread override) var obj7 = { x: 'foo' }; <test1 x={32} {...obj7} />
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeResolution4.tsx
TypeScript (TSX)
//@filename: file.tsx //@jsx: preserve declare module JSX { interface Element { } interface IntrinsicElements { test1: Attribs1; } } interface Attribs1 { x(n: string): void; } // OK <test1 {... {x: (n) => 0} } />; // Error, no member 'len' on 'string' <test1 {... {x: (n) => n.len} } />;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeResolution5.tsx
TypeScript (TSX)
//@filename: file.tsx //@jsx: preserve declare module JSX { interface Element { } interface IntrinsicElements { test1: Attribs1; test2: Attribs2; } } interface Attribs1 { x: string; } interface Attribs2 { toString(): string; } function make1<T extends {x: string}> (obj: T) { return <test1 {...obj} />; // OK } function make2<T extends {x: number}> (obj: T) { return <test1 {...obj} />; // Error (x is number, not string) } function make3<T extends {y: string}> (obj: T) { return <test1 {...obj} />; // Error, missing x } <test1 {...{}} />; // Error, missing x <test2 {...{}} />; // Error, missing toString
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeResolution6.tsx
TypeScript (TSX)
//@filename: file.tsx //@jsx: preserve declare module JSX { interface Element { } interface IntrinsicElements { test1: { n?: boolean; s?: string}; test2: { n: boolean; }; } } // Error <test1 s />; <test1 n='true' />; <test2 />; // OK <test1 n />; <test1 n={false} />; <test2 n />;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeResolution7.tsx
TypeScript (TSX)
//@filename: file.tsx //@jsx: preserve declare module JSX { interface Element { } interface IntrinsicElements { test1: { "data-foo"?: string }; } } // Error <test1 data-foo={32} />; // OK <test1 data-foo={'32'} />; <test1 data-bar={'32'} />; <test1 data-bar={32} />;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeResolution8.tsx
TypeScript (TSX)
//@filename: file.tsx //@jsx: preserve declare module JSX { interface Element { } interface IntrinsicElements { test1: {x: string}; } } var x: any; // Should be OK <test1 {...x} />
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxAttributeResolution9.tsx
TypeScript (TSX)
//@jsx: preserve //@module: amd //@filename: react.d.ts declare module JSX { interface Element { } interface IntrinsicElements { } interface ElementAttributesProperty { props; } } interface Props { foo: string; } //@filename: file.tsx export class MyComponent { render() { } props: { foo: string; } } <MyComponent foo="bar" />; // ok <MyComponent foo={0} />; // should be an error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxCorrectlyParseLessThanComparison1.tsx
TypeScript (TSX)
// @jsx: react declare module JSX { interface Element { div: string; } } declare namespace React { class Component<P, S> { constructor(props?: P, context?: any); props: P; } } export class ShortDetails extends React.Component<{ id: number }, {}> { public render(): JSX.Element { if (this.props.id < 1) { return (<div></div>); } } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxDefaultAttributesResolution1.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts import React = require('react'); interface Prop { x: boolean; } class Poisoned extends React.Component<Prop, {}> { render() { return <div>Hello</div>; } } // OK let p = <Poisoned x/>;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxDefaultAttributesResolution2.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts import React = require('react'); interface Prop { x: true; } class Poisoned extends React.Component<Prop, {}> { render() { return <div>Hello</div>; } } // OK let p = <Poisoned x/>;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxDefaultAttributesResolution3.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts import React = require('react'); interface Prop { x: false; } class Poisoned extends React.Component<Prop, {}> { render() { return <div>Hello</div>; } } // Error let p = <Poisoned x/>;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxDynamicTagName1.tsx
TypeScript (TSX)
// @jsx: preserve var CustomTag = "h1"; <CustomTag> Hello World </CustomTag> // No error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxDynamicTagName2.tsx
TypeScript (TSX)
// @jsx: preserve declare module JSX { interface Element { } interface IntrinsicElements { div: any } } var customTag = "h1"; <customTag> Hello World </customTag> // This should be an error. The lower-case is look up as an intrinsic element name
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxDynamicTagName3.tsx
TypeScript (TSX)
// @jsx: preserve declare module JSX { interface Element { } interface IntrinsicElements { div: any } } var CustomTag: "h1" = "h1"; <CustomTag> Hello World </CustomTag> // This should be an error. we will try look up string literal type in JSX.IntrinsicElements
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxDynamicTagName4.tsx
TypeScript (TSX)
// @jsx: preserve declare module JSX { interface Element { } interface IntrinsicElements { div: any h1: any } } var CustomTag: "h1" = "h1"; <CustomTag> Hello World </CustomTag>
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxDynamicTagName5.tsx
TypeScript (TSX)
// @jsx: preserve //@filename: react.d.ts declare module 'react' { class Component<T, U> { } } //@filename: app.tsx import * as React from 'react'; export class Text extends React.Component<{}, {}> { _tagName: string = 'div'; render() { return ( <this._tagName /> ); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxDynamicTagName6.tsx
TypeScript (TSX)
// @jsx: preserve declare module JSX { interface Element { } interface IntrinsicElements { div: any } } const t = {tag:'h1'} const foo = <t.tag/> // No error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/tsxDynamicTagName7.tsx
TypeScript (TSX)
// @jsx: preserve //@filename: react.d.ts declare module 'react' { class Component<T, U> { } } //@filename: app.tsx import * as React from 'react'; export class Text extends React.Component<{}, {}> { _tagName: string = 'div'; render() { return ( <this/> // this should be an error ); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University