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/mixinAbstractClasses.ts
TypeScript
// @target: esnext // @declaration: true interface Mixin { mixinMethod(): void; } function Mixin<TBaseClass extends abstract new (...args: any) => any>(baseClass: TBaseClass): TBaseClass & (abstract new (...args: any) => Mixin) { abstract class MixinClass extends baseClass implements Mixin { mixinMethod() { } } return MixinClass; } class ConcreteBase { baseMethod() {} } abstract class AbstractBase { abstract abstractBaseMethod(): void; } class DerivedFromConcrete extends Mixin(ConcreteBase) { } const wasConcrete = new DerivedFromConcrete(); wasConcrete.baseMethod(); wasConcrete.mixinMethod(); class DerivedFromAbstract extends Mixin(AbstractBase) { abstractBaseMethod() {} } const wasAbstract = new DerivedFromAbstract(); wasAbstract.abstractBaseMethod(); wasAbstract.mixinMethod();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mixinAbstractClassesReturnTypeInference.ts
TypeScript
// @target: esnext // @declaration: true interface Mixin1 { mixinMethod(): void; } abstract class AbstractBase { abstract abstractBaseMethod(): void; } function Mixin2<TBase extends abstract new (...args: any[]) => any>(baseClass: TBase) { // must be `abstract` because we cannot know *all* of the possible abstract members that need to be // implemented for this to be concrete. abstract class MixinClass extends baseClass implements Mixin1 { mixinMethod(): void {} static staticMixinMethod(): void {} } return MixinClass; } class DerivedFromAbstract2 extends Mixin2(AbstractBase) { abstractBaseMethod() {} }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mixinAccessModifiers.ts
TypeScript
// @declaration: true type Constructable = new (...args: any[]) => object; class Private { constructor (...args: any[]) {} private p: string; } class Private2 { constructor (...args: any[]) {} private p: string; } class Protected { constructor (...args: any[]) {} protected p: string; protected static s: string; } class Protected2 { constructor (...args: any[]) {} protected p: string; protected static s: string; } class Public { constructor (...args: any[]) {} public p: string; public static s: string; } class Public2 { constructor (...args: any[]) {} public p: string; public static s: string; } function f1(x: Private & Private2) { x.p; // Error, private constituent makes property inaccessible } function f2(x: Private & Protected) { x.p; // Error, private constituent makes property inaccessible } function f3(x: Private & Public) { x.p; // Error, private constituent makes property inaccessible } function f4(x: Protected & Protected2) { x.p; // Error, protected when all constituents are protected } function f5(x: Protected & Public) { x.p; // Ok, public if any constituent is public } function f6(x: Public & Public2) { x.p; // Ok, public if any constituent is public } declare function Mix<T, U>(c1: T, c2: U): T & U; // Can't derive from type with inaccessible properties class C1 extends Mix(Private, Private2) {} class C2 extends Mix(Private, Protected) {} class C3 extends Mix(Private, Public) {} class C4 extends Mix(Protected, Protected2) { f(c4: C4, c5: C5, c6: C6) { c4.p; c5.p; c6.p; } static g() { C4.s; C5.s; C6.s } } class C5 extends Mix(Protected, Public) { f(c4: C4, c5: C5, c6: C6) { c4.p; // Error, not in class deriving from Protected2 c5.p; c6.p; } static g() { C4.s; // Error, not in class deriving from Protected2 C5.s; C6.s } } class C6 extends Mix(Public, Public2) { f(c4: C4, c5: C5, c6: C6) { c4.p; // Error, not in class deriving from Protected2 c5.p; c6.p; } static g() { C4.s; // Error, not in class deriving from Protected2 C5.s; C6.s } } class ProtectedGeneric<T> { private privateMethod() {} protected protectedMethod() {} } class ProtectedGeneric2<T> { private privateMethod() {} protected protectedMethod() {} } function f7(x: ProtectedGeneric<{}> & ProtectedGeneric<{}>) { x.privateMethod(); // Error, private constituent makes method inaccessible x.protectedMethod(); // Error, protected when all constituents are protected } function f8(x: ProtectedGeneric<{a: void;}> & ProtectedGeneric2<{a:void;b:void;}>) { x.privateMethod(); // Error, private constituent makes method inaccessible x.protectedMethod(); // Error, protected when all constituents are protected } function f9(x: ProtectedGeneric<{a: void;}> & ProtectedGeneric<{a:void;b:void;}>) { x.privateMethod(); // Error, private constituent makes method inaccessible x.protectedMethod(); // Error, protected when all constituents are protected }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mixinClassesAnnotated.ts
TypeScript
// @declaration: true type Constructor<T> = new(...args: any[]) => T; class Base { constructor(public x: number, public y: number) {} } class Derived extends Base { constructor(x: number, y: number, public z: number) { super(x, y); } } interface Printable { print(): void; } const Printable = <T extends Constructor<Base>>(superClass: T): Constructor<Printable> & { message: string } & T => class extends superClass { static message = "hello"; print() { const output = this.x + "," + this.y; } } interface Tagged { _tag: string; } function Tagged<T extends Constructor<{}>>(superClass: T): Constructor<Tagged> & T { class C extends superClass { _tag: string; constructor(...args: any[]) { super(...args); this._tag = "hello"; } } return C; } const Thing1 = Tagged(Derived); const Thing2 = Tagged(Printable(Derived)); Thing2.message; function f1() { const thing = new Thing1(1, 2, 3); thing.x; thing._tag; } function f2() { const thing = new Thing2(1, 2, 3); thing.x; thing._tag; thing.print(); } class Thing3 extends Thing2 { constructor(tag: string) { super(10, 20, 30); this._tag = tag; } test() { this.print(); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mixinClassesAnonymous.ts
TypeScript
type Constructor<T> = new(...args: any[]) => T; class Base { constructor(public x: number, public y: number) {} } class Derived extends Base { constructor(x: number, y: number, public z: number) { super(x, y); } } const Printable = <T extends Constructor<Base>>(superClass: T) => class extends superClass { static message = "hello"; print() { const output = this.x + "," + this.y; } } function Tagged<T extends Constructor<{}>>(superClass: T) { class C extends superClass { _tag: string; constructor(...args: any[]) { super(...args); this._tag = "hello"; } } return C; } const Thing1 = Tagged(Derived); const Thing2 = Tagged(Printable(Derived)); Thing2.message; function f1() { const thing = new Thing1(1, 2, 3); thing.x; thing._tag; } function f2() { const thing = new Thing2(1, 2, 3); thing.x; thing._tag; thing.print(); } class Thing3 extends Thing2 { constructor(tag: string) { super(10, 20, 30); this._tag = tag; } test() { this.print(); } } // Repro from #13805 const Timestamped = <CT extends Constructor<object>>(Base: CT) => { return class extends Base { timestamp = new Date(); }; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/mixinClassesMembers.ts
TypeScript
// @declaration: true declare class C1 { public a: number; protected b: number; private c: number; constructor(s: string); constructor(n: number); } declare class M1 { constructor(...args: any[]); p: number; static p: number; } declare class M2 { constructor(...args: any[]); f(): number; static f(): number; } declare const Mixed1: typeof M1 & typeof C1; declare const Mixed2: typeof C1 & typeof M1; declare const Mixed3: typeof M2 & typeof M1 & typeof C1; declare const Mixed4: typeof C1 & typeof M1 & typeof M2; declare const Mixed5: typeof M1 & typeof M2; function f1() { let x1 = new Mixed1("hello"); let x2 = new Mixed1(42); let x3 = new Mixed2("hello"); let x4 = new Mixed2(42); let x5 = new Mixed3("hello"); let x6 = new Mixed3(42); let x7 = new Mixed4("hello"); let x8 = new Mixed4(42); let x9 = new Mixed5(); } function f2() { let x = new Mixed1("hello"); x.a; x.p; Mixed1.p; } function f3() { let x = new Mixed2("hello"); x.a; x.p; Mixed2.p; } function f4() { let x = new Mixed3("hello"); x.a; x.p; x.f(); Mixed3.p; Mixed3.f(); } function f5() { let x = new Mixed4("hello"); x.a; x.p; x.f(); Mixed4.p; Mixed4.f(); } function f6() { let x = new Mixed5(); x.p; x.f(); Mixed5.p; Mixed5.f(); } class C2 extends Mixed1 { constructor() { super("hello"); this.a; this.b; this.p; } } class C3 extends Mixed3 { constructor() { super(42); this.a; this.b; this.p; this.f(); } f() { return super.f(); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/modifierOnClassDeclarationMemberInFunction.ts
TypeScript
// @declaration: true function f() { class C { public baz = 1; static foo() { } public bar() { } } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/modifierOnClassExpressionMemberInFunction.ts
TypeScript
// @declaration: true // @declaration: true function g() { var x = class C { public prop1 = 1; private foo() { } static prop2 = 43; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportAlias.ts
TypeScript
// @allowJS: true // @noEmit: true // @filename: a.ts import b = require("./b.js"); b.func1; b.func2; b.func3; b.func4; b.func5; b.func6; b.func7; b.func8; b.func9; b.func10; b.func11; b.func12; b.func13; b.func14; b.func15; b.func16; b.func17; b.func18; b.func19; b.func20; // @filename: b.js var exportsAlias = exports; exportsAlias.func1 = function () { }; exports.func2 = function () { }; var moduleExportsAlias = module.exports; moduleExportsAlias.func3 = function () { }; module.exports.func4 = function () { }; var multipleDeclarationAlias1 = exports = module.exports; multipleDeclarationAlias1.func5 = function () { }; var multipleDeclarationAlias2 = module.exports = exports; multipleDeclarationAlias2.func6 = function () { }; var someOtherVariable; var multipleDeclarationAlias3 = someOtherVariable = exports; multipleDeclarationAlias3.func7 = function () { }; var multipleDeclarationAlias4 = someOtherVariable = module.exports; multipleDeclarationAlias4.func8 = function () { }; var multipleDeclarationAlias5 = module.exports = exports = {}; multipleDeclarationAlias5.func9 = function () { }; var multipleDeclarationAlias6 = exports = module.exports = {}; multipleDeclarationAlias6.func10 = function () { }; exports = module.exports = someOtherVariable = {}; exports.func11 = function () { }; module.exports.func12 = function () { }; exports = module.exports = someOtherVariable = {}; exports.func11 = function () { }; module.exports.func12 = function () { }; exports = module.exports = {}; exports.func13 = function () { }; module.exports.func14 = function () { }; exports = module.exports = {}; exports.func15 = function () { }; module.exports.func16 = function () { }; module.exports = exports = {}; exports.func17 = function () { }; module.exports.func18 = function () { }; module.exports = {}; exports.func19 = function () { }; module.exports.func20 = function () { };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportAlias2.ts
TypeScript
// @checkJs: true // @allowJS: true // @noEmit: true // @Filename: node.d.ts declare function require(name: string): any; declare var exports: any; declare var module: { exports: any }; // @Filename: semver.js /// <reference path='node.d.ts' /> exports = module.exports = C exports.f = n => n + 1 function C() { this.p = 1 } // @filename: index.js /// <reference path='node.d.ts' /> const C = require("./semver") var two = C.f(1) var c = new C
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportAlias3.ts
TypeScript
// @checkJs: true // @allowJS: true // @noEmit: true // @Filename: bug24062.js // #24062 class C { } module.exports = { C };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportAlias4.ts
TypeScript
// @checkJs: true // @noEmit: true // @Filename: bug24024.js // #24024 var wat = require('./bug24024') module.exports = class C {} module.exports.D = class D { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportAlias5.ts
TypeScript
// @checkJs: true // @allowJS: true // @noEmit: true // @Filename: bug24754.js // #24754 const webpack = function (){ } exports = module.exports = webpack; exports.version = 1001; webpack.WebpackOptionsDefaulter = 1111;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportAliasElementAccessExpression.ts
TypeScript
// @declaration: true // @checkJs: true // @filename: moduleExportAliasElementAccessExpression.js // @outdir: out function D () { } exports["D"] = D; // (the only package I could find that uses spaces in identifiers is webidl-conversions) exports["Does not work yet"] = D;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportAliasExports.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: Eloquent.js // bug #27365, crashes from github.com/marijnh/Eloquent-JavaScript (function() { exports.bigOak = 1 exports.everywhere = 2 module.exports = exports })()
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportAliasImported.ts
TypeScript
// @allowJs: true // @noEmit: true // @checkJs: true // @target: esnext // @module: esnext // @Filename: bug28014.js exports.version = 1 function alias() { } module.exports = alias // @Filename: importer.js import('./bug28014')
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportAliasUnknown.ts
TypeScript
// @allowJs: true // @noEmit: true // @checkJs: true // @Filename: bug27025.js module.exports = window.nonprop; exports.foo = bar;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportAssignment.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: npmlog.js class EE { /** @param {string} s */ on(s) { } } var npmlog = module.exports = new EE() npmlog.on('hi') // both references should see EE.on module.exports.on('hi') // here too npmlog.x = 1 module.exports.y = 2 npmlog.y module.exports.x // @Filename: use.js var npmlog = require('./npmlog') npmlog.x npmlog.on
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportAssignment2.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: npm.js var npm = module.exports = function (tree) { } module.exports.asReadInstalled = function (tree) { npm(tree) // both references should be callable module.exports(tree) }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportAssignment3.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: mod.js module.exports = function x() { } module.exports() // should be callable // @Filename: npm.js var mod = require('./mod') mod() // should be callable from here too
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportAssignment4.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: async.js exports.default = { m: 1, a: 1 } module.exports = exports['default'];
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportAssignment5.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: axios.js class Axios { constructor() { } m() { } } var axios = new Axios(); // none of the 3 references should have a use-before-def error axios.m() module.exports = axios; module.exports.default = axios;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportAssignment6.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: webpackLibNormalModule.js class C { /** @param {number} x */ constructor(x) { this.x = x this.exports = [x] } /** @param {number} y */ m(y) { return this.x + y } } function exec() { const module = new C(12); return module.exports; // should be fine because `module` is defined locally } function tricky() { // (a trickier variant of what webpack does) const module = new C(12); return () => { return module.exports; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportAssignment7.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: mod.js class Thing { x = 1 } class AnotherThing { y = 2 } function foo() { return 3 } function bar() { return 4 } /** @typedef {() => number} buz */ module.exports = { Thing, AnotherThing, foo, qux: bar, baz() { return 5 }, literal: "", } // @Filename: main.js /** * @param {import("./mod").Thing} a * @param {import("./mod").AnotherThing} b * @param {import("./mod").foo} c * @param {import("./mod").qux} d * @param {import("./mod").baz} e * @param {import("./mod").buz} f * @param {import("./mod").literal} g */ function jstypes(a, b, c, d, e, f, g) { return a.x + b.y + c() + d() + e() + f() + g.length } /** * @param {typeof import("./mod").Thing} a * @param {typeof import("./mod").AnotherThing} b * @param {typeof import("./mod").foo} c * @param {typeof import("./mod").qux} d * @param {typeof import("./mod").baz} e * @param {typeof import("./mod").buz} f * @param {typeof import("./mod").literal} g */ function jsvalues(a, b, c, d, e, f, g) { return a.length + b.length + c() + d() + e() + f() + g.length } // @Filename: index.ts function types( a: import('./mod').Thing, b: import('./mod').AnotherThing, c: import('./mod').foo, d: import('./mod').qux, e: import('./mod').baz, f: import('./mod').buz, g: import('./mod').literal, ) { return a.x + b.y + c() + d() + e() + f() + g.length } function values( a: typeof import('./mod').Thing, b: typeof import('./mod').AnotherThing, c: typeof import('./mod').foo, d: typeof import('./mod').qux, e: typeof import('./mod').baz, f: typeof import('./mod').buz, g: typeof import('./mod').literal, ) { return a.length + b.length + c() + d() + e() + f() + g.length }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportDuplicateAlias.ts
TypeScript
// @checkJs: true // @strict: true // @declaration: true // @outdir: out // @filename: moduleExportAliasDuplicateAlias.js exports.apply = undefined; function a() { } exports.apply() exports.apply = a; exports.apply() // @filename: test.js const { apply } = require('./moduleExportAliasDuplicateAlias') apply()
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportDuplicateAlias2.ts
TypeScript
// @checkJs: true // @strict: true // @declaration: true // @outdir: out // @filename: moduleExportAliasDuplicateAlias.js module.exports.apply = undefined; function a() { } module.exports.apply = a; module.exports.apply = a; module.exports.apply() // @filename: test.js const { apply } = require('./moduleExportAliasDuplicateAlias') apply()
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportDuplicateAlias3.ts
TypeScript
// @checkJs: true // @strict: true // @declaration: true // @filename: moduleExportAliasDuplicateAlias.js // @outdir: out exports.apply = undefined; exports.apply = undefined; function a() { } exports.apply = a; exports.apply() exports.apply = 'ok' var OK = exports.apply.toUpperCase() exports.apply = 1 // @filename: test.js const { apply } = require('./moduleExportAliasDuplicateAlias') const result = apply.toFixed()
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportNestedNamespaces.ts
TypeScript
// @allowJs: true // @checkJs: true // @noEmit: true // @Filename: mod.js module.exports.n = {}; module.exports.n.K = function C() { this.x = 10; } module.exports.Classic = class { constructor() { this.p = 1 } } // @Filename: use.js import * as s from './mod' var k = new s.n.K() k.x var classic = new s.Classic() /** @param {s.n.K} c @param {s.Classic} classic */ function f(c, classic) { c.x classic.p }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportPropertyAssignmentDefault.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: axios.js var axios = {} module.exports = axios // both assignments should be ok module.exports.default = axios
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportWithExportPropertyAssignment.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: requires.d.ts declare var module: { exports: any }; declare function require(name: string): any; // @Filename: mod1.js /// <reference path='./requires.d.ts' /> module.exports = function () { } /** @param {number} a */ module.exports.f = function (a) { } // @Filename: a.js /// <reference path='./requires.d.ts' /> var mod1 = require('./mod1') mod1() mod1.f() // error, not enough arguments
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportWithExportPropertyAssignment2.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: requires.d.ts declare var module: { exports: any }; declare function require(name: string): any; // @Filename: mod1.js /// <reference path='./requires.d.ts' /> module.exports = 1 module.exports.f = function () { } // @Filename: a.js /// <reference path='./requires.d.ts' /> var mod1 = require('./mod1') mod1.toFixed(12) mod1.f() // error, 'f' is not a property on 'number'
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportWithExportPropertyAssignment3.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: requires.d.ts declare var module: { exports: any }; declare function require(name: string): any; // @Filename: mod1.js /// <reference path='./requires.d.ts' /> module.exports.bothBefore = 'string' module.exports = { justExport: 1, bothBefore: 2, bothAfter: 3, } module.exports.bothAfter = 'string' module.exports.justProperty = 'string' // @Filename: a.js /// <reference path='./requires.d.ts' /> var mod1 = require('./mod1') mod1.justExport.toFixed() mod1.bothBefore.toFixed() // error, 'toFixed' not on 'string | number' mod1.bothAfter.toFixed() // error, 'toFixed' not on 'string | number' mod1.justProperty.length
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportWithExportPropertyAssignment4.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: requires.d.ts declare var module: { exports: any }; declare function require(name: string): any; // @Filename: mod1.js /// <reference path='./requires.d.ts' /> module.exports.bothBefore = 'string' A.justExport = 4 A.bothBefore = 2 A.bothAfter = 3 module.exports = A function A() { this.p = 1 } module.exports.bothAfter = 'string' module.exports.justProperty = 'string' // @Filename: a.js /// <reference path='./requires.d.ts' /> var mod1 = require('./mod1') mod1.justExport.toFixed() mod1.bothBefore.toFixed() // error mod1.bothAfter.toFixed() mod1.justProperty.length
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportsAliasLoop1.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @filename: x.js exports.fn1(); exports.fn2 = Math.min;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportsAliasLoop2.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @filename: x.js const Foo = { min: 3 }; exports.fn1(); exports.fn2 = Foo.min;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportsElementAccessAssignment.ts
TypeScript
// @allowJs: true // @strict: true // @checkJs: true // @emitDeclarationOnly: true // @declaration: true // @filename: mod1.js exports.a = { x: "x" }; exports["b"] = { x: "x" }; exports["default"] = { x: "x" }; module.exports["c"] = { x: "x" }; module["exports"]["d"] = {}; module["exports"]["d"].e = 0; // @filename: mod2.js const mod1 = require("./mod1"); mod1.a; mod1.b; mod1.c; mod1.d; mod1.d.e; mod1.default;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleExportsElementAccessAssignment2.ts
TypeScript
// @noEmit: true // @checkJs: true // @allowJs: true // @strict: true // @Filename: file1.js // this file _should_ be a global file var GlobalThing = { x: 12 }; /** * @param {*} type * @param {*} ctor * @param {*} exports */ function f(type, ctor, exports) { if (typeof exports !== "undefined") { exports["AST_" + type] = ctor; } } // @Filename: ref.js GlobalThing.x
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleResolutionWithExtensions.ts
TypeScript
// @traceResolution: true // @Filename: /src/a.ts export default 0; // No extension: '.ts' added // @Filename: /src/b.ts import a from './a'; // '.js' extension: stripped and replaced with '.ts' // @Filename: /src/d.ts import a from './a.js'; // @Filename: /src/jquery.d.ts declare var x: number; export default x; // No extension: '.d.ts' added // @Filename: /src/jquery_user_1.ts import j from "./jquery"; // '.js' extension: stripped and replaced with '.d.ts' // @Filename: /src/jquery_user_1.ts import j from "./jquery.js"
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleResolutionWithoutExtension1.ts
TypeScript
// @moduleResolution: node16 // @module: node16 // @filename: /src/foo.mts export function foo() { return ""; } // @filename: /src/bar.mts // Extensionless relative path ES import in an ES module import { foo } from "./foo"; // should error, suggest adding ".mjs" import { baz } from "./baz"; // should error, ask for extension, no extension suggestion
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleResolutionWithoutExtension2.ts
TypeScript
// @moduleResolution: node16 // @module: node16 // @filename: /src/buzz.mts // Extensionless relative path cjs import in an ES module import foo = require("./foo"); // should error, should not ask for extension
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleResolutionWithoutExtension3.ts
TypeScript
// @moduleResolution: nodenext // @module: nodenext // @jsx: preserve // @filename: /src/foo.tsx export function foo() { return ""; } // @filename: /src/bar.mts // Extensionless relative path ES import in an ES module import { foo } from "./foo"; // should error, suggest adding ".jsx"
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleResolutionWithoutExtension4.ts
TypeScript
// @moduleResolution: nodenext // @module: nodenext // @jsx: react // @filename: /src/foo.tsx export function foo() { return ""; } // @filename: /src/bar.mts // Extensionless relative path ES import in an ES module import { foo } from "./foo"; // should error, suggest adding ".js"
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleResolutionWithoutExtension5.ts
TypeScript
// @moduleResolution: node16 // @module: node16 // @filename: /src/buzz.mts // Extensionless relative path dynamic import in an ES module import("./foo").then(x => x); // should error, ask for extension
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleResolutionWithoutExtension6.ts
TypeScript
// @moduleResolution: node16 // @module: node16 // @filename: /src/bar.cts // Extensionless relative path import statement in a cjs module // Import statements are not allowed in cjs files, // but other errors should not assume that they are allowed import { foo } from "./foo"; // should error, should not ask for extension
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleResolutionWithoutExtension7.ts
TypeScript
// @moduleResolution: node16 // @module: node16 // @filename: /src/bar.cts // Extensionless relative path cjs import in a cjs module import foo = require("./foo"); // should error, should not ask for extension
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleResolutionWithoutExtension8.ts
TypeScript
// @moduleResolution: node16 // @module: node16 // @filename: /src/bar.cts // Extensionless relative path dynamic import in a cjs module import("./foo").then(x => x); // should error, ask for extension
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleScoping.ts
TypeScript
// @Filename: file1.ts var v1 = "sausages"; // Global scope // @Filename: file2.ts var v2 = 42; // Global scope var v4 = () => 5; // @Filename: file3.ts export var v3 = true; var v2 = [1,2,3]; // Module scope. Should not appear in global scope // @Filename: file4.ts import file3 = require('./file3'); var t1 = v1; var t2 = v2; var t3 = file3.v3; var v4 = {a: true, b: NaN}; // Should shadow global v2 in this module // @Filename: file5.ts var x = v2; // Should be global v2 of type number again
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/moduleWithStatementsOfEveryKind.ts
TypeScript
module A { class A { s: string } class AA<T> { s: T } interface I { id: number } class B extends AA<string> implements I { id: number } class BB<T> extends A { id: number; } module Module { class A { s: string } } enum Color { Blue, Red } var x = 12; function F(s: string): number { return 2; } var array: I[] = null; var fn = (s: string) => { return 'hello ' + s; } var ol = { s: 'hello', id: 2, isvalid: true }; declare class DC { static x: number; } } module Y { export class A { s: string } export class AA<T> { s: T } export interface I { id: number } export class B extends AA<string> implements I { id: number } export class BB<T> extends A { id: number; } export module Module { class A { s: string } } export enum Color { Blue, Red } export var x = 12; export function F(s: string): number { return 2; } export var array: I[] = null; export var fn = (s: string) => { return 'hello ' + s; } export var ol = { s: 'hello', id: 2, isvalid: true }; export declare class DC { static x: number; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/multiline.tsx
TypeScript (TSX)
// @filename: a.ts export const texts: string[] = []; /** @ts-ignore */ texts.push(100); /** @ts-expect-error */ texts.push(100); /** @ts-expect-error */ texts.push("100"); // @filename: b.tsx // @jsx: react // @libFiles: react.d.ts,lib.d.ts import * as React from "react"; export function MyComponent(props: { foo: string }) { return <div />; } let x = ( <div> {/* @ts-ignore */} <MyComponent foo={100} /> {/*@ts-ignore*/} <MyComponent foo={100} /> {/* @ts-expect-error */} <MyComponent foo={100} /> {/* // @ts-expect-error */} <MyComponent foo={100} /> {/* * @ts-expect-error */} <MyComponent foo={100} /> {/*@ts-expect-error*/} <MyComponent foo={100} /> {/* @ts-expect-error */} <MyComponent foo={"hooray"} /> </div> );
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/multipleDeclarations.ts
TypeScript
// @filename: input.js // @outFile: output.js // @allowJs: true function C() { this.m = null; } C.prototype.m = function() { this.nothing(); } class X { constructor() { this.m = this.m.bind(this); this.mistake = 'frankly, complete nonsense'; } m() { } mistake() { } } let x = new X(); X.prototype.mistake = false; x.m(); x.mistake; class Y { mistake() { } m() { } constructor() { this.m = this.m.bind(this); this.mistake = 'even more nonsense'; } } Y.prototype.mistake = true; let y = new Y(); y.m(); y.mistake();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/multipleDefaultExports01.ts
TypeScript
// @module: commonjs // @target: ES5 // @filename: m1.ts export default class foo { } export default function bar() { } var x = 10; export default x; // @filename: m2.ts import Entity from "./m1" Entity();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/multipleDefaultExports02.ts
TypeScript
// @module: commonjs // @target: ES5 // @filename: m1.ts export default function foo() { } export default function bar() { } // @filename: m2.ts import Entity from "./m1" Entity();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/multipleDefaultExports03.ts
TypeScript
// @module: commonjs // @target: ES5 export default class C { } export default class C { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/multipleDefaultExports04.ts
TypeScript
// @module: commonjs // @target: ES5 export default function f() { } export default function f() { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/multipleDefaultExports05.ts
TypeScript
// @module: commonjs // @target: ES5 export default class AA1 {} export default class BB1 {} export default class CC1 {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/multipleExportDefault1.ts
TypeScript
export default function Foo (){ } export default { uhoh: "another default", };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/multipleExportDefault2.ts
TypeScript
export default { uhoh: "another default", }; export default function Foo() { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/multipleExportDefault3.ts
TypeScript
export default { uhoh: "another default", }; export default class C { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/multipleExportDefault4.ts
TypeScript
export default class C { } export default { uhoh: "another default", };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/multipleExportDefault5.ts
TypeScript
export default function bar() { } export default class C {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/multipleExportDefault6.ts
TypeScript
export default { lol: 1 } export default { lol: 2 }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/multipleNumericIndexers.ts
TypeScript
// Multiple indexers of the same type are an error class C { [x: number]: string; [x: number]: string; } interface I { [x: number]: string; [x: number]: string; } var a: { [x: number]: string; [x: number]: string; } var b: { [x: number]: string; [x: number]: string } = { 1: '', "2": '' } class C2<T> { [x: number]: string; [x: number]: string; } interface I<T> { [x: number]: string; [x: number]: string; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/multipleStringIndexers.ts
TypeScript
// Multiple indexers of the same type are an error class C { [x: string]: string; [x: string]: string; } interface I { [x: string]: string; [x: string]: string; } var a: { [x: string]: string; [x: string]: string; } var b: { [x: string]: string; [x: string]: string; } = { y: '' } class C2<T> { [x: string]: string; [x: string]: string; } interface I2<T> { [x: string]: string; [x: string]: string; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/nameCollision.ts
TypeScript
module A { // these 2 statements force an underscore before the 'A' // in the generated function call. var A = 12; var _A = ''; } module B { var A = 12; } module B { // re-opened module with colliding name // this should add an underscore. class B { name: string; } } module X { var X = 13; export module Y { var Y = 13; export module Z { var X = 12; var Y = 12; var Z = 12; } } } module Y.Y { export enum Y { Red, Blue } } // no collision, since interface doesn't // generate code. module D { export interface D { id: number; } export var E = 'hello'; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/nameDelimitedBySlashes.ts
TypeScript
// @module: commonjs // @Filename: test/foo_0.ts export var foo = 42; // @Filename: foo_1.ts import foo = require('./test/foo_0'); var x = foo.foo + 42;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/nameWithFileExtension.ts
TypeScript
// @module: commonjs // @Filename: foo_0.ts export var foo = 42; // @Filename: foo_1.ts import foo = require('./foo_0.js'); var x = foo.foo + 42;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/nameWithRelativePaths.ts
TypeScript
// @module: commonjs // @Filename: foo_0.ts export var foo = 42; // @Filename: test/test/foo_1.ts export function f(){ return 42; } // @Filename: test/foo_2.ts export module M2 { export var x = true; } // @Filename: test/foo_3.ts import foo0 = require('../foo_0'); import foo1 = require('./test/foo_1'); import foo2 = require('./.././test/foo_2'); if(foo2.M2.x){ var x = foo0.foo + foo1.f(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/namedTupleMembers.ts
TypeScript
// @declaration: true export type Segment = [length: number, count: number]; export type SegmentAnnotated = [ /** * Size of message buffer segment handles */ length: number, /** * Number of segments handled at once */ count: number ]; declare var a: Segment; declare var b: SegmentAnnotated; declare var c: [number, number]; declare var d: [a: number, b: number]; a = b; a = c; a = d; b = a; b = c; b = d; c = a; c = b; c = d; d = a; d = b; d = c; export type WithOptAndRest = [first: number, second?: number, ...rest: string[]]; export type Func<T extends any[]> = (...x: T) => void; export const func = null as any as Func<SegmentAnnotated>; export function useState<T>(initial: T): [value: T, setter: (T) => void] { return null as any; } export type Iter = Func<[step: number, iterations: number]>; export function readSegment([length, count]: [number, number]) {} // documenting binding pattern behavior (currently does _not_ generate tuple names) export const val = null as any as Parameters<typeof readSegment>[0]; export type RecursiveTupleA = [initial: string, next: RecursiveTupleA]; export type RecursiveTupleB = [first: string, ptr: RecursiveTupleB]; declare var q: RecursiveTupleA; declare var r: RecursiveTupleB; q = r; r = q; export type RecusiveRest = [first: string, ...rest: RecusiveRest[]]; export type RecusiveRest2 = [string, ...RecusiveRest2[]]; declare var x: RecusiveRest; declare var y: RecusiveRest2; x = y; y = x; declare function f<T extends any[]>(...x: T): T; declare function g(elem: object, index: number): object; declare function getArgsForInjection<T extends (...args: any[]) => any>(x: T): Parameters<T>; export const argumentsOfGAsFirstArgument = f(getArgsForInjection(g)); // one tuple with captures arguments as first member export const argumentsOfG = f(...getArgsForInjection(g)); // captured arguments list re-spread
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/namespaceAssignmentToRequireAlias.ts
TypeScript
// @allowJs: true // @checkJs: true // @strict: true // @outDir: out // @declaration: true // @filename: node_modules/untyped/index.js module.exports = {} // @filename: bug40140.js const u = require('untyped'); u.assignment.nested = true u.noError()
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/namespaceImportTypeQuery.ts
TypeScript
// @Filename: /a.ts class A {} export type { A }; export class B {}; // @Filename: /b.ts import * as types from './a'; let A: typeof types.A; let B: typeof types.B; let t: typeof types = { // error: while you can ask for `typeof types.A`, // `typeof types` does not include `A` A: undefined as any, B: undefined as any, }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/namespaceImportTypeQuery2.ts
TypeScript
// @Filename: /z.ts interface A {} export type { A }; // @Filename: /a.ts import { A } from './z'; const A = 0; export { A }; export class B {}; // @Filename: /b.ts import * as types from './a'; let t: typeof types = { A: undefined as any, // ok B: undefined as any, }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/namespaceImportTypeQuery3.ts
TypeScript
// @Filename: /a.ts import type { A } from './z'; // unresolved const A = 0; export { A }; export class B {}; // @Filename: /b.ts import * as types from './a'; let t: typeof types = { A: undefined as any, // ok B: undefined as any, }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/namespaceImportTypeQuery4.ts
TypeScript
// @Filename: /a.ts import type { A } from './z'; // unresolved type A = 0; export { A }; export class B {}; // @Filename: /b.ts import * as types from './a'; let t: typeof types = { A: undefined as any, // error B: undefined as any, }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/namespaceMemberAccess.ts
TypeScript
// @Filename: /a.ts class A { a!: string } export type { A }; // @Filename: /b.ts import * as types from './a'; types.A; const { A } = types;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/narrowExceptionVariableInCatchClause.ts
TypeScript
declare function isFooError(x: any): x is { type: 'foo'; dontPanic(); }; function tryCatch() { try { // do stuff... } catch (err) { // err is implicitly 'any' and cannot be annotated if (isFooError(err)) { err.dontPanic(); // OK err.doPanic(); // ERROR: Property 'doPanic' does not exist on type '{...}' } else if (err instanceof Error) { err.message; err.massage; // ERROR: Property 'massage' does not exist on type 'Error' } else { throw err; } } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/narrowFromAnyWithInstanceof.ts
TypeScript
declare var x: any; if (x instanceof Function) { // 'any' is not narrowed when target type is 'Function' x(); x(1, 2, 3); x("hello!"); x.prop; } if (x instanceof Object) { // 'any' is not narrowed when target type is 'Object' x.method(); x(); } if (x instanceof Error) { // 'any' is narrowed to types other than 'Function'/'Object' x.message; x.mesage; } if (x instanceof Date) { x.getDate(); x.getHuors(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/narrowFromAnyWithTypePredicate.ts
TypeScript
declare var x: any; declare function isFunction(x): x is Function; declare function isObject(x): x is Object; declare function isAnything(x): x is {}; declare function isError(x): x is Error; declare function isDate(x): x is Date; if (isFunction(x)) { // 'any' is not narrowed when target type is 'Function' x(); x(1, 2, 3); x("hello!"); x.prop; } if (isObject(x)) { // 'any' is not narrowed when target type is 'Object' x.method(); x(); } if (isAnything(x)) { // 'any' is narrowed to types other than 'Function'/'Object' (including {}) x.method(); x(); } if (isError(x)) { x.message; x.mesage; } if (isDate(x)) { x.getDate(); x.getHuors(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/narrowingConstrainedTypeVariable.ts
TypeScript
// @strict: true // Repro from #20138 class C { } function f1<T extends C>(v: T | string): void { if (v instanceof C) { const x: T = v; } else { const s: string = v; } } class D { } function f2<T extends C, U extends D>(v: T | U) { if (v instanceof C) { const x: T = v; } else { const y: U = v; } } class E { x: string | undefined } function f3<T extends E>(v: T | { x: string }) { if (v instanceof E) { const x: T = v; } else { const y: { x: string } = v; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/narrowingGenericTypeFromInstanceof01.ts
TypeScript
class A<T> { constructor(private a: string) { } } class B<T> { } function acceptA<T>(a: A<T>) { } function acceptB<T>(b: B<T>) { } function test<T>(x: A<T> | B<T>) { if (x instanceof B) { acceptA(x); } if (x instanceof A) { acceptA(x); } if (x instanceof B) { acceptB(x); } if (x instanceof B) { acceptB(x); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/negateOperatorWithBooleanType.ts
TypeScript
// - operator on boolean type var BOOLEAN: boolean; function foo(): boolean { return true; } class A { public a: boolean; static foo() { return false; } } module M { export var n: boolean; } var objA = new A(); // boolean type var var ResultIsNumber1 = -BOOLEAN; // boolean type literal var ResultIsNumber2 = -true; var ResultIsNumber3 = -{ x: true, y: false }; // boolean type expressions var ResultIsNumber4 = -objA.a; var ResultIsNumber5 = -M.n; var ResultIsNumber6 = -foo(); var ResultIsNumber7 = -A.foo(); // miss assignment operators -true; -BOOLEAN; -foo(); -true, false; -objA.a; -M.n;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/negateOperatorWithEnumType.ts
TypeScript
// - operator on enum type enum ENUM { }; enum ENUM1 { A, B, "" }; // enum type var var ResultIsNumber1 = -ENUM; // expressions var ResultIsNumber2 = -ENUM1["B"]; var ResultIsNumber3 = -(ENUM1.B + ENUM1[""]); // miss assignment operators -ENUM; -ENUM1; -ENUM1["B"]; -ENUM, ENUM1;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/negateOperatorWithNumberType.ts
TypeScript
// - operator on number type var NUMBER: number; var NUMBER1: number[] = [1, 2]; function foo(): number { return 1; } class A { public a: number; static foo() { return 1; } } module M { export var n: number; } var objA = new A(); // number type var var ResultIsNumber1 = -NUMBER; var ResultIsNumber2 = -NUMBER1; // number type literal var ResultIsNumber3 = -1; var ResultIsNumber4 = -{ x: 1, y: 2}; var ResultIsNumber5 = -{ x: 1, y: (n: number) => { return n; } }; // number type expressions var ResultIsNumber6 = -objA.a; var ResultIsNumber7 = -M.n; var ResultIsNumber8 = -NUMBER1[0]; var ResultIsNumber9 = -foo(); var ResultIsNumber10 = -A.foo(); var ResultIsNumber11 = -(NUMBER - NUMBER); // miss assignment operators -1; -NUMBER; -NUMBER1; -foo(); -objA.a; -M.n; -objA.a, M.n;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/negateOperatorWithStringType.ts
TypeScript
// - operator on string type var STRING: string; var STRING1: string[] = ["", "abc"]; function foo(): string { return "abc"; } class A { public a: string; static foo() { return ""; } } module M { export var n: string; } var objA = new A(); // string type var var ResultIsNumber1 = -STRING; var ResultIsNumber2 = -STRING1; // string type literal var ResultIsNumber3 = -""; var ResultIsNumber4 = -{ x: "", y: "" }; var ResultIsNumber5 = -{ x: "", y: (s: string) => { return s; } }; // string type expressions var ResultIsNumber6 = -objA.a; var ResultIsNumber7 = -M.n; var ResultIsNumber8 = -STRING1[0]; var ResultIsNumber9 = -foo(); var ResultIsNumber10 = -A.foo(); var ResultIsNumber11 = -(STRING + STRING); var ResultIsNumber12 = -STRING.charAt(0); // miss assignment operators -""; -STRING; -STRING1; -foo(); -objA.a,M.n;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/nestedDestructuringOfRequire.ts
TypeScript
// @allowJs: true // @checkJs: true // @outDir: out // @declaration: true // @filename: mod1.js const chalk = { grey: {} }; module.exports.chalk = chalk // @filename: main.js const { chalk: { grey } } = require('./mod1'); grey chalk
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/nestedModules.ts
TypeScript
module A.B.C { export interface Point { x: number; y: number; } } module A { export module B { var Point: C.Point = { x: 0, y: 0 }; // bug 832088: could not find module 'C' } } module M2.X { export interface Point { x: number; y: number; } } module M2 { export module X { export var Point: number; } } var m = M2.X; var point: number; var point = m.Point; var p: { x: number; y: number; } var p: M2.X.Point;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/nestedNamespace.ts
TypeScript
// @Filename: a.ts export namespace types { export class A {} } // @Filename: b.ts import type * as a from './a'; interface B extends a.types.A {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/nestedPrototypeAssignment.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @noImplicitAny: true // @Filename: mod.js // #24111 -- shouldn't assert C.prototype = {} C.prototype.bar.foo = {};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/neverInference.ts
TypeScript
// @lib: es2015 // @strict: true // @target: es2015 declare function f1<T>(x: T[]): T; let neverArray: never[] = []; let a1 = f1([]); // never let a2 = f1(neverArray); // never // Repro from #19576 type Comparator<T> = (x: T, y: T) => number; interface LinkedList<T> { comparator: Comparator<T>, nodes: Node<T> } type Node<T> = { value: T, next: Node<T> } | null declare function compareNumbers(x: number, y: number): number; declare function mkList<T>(items: T[], comparator: Comparator<T>): LinkedList<T>; const list: LinkedList<number> = mkList([], compareNumbers); // Repro from #19858 declare function f2<a>(as1: a[], as2: a[], cmp: (a1: a, a2: a) => number): void; f2(Array.from([0]), [], (a1, a2) => a1 - a2); f2(Array.from([]), [0], (a1, a2) => a1 - a2);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/neverIntersectionNotCallable.ts
TypeScript
declare const f: { (x: string): number, a: "" } & { a: number } f()
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/neverReturningFunctions1.ts
TypeScript
// @strict: true // @allowUnreachableCode: false // @declaration: true function fail(message?: string): never { throw new Error(message); } function f01(x: string | undefined) { if (x === undefined) fail("undefined argument"); x.length; // string } function f02(x: number): number { if (x >= 0) return x; fail("negative number"); x; // Unreachable } function f03(x: string) { x; // string fail(); x; // Unreachable } function f11(x: string | undefined, fail: (message?: string) => never) { if (x === undefined) fail("undefined argument"); x.length; // string } function f12(x: number, fail: (message?: string) => never): number { if (x >= 0) return x; fail("negative number"); x; // Unreachable } function f13(x: string, fail: (message?: string) => never) { x; // string fail(); x; // Unreachable } namespace Debug { export declare function fail(message?: string): never; } function f21(x: string | undefined) { if (x === undefined) Debug.fail("undefined argument"); x.length; // string } function f22(x: number): number { if (x >= 0) return x; Debug.fail("negative number"); x; // Unreachable } function f23(x: string) { x; // string Debug.fail(); x; // Unreachable } function f24(x: string) { x; // string ((Debug).fail)(); x; // Unreachable } class Test { fail(message?: string): never { throw new Error(message); } f1(x: string | undefined) { if (x === undefined) this.fail("undefined argument"); x.length; // string } f2(x: number): number { if (x >= 0) return x; this.fail("negative number"); x; // Unreachable } f3(x: string) { x; // string this.fail(); x; // Unreachable } } function f30(x: string | number | undefined) { if (typeof x === "string") { fail(); x; // Unreachable } else { x; // number | undefined if (x !== undefined) { x; // number fail(); x; // Unreachable } else { x; // undefined fail(); x; // Unreachable } x; // Unreachable } x; // Unreachable } function f31(x: { a: string | number }) { if (typeof x.a === "string") { fail(); x; // Unreachable x.a; // Unreachable } x; // { a: string | number } x.a; // number } function f40(x: number) { try { x; fail(); x; // Unreachable } finally { x; fail(); x; // Unreachable } x; // Unreachable } function f41(x: number) { try { x; } finally { x; fail(); x; // Unreachable } x; // Unreachable } function f42(x: number) { try { x; fail(); x; // Unreachable } finally { x; } x; // Unreachable } function f43() { const fail = (): never => { throw new Error(); }; const f = [fail]; fail(); // No effect (missing type annotation) f[0](); // No effect (not a dotted name) f; } // Repro from #33582 export interface Component<T extends object = any> { attrName?: string; data: T; dependencies?: string[]; el: any; id: string; multiple?: boolean; name: string; schema: unknown; system: any; init(data?: T): void; pause(): void; play(): void; remove(): void; tick?(time: number, timeDelta: number): void; update(oldData: T): void; updateSchema?(): void; extendSchema(update: unknown): void; flushToDOM(): void; } export interface ComponentConstructor<T extends object> { new (el: unknown, attrValue: string, id: string): T & Component; prototype: T & { name: string; system: unknown; play(): void; pause(): void; }; } declare function registerComponent<T extends object>( name: string, component: ComponentDefinition<T> ): ComponentConstructor<T>; export type ComponentDefinition<T extends object = object> = T & Partial<Component> & ThisType<T & Component>; const Component = registerComponent('test-component', { schema: { myProperty: { default: [], parse() { return [true]; } }, string: { type: 'string' }, num: 0 }, init() { this.data.num = 0; this.el.setAttribute('custom-attribute', 'custom-value'); }, update() {}, tick() {}, remove() {}, pause() {}, play() {}, multiply(f: number) { // Reference to system because both were registered with the same name. return f * this.data.num * this.system!.data.counter; } }); // Repro from #36147 class MyThrowable { throw(): never { throw new Error(); } } class SuperThrowable extends MyThrowable { err(msg: string): never { super.throw() } ok(): never { this.throw() } } // Repro from #40346 interface Services { panic(message: string): never; } function foo(services: Readonly<Services>, s: string | null): string { if (s === null) { services.panic("ouch"); } else { return s; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/neverType.ts
TypeScript
// @strictNullChecks: true // @declaration: true function error(message: string): never { throw new Error(message); } function errorVoid(message: string) { throw new Error(message); } function fail() { return error("Something failed"); } function failOrThrow(shouldFail: boolean) { if (shouldFail) { return fail(); } throw new Error(); } function infiniteLoop1() { while (true) { } } function infiniteLoop2(): never { while (true) { } } function move1(direction: "up" | "down") { switch (direction) { case "up": return 1; case "down": return -1; } return error("Should never get here"); } function move2(direction: "up" | "down") { return direction === "up" ? 1 : direction === "down" ? -1 : error("Should never get here"); } function check<T>(x: T | undefined) { return x || error("Undefined value"); } class C { void1() { throw new Error(); } void2() { while (true) {} } never1(): never { throw new Error(); } never2(): never { while (true) {} } } function f1(x: string | number) { if (typeof x === "boolean") { x; // never } } function f2(x: string | number) { while (true) { if (typeof x === "boolean") { return x; // never } } } function test(cb: () => string) { let s = cb(); return s; } let errorCallback = () => error("Error callback"); test(() => "hello"); test(() => fail()); test(() => { throw new Error(); }) test(errorCallback);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/neverTypeErrors1.ts
TypeScript
function f1() { let x: never; x = 1; x = "abc"; x = false; x = undefined; x = null; x = {}; x(); } function f2(): never { return; } function f3(): never { return 1; } function f4(): never { } for (const n of f4()) {} for (const n in f4()) {} function f5() { let x: never[] = []; // Ok } // Repro from #46032 interface A { foo: "a"; } interface B { foo: "b"; } type Union = A & B; function func(): { value: Union[] } { return { value: [], }; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/neverTypeErrors2.ts
TypeScript
// @strictNullChecks: true function f1() { let x: never; x = 1; x = "abc"; x = false; x = undefined; x = null; x = {}; x(); } function f2(): never { return; } function f3(): never { return 1; } function f4(): never { } for (const n of f4()) {} for (const n in f4()) {} function f5() { let x: never[] = []; // Ok } // Repro from #46032 interface A { foo: "a"; } interface B { foo: "b"; } type Union = A & B; function func(): { value: Union[] } { return { value: [], }; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/neverUnionIntersection.ts
TypeScript
// @strict: true type T01 = string | never; type T02 = string & never; type T03 = string | number | never; type T04 = string & number & never; type T05 = any | never; type T06 = any & never; type T07 = undefined | never; type T08 = undefined & never; type T09 = null | never; type T10 = null & never; type T11 = { a: string } | never; type T12 = { a: string } & never;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/newOperatorConformance.ts
TypeScript
class C0 { } class C1 { constructor(n: number, s: string) { } } class T<T> { constructor(n?: T) { } } var anyCtor: { new (): any; }; var anyCtor1: { new (n): any; }; interface nestedCtor { new (): nestedCtor; } var nestedCtor: nestedCtor; // Construct expression with no parentheses for construct signature with 0 parameters var a = new C0; var a: C0; // Generic construct expression with no parentheses var c1 = new T; var c1: T<{}>; // Construct expression where constructor is of type 'any' with no parentheses var d = new anyCtor; var d: any; // Construct expression where constructor is of type 'any' with > 1 arg var d = new anyCtor1(undefined); // Construct expression of type where apparent type has a construct signature with 0 arguments function newFn1<T extends { new (): number }>(s: T) { var p = new s; var p: number; } // Construct expression of type where apparent type has a construct signature with 1 arguments function newFn2<T extends { new (s: number): string}>(s: T) { var p = new s(32); var p: string; } // Construct expression of void returning function function fnVoid(): void { } var t = new fnVoid(); var t: any; // Chained new expressions var nested = new (new (new nestedCtor())())(); var n = new nested(); var n = new nested();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/newOperatorErrorCases_noImplicitAny.ts
TypeScript
// @noImplicitAny: true function fnNumber(this: void): number { return 90; } new fnNumber(); // Error function fnVoid(this: void): void {} new fnVoid(); // Error function functionVoidNoThis(): void {} new functionVoidNoThis(); // Error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/newTarget.es5.ts
TypeScript
// @target: es5 class A { constructor() { const a = new.target; const b = () => new.target; } static c = function () { return new.target; } d = function () { return new.target; } } class B extends A { constructor() { super(); const e = new.target; const f = () => new.target; } } function f1() { const g = new.target; const h = () => new.target; } const f2 = function () { const i = new.target; const j = () => new.target; } const O = { k: function () { return new.target; } };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/newTarget.es6.ts
TypeScript
// @target: es6 class A { constructor() { const a = new.target; const b = () => new.target; } static c = function () { return new.target; } d = function () { return new.target; } } class B extends A { constructor() { super(); const e = new.target; const f = () => new.target; } } function f1() { const g = new.target; const h = () => new.target; } const f2 = function () { const i = new.target; const j = () => new.target; } const O = { k: function () { return new.target; } };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/newTargetNarrowing.ts
TypeScript
// @target: es6 // @strict: true function foo(x: true) { } function f() { if (new.target.marked === true) { foo(new.target.marked); } } f.marked = true;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/newWithSpread.ts
TypeScript
function f(x: number, y: number, ...z: string[]) { } function f2(...x: string[]) { } interface A { f: { new (x: number, y: number, ...z: string[]); } } class B { constructor(x: number, y: number, ...z: string[]) {} } interface C { "a-b": typeof B; } interface D { 1: typeof B; } var a: string[]; var b: A; var c: C; var d: A[]; var e: { [key: string]: A }; var g: C[]; var h: { [key: string]: C }; var i: C[][]; // Basic expression new f(1, 2, "string"); new f(1, 2, ...a); new f(1, 2, ...a, "string"); // Multiple spreads arguments new f2(...a, ...a); new f(1 ,2, ...a, ...a); // Call expression new f(1, 2, "string")(); new f(1, 2, ...a)(); new f(1, 2, ...a, "string")(); // Property access expression new b.f(1, 2, "string"); new b.f(1, 2, ...a); new b.f(1, 2, ...a, "string"); // Parenthesised expression new (b.f)(1, 2, "string"); new (b.f)(1, 2, ...a); new (b.f)(1, 2, ...a, "string"); // Element access expression new d[1].f(1, 2, "string"); new d[1].f(1, 2, ...a); new d[1].f(1, 2, ...a, "string"); // Element access expression with a punctuated key new e["a-b"].f(1, 2, "string"); new e["a-b"].f(1, 2, ...a); new e["a-b"].f(1, 2, ...a, "string"); // Basic expression new B(1, 2, "string"); new B(1, 2, ...a); new B(1, 2, ...a, "string"); // Property access expression new c["a-b"](1, 2, "string"); new c["a-b"](1, 2, ...a); new c["a-b"](1, 2, ...a, "string"); // Parenthesised expression new (c["a-b"])(1, 2, "string"); new (c["a-b"])(1, 2, ...a); new (c["a-b"])(1, 2, ...a, "string"); // Element access expression new g[1]["a-b"](1, 2, "string"); new g[1]["a-b"](1, 2, ...a); new g[1]["a-b"](1, 2, ...a, "string"); // Element access expression with a punctuated key new h["a-b"]["a-b"](1, 2, "string"); new h["a-b"]["a-b"](1, 2, ...a); new h["a-b"]["a-b"](1, 2, ...a, "string"); // Element access expression with a number new i["a-b"][1](1, 2, "string"); new i["a-b"][1](1, 2, ...a); new i["a-b"][1](1, 2, ...a, "string");
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University