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/generatorTypeCheck7.ts | TypeScript | //@target: ES6
interface WeirdIter extends IterableIterator<number> {
hello: string;
}
function* g1(): WeirdIter { } | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/generatorTypeCheck8.ts | TypeScript | //@target: ES6
interface BadGenerator extends Iterator<number>, Iterable<string> { }
function* g3(): BadGenerator { } | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/generatorTypeCheck9.ts | TypeScript | //@target: ES6
function* g3(): void { } | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/generatorYieldContextualType.ts | TypeScript | // @target: esnext
// @strict: true
// @noEmit: true
declare function f1<T, R, S>(gen: () => Generator<R, T, S>): void;
f1<0, 0, 1>(function* () {
const a = yield 0;
return 0;
});
declare function f2<T, R, S>(gen: () => Generator<R, T, S> | AsyncGenerator<R, T, S>): void;
f2<0, 0, 1>(async function* () {
const a = yield 0;
return 0;
});
// repro from #41428
enum Directive {
Back,
Cancel,
LoadMore,
Noop,
}
namespace Directive {
export function is<T>(value: Directive | T): value is Directive {
return typeof value === "number" && Directive[value] != null;
}
}
interface QuickPickItem {
label: string;
description?: string;
detail?: string;
picked?: boolean;
alwaysShow?: boolean;
}
interface QuickInputStep {
placeholder?: string;
prompt?: string;
title?: string;
}
interface QuickPickStep<T extends QuickPickItem = QuickPickItem> {
placeholder?: string;
title?: string;
}
type StepGenerator =
| Generator<
QuickPickStep | QuickInputStep,
StepResult<void | undefined>,
any | undefined
>
| AsyncGenerator<
QuickPickStep | QuickInputStep,
StepResult<void | undefined>,
any | undefined
>;
type StepItemType<T> = T extends QuickPickStep<infer U>
? U[]
: T extends QuickInputStep
? string
: never;
namespace StepResult {
export const Break = Symbol("BreakStep");
}
type StepResult<T> = typeof StepResult.Break | T;
type StepResultGenerator<T> =
| Generator<QuickPickStep | QuickInputStep, StepResult<T>, any | undefined>
| AsyncGenerator<
QuickPickStep | QuickInputStep,
StepResult<T>,
any | undefined
>;
type StepSelection<T> = T extends QuickPickStep<infer U>
? U[] | Directive
: T extends QuickInputStep
? string | Directive
: never;
type PartialStepState<T = unknown> = Partial<T> & {
counter: number;
confirm?: boolean;
startingStep?: number;
};
type StepState<T = Record<string, unknown>> = T & {
counter: number;
confirm?: boolean;
startingStep?: number;
};
function canPickStepContinue<T extends QuickPickStep>(
_step: T,
_state: PartialStepState,
_selection: StepItemType<T> | Directive
): _selection is StepItemType<T> {
return false;
}
function createPickStep<T extends QuickPickItem>(
step: QuickPickStep<T>
): QuickPickStep<T> {
return step;
}
function* showStep<
State extends PartialStepState & { repo: any },
Context extends { repos: any[]; title: string; status: any }
>(state: State, _context: Context): StepResultGenerator<QuickPickItem> {
const step: QuickPickStep<QuickPickItem> = createPickStep<QuickPickItem>({
title: "",
placeholder: "",
});
const selection: StepSelection<typeof step> = yield step;
return canPickStepContinue(step, state, selection)
? selection[0]
: StepResult.Break;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/generic.ts | TypeScript | // @Filename: /a.ts
export class A<T> { a!: T }
export type { A as B };
// @Filename: /b.ts
import type { A } from './a';
import { B } from './a';
let a: A<string> = { a: "" };
let b: B<number> = { a: 3 };
let c: A<boolean> = {};
let d: B = { a: "" }; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericAndNonGenericInterfaceWithTheSameName.ts | TypeScript | // generic and non-generic interfaces with the same name do not merge
interface A {
foo: string;
}
interface A<T> { // error
bar: T;
}
module M {
interface A<T> {
bar: T;
}
interface A { // error
foo: string;
}
}
module M2 {
interface A {
foo: string;
}
}
module M2 {
interface A<T> { // ok, different declaration space than other M2
bar: T;
}
}
module M3 {
export interface A {
foo: string;
}
}
module M3 {
export interface A<T> { // error
bar: T;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericAndNonGenericInterfaceWithTheSameName2.ts | TypeScript | // generic and non-generic interfaces with the same name do not merge
module M {
interface A<T> {
bar: T;
}
}
module M2 {
interface A { // ok
foo: string;
}
}
module N {
module M {
interface A<T> {
bar: T;
}
}
module M2 {
interface A { // ok
foo: string;
}
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallToOverloadedMethodWithOverloadedArguments.ts | TypeScript |
module m1 {
interface Promise<T> {
then<U>(cb: (x: T) => Promise<U>): Promise<U>;
}
declare function testFunction(n: number): Promise<number>;
var numPromise: Promise<number>;
var newPromise = numPromise.then(testFunction);
}
//////////////////////////////////////
module m2 {
interface Promise<T> {
then<U>(cb: (x: T) => Promise<U>): Promise<U>;
}
declare function testFunction(n: number): Promise<number>;
declare function testFunction(s: string): Promise<string>;
var numPromise: Promise<number>;
var newPromise = numPromise.then(testFunction);
}
//////////////////////////////////////
module m3 {
interface Promise<T> {
then<U>(cb: (x: T) => Promise<U>): Promise<U>;
then<U>(cb: (x: T) => Promise<U>, error?: (error: any) => Promise<U>): Promise<U>;
}
declare function testFunction(n: number): Promise<number>;
var numPromise: Promise<number>;
var newPromise = numPromise.then(testFunction);
}
//////////////////////////////////////
module m4 {
interface Promise<T> {
then<U>(cb: (x: T) => Promise<U>): Promise<U>;
then<U>(cb: (x: T) => Promise<U>, error?: (error: any) => Promise<U>): Promise<U>;
}
declare function testFunction(n: number): Promise<number>;
declare function testFunction(s: string): Promise<string>;
var numPromise: Promise<number>;
var newPromise = numPromise.then(testFunction);
}
//////////////////////////////////////
module m5 {
interface Promise<T> {
then<U>(cb: (x: T) => Promise<U>): Promise<U>;
then<U>(cb: (x: T) => Promise<U>, error?: (error: any) => Promise<U>): Promise<U>;
then<U>(cb: (x: T) => Promise<U>, error?: (error: any) => U, progress?: (preservation: any) => void): Promise<U>;
}
declare function testFunction(n: number): Promise<number>;
declare function testFunction(s: string): Promise<string>;
var numPromise: Promise<number>;
var newPromise = numPromise.then(testFunction);
}
//////////////////////////////////////
module m6 {
interface Promise<T> {
then<U>(cb: (x: T) => Promise<U>): Promise<U>;
then<U>(cb: (x: T) => Promise<U>, error?: (error: any) => Promise<U>): Promise<U>;
}
declare function testFunction(n: number): Promise<number>;
declare function testFunction(s: string): Promise<string>;
declare function testFunction(b: boolean): Promise<boolean>;
var numPromise: Promise<number>;
var newPromise = numPromise.then(testFunction);
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallTypeArgumentInference.ts | TypeScript | // Basic type inference with generic calls, no errors expected
function foo<T>(t: T) {
return t;
}
var r = foo(''); // string
function foo2<T, U>(t: T, u: U) {
return u;
}
function foo2b<T, U>(u: U) {
var x: T;
return x;
}
var r2 = foo2('', 1); // number
var r3 = foo2b(1); // {}
class C<T, U> {
constructor(public t: T, public u: U) {
}
foo(t: T, u: U) {
return t;
}
foo2(t: T, u: U) {
return u;
}
foo3<T>(t: T, u: U) {
return t;
}
foo4<U>(t: T, u: U) {
return t;
}
foo5<T,U>(t: T, u: U) {
return t;
}
foo6<T, U>() {
var x: T;
return x;
}
foo7<T, U>(u: U) {
var x: T;
return x;
}
foo8<T, U>() {
var x: T;
return x;
}
}
var c = new C('', 1);
var r4 = c.foo('', 1); // string
var r5 = c.foo2('', 1); // number
var r6 = c.foo3(true, 1); // boolean
var r7 = c.foo4('', true); // string
var r8 = c.foo5(true, 1); // boolean
var r9 = c.foo6(); // {}
var r10 = c.foo7(''); // {}
var r11 = c.foo8(); // {}
interface I<T, U> {
new (t: T, u: U);
foo(t: T, u: U): T;
foo2(t: T, u: U): U;
foo3<T>(t: T, u: U): T;
foo4<U>(t: T, u: U): T;
foo5<T, U>(t: T, u: U): T;
foo6<T, U>(): T;
foo7<T, U>(u: U): T;
foo8<T, U>(): T;
}
var i: I<string, number>;
var r4 = i.foo('', 1); // string
var r5 = i.foo2('', 1); // number
var r6 = i.foo3(true, 1); // boolean
var r7 = i.foo4('', true); // string
var r8 = i.foo5(true, 1); // boolean
var r9 = i.foo6(); // {}
var r10 = i.foo7(''); // {}
var r11 = i.foo8(); // {} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithArrayLiteralArgs.ts | TypeScript | function foo<T>(t: T) {
return t;
}
var r = foo([1, 2]); // number[]
var r = foo<number[]>([1, 2]); // number[]
var ra = foo<any[]>([1, 2]); // any[]
var r2 = foo([]); // any[]
var r3 = foo<number[]>([]); // number[]
var r4 = foo([1, '']); // {}[]
var r5 = foo<any[]>([1, '']); // any[]
var r6 = foo<Object[]>([1, '']); // Object[]
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithConstraintsTypeArgumentInference.ts | TypeScript | // Basic type inference with generic calls and constraints, no errors expected
class Base { foo: string; }
class Derived extends Base { bar: string; }
class Derived2 extends Derived { baz: string; }
var b: Base;
var d1: Derived;
var d2: Derived2;
function foo<T extends Base>(t: T) {
return t;
}
var r = foo(b); // Base
var r2 = foo(d1); // Derived
function foo2<T extends Base, U extends Derived>(t: T, u: U) {
return u;
}
function foo2b<T extends Base, U extends Derived>(u: U) {
var x: T;
return x;
}
function foo2c<T extends Base, U extends Derived>() {
var x: T;
return x;
}
var r3 = foo2b(d1); // Base
var r3b = foo2c(); // Base
class C<T extends Base, U extends Derived> {
constructor(public t: T, public u: U) {
}
foo(t: T, u: U) {
return t;
}
foo2(t: T, u: U) {
return u;
}
foo3<T extends Derived>(t: T, u: U) {
return t;
}
foo4<U extends Derived2>(t: T, u: U) {
return t;
}
foo5<T extends Derived, U extends Derived2>(t: T, u: U) {
return t;
}
foo6<T extends Derived, U extends Derived2>() {
var x: T;
return x;
}
foo7<T extends Base, U extends Derived>(u: U) {
var x: T;
return x;
}
foo8<T extends Base, U extends Derived>() {
var x: T;
return x;
}
}
var c = new C(b, d1);
var r4 = c.foo(d1, d2); // Base
var r5 = c.foo2(b, d2); // Derived
var r6 = c.foo3(d1, d1); // Derived
var r7 = c.foo4(d1, d2); // Base
var r8 = c.foo5(d1, d2); // Derived
var r8b = c.foo5(d2, d2); // Derived2
var r9 = c.foo6(); // Derived
var r10 = c.foo7(d1); // Base
var r11 = c.foo8(); // Base
interface I<T extends Base, U extends Derived> {
new (t: T, u: U);
foo(t: T, u: U): T;
foo2(t: T, u: U): U;
foo3<T extends Derived>(t: T, u: U): T;
foo4<U extends Derived2>(t: T, u: U): T;
foo5<T extends Derived, U extends Derived2>(t: T, u: U): T;
foo6<T extends Derived, U extends Derived2>(): T;
foo7<T extends Base, U extends Derived>(u: U): T;
foo8<T extends Base, U extends Derived>(): T;
}
var i: I<Base, Derived>;
var r4 = i.foo(d1, d2); // Base
var r5 = i.foo2(b, d2); // Derived
var r6 = i.foo3(d1, d1); // Derived
var r7 = i.foo4(d1, d2); // Base
var r8 = i.foo5(d1, d2); // Derived
var r8b = i.foo5(d2, d2); // Derived2
var r9 = i.foo6(); // Derived
var r10 = i.foo7(d1); // Base
var r11 = i.foo8(); // Base
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithConstraintsTypeArgumentInference2.ts | TypeScript | // Generic call with parameters of T and U, U extends T, no parameter of type U
function foo<T, U extends T>(t: T) {
var u: U;
return u;
}
var r = foo(1); // ok
var r2 = foo(null); // {}
var r3 = foo(new Object()); // {}
var r4 = foo<Date, Date>(1); // error
var r5 = foo<Date, Date>(new Date()); // no error | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithConstructorTypedArguments5.ts | TypeScript | // Generic call with parameter of object type with member of function type of n args passed object whose associated member is call signature with n+1 args
function foo<T, U>(arg: { cb: new(t: T) => U }) {
return new arg.cb(null);
}
var arg: { cb: new<T>(x: T) => string };
var r = foo(arg); // {}
// more args not allowed
var arg2: { cb: new <T>(x: T, y: T) => string };
var r2 = foo(arg2); // error
var arg3: { cb: new (x: string, y: number) => string };
var r3 = foo(arg3); // error
function foo2<T, U>(arg: { cb: new(t: T, t2: T) => U }) {
return new arg.cb(null, null);
}
// fewer args ok
var r4 = foo(arg); // {}
var arg4: { cb: new (x: string) => string };
var r6 = foo(arg4); // string
var arg5: { cb: new () => string };
var r7 = foo(arg5); // string
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithFunctionTypedArguments.ts | TypeScript | // Generic functions used as arguments for function typed parameters are not used to make inferences from
// Using function arguments, no errors expected
function foo<T>(x: (a: T) => T) {
return x(null);
}
var r = foo(<U>(x: U) => ''); // {}
var r2 = foo<string>(<U>(x: U) => ''); // string
var r3 = foo(x => ''); // {}
function foo2<T, U>(x: T, cb: (a: T) => U) {
return cb(x);
}
var r4 = foo2(1, function <Z>(a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions
var r5 = foo2(1, (a) => ''); // string
var r6 = foo2<string, number>('', <Z>(a: Z) => 1);
function foo3<T, U>(x: T, cb: (a: T) => U, y: U) {
return cb(x);
}
var r7 = foo3(1, <Z>(a: Z) => '', ''); // string
var r8 = foo3(1, function (a) { return '' }, 1); // error
var r9 = foo3<number, string>(1, (a) => '', ''); // string
function other<T, U>(t: T, u: U) {
var r10 = foo2(1, (x: T) => ''); // error
var r10 = foo2(1, (x) => ''); // string
var r11 = foo3(1, (x: T) => '', ''); // error
var r11b = foo3(1, (x: T) => '', 1); // error
var r12 = foo3(1, function (a) { return '' }, 1); // error
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithFunctionTypedArguments2.ts | TypeScript | // Generic functions used as arguments for function typed parameters are not used to make inferences from
// Using construct signature arguments, no errors expected
function foo<T>(x: new(a: T) => T) {
return new x(null);
}
interface I {
new <T>(x: T): T;
}
interface I2<T> {
new (x: T): T;
}
var i: I;
var i2: I2<string>;
var a: {
new <T>(x: T): T;
}
var r = foo(i); // any
var r2 = foo<string>(i); // string
var r3 = foo(i2); // string
var r3b = foo(a); // any
function foo2<T, U>(x: T, cb: new(a: T) => U) {
return new cb(x);
}
var r4 = foo2(1, i2); // error
var r4b = foo2(1, a); // any
var r5 = foo2(1, i); // any
var r6 = foo2<string, string>('', i2); // string
function foo3<T, U>(x: T, cb: new(a: T) => U, y: U) {
return new cb(x);
}
var r7 = foo3(null, i, ''); // any
var r7b = foo3(null, a, ''); // any
var r8 = foo3(1, i2, 1); // error
var r9 = foo3<string, string>('', i2, ''); // string | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithFunctionTypedArguments3.ts | TypeScript | // No inference is made from function typed arguments which have multiple call signatures
var a: {
(x: boolean): boolean;
(x: string): any;
}
function foo4<T, U>(cb: (x: T) => U) {
var u: U;
return u;
}
var r = foo4(a); // T is {} (candidates boolean and string), U is any (candidates any and boolean)
var b: {
<T>(x: boolean): T;
<T>(x: T): any;
}
var r2 = foo4(b); // T is {} (candidates boolean and {}), U is any (candidates any and {}) | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithFunctionTypedArguments4.ts | TypeScript | // No inference is made from function typed arguments which have multiple call signatures
class C { foo: string }
class D { bar: string }
var a: {
new(x: boolean): C;
new(x: string): D;
}
function foo4<T, U>(cb: new(x: T) => U) {
var u: U;
return u;
}
var r = foo4(a); // T is {} (candidates boolean and string), U is {} (candidates C and D)
var b: {
new<T>(x: boolean): T;
new<T>(x: T): any;
}
var r2 = foo4(b); // T is {} (candidates boolean and {}), U is any (candidates any and {}) | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithFunctionTypedArguments5.ts | TypeScript | // Generic call with parameter of object type with member of function type of n args passed object whose associated member is call signature with n+1 args
function foo<T, U>(arg: { cb: (t: T) => U }) {
return arg.cb(null);
}
var arg = { cb: <T>(x: T) => '' };
var r = foo(arg); // {}
// more args not allowed
var r2 = foo({ cb: <T>(x: T, y: T) => '' }); // error
var r3 = foo({ cb: (x: string, y: number) => '' }); // error
function foo2<T, U>(arg: { cb: (t: T, t2: T) => U }) {
return arg.cb(null, null);
}
// fewer args ok
var r4 = foo(arg); // {}
var r5 = foo({ cb: <T>(x: T) => '' }); // {}
var r6 = foo({ cb: (x: string) => '' }); // string
var r7 = foo({ cb: () => '' }); // string
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithGenericSignatureArguments.ts | TypeScript | // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made,
// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them.
function foo<T>(a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
//var r1 = foo((x: number) => 1, (x: string) => ''); // error
var r1b = foo((x) => 1, (x) => ''); // {} => {}
var r2 = foo((x: Object) => null, (x: string) => ''); // Object => Object
var r3 = foo((x: number) => 1, (x: Object) => null); // number => number
var r3ii = foo((x: number) => 1, (x: number) => 1); // number => number
var a: { x: number; y?: number; };
var b: { x: number; z?: number; };
var r4 = foo((x: typeof a) => a, (x: typeof b) => b); // typeof a => typeof a
var r5 = foo((x: typeof b) => b, (x: typeof a) => a); // typeof b => typeof b
function other<T>(x: T) {
var r6 = foo((a: T) => a, (b: T) => b); // T => T
var r6b = foo((a) => a, (b) => b); // {} => {}
}
function other2<T extends Date>(x: T) {
var r7 = foo((a: T) => a, (b: T) => b); // T => T
var r7b = foo((a) => a, (b) => b); // {} => {}
var r8 = r7(null);
// BUG 835518
//var r9 = r7(new Date());
}
function foo2<T extends Date>(a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
function other3<T extends RegExp>(x: T) {
var r8 = foo2((a: Date) => a, (b: Date) => b); // Date => Date
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithGenericSignatureArguments2.ts | TypeScript | // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made,
// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them.
module onlyT {
function foo<T>(a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => '');
function other2<T extends Date>(x: T) {
var r7 = foo((a: T) => a, (b: T) => b); // T => T
// BUG 835518
var r9 = r7(new Date()); // should be ok
var r10 = r7(1); // error
}
function foo2<T extends Date>(a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
function other3<T extends RegExp>(x: T) {
var r7 = foo2((a: T) => a, (b: T) => b); // error
var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date
}
enum E { A }
enum F { A }
function foo3<T>(x: T, a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error
}
module TU {
function foo<T, U>(a: (x: T) => T, b: (x: U) => U) {
var r: (x: T) => T;
return r;
}
var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => '');
function other2<T extends Date>(x: T) {
var r7 = foo((a: T) => a, (b: T) => b);
var r9 = r7(new Date());
var r10 = r7(1);
}
function foo2<T extends Date, U extends Date>(a: (x: T) => T, b: (x: U) => U) {
var r: (x: T) => T;
return r;
}
function other3<T extends RegExp>(x: T) {
var r7 = foo2((a: T) => a, (b: T) => b);
var r7b = foo2((a) => a, (b) => b);
}
enum E { A }
enum F { A }
function foo3<T>(x: T, a: (x: T) => T, b: (x: U) => U) {
var r: (x: T) => T;
return r;
}
var r7 = foo3(E.A, (x) => E.A, (x) => F.A);
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithGenericSignatureArguments3.ts | TypeScript | // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made,
// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them.
function foo<T>(x: T, a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
var r1 = foo('', (x: string) => '', (x: Object) => null); // any => any
var r1ii = foo('', (x) => '', (x) => null); // string => string
var r2 = foo('', (x: string) => '', (x: Object) => ''); // string => string
var r3 = foo(null, (x: Object) => '', (x: string) => ''); // Object => Object
var r4 = foo(null, (x) => '', (x) => ''); // any => any
var r5 = foo(new Object(), (x) => '', (x) => ''); // Object => Object
enum E { A }
enum F { A }
var r6 = foo(E.A, (x: number) => E.A, (x: F) => F.A); // number => number
function foo2<T, U>(x: T, a: (x: T) => U, b: (x: T) => U) {
var r: (x: T) => U;
return r;
}
var r8 = foo2('', (x) => '', (x) => null); // string => string
var r9 = foo2(null, (x) => '', (x) => ''); // any => any
var r10 = foo2(null, (x: Object) => '', (x: string) => ''); // Object => Object
var x: (a: string) => boolean;
var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // error
var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // error | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithNonSymmetricSubtypes.ts | TypeScript | // generic type argument inference where inference leads to two candidates that are both supertypes of all candidates
// we choose the first candidate so the result is dependent on the order of the arguments provided
function foo<T>(x: T, y: T) {
var r: T;
return r;
}
var a: { x: number; y?: number; };
var b: { x: number; z?: number; };
var r = foo(a, b); // { x: number; y?: number; };
var r2 = foo(b, a); // { x: number; z?: number; };
var x: { x: number; };
var y: { x?: number; };
var r3 = foo(a, x); // { x: number; y?: number; };
var r4 = foo(x, a); // { x: number; };
var r5 = foo(a, y); // { x?: number; };
var r5 = foo(y, a); // { x?: number; };
var r6 = foo(x, y); // { x?: number; };
var r6 = foo(y, x); // { x?: number; };
var s1: (x: Object) => string;
var s2: (x: string) => string;
var r7 = foo(s1, s2); // (x: Object) => string;
var r8 = foo(s2, s1); // (x: string) => string; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithObjectLiteralArgs.ts | TypeScript | function foo<T>(x: { bar: T; baz: T }) {
return x;
}
var r = foo({ bar: 1, baz: '' }); // error
var r2 = foo({ bar: 1, baz: 1 }); // T = number
var r3 = foo({ bar: foo, baz: foo }); // T = typeof foo
var r4 = foo<Object>({ bar: 1, baz: '' }); // T = Object | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithObjectTypeArgs.ts | TypeScript | class C {
private x: string;
}
class D {
private x: string;
}
class X<T> {
x: T;
}
function foo<T>(t: X<T>, t2: X<T>) {
var x: T;
return x;
}
var c1 = new X<C>();
var d1 = new X<D>();
var r = foo(c1, d1); // error
var r2 = foo(c1, c1); // ok | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithObjectTypeArgs2.ts | TypeScript | class Base {
x: string;
}
class Derived extends Base {
y: string;
}
class Derived2 extends Base {
z: string;
}
// returns {}[]
function f<T extends Base, U extends Base>(a: { x: T; y: U }) {
return [a.x, a.y];
}
var r = f({ x: new Derived(), y: new Derived2() }); // {}[]
var r2 = f({ x: new Base(), y: new Derived2() }); // {}[]
function f2<T extends Base, U extends Base>(a: { x: T; y: U }) {
return (x: T) => a.y;
}
var r3 = f2({ x: new Derived(), y: new Derived2() }); // Derived => Derived2
interface I<T, U> {
x: T;
y: U;
}
var i: I<Base, Derived>;
var r4 = f2(i); // Base => Derived | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithObjectTypeArgsAndConstraints.ts | TypeScript | // Generic call with constraints infering type parameter from object member properties
// No errors expected
class C {
x: string;
}
class D {
x: string;
y: string;
}
class X<T> {
x: T;
}
function foo<T extends { x: string }>(t: X<T>, t2: X<T>) {
var x: T;
return x;
}
var c1 = new X<C>();
var d1 = new X<D>();
var r = foo(c1, d1);
var r2 = foo(c1, c1);
function foo2<T extends C>(t: X<T>, t2: X<T>) {
var x: T;
return x;
}
var r = foo2(c1, d1);
var r2 = foo2(c1, c1); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithObjectTypeArgsAndConstraints2.ts | TypeScript | // Generic call with constraints infering type parameter from object member properties
// No errors expected
class Base {
x: string;
}
class Derived extends Base {
y: string;
}
function f<T extends Base>(x: { foo: T; bar: T }) {
var r: T;
return r;
}
var r = f({ foo: new Base(), bar: new Derived() });
var r2 = f({ foo: new Derived(), bar: new Derived() });
interface I<T> {
a: T;
}
function f2<T extends Base>(x: I<T>) {
var r: T;
return r;
}
var i: I<Derived>;
var r3 = f2(i);
function f3<T extends Base>(x: T, y: (a: T) => T) {
return y(null);
}
var r4 = f3(new Base(), x => x);
var r5 = f3(new Derived(), x => x);
var r6 = f3(null, null); // any
var r7 = f3(null, x => x); // any
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithObjectTypeArgsAndConstraints3.ts | TypeScript | // Generic call with constraints infering type parameter from object member properties
class Base {
x: string;
}
class Derived extends Base {
y: string;
}
class Derived2 extends Base {
z: string;
}
function f<T extends Base>(a: { x: T; y: T }) {
var r: T;
return r;
}
var r1 = f({ x: new Derived(), y: new Derived2() }); // error because neither is supertype of the other
function f2<T extends Base, U extends { x: T; y: T }>(a: U) {
var r: T;
return r;
}
var r2 = f2({ x: new Derived(), y: new Derived2() }); // ok
var r3 = f2({ x: new Derived(), y: new Derived2() }); // ok
function f3<T extends Base>(y: (a: T) => T, x: T) {
return y(null);
}
// all ok - second argument is processed before x is fixed
var r4 = f3(x => x, new Base());
var r5 = f3(x => x, new Derived());
var r6 = f3(x => x, null);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithObjectTypeArgsAndConstraints4.ts | TypeScript | // Generic call with constraints infering type parameter from object member properties
class C {
x: string;
}
class D {
x: string;
y: string;
}
function foo<T, U extends T>(t: T, t2: U) {
return (x: T) => t2;
}
var c: C;
var d: D;
var r = foo(c, d);
var r2 = foo(d, c); // error because C does not extend D
var r3 = foo(c, { x: '', foo: c });
var r4 = foo(null, null);
var r5 = foo({}, null);
var r6 = foo(null, {});
var r7 = foo({}, {});
var r8 = foo(() => { }, () => { });
var r9 = foo(() => { }, () => 1);
function other<T, U extends T>() {
var r4 = foo(c, d);
var r5 = foo<T, U>(c, d); // error
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithObjectTypeArgsAndConstraints5.ts | TypeScript | // Generic call with constraints infering type parameter from object member properties
class C {
x: string;
}
class D {
x: string;
y: string;
}
function foo<T, U extends T>(t: T, t2: U) {
return (x: T) => t2;
}
var c: C;
var d: D;
var r2 = foo(d, c); // the constraints are self-referencing, no downstream error
var r9 = foo(() => 1, () => { }); // the constraints are self-referencing, no downstream error
function other<T, U extends T>() {
var r5 = foo<T, U>(c, d); // error
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithObjectTypeArgsAndIndexers.ts | TypeScript | // Type inference infers from indexers in target type, no errors expected
function foo<T>(x: T) {
return x;
}
var a: {
[x: string]: Object;
[x: number]: Date;
};
var r = foo(a);
function other<T extends Date>(arg: T) {
var b: {
[x: string]: Object;
[x: number]: T
};
var r2 = foo(b);
var d = r2[1];
var e = r2['1'];
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithObjectTypeArgsAndIndexersErrors.ts | TypeScript | // Type inference infers from indexers in target type, error cases
function foo<T>(x: T) {
return x;
}
function other<T>(arg: T) {
var b: {
[x: string]: Object;
[x: number]: T; // ok, T is a subtype of Object because its apparent type is {}
};
var r2 = foo(b); // T
}
function other3<T extends U, U extends Date>(arg: T) {
var b: {
[x: string]: Object;
[x: number]: T;
};
var r2 = foo(b);
var d = r2[1];
var e = r2['1'];
var u: U = r2[1]; // ok
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithObjectTypeArgsAndInitializers.ts | TypeScript | // Generic typed parameters with initializers
function foo<T>(x: T = null) { return x; } // ok
function foo2<T>(x: T = undefined) { return x; } // ok
function foo3<T extends Number>(x: T = 1) { } // error
function foo4<T, U extends T>(x: T, y: U = x) { } // error
function foo5<T, U extends T>(x: U, y: T = x) { } // ok
function foo6<T, U extends T, V extends U>(x: T, y: U, z: V = y) { } // error
function foo7<T, U extends T, V extends U>(x: V, y: U = x) { } // should be ok | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithObjectTypeArgsAndNumericIndexer.ts | TypeScript | // Type inference infers from indexers in target type, no errors expected
function foo<T>(x: T) {
return x;
}
var a: { [x: number]: Date };
var r = foo(a);
function other<T>(arg: T) {
var b: { [x: number]: T };
var r2 = foo(b); // T
}
function other2<T extends Date>(arg: T) {
var b: { [x: number]: T };
var r2 = foo(b);
var d = r2[1];
}
function other3<T extends Date, U extends Date>(arg: T) {
var b: { [x: number]: T };
var r2 = foo(b);
var d = r2[1];
// BUG 821629
//var u: U = r2[1]; // ok
}
//function other3<T extends U, U extends Date>(arg: T) {
// var b: { [x: number]: T };
// var r2 = foo(b);
// var d = r2[1];
// // BUG 821629
// //var u: U = r2[1]; // ok
//} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithObjectTypeArgsAndStringIndexer.ts | TypeScript | // Type inference infers from indexers in target type, no errors expected
function foo<T>(x: T) {
return x;
}
var a: { [x: string]: Date };
var r = foo(a);
function other<T>(arg: T) {
var b: { [x: string]: T };
var r2 = foo(b); // T
}
function other2<T extends Date>(arg: T) {
var b: { [x: string]: T };
var r2 = foo(b);
var d: Date = r2['hm']; // ok
}
function other3<T extends Date, U extends Date>(arg: T) {
var b: { [x: string]: T };
var r2 = foo(b);
var d: Date = r2['hm']; // ok
// BUG 821629
//var u: U = r2['hm']; // ok
}
//function other3<T extends U, U extends Date>(arg: T) {
// var b: { [x: string]: T };
// var r2 = foo(b);
// var d: Date = r2['hm']; // ok
// // BUG 821629
// //var u: U = r2['hm']; // ok
//} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithOverloadedConstructorTypedArguments.ts | TypeScript | // Function typed arguments with multiple signatures must be passed an implementation that matches all of them
// Inferences are made quadratic-pairwise to and from these overload sets
module NonGenericParameter {
var a: {
new(x: boolean): boolean;
new(x: string): string;
}
function foo4(cb: typeof a) {
return new cb(null);
}
var r = foo4(a);
var b: { new <T>(x: T): T };
var r2 = foo4(b);
}
module GenericParameter {
function foo5<T>(cb: { new(x: T): string; new(x: number): T }) {
return cb;
}
var a: {
new (x: boolean): string;
new (x: number): boolean;
}
var r5 = foo5(a); // new{} => string; new(x:number) => {}
var b: { new<T>(x: T): string; new<T>(x: number): T; }
var r7 = foo5(b); // new any => string; new(x:number) => any
function foo6<T>(cb: { new(x: T): string; new(x: T, y?: T): string }) {
return cb;
}
var r8 = foo6(a); // error
var r9 = foo6(b); // new any => string; new(x:any, y?:any) => string
function foo7<T>(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }) {
return cb;
}
var r13 = foo7(1, b); // new any => string; new(x:any, y?:any) => string
var c: { new <T>(x: T): string; <T>(x: number): T; }
var c2: { new <T>(x: T): string; new<T>(x: number): T; }
var r14 = foo7(1, c); // new any => string; new(x:any, y?:any) => string
var r15 = foo7(1, c2); // new any => string; new(x:any, y?:any) => string
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithOverloadedConstructorTypedArguments2.ts | TypeScript | // Function typed arguments with multiple signatures must be passed an implementation that matches all of them
// Inferences are made quadratic-pairwise to and from these overload sets
module NonGenericParameter {
var a: {
new(x: boolean): boolean;
new(x: string): string;
}
function foo4(cb: typeof a) {
return cb;
}
var b: { new <T, U>(x: T): U }
var r3 = foo4(b); // ok
}
module GenericParameter {
function foo5<T>(cb: { new(x: T): string; new(x: number): T }) {
return cb;
}
var a: { new <T>(x: T): T };
var r6 = foo5(a); // ok
function foo6<T>(cb: { new(x: T): string; new(x: T, y?: T): string }) {
return cb;
}
var b: { new <T>(x: T, y: T): string };
var r10 = foo6(b); // error
function foo7<T>(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }) {
return cb;
}
var r13 = foo7(1, a); // ok
var c: { new<T>(x: T): number; new<T>(x: number): T; }
var r14 = foo7(1, c); // ok
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithOverloadedFunctionTypedArguments.ts | TypeScript | // Function typed arguments with multiple signatures must be passed an implementation that matches all of them
// Inferences are made quadratic-pairwise to and from these overload sets
module NonGenericParameter {
var a: {
(x: boolean): boolean;
(x: string): string;
}
function foo4(cb: typeof a) {
return cb;
}
var r = foo4(a);
var r2 = foo4(<T>(x: T) => x);
var r4 = foo4(x => x);
}
module GenericParameter {
function foo5<T>(cb: { (x: T): string; (x: number): T }) {
return cb;
}
var r5 = foo5(x => x); // any => string (+1 overload) [inferences are made for T, but lambda not contextually typed]. T is any
var a: { <T>(x: T): string; <T>(x: number): T; }
var r7 = foo5(a); // any => string (+1 overload)
function foo6<T>(cb: { (x: T): string; (x: T, y?: T): string }) {
return cb;
}
var r8 = foo6(x => x); // any => string (+1 overload) [inferences are made for T, but lambda not contextually typed]. T is any
var r9 = foo6(<T>(x: T) => ''); // any => string (+1 overload)
var r11 = foo6(<T>(x: T, y?: T) => ''); // any => string (+1 overload)
function foo7<T>(x:T, cb: { (x: T): string; (x: T, y?: T): string }) {
return cb;
}
var r12 = foo7(1, (x) => x); // any => string (+1 overload) [inferences are made for T, but lambda not contextually typed]
var r13 = foo7(1, <T>(x: T) => ''); // any => string (+1 overload) [inferences are made for T, but lambda not contextually typed]
var a: { <T>(x: T): string; <T>(x: number): T; }
var r14 = foo7(1, a); // any => string (+1 overload) [inferences are made for T, but lambda not contextually typed]
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithOverloadedFunctionTypedArguments2.ts | TypeScript | // Function typed arguments with multiple signatures must be passed an implementation that matches all of them
// Inferences are made quadratic-pairwise to and from these overload sets
module NonGenericParameter {
var a: {
(x: boolean): boolean;
(x: string): string;
}
function foo4(cb: typeof a) {
return cb;
}
var r3 = foo4(<T, U>(x: T) => { var r: U; return r }); // ok
}
module GenericParameter {
function foo5<T>(cb: { (x: T): string; (x: number): T }) {
return cb;
}
var r6 = foo5(<T>(x: T) => x); // ok
function foo6<T>(cb: { (x: T): string; (x: T, y?: T): string }) {
return cb;
}
var r10 = foo6(<T>(x: T, y: T) => ''); // error
function foo7<T>(x:T, cb: { (x: T): string; (x: T, y?: T): string }) {
return cb;
}
var r13 = foo7(1, <T>(x: T) => x); // ok
var a: { <T>(x: T): number; <T>(x: number): T; }
var r14 = foo7(1, a); // ok
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericCallWithTupleType.ts | TypeScript | interface I<T, U> {
tuple1: [T, U];
}
var i1: I<string, number>;
var i2: I<{}, {}>;
// no error
i1.tuple1 = ["foo", 5];
var e1 = i1.tuple1[0]; // string
var e2 = i1.tuple1[1]; // number
i1.tuple1 = ["foo", 5, false, true];
var e3 = i1.tuple1[2]; // {}
i1.tuple1[3] = { a: "string" };
var e4 = i1.tuple1[3]; // {}
i2.tuple1 = ["foo", 5];
i2.tuple1 = ["foo", "bar"];
i2.tuple1 = [5, "bar"];
i2.tuple1 = [{}, {}];
// error
i1.tuple1 = [5, "foo"];
i1.tuple1 = [{}, {}];
i2.tuple1 = [{}];
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericClassExpressionInFunction.ts | TypeScript | class A<T> {
genericVar: T
}
function B1<U>() {
// class expression can use T
return class extends A<U> { }
}
class B2<V> {
anon = class extends A<V> { }
}
function B3<W>() {
return class Inner<TInner> extends A<W> { }
}
// extends can call B
class K extends B1<number>() {
namae: string;
}
class C extends (new B2<number>().anon) {
name: string;
}
let b3Number = B3<number>();
class S extends b3Number<string> {
nom: string;
}
var c = new C();
var k = new K();
var s = new S();
c.genericVar = 12;
k.genericVar = 12;
s.genericVar = 12;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericClassWithFunctionTypedMemberArguments.ts | TypeScript | // Generic functions used as arguments for function typed parameters are not used to make inferences from
// Using function arguments, no errors expected
module ImmediatelyFix {
class C<T> {
foo<T>(x: (a: T) => T) {
return x(null);
}
}
var c = new C<number>();
var r = c.foo(<U>(x: U) => ''); // {}
var r2 = c.foo<string>(<U>(x: U) => ''); // string
var r3 = c.foo(x => ''); // {}
class C2<T> {
foo(x: (a: T) => T) {
return x(null);
}
}
var c2 = new C2<number>();
var ra = c2.foo(<U>(x: U) => 1); // number
var r3a = c2.foo(x => 1); // number
}
module WithCandidates {
class C<T> {
foo2<T, U>(x: T, cb: (a: T) => U) {
return cb(x);
}
}
var c: C<number>;
var r4 = c.foo2(1, function <Z>(a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions
var r5 = c.foo2(1, (a) => ''); // string
var r6 = c.foo2<string, number>('', <Z>(a: Z) => 1); // number
class C2<T, U> {
foo3(x: T, cb: (a: T) => U, y: U) {
return cb(x);
}
}
var c2: C2<number, string>;
var r7 = c2.foo3(1, <Z>(a: Z) => '', ''); // string
var r8 = c2.foo3(1, function (a) { return '' }, ''); // string
class C3<T, U> {
foo3<T,U>(x: T, cb: (a: T) => U, y: U) {
return cb(x);
}
}
var c3: C3<number, string>;
function other<T, U>(t: T, u: U) {
var r10 = c.foo2(1, (x: T) => ''); // error
var r10 = c.foo2(1, (x) => ''); // string
var r11 = c3.foo3(1, (x: T) => '', ''); // error
var r11b = c3.foo3(1, (x: T) => '', 1); // error
var r12 = c3.foo3(1, function (a) { return '' }, 1); // error
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericClassWithObjectTypeArgsAndConstraints.ts | TypeScript | // Generic call with constraints infering type parameter from object member properties
// No errors expected
class C {
x: string;
}
class D {
x: string;
y: string;
}
class X<T> {
x: T;
}
module Class {
class G<T extends { x: string }> {
foo<T extends { x: string }>(t: X<T>, t2: X<T>) {
var x: T;
return x;
}
}
var c1 = new X<C>();
var d1 = new X<D>();
var g: G<{ x: string; y: string }>;
var r = g.foo(c1, d1);
var r2 = g.foo(c1, c1);
class G2<T extends C> {
foo2<T extends C>(t: X<T>, t2: X<T>) {
var x: T;
return x;
}
}
var g2: G2<D>;
var r = g2.foo2(c1, d1);
var r2 = g2.foo2(c1, c1);
}
module Interface {
interface G<T extends { x: string }> {
foo<T extends { x: string }>(t: X<T>, t2: X<T>): T;
}
var c1 = new X<C>();
var d1 = new X<D>();
var g: G<{ x: string; y: string }>;
var r = g.foo(c1, d1);
var r2 = g.foo(c1, c1);
interface G2<T extends C> {
foo2<T extends C>(t: X<T>, t2: X<T>): T;
}
var g2: G2<D>;
var r = g2.foo2(c1, d1);
var r2 = g2.foo2(c1, c1);
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericContextualTypes1.ts | TypeScript | // @strict: true
// @declaration: true
type Box<T> = { value: T };
declare function wrap<A, B>(f: (a: A) => B): (a: A) => B;
declare function compose<A, B, C>(f: (a: A) => B, g: (b: B) => C): (a: A) => C;
declare function list<T>(a: T): T[];
declare function unlist<T>(a: T[]): T;
declare function box<V>(x: V): Box<V>;
declare function unbox<W>(x: Box<W>): W;
declare function map<T, U>(a: T[], f: (x: T) => U): U[];
declare function identity<T>(x: T): T;
declare function zip<A, B>(a: A, b: B): [A, B];
declare function flip<X, Y, Z>(f: (x: X, y: Y) => Z): (y: Y, x: X) => Z;
const f00: <A>(x: A) => A[] = list;
const f01: <A>(x: A) => A[] = x => [x];
const f02: <A>(x: A) => A[] = wrap(list);
const f03: <A>(x: A) => A[] = wrap(x => [x]);
const f10: <T>(x: T) => Box<T[]> = compose(a => list(a), b => box(b));
const f11: <T>(x: T) => Box<T[]> = compose(list, box);
const f12: <T>(x: Box<T[]>) => T = compose(a => unbox(a), b => unlist(b));
const f13: <T>(x: Box<T[]>) => T = compose(unbox, unlist);
const arrayMap = <T, U>(f: (x: T) => U) => (a: T[]) => a.map(f);
const arrayFilter = <T>(f: (x: T) => boolean) => (a: T[]) => a.filter(f);
const f20: (a: string[]) => number[] = arrayMap(x => x.length);
const f21: <A>(a: A[]) => A[][] = arrayMap(x => [x]);
const f22: <A>(a: A[]) => A[] = arrayMap(identity);
const f23: <A>(a: A[]) => Box<A>[] = arrayMap(value => ({ value }));
const f30: (a: string[]) => string[] = arrayFilter(x => x.length > 10);
const f31: <T extends Box<number>>(a: T[]) => T[] = arrayFilter(x => x.value > 10);
const f40: <A, B>(b: B, a: A) => [A, B] = flip(zip);
// Repro from #16293
type fn = <A>(a: A) => A;
const fn: fn = a => a;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericContextualTypes2.ts | TypeScript | // @strict: true
// @noEmit: true
type LowInfer<T> = T & {};
type PartialAssigner<TContext, TKey extends keyof TContext> = (
context: TContext
) => TContext[TKey];
type PropertyAssigner<TContext> = {
[K in keyof TContext]?: PartialAssigner<TContext, K> | TContext[K];
};
type Meta<TContext> = {
action: (ctx: TContext) => void
}
interface AssignAction<TContext> {
type: "xstate.assign";
exec: (arg: TContext, meta: Meta<TContext>) => void;
}
declare function assign<TContext>(
assignment: PropertyAssigner<LowInfer<TContext>>
): AssignAction<TContext>;
type Config<TContext> = {
context: TContext;
entry?: AssignAction<TContext>;
};
declare function createMachine<TContext>(config: Config<TContext>): void;
createMachine<{ count: number }>({
context: {
count: 0,
},
entry: assign({
count: (ctx: { count: number }) => ++ctx.count,
}),
});
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericContextualTypes3.ts | TypeScript | // @strict: true
// @noEmit: true
type LowInfer<T> = T & {};
type PartialAssigner<TContext, TKey extends keyof TContext> = (
context: TContext
) => TContext[TKey];
type PropertyAssigner<TContext> = {
[K in keyof TContext]?: PartialAssigner<TContext, K> | TContext[K];
};
type Meta<TContext> = {
action: (ctx: TContext) => void
}
interface AssignAction<TContext> {
type: "xstate.assign";
(arg: TContext, meta: Meta<TContext>): void;
}
declare function assign<TContext>(
assignment: PropertyAssigner<LowInfer<TContext>>
): AssignAction<TContext>;
type Config<TContext> = {
context: TContext;
entry?: AssignAction<TContext>;
};
declare function createMachine<TContext>(config: Config<TContext>): void;
createMachine<{ count: number }>({
context: {
count: 0,
},
entry: assign({
count: (ctx: { count: number }) => ++ctx.count,
}),
});
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericFunctionParameters.ts | TypeScript | // @strict: true
// @declaration: true
declare function f1<T>(cb: <S>(x: S) => T): T;
declare function f2<T>(cb: <S extends number>(x: S) => T): T;
declare function f3<T>(cb: <S extends Array<S>>(x: S) => T): T;
let x1 = f1(x => x); // {}
let x2 = f2(x => x); // number
let x3 = f3(x => x); // Array<any>
// Repro from #19345
declare const s: <R>(go: <S>(ops: { init(): S; }) => R) => R;
const x = s(a => a.init()); // x is any, should have been {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericInstantiationEquivalentToObjectLiteral.ts | TypeScript | interface Pair<T1, T2> { first: T1; second: T2; }
var x: Pair<string, number>
var y: { first: string; second: number; }
x = y;
y = x;
declare function f<T, U>(x: Pair<T, U>);
declare function f2<T, U>(x: { first: T; second: U; });
f(x);
f(y);
f2(x);
f2(y); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericObjectRest.ts | TypeScript | // @strict: true
// @target: es2015
const a = 'a';
function f1<T extends { a: string, b: number }>(obj: T) {
let { ...r0 } = obj;
let { a: a1, ...r1 } = obj;
let { a: a2, b: b2, ...r2 } = obj;
let { 'a': a3, ...r3 } = obj;
let { ['a']: a4, ...r4 } = obj;
let { [a]: a5, ...r5 } = obj;
}
const sa = Symbol();
const sb = Symbol();
function f2<T extends { [sa]: string, [sb]: number }>(obj: T) {
let { [sa]: a1, [sb]: b1, ...r1 } = obj;
}
function f3<T, K1 extends keyof T, K2 extends keyof T>(obj: T, k1: K1, k2: K2) {
let { [k1]: a1, [k2]: a2, ...r1 } = obj;
}
type Item = { a: string, b: number, c: boolean };
function f4<K1 extends keyof Item, K2 extends keyof Item>(obj: Item, k1: K1, k2: K2) {
let { [k1]: a1, [k2]: a2, ...r1 } = obj;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericRestArity.ts | TypeScript | // Repro from #25559
declare function call<TS extends unknown[]>(
handler: (...args: TS) => void,
...args: TS): void;
call((x: number, y: number) => x + y);
call((x: number, y: number) => x + y, 1, 2, 3, 4, 5, 6, 7);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericRestArityStrict.ts | TypeScript | // @strict: true
// Repro from #25559
declare function call<TS extends unknown[]>(
handler: (...args: TS) => void,
...args: TS): void;
call((x: number, y: number) => x + y);
call((x: number, y: number) => x + y, 1, 2, 3, 4, 5, 6, 7);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericRestParameters1.ts | TypeScript | // @strict: true
// @declaration: true
declare let f1: (...x: [number, string, boolean]) => void;
declare let f2: (x0: number, x1: string, x2: boolean) => void;
f1 = f2;
f2 = f1;
declare const t3: [number, string, boolean];
declare const t2: [string, boolean];
declare const t1: [boolean];
declare const t0: [];
declare const ns: [number, string];
declare const sn: [string, number];
f1(42, "hello", true);
f1(t3[0], t3[1], t3[2]);
f1(...t3);
f1(42, ...t2);
f1(42, "hello", ...t1);
f1(42, "hello", true, ...t0);
f1(ns[0], ns[1], true);
f1(...ns, true); // FIXME: Error, since ...ns is considered as string|number here
f2(42, "hello", true);
f2(t3[0], t3[1], t3[2]);
f2(...t3);
f2(42, ...t2);
f2(42, "hello", ...t1);
f2(42, "hello", true, ...t0);
f2(ns[0], ns[1], true);
f2(...ns, true); // FIXME: Error, since ...ns is considered as string|number here
declare function f10<T extends unknown[]>(...args: T): T;
const x10 = f10(42, "hello", true); // [number, string, boolean]
const x11 = f10(42, "hello"); // [number, string]
const x12 = f10(42); // [number]
const x13 = f10(); // []
const x14 = f10(...t3); // [number, string, boolean]
const x15 = f10(42, ...t2); // [number, string, boolean]
const x16 = f10(42, "hello", ...t1); // [number, string, boolean]
const x17 = f10(42, "hello", true, ...t0); // [number, string, boolean]
const x18 = f10(...ns, true); // (string | number | boolean)[]
function g10<U extends string[], V extends [number, number]>(u: U, v: V) {
let x1 = f10(...u); // U
let x2 = f10(...v); // V
let x3 = f10(1, ...u); // [number, ...string[]]
let x4 = f10(...u, ...v); // (string | number)[]
}
declare function f11<T extends (string | number | boolean)[]>(...args: T): T;
const z10 = f11(42, "hello", true); // [42, "hello", true]
const z11 = f11(42, "hello"); // [42, "hello"]
const z12 = f11(42); // [42]
const z13 = f11(); // []
const z14 = f11(...t3); // [number, string, boolean]
const z15 = f11(42, ...t2); // [42, string, boolean]
const z16 = f11(42, "hello", ...t1); // [42, "hello", boolean]
const z17 = f11(42, "hello", true, ...t0); // [42, "hello", true]
const z18 = f11(...ns, true); // (string | number | true)[]
function g11<U extends string[], V extends [number, number]>(u: U, v: V) {
let x1 = f11(...u); // U
let x2 = f11(...v); // V
let x3 = f11(1, ...u); // [1, ...string[]]
let x4 = f11(...u, ...v); // (string | number)[]
}
function call<T extends unknown[], U>(f: (...args: T) => U, ...args: T) {
return f(...args);
}
function callr<T extends unknown[], U>(args: T, f: (...args: T) => U) {
return f(...args);
}
declare function f15(a: string, b: number): string | number;
declare function f16<A, B>(a: A, b: B): A | B;
let x20 = call((x, y) => x + y, 10, 20); // number
let x21 = call((x, y) => x + y, 10, "hello"); // string
let x22 = call(f15, "hello", 42); // string | number
let x23 = call(f16, "hello", 42); // unknown
let x24 = call<[string, number], string | number>(f16, "hello", 42); // string | number
let x30 = callr(sn, (x, y) => x + y); // string
let x31 = callr(sn, f15); // string | number
let x32 = callr(sn, f16); // string | number
function bind<T, U extends unknown[], V>(f: (x: T, ...rest: U) => V, x: T) {
return (...rest: U) => f(x, ...rest);
}
declare const f20: (x: number, y: string, z: boolean) => string[];
const f21 = bind(f20, 42); // (y: string, z: boolean) => string[]
const f22 = bind(f21, "hello"); // (z: boolean) => string[]
const f23 = bind(f22, true); // () => string[]
f20(42, "hello", true);
f21("hello", true);
f22(true);
f23();
declare const g20: (x: number, y?: string, z?: boolean) => string[];
const g21 = bind(g20, 42); // (y: string, z: boolean) => string[]
const g22 = bind(g21, "hello"); // (z: boolean) => string[]
const g23 = bind(g22, true); // () => string[]
g20(42, "hello", true);
g20(42, "hello");
g20(42);
g21("hello", true);
g21("hello");
g21();
g22(true);
g22();
g23();
declare function f30<T, U extends ((x: T) => any)[]>(x: T, ...args: U): U;
const c30 = f30(42, x => "" + x, x => x + 1); // [(x: number) => string, (x: number) => number]
type T01 = Parameters<(x: number, y: string, z: boolean) => void>;
type T02 = Parameters<(...args: [number, string, boolean]) => void>;
type T03 = ConstructorParameters<new (x: number, y: string, z: boolean) => void>;
type T04 = ConstructorParameters<new (...args: [number, string, boolean]) => void>;
type T05<T> = Parameters<(...args: T[]) => void>;
type T06<T> = ConstructorParameters<new (...args: []) => void>;
type T07<T extends any[]> = Parameters<(...args: T) => void>;
type T08<T extends any[]> = ConstructorParameters<new (...args: T) => void>;
type T09 = Parameters<Function>;
type Record1 = {
move: [number, 'left' | 'right'];
jump: [number, 'up' | 'down'];
stop: string;
done: [];
}
type EventType<T> = {
emit<K extends keyof T = keyof T>(e: K, ...payload: T[K] extends any[] ? T[K] : [T[K]]): void;
}
declare var events: EventType<Record1>;
events.emit('move', 10, 'left');
events.emit('jump', 20, 'up');
events.emit('stop', 'Bye!');
events.emit('done');
// Repro from #25871
declare var ff1: (... args: any[]) => void;
declare var ff2: () => void;
declare var ff3: (...args: []) => void;
declare var ff4: (a: never) => void;
ff1 = ff2;
ff1 = ff3;
ff1 = ff4; // Error
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericRestParameters2.ts | TypeScript | // @strict: true
// @declaration: true
declare const t1: [number, string, ...boolean[]];
declare const t2: [string, ...boolean[]];
declare const t3: [...boolean[]];
declare const t4: [];
declare let f00: (...x: [number, string, boolean]) => void;
declare let f01: (a: number, ...x: [string, boolean]) => void;
declare let f02: (a: number, b: string, ...x: [boolean]) => void;
declare let f03: (a: number, b: string, c: boolean) => void;
declare let f04: (a: number, b: string, c: boolean, ...x: []) => void;
declare let f10: (...x: [number, string, ...boolean[]]) => void;
declare let f11: (a: number, ...x: [string, ...boolean[]]) => void;
declare let f12: (a: number, b: string, ...x: [...boolean[]]) => void;
declare let f13: (a: number, b: string, ...c: boolean[]) => void;
declare const ns: [number, string];
declare const sn: [string, number];
f10(42, "hello");
f10(42, "hello", true);
f10(42, "hello", true, false);
f10(t1[0], t1[1], t1[2], t1[3]);
f10(...t1);
f10(42, ...t2);
f10(42, "hello", ...t3);
f10(42, "hello", true, ...t4);
f10(42, "hello", true, ...t4, false, ...t3);
f11(42, "hello");
f11(42, "hello", true);
f11(42, "hello", true, false);
f11(t1[0], t1[1], t1[2], t1[3]);
f11(...t1);
f11(42, ...t2);
f11(42, "hello", ...t3);
f11(42, "hello", true, ...t4);
f11(42, "hello", true, ...t4, false, ...t3);
f12(42, "hello");
f12(42, "hello", true);
f12(42, "hello", true, false);
f12(t1[0], t1[1], t1[2], t1[3]);
f12(...t1);
f12(42, ...t2);
f12(42, "hello", ...t3);
f12(42, "hello", true, ...t4);
f12(42, "hello", true, ...t4, false, ...t3);
f13(42, "hello");
f13(42, "hello", true);
f13(42, "hello", true, false);
f13(t1[0], t1[1], t1[2], t1[3]);
f13(...t1);
f13(42, ...t2);
f13(42, "hello", ...t3);
f13(42, "hello", true, ...t4);
f13(42, "hello", true, ...t4, false, ...t3);
declare const f20: <T extends unknown[]>(...args: T) => T;
f20(...t1);
f20(42, ...t2);
f20(42, "hello", ...t3);
f20(42, "hello", ...t2, true);
type T01 = Parameters<(x: number, y: string, ...z: boolean[]) => void>;
type T02 = Parameters<(...args: [number, string, ...boolean[]]) => void>;
type T03 = ConstructorParameters<new (x: number, y: string, ...z: boolean[]) => void>;
type T04 = ConstructorParameters<new (...args: [number, string, ...boolean[]]) => void>;
type T05<T extends any[]> = Parameters<(x: string, ...args: T) => void>;
type T06 = T05<[number, ...boolean[]]>;
type P1<T extends Function> = T extends (head: infer A, ...tail: infer B) => any ? { head: A, tail: B } : any[];
type T10 = P1<(x: number, y: string, ...z: boolean[]) => void>;
type T11 = P1<(...z: number[]) => void>;
type T12 = P1<(x: number, y: number) => void>;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericRestParameters3.ts | TypeScript | // @strict: true
// @declaration: true
declare let f1: (x: string, ...args: [string] | [number, boolean]) => void;
declare let f2: (x: string, y: string) => void;
declare let f3: (x: string, y: number, z: boolean) => void;
declare let f4: (...args: [string, string] | [string, number, boolean]) => void;
declare const t1: [string] | [number, boolean];
declare const t2: readonly [string] | [number, boolean];
declare const t3: [string] | readonly [number, boolean];
declare const t4: readonly [string] | readonly [number, boolean];
f1("foo", "abc");
f1("foo", 10, true);
f1("foo", ...t1);
f1("foo", ...t2);
f1("foo", ...t3);
f1("foo", ...t4);
f1("foo", 10); // Error
f1("foo"); // Error
f2 = f1;
f3 = f1;
f4 = f1;
f1 = f2; // Error
f1 = f3; // Error
f1 = f4;
// Repro from #26110
interface CoolArray<E> extends Array<E> {
hello: number;
}
declare function foo<T extends any[]>(cb: (...args: T) => void): void;
foo<CoolArray<any>>(); // Error
foo<CoolArray<any>>(100); // Error
foo<CoolArray<any>>(foo); // Error
function bar<T extends any[]>(...args: T): T {
return args;
}
let a = bar(10, 20);
let b = bar<CoolArray<number>>(10, 20); // Error
declare function baz<T>(...args: CoolArray<T>): void;
declare const ca: CoolArray<number>;
baz(); // Error
baz(1); // Error
baz(1, 2); // Error
baz(...ca); // Error
// Repro from #26491
declare function hmm<A extends [] | [number, string]>(...args: A): void;
hmm(); // okay, A = []
hmm(1, "s"); // okay, A = [1, "s"]
hmm("what"); // no error? A = [] | [number, string] ?
// Repro from #35066
declare function foo2(...args: string[] | number[]): void;
let x2: ReadonlyArray<string> = ["hello"];
foo2(...x2);
// Repros from #47754
type RestParams = [y: string] | [y: number];
type Signature = (x: string, ...rest: RestParams) => void;
type MergedParams = Parameters<Signature>; // [x: string, y: string] | [x: string, y: number]
declare let ff1: (...rest: [string, string] | [string, number]) => void;
declare let ff2: (x: string, ...rest: [string] | [number]) => void;
ff1 = ff2;
ff2 = ff1;
function ff3<A extends unknown[]>(s1: (...args: [x: string, ...rest: A | [number]]) => void, s2: (x: string, ...rest: A | [number]) => void) {
s1 = s2;
s2 = s1;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericSetterInClassType.ts | TypeScript | // @target: esnext
module Generic {
class C<T> {
get y(): T {
return 1 as never;
}
set y(v) { }
}
var c = new C<number>();
c.y = c.y;
class Box<T> {
#value!: T;
get value() {
return this.#value;
}
set value(value) {
this.#value = value;
}
}
new Box<number>().value = 3;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericSetterInClassTypeJsDoc.ts | TypeScript | // @target: esnext
// @lib: esnext
// @declaration: true
// @allowJs: true
// @checkJs: true
// @filename: genericSetterInClassTypeJsDoc.js
// @outFile: genericSetterInClassTypeJsDoc-out.js
/**
* @template T
*/
class Box {
#value;
/** @param {T} initialValue */
constructor(initialValue) {
this.#value = initialValue;
}
/** @type {T} */
get value() {
return this.#value;
}
set value(value) {
this.#value = value;
}
}
new Box(3).value = 3;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/genericTypeAliases.ts | TypeScript | type Tree<T> = T | { left: Tree<T>, right: Tree<T> };
var tree: Tree<number> = {
left: {
left: 0,
right: {
left: 1,
right: 2
},
},
right: 3
};
type Lazy<T> = T | (() => T);
var ls: Lazy<string>;
ls = "eager";
ls = () => "lazy";
type Foo<T> = T | { x: Foo<T> };
type Bar<U> = U | { x: Bar<U> };
// Deeply instantiated generics
var x: Foo<string>;
var y: Bar<string>;
x = y;
y = x;
x = "string";
x = { x: "hello" };
x = { x: { x: "world" } };
var z: Foo<number>;
z = 42;
z = { x: 42 };
z = { x: { x: 42 } };
type Strange<T> = string; // Type parameter not used
var s: Strange<number>;
s = "hello";
interface AB<A, B> {
a: A;
b: B;
}
type Pair<T> = AB<T, T>;
interface TaggedPair<T> extends Pair<T> {
tag: string;
}
var p: TaggedPair<number>;
p.a = 1;
p.b = 2;
p.tag = "test";
function f<A>() {
type Foo<T> = T | { x: Foo<T> };
var x: Foo<A[]>;
return x;
}
function g<B>() {
type Bar<U> = U | { x: Bar<U> };
var x: Bar<B[]>;
return x;
}
// Deeply instantiated generics
var a = f<string>();
var b = g<string>();
a = b;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/getSetAccessorContextualTyping.ts | TypeScript | // @target: es5
// In the body of a get accessor with no return type annotation,
// if a matching set accessor exists and that set accessor has a parameter type annotation,
// return expressions are contextually typed by the type given in the set accessor's parameter type annotation.
class C {
set X(x: number) { }
get X() {
return "string"; // Error; get contextual type by set accessor parameter type annotation
}
set Y(y) { }
get Y() {
return true;
}
set W(w) { }
get W(): boolean {
return true;
}
set Z(z: number) { }
get Z() {
return 1;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/globalAugmentationModuleResolution.ts | TypeScript | // @traceResolution: true
// @fileName: a.ts
export { };
declare global {
var x: number;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/globalMergeWithCommonJSAssignmentDeclaration.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: bug27099.js
window.name = 1;
window.console; // should not have error: Property 'console' does not exist on type 'typeof window'.
module.exports = 'anything';
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/globalThisAmbientModules.ts | TypeScript | declare module "ambientModule" {
export type typ = 1
export var val: typ
}
namespace valueModule { export var val = 1 }
namespace namespaceModule { export type typ = 1 }
// should error
type GlobalBad1 = (typeof globalThis)["\"ambientModule\""]
type GlobalOk1 = (typeof globalThis)["valueModule"]
type GlobalOk2 = globalThis.namespaceModule.typ
const bad1: (typeof globalThis)["\"ambientModule\""] = 'ambientModule'
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/globalThisBlockscopedProperties.ts | TypeScript | // @noImplicitAny: true
var x = 1
const y = 2
let z = 3
globalThis.x // ok
globalThis.y // should error, no property 'y'
globalThis.z // should error, no property 'z'
globalThis['x'] // ok
globalThis['y'] // should error, no property 'y'
globalThis['z'] // should error, no property 'z'
globalThis.Float64Array // ok
globalThis.Infinity // ok
declare let test1: (typeof globalThis)['x'] // ok
declare let test2: (typeof globalThis)['y'] // error
declare let test3: (typeof globalThis)['z'] // error
declare let themAll: keyof typeof globalThis
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/globalThisCollision.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @filename: globalThisCollision.js
var globalThis; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/globalThisGlobalExportAsGlobal.ts | TypeScript | // https://github.com/microsoft/TypeScript/issues/33754
declare global {
export { globalThis as global }
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/globalThisPropertyAssignment.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: globalThisPropertyAssignment.js
this.x = 1
var y = 2
// should work in JS
window.z = 3
// should work in JS (even though it's a secondary declaration)
globalThis.alpha = 4
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/globalThisReadonlyProperties.ts | TypeScript | globalThis.globalThis = 1 as any // should error
var x = 1
const y = 2
globalThis.x = 3
globalThis.y = 4 // should error
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/globalThisTypeIndexAccess.ts | TypeScript |
declare const w_e: (typeof globalThis)["globalThis"]
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/globalThisUnknown.ts | TypeScript | declare let win: Window & typeof globalThis;
// this access should be an error
win.hi
// these two should be fine, with type any
this.hi
globalThis.hi
// element access is always ok without noImplicitAny
win['hi']
this['hi']
globalThis['hi']
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/globalThisUnknownNoImplicitAny.ts | TypeScript | // @noImplicitAny: true
declare let win: Window & typeof globalThis;
// all accesses should be errors
win.hi
this.hi
globalThis.hi
win['hi']
this['hi']
globalThis['hi']
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/globalThisVarDeclaration.ts | TypeScript | // @outFile: output.js
// @target: esnext
// @lib: esnext, dom
// @Filename: b.js
// @allowJs: true
// @checkJs: true
var a = 10;
this.a;
this.b;
globalThis.a;
globalThis.b;
// DOM access is not supported until the index signature is handled more strictly
self.a;
self.b;
window.a;
window.b;
top.a;
top.b;
// @Filename: actual.ts
var b = 10;
this.a;
this.b;
globalThis.a;
globalThis.b;
// same here -- no DOM access to globalThis yet
self.a;
self.b;
window.a;
window.b;
top.a;
top.b;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/grammarAmbiguities.ts | TypeScript | function f(n: any) { return null; }
function g<A, B>(x: any) { return null; }
interface A { }
interface B { }
var A, B;
f(g<A, B>(7));
f(g < A, B > 7); // Should error
f(g < A, B > +(7)); // Should error
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/heterogeneousArrayLiterals.ts | TypeScript | // type of an array is the best common type of its elements (plus its contextual type if it exists)
var a = [1, '']; // {}[]
var b = [1, null]; // number[]
var c = [1, '', null]; // {}[]
var d = [{}, 1]; // {}[]
var e = [{}, Object]; // {}[]
var f = [[], [1]]; // number[][]
var g = [[1], ['']]; // {}[]
var h = [{ foo: 1, bar: '' }, { foo: 2 }]; // {foo: number}[]
var i = [{ foo: 1, bar: '' }, { foo: '' }]; // {}[]
var j = [() => 1, () => '']; // {}[]
var k = [() => 1, () => 1]; // { (): number }[]
var l = [() => 1, () => null]; // { (): any }[]
var m = [() => 1, () => '', () => null]; // { (): any }[]
var n = [[() => 1], [() => '']]; // {}[]
class Base { foo: string; }
class Derived extends Base { bar: string; }
class Derived2 extends Base { baz: string; }
var base: Base;
var derived: Derived;
var derived2: Derived2;
module Derived {
var h = [{ foo: base, basear: derived }, { foo: base }]; // {foo: Base}[]
var i = [{ foo: base, basear: derived }, { foo: derived }]; // {foo: Derived}[]
var j = [() => base, () => derived]; // { {}: Base }
var k = [() => base, () => 1]; // {}[]~
var l = [() => base, () => null]; // { (): any }[]
var m = [() => base, () => derived, () => null]; // { (): any }[]
var n = [[() => base], [() => derived]]; // { (): Base }[]
var o = [derived, derived2]; // {}[]
var p = [derived, derived2, base]; // Base[]
var q = [[() => derived2], [() => derived]]; // {}[]
}
module WithContextualType {
// no errors
var a: Base[] = [derived, derived2];
var b: Derived[] = [null];
var c: Derived[] = [];
var d: { (): Base }[] = [() => derived, () => derived2];
}
function foo<T, U>(t: T, u: U) {
var a = [t, t]; // T[]
var b = [t, null]; // T[]
var c = [t, u]; // {}[]
var d = [t, 1]; // {}[]
var e = [() => t, () => u]; // {}[]
var f = [() => t, () => u, () => null]; // { (): any }[]
}
function foo2<T extends Base, U extends Derived>(t: T, u: U) {
var a = [t, t]; // T[]
var b = [t, null]; // T[]
var c = [t, u]; // {}[]
var d = [t, 1]; // {}[]
var e = [() => t, () => u]; // {}[]
var f = [() => t, () => u, () => null]; // { (): any }[]
var g = [t, base]; // Base[]
var h = [t, derived]; // Derived[]
var i = [u, base]; // Base[]
var j = [u, derived]; // Derived[]
}
function foo3<T extends Derived, U extends Derived>(t: T, u: U) {
var a = [t, t]; // T[]
var b = [t, null]; // T[]
var c = [t, u]; // {}[]
var d = [t, 1]; // {}[]
var e = [() => t, () => u]; // {}[]
var f = [() => t, () => u, () => null]; // { (): any }[]
var g = [t, base]; // Base[]
var h = [t, derived]; // Derived[]
var i = [u, base]; // Base[]
var j = [u, derived]; // Derived[]
}
function foo4<T extends Base, U extends Base>(t: T, u: U) {
var a = [t, t]; // T[]
var b = [t, null]; // T[]
var c = [t, u]; // BUG 821629
var d = [t, 1]; // {}[]
var e = [() => t, () => u]; // {}[]
var f = [() => t, () => u, () => null]; // { (): any }[]
var g = [t, base]; // Base[]
var h = [t, derived]; // Derived[]
var i = [u, base]; // Base[]
var j = [u, derived]; // Derived[]
var k: Base[] = [t, u];
}
//function foo3<T extends U, U extends Derived>(t: T, u: U) {
// var a = [t, t]; // T[]
// var b = [t, null]; // T[]
// var c = [t, u]; // {}[]
// var d = [t, 1]; // {}[]
// var e = [() => t, () => u]; // {}[]
// var f = [() => t, () => u, () => null]; // { (): any }[]
// var g = [t, base]; // Base[]
// var h = [t, derived]; // Derived[]
// var i = [u, base]; // Base[]
// var j = [u, derived]; // Derived[]
//}
//function foo4<T extends U, U extends Base>(t: T, u: U) {
// var a = [t, t]; // T[]
// var b = [t, null]; // T[]
// var c = [t, u]; // BUG 821629
// var d = [t, 1]; // {}[]
// var e = [() => t, () => u]; // {}[]
// var f = [() => t, () => u, () => null]; // { (): any }[]
// var g = [t, base]; // Base[]
// var h = [t, derived]; // Derived[]
// var i = [u, base]; // Base[]
// var j = [u, derived]; // Derived[]
// var k: Base[] = [t, u];
//} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/identicalCallSignatures.ts | TypeScript | // Each pair of call signatures in these types have a duplicate signature error.
// Identical call signatures should generate an error.
interface I {
(x): number;
(x: any): number;
<T>(x: T): T;
<U>(x: U): U; // error
}
interface I2<T> {
(x: T): T;
(x: T): T; // error
}
var a: {
(x): number;
(x: any): number;
<T>(x: T): T;
<T>(x: T): T; // error
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/identicalCallSignatures2.ts | TypeScript | // Normally it is an error to have multiple overloads with identical signatures in a single type declaration.
// Here the multiple overloads come from multiple bases.
interface Base<T> {
(x: number): string;
}
interface I extends Base<string>, Base<number> { }
interface I2<T> extends Base<string>, Base<number> { } | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/identicalCallSignatures3.ts | TypeScript | // Normally it is an error to have multiple overloads with identical signatures in a single type declaration.
// Here the multiple overloads come from multiple merged declarations, so we do not report errors.
interface I {
(x: number): string;
}
interface I {
(x: number): string;
}
interface I2<T> {
(x: number): string;
}
interface I2<T> {
(x: number): string;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/ifDoWhileStatements.ts | TypeScript | // @allowUnreachableCode: true
interface I {
id: number;
}
class C implements I {
id: number;
name: string;
}
class C2 extends C {
valid: boolean;
}
class D<T>{
source: T;
recurse: D<T>;
wrapped: D<D<T>>
}
function F(x: string): number { return 42; }
function F2(x: number): boolean { return x < 42; }
module M {
export class A {
name: string;
}
export function F2(x: number): string { return x.toString(); }
}
module N {
export class A {
id: number;
}
export function F2(x: number): string { return x.toString(); }
}
// literals
if (true) { }
while (true) { }
do { }while(true)
if (null) { }
while (null) { }
do { }while(null)
if (undefined) { }
while (undefined) { }
do { }while(undefined)
if (0.0) { }
while (0.0) { }
do { }while(0.0)
if ('a string') { }
while ('a string') { }
do { }while('a string')
if ('') { }
while ('') { }
do { }while('')
if (/[a-z]/) { }
while (/[a-z]/) { }
do { }while(/[a-z]/)
if ([]) { }
while ([]) { }
do { }while([])
if ([1, 2]) { }
while ([1, 2]) { }
do { }while([1, 2])
if ({}) { }
while ({}) { }
do { }while({})
if ({ x: 1, y: 'a' }) { }
while ({ x: 1, y: 'a' }) { }
do { }while({ x: 1, y: 'a' })
if (() => 43) { }
while (() => 43) { }
do { }while(() => 43)
if (new C()) { }
while (new C()) { }
do { }while(new C())
if (new D<C>()) { }
while (new D<C>()) { }
do { }while(new D<C>())
// references
var a = true;
if (a) { }
while (a) { }
do { }while(a)
var b = null;
if (b) { }
while (b) { }
do { }while(b)
var c = undefined;
if (c) { }
while (c) { }
do { }while(c)
var d = 0.0;
if (d) { }
while (d) { }
do { }while(d)
var e = 'a string';
if (e) { }
while (e) { }
do { }while(e)
var f = '';
if (f) { }
while (f) { }
do { }while(f)
var g = /[a-z]/
if (g) { }
while (g) { }
do { }while(g)
var h = [];
if (h) { }
while (h) { }
do { }while(h)
var i = [1, 2];
if (i) { }
while (i) { }
do { }while(i)
var j = {};
if (j) { }
while (j) { }
do { }while(j)
var k = { x: 1, y: 'a' };
if (k) { }
while (k) { }
do { }while(k)
function fn(x?: string): I { return null; }
if (fn()) { }
while (fn()) { }
do { }while(fn())
if (fn) { }
while (fn) { }
do { }while(fn)
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/implementingAnInterfaceExtendingClassWithPrivates.ts | TypeScript | class Foo {
private x: string;
}
interface I extends Foo {
y: number;
}
class Bar implements I { // error
}
class Bar2 implements I { // error
y: number;
}
class Bar3 implements I { // error
x: string;
y: number;
}
class Bar4 implements I { // error
private x: string;
y: number;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/implementingAnInterfaceExtendingClassWithPrivates2.ts | TypeScript | class Foo {
private x: string;
}
interface I extends Foo {
y: number;
}
class Bar extends Foo implements I { // ok
y: number;
}
class Bar2 extends Foo implements I { // error
x: string;
y: number;
}
class Bar3 extends Foo implements I { // error
private x: string;
y: number;
}
// another level of indirection
module M {
class Foo {
private x: string;
}
class Baz extends Foo {
z: number;
}
interface I extends Baz {
y: number;
}
class Bar extends Foo implements I { // ok
y: number;
z: number;
}
class Bar2 extends Foo implements I { // error
x: string;
y: number;
}
class Bar3 extends Foo implements I { // error
private x: string;
y: number;
}
}
// two levels of privates
module M2 {
class Foo {
private x: string;
}
class Baz extends Foo {
private y: number;
}
interface I extends Baz {
z: number;
}
class Bar extends Foo implements I { // error
z: number;
}
var b: Bar;
var r1 = b.z;
var r2 = b.x; // error
var r3 = b.y; // error
class Bar2 extends Foo implements I { // error
x: string;
z: number;
}
class Bar3 extends Foo implements I { // error
private x: string;
z: number;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/implementingAnInterfaceExtendingClassWithProtecteds.ts | TypeScript | class Foo {
protected x: string;
}
interface I extends Foo {
y: number;
}
class Bar implements I { // error
}
class Bar2 implements I { // error
y: number;
}
class Bar3 implements I { // error
x: string;
y: number;
}
class Bar4 implements I { // error
protected x: string;
y: number;
}
class Bar5 extends Foo implements I { // error
}
class Bar6 extends Foo implements I { // error
protected y: number;
}
class Bar7 extends Foo implements I {
y: number;
}
class Bar8 extends Foo implements I {
x: string;
y: number;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/implementsClause.ts | TypeScript | // @Filename: types.ts
export interface Component {}
// @Filename: ns.ts
import type * as types from './types';
export { types };
// @Filename: index.ts
import type * as types from './types';
import * as nestedNamespace from './ns';
class C implements types.Component {}
class D implements nestedNamespace.types.Component {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importAliasIdentifiers.ts | TypeScript | module moduleA {
export class Point {
constructor(public x: number, public y: number) { }
}
}
import alias = moduleA;
var p: alias.Point;
var p: moduleA.Point;
var p: { x: number; y: number; };
class clodule {
name: string;
}
module clodule {
export interface Point {
x: number; y: number;
}
var Point: Point = { x: 0, y: 0 };
}
import clolias = clodule;
var p: clolias.Point;
var p: clodule.Point;
var p: { x: number; y: number; };
function fundule() {
return { x: 0, y: 0 };
}
module fundule {
export interface Point {
x: number; y: number;
}
var Point: Point = { x: 0, y: 0 };
}
import funlias = fundule;
var p: funlias.Point;
var p: fundule.Point;
var p: { x: number; y: number; }; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importAliasModuleExports.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @esModuleInterop: true
// @filename: mod1.js
class Alias {
bar() { return 1 }
}
module.exports = Alias;
// @filename: main.js
import A from './mod1'
A.prototype.foo = 0
A.prototype.func = function() { this._func = 0; }
Object.defineProperty(A.prototype, "def", { value: 0 });
new A().bar
new A().foo
new A().func()
new A().def
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importAssertion2.ts | TypeScript | // @declaration: true
// @target: es2015
// @module: es2015, commonjs, esnext
// @filename: 0.ts
export const a = 1;
export const b = 2;
// @filename: 1.ts
export {} from './0' assert { type: "json" }
export { a, b } from './0' assert { type: "json" }
export * from './0' assert { type: "json" }
export * as ns from './0' assert { type: "json" }
// @filename: 2.ts
export { a, b } from './0' assert {}
export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importAssertion3.ts | TypeScript | // @declaration: true
// @target: es2015
// @module: es2015, esnext
// @filename: 0.ts
export interface I { }
// @filename: 1.ts
export type {} from './0' assert { type: "json" }
export type { I } from './0' assert { type: "json" }
// @filename: 2.ts
import type { I } from './0' assert { type: "json" }
import type * as foo from './0' assert { type: "json" }
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importAttributes2.ts | TypeScript | // @declaration: true
// @target: es2015
// @module: es2015, commonjs, esnext
// @filename: 0.ts
export const a = 1;
export const b = 2;
// @filename: 1.ts
export {} from './0' with { type: "json" }
export { a, b } from './0' with { type: "json" }
export * from './0' with { type: "json" }
export * as ns from './0' with { type: "json" }
// @filename: 2.ts
export { a, b } from './0' with {}
export { a as c, b as d } from './0' with { a: "a", b: "b", c: "c" }
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importAttributes3.ts | TypeScript | // @declaration: true
// @target: es2015
// @module: es2015, esnext
// @filename: 0.ts
export interface I { }
// @filename: 1.ts
export type {} from './0' with { type: "json" }
export type { I } from './0' with { type: "json" }
// @filename: 2.ts
import type { I } from './0' with { type: "json" }
import type * as foo from './0' with { type: "json" }
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importAttributes6.ts | TypeScript | // @module: nodenext
// @filename: mod.mts
import * as thing1 from "./mod.mjs" with { field: 0 };
import * as thing2 from "./mod.mjs" with { field: `a` };
import * as thing3 from "./mod.mjs" with { field: /a/g };
import * as thing4 from "./mod.mjs" with { field: ["a"] };
import * as thing5 from "./mod.mjs" with { field: { a: 0 } };
import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() };
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importAttributes8.ts | TypeScript | // @module: esnext
// @lib: es2015
// @filename: /a.ts
export default {
a: "a",
b: "b",
}
// @filename: /b.ts
import a from "./a" with { a: "a", "b": "b" }; // ok
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importCallExpression1ES2020.ts | TypeScript | // @module: es2020
// @target: es2020
// @filename: 0.ts
export function foo() { return "foo"; }
// @filename: 1.ts
import("./0");
var p1 = import("./0");
p1.then(zero => {
return zero.foo();
})
export var p2 = import("./0");
function foo() {
const p2 = import("./0");
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importCallExpression2ES2020.ts | TypeScript | // @module: es2020
// @target: es2020
// @filename: 0.ts
export class B {
print() { return "I am B"}
}
// @filename: 2.ts
function foo(x: Promise<any>) {
x.then(value => {
let b = new value.B();
b.print();
})
}
foo(import("./0"));
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importCallExpression3ES2020.ts | TypeScript | // @module: es2020
// @target: es2020
// @filename: 0.ts
export class B {
print() { return "I am B"}
}
// @filename: 2.ts
async function foo() {
class C extends (await import("./0")).B {}
var c = new C();
c.print();
}
foo();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importCallExpression4ES2020.ts | TypeScript | // @lib: es2020
// @module: es2020
// @target: es2020
// @filename: 0.ts
export class B {
print() { return "I am B"}
}
export function foo() { return "foo" }
// @filename: 1.ts
export function backup() { return "backup"; }
// @filename: 2.ts
declare var console: any;
class C {
private myModule = import("./0");
method() {
const loadAsync = import ("./0");
this.myModule.then(Zero => {
console.log(Zero.foo());
}, async err => {
console.log(err);
let one = await import("./1");
console.log(one.backup());
});
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importCallExpression5ES2020.ts | TypeScript | // @module: es2020
// @target: es2020
// @strictNullChecks: true
// @filename: 0.ts
export class B {
print() { return "I am B"}
}
export function foo() { return "foo" }
// @filename: 1.ts
export function backup() { return "backup"; }
// @filename: 2.ts
declare function bar(): boolean;
const specify = bar() ? "./0" : undefined;
let myModule = import(specify);
let myModule1 = import(undefined);
let myModule2 = import(bar() ? "./1" : null);
let myModule3 = import(null);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importCallExpression6ES2020.ts | TypeScript | // @module: es2020
// @target: es2020
// @filename: 0.ts
export class B {
print() { return "I am B"}
}
export function foo() { return "foo" }
// @filename: 1.ts
export function backup() { return "backup"; }
// @filename: 2.ts
declare function bar(): boolean;
const specify = bar() ? "./0" : undefined;
let myModule = import(specify);
let myModule1 = import(undefined);
let myModule2 = import(bar() ? "./1" : null);
let myModule3 = import(null);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importCallExpressionAsyncES2020.ts | TypeScript | // @module: es2020
// @target: es2020
// @filename: test.ts
export async function fn() {
const req = await import('./test') // ONE
}
export class cl1 {
public async m() {
const req = await import('./test') // TWO
}
}
export const obj = {
m: async () => {
const req = await import('./test') // THREE
}
}
export class cl2 {
public p = {
m: async () => {
const req = await import('./test') // FOUR
}
}
}
export const l = async () => {
const req = await import('./test') // FIVE
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importCallExpressionAsyncES5AMD.ts | TypeScript | // @module: amd
// @target: es5
// @lib: es6
// @filename: test.ts
export async function fn() {
const req = await import('./test') // ONE
}
export class cl1 {
public async m() {
const req = await import('./test') // TWO
}
}
export const obj = {
m: async () => {
const req = await import('./test') // THREE
}
}
export class cl2 {
public p = {
m: async () => {
const req = await import('./test') // FOUR
}
}
}
export const l = async () => {
const req = await import('./test') // FIVE
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importCallExpressionAsyncES5CJS.ts | TypeScript | // @module: commonjs
// @target: es5
// @lib: es6
// @filename: test.ts
export async function fn() {
const req = await import('./test') // ONE
}
export class cl1 {
public async m() {
const req = await import('./test') // TWO
}
}
export const obj = {
m: async () => {
const req = await import('./test') // THREE
}
}
export class cl2 {
public p = {
m: async () => {
const req = await import('./test') // FOUR
}
}
}
export const l = async () => {
const req = await import('./test') // FIVE
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importCallExpressionAsyncES5System.ts | TypeScript | // @module: system
// @target: es5
// @lib: es6
// @filename: test.ts
export async function fn() {
const req = await import('./test') // ONE
}
export class cl1 {
public async m() {
const req = await import('./test') // TWO
}
}
export const obj = {
m: async () => {
const req = await import('./test') // THREE
}
}
export class cl2 {
public p = {
m: async () => {
const req = await import('./test') // FOUR
}
}
}
export const l = async () => {
const req = await import('./test') // FIVE
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importCallExpressionAsyncES5UMD.ts | TypeScript | // @module: umd
// @target: es5
// @lib: es6
// @filename: test.ts
export async function fn() {
const req = await import('./test') // ONE
}
export class cl1 {
public async m() {
const req = await import('./test') // TWO
}
}
export const obj = {
m: async () => {
const req = await import('./test') // THREE
}
}
export class cl2 {
public p = {
m: async () => {
const req = await import('./test') // FOUR
}
}
}
export const l = async () => {
const req = await import('./test') // FIVE
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/importCallExpressionAsyncES6AMD.ts | TypeScript | // @module: amd
// @target: es6
// @filename: test.ts
export async function fn() {
const req = await import('./test') // ONE
}
export class cl1 {
public async m() {
const req = await import('./test') // TWO
}
}
export const obj = {
m: async () => {
const req = await import('./test') // THREE
}
}
export class cl2 {
public p = {
m: async () => {
const req = await import('./test') // FOUR
}
}
}
export const l = async () => {
const req = await import('./test') // FIVE
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.