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/newWithSpreadES5.ts | TypeScript | //@target: ES5
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 | |
crates/swc_ecma_parser/tests/tsc/newWithSpreadES6.ts | TypeScript | //@target: ES6
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 | |
crates/swc_ecma_parser/tests/tsc/noAssertForUnparseableTypedefs.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: bug26693.js
/** @typedef {module:locale} hi */
import { nope } from 'nope';
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/noDuplicateJsdoc1.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: a.js
/** doc */
const a = b = () => 0;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/noInfer.ts | TypeScript | // @strict: true
// @declaration: true
// NoInfer<T> is erased for primitives
type T00 = NoInfer<string>;
type T01 = NoInfer<string | number | boolean>;
type T02 = NoInfer<undefined>;
type T03 = NoInfer<"foo">;
type T04 = NoInfer<`foo${string}`>;
type T05 = NoInfer<`foo${string}` & `${string}bar`>;
type T06 = NoInfer<{}>;
// NoInfer<T> is preserved for object types
type T10 = NoInfer<string[]>;
type T11 = NoInfer<{ x: string }>;
// NoInfer<T> is erased if it has no effect
type T20<T> = NoInfer<NoInfer<T>>;
type T21<T> = NoInfer<NoInfer<T> & string>;
type T22<T> = NoInfer<NoInfer<T> & string[]>;
// keyof NoInfer<T> is transformed into NoInfer<keyof T>
type T30 = keyof NoInfer<{ a: string, b: string }>;
type T31<T> = keyof NoInfer<T>;
type T32 = { [K in keyof NoInfer<{ a: string, b: string }>]: K };
declare function foo1<T extends string>(a: T, b: NoInfer<T>): void
declare function foo2<T extends string>(a: T, b: NoInfer<T>[]): void
declare function foo3<T extends string>(a: T, b: NoInfer<T[]>): void
declare function foo4<T extends string>(a: T, b: { x: NoInfer<T> }): void
declare function foo5<T extends string>(a: T, b: NoInfer<{ x: T }>): void
foo1('foo', 'foo') // ok
foo1('foo', 'bar') // error
foo2('foo', ['bar']) // error
foo3('foo', ['bar']) // error
foo4('foo', { x: 'bar' }) // error
foo5('foo', { x: 'bar' }) // error
declare class Animal { move(): void }
declare class Dog extends Animal { woof(): void }
declare function doSomething<T>(value: T, getDefault: () => NoInfer<T>): void;
doSomething(new Animal(), () => new Animal()); // ok
doSomething(new Animal(), () => new Dog()); // ok
doSomething(new Dog(), () => new Animal()); // error
declare function assertEqual<T>(actual: T, expected: NoInfer<T>): boolean;
assertEqual({ x: 1 }, { x: 3 }); // ok
const g = { x: 3, y: 2 };
assertEqual(g, { x: 3 }); // error
declare function invoke<T, R>(func: (value: T) => R, value: NoInfer<T>): R;
declare function test(value: { x: number; }): number;
invoke(test, { x: 1, y: 2 }); // error
test({ x: 1, y: 2 }); // error
type Component<Props> = { props: Props; };
declare function doWork<Props>(Component: Component<Props>, props: NoInfer<Props>): void;
declare const comp: Component<{ foo: number }>;
doWork(comp, { foo: 42 }); // ok
doWork(comp, {}); // error
declare function mutate<T>(callback: (a: NoInfer<T>, b: number) => T): T;
const mutate1 = mutate((a, b) => b);
declare class ExampleClass<T> {}
class OkClass<T> {
constructor(private clazz: ExampleClass<T>, private _value: NoInfer<T>) {}
get value(): T {
return this._value; // ok
}
}
class OkClass2<T> {
constructor(private clazz: ExampleClass<T>, public _value: NoInfer<T>) {}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/noInferRedeclaration.ts | TypeScript | // @strict: true
// @declaration: true
// @target: esnext
// @filename: a.ts
export const f = <T>(x: T, y: NoInfer<T>) => x;
// @filename: b.ts
import { f } from "./a";
type NoInfer<T> = T & number;
export const g = f;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/noPropertyAccessFromIndexSignature1.ts | TypeScript | // @noPropertyAccessFromIndexSignature: true
interface A {
foo: string
}
interface B {
[k: string]: string
}
interface C {
foo: string
[k: string]: string
}
declare const a: A;
declare const b: B;
declare const c: C;
declare const d: C | undefined;
// access property
a.foo;
a["foo"]
// access index signature
b.foo;
b["foo"];
// access property
c.foo;
c["foo"]
// access index signature
c.bar;
c["bar"];
// optional access property
d?.foo;
d?.["foo"]
// optional access index signature
d?.bar;
d?.["bar"];
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/noUncheckedIndexedAccess.ts | TypeScript | // @strict: true
// @noUncheckedIndexedAccess: true
type CheckBooleanOnly<T extends boolean> = any;
// Validate CheckBooleanOnly works - should error
type T_ERR1 = CheckBooleanOnly<boolean | undefined>;
enum NumericEnum1 { A, B, C }
enum NumericEnum2 { A = 0, B = 1 , C = 2 }
enum StringEnum1 { A = "Alpha", B = "Beta" }
declare const strMap: { [s: string]: boolean };
// All of these should be errors
const e1: boolean = strMap["foo"];
const e2: boolean = strMap.bar;
const e3: boolean = strMap[0];
const e4: boolean = strMap[0 as string | number];
const e5: boolean = strMap[0 as string | 0 | 1];
const e6: boolean = strMap[0 as 0 | 1];
const e7: boolean = strMap["foo" as "foo" | "baz"];
const e8: boolean = strMap[NumericEnum1.A];
const e9: boolean = strMap[NumericEnum2.A];
const e10: boolean = strMap[StringEnum1.A];
const e11: boolean = strMap[StringEnum1.A as StringEnum1];
const e12: boolean = strMap[NumericEnum1.A as NumericEnum1];
const e13: boolean = strMap[NumericEnum2.A as NumericEnum2];
const e14: boolean = strMap[null as any];
// Should be OK
const ok1: boolean | undefined = strMap["foo"];
const ok2: boolean | undefined = strMap.bar;
type T_OK1 = CheckBooleanOnly<(typeof strMap)[string]>;
type T_OK2 = CheckBooleanOnly<(typeof strMap)["foo"]>;
type T_OK3 = CheckBooleanOnly<(typeof strMap)["bar" | "baz"]>;
type T_OK4 = CheckBooleanOnly<(typeof strMap)[number]>;
type T_OK5 = CheckBooleanOnly<(typeof strMap)[any]>;
// Writes don't allow 'undefined'; all should be errors
strMap["baz"] = undefined;
strMap.qua = undefined;
strMap[0] = undefined;
strMap[null as any] = undefined;
// Numeric lookups are unaffected
declare const numMap: { [s: number]: boolean };
// All of these should be ok
const num_ok1: boolean = numMap[0];
const num_ok2: boolean = numMap[0 as number];
const num_ok3: boolean = numMap[0 as 0 | 1];
const num_ok4: boolean = numMap[NumericEnum1.A];
const num_ok5: boolean = numMap[NumericEnum2.A];
// Generics
function generic1<T extends { [s: string]: boolean }>(arg: T): boolean {
// Should error
return arg["blah"];
}
function generic2<T extends { [s: string]: boolean }>(arg: T): boolean {
// Should OK
return arg["blah"]!;
}
function generic3<T extends string>(arg: T): boolean {
// Should error
return strMap[arg];
}
// Element access into known properties is ok
declare const obj1: { x: string, y: number, [key: string]: string | number };
obj1["x"];
const y = "y";
obj1[y];
let yy = "y";
obj1[yy];
let z = "z";
obj1[z];
// Distributivity cases
declare const strMapUnion: { [s: string]: boolean } | { [s: string]: number };
// Should error
const f1: boolean | number = strMapUnion["foo"];
// Symbol index signatures
declare const s: unique symbol;
declare const symbolMap: { [s]: string };
const e15: string = symbolMap[s]; // Should OK
symbolMap[s] = undefined; // Should error
// Variadic tuples
declare const nonEmptyStringArray: [string, ...string[]];
const variadicOk1: string = nonEmptyStringArray[0]; // Should OK
const variadicError1: string = nonEmptyStringArray[1]; // Should error
// Generic index type
declare const myRecord1: { a: string; b: string };
declare const myRecord2: { a: string; b: string, [key: string]: string };
const fn1 = <Key extends keyof typeof myRecord1>(key: Key): string => myRecord1[key]; // Should OK
const fn2 = <Key extends keyof typeof myRecord1>(key: Key): string => myRecord2[key]; // Should OK
const fn3 = <Key extends keyof typeof myRecord2>(key: Key) => {
myRecord2[key] = undefined; // Should error
const v: string = myRecord2[key]; // Should error
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/noUncheckedIndexedAccessDestructuring.ts | TypeScript | // @strict: true
// @noUncheckedIndexedAccess: true
declare const strArray: string[];
declare const strStrTuple: [string, string];
// Declaration forms for array destructuring
// Destructuring from a simple array -> include undefined
const [s1] = strArray;
s1.toString(); // Should error, s1 possibly undefined
// Destructuring a rest element -> do not include undefined
const [...s2] = strArray;
s2.push(undefined); // Should error, 'undefined' not part of s2's element type
// Destructuring a rest element -> do not include undefined
const [, , ...s3] = strArray;
s3.push(undefined); // Should error, 'undefined' not part of s2's element type
// Declaration forms for object destructuring
declare const strMap: { [s: string]: string };
const { t1 } = strMap;
t1.toString(); // Should error, t1 possibly undefined
const { ...t2 } = strMap;
t2.z.toString(); // Should error
// Test intersections with declared properties
declare const numMapPoint: { x: number, y: number} & { [s: string]: number };
{
const { x, y, z } = numMapPoint;
x.toFixed(); // Should OK
y.toFixed(); // Should OK
z.toFixed(); // Should error
}
{
const { x, ...q } = numMapPoint;
x.toFixed(); // Should OK
q.y.toFixed(); // Should OK
q.z.toFixed(); // Should error
}
{
const { x, ...q } = numMapPoint;
x.
toFixed(); // Should OK
q.
y.toFixed(); // Should OK
q.
z.toFixed(); // Should error
}
declare let target_string: string;
declare let target_string_undef: string | undefined;
declare let target_string_arr: string[];
// Assignment forms
[target_string] = strArray; // Should error
[target_string_undef] = strArray; // Should OK
[,,, ...target_string_arr] = strArray; // Should OK
{
let x: number, y: number, z: number | undefined;
({ x, y, z } = numMapPoint); // Should OK
let q: number;
({ q } = numMapPoint); // Should error
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nodeModulesAllowJsCjsFromJs.ts | TypeScript | // @module: node16,nodenext
// @allowJs: true
// @noEmit: true
// @filename: foo.cjs
exports.foo = "foo"
// @filename: bar.ts
import foo from "./foo.cjs"
foo.foo; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nodeModulesAllowJsExportlessJsModuleDetectionAuto.ts | TypeScript | // @module: node16,nodenext
// @allowJs: true
// @outDir: ./out
// @moduleDetection: auto
// @filename: foo.cjs
// this file is a module despite having no imports
// @filename: bar.js
// however this file is _not_ a module | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nodeModulesAtTypesPriority.ts | TypeScript | // @module: node16
// @strict: true
// @noEmit: true
// @traceResolution: true
// @Filename: /node_modules/@types/react/index.d.ts
declare const React: any;
export = React;
// @Filename: /node_modules/@types/redux/index.d.ts
export declare function createStore(): void;
// @Filename: /packages/a/node_modules/react/index.js
module.exports = {};
// @Filename: /packages/a/node_modules/redux/index.d.ts
export declare function createStore(): void;
// @Filename: /packages/a/node_modules/redux/index.js
module.exports = {};
// @Filename: /packages/a/index.ts
import React from "react";
import { createStore } from "redux";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nodeModulesCJSResolvingToESM1_emptyPackageJson.ts | TypeScript | // @noEmit: true
// @noTypesAndSymbols: true
// @module: node16
// @allowJs: true
// @checkJs: true
// @jsx: preserve
// @Filename: /package.json
{}
// @Filename: /module.mts
export {};
// @Filename: /tsExtension.ts
import {} from "./module.mjs";
// @Filename: /jsExtension.js
import {} from "./module.mjs";
// @Filename: /ctsExtension.cts
import {} from "./module.mjs";
// @Filename: /tsxExtension.tsx
import {} from "./module.mjs";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nodeModulesCJSResolvingToESM4_noPackageJson.ts | TypeScript | // @noEmit: true
// @noTypesAndSymbols: true
// @module: node16
// @allowJs: true
// @checkJs: true
// @jsx: preserve
// @Filename: /module.mts
export {};
// @Filename: /tsExtension.ts
import {} from "./module.mjs";
// @Filename: /jsExtension.js
import {} from "./module.mjs";
// @Filename: /ctsExtension.cts
import {} from "./module.mjs";
// @Filename: /tsxExtension.tsx
import {} from "./module.mjs";
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nominalSubtypeCheckOfTypeParameter.ts | TypeScript | interface BinaryTuple<T, S> {
first: T
second: S
}
interface Sequence<T> {
hasNext(): boolean
pop(): T
zip<S>(seq: Sequence<S>): Sequence<BinaryTuple<T, S>>
}
// error, despite the fact that the code explicitly says List<T> extends Sequence<T>, the current rules for infinitely expanding type references
// perform nominal subtyping checks that allow variance for type arguments, but not nominal subtyping for the generic type itself
interface List<T> extends Sequence<T> {
getLength(): number
zip<S>(seq: Sequence<S>): List<BinaryTuple<T, S>>
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nominalSubtypeCheckOfTypeParameter2.ts | TypeScript | interface B<T> {
bar: T;
}
// ok
interface A<T> extends B<T> {
foo: T;
}
// ok
interface A2<T> extends B<B<string>> {
baz: T;
}
interface C<T> {
bam: T;
}
// ok
interface A3<T> extends B<C<T>> {
bing: T;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonGenericTypeReferenceWithTypeArguments.ts | TypeScript | // Check that errors are reported for non-generic types with type arguments
class C { }
interface I { }
enum E { }
type T = { };
var v1: C<string>;
var v2: I<string>;
var v3: E<string>;
var v4: T<string>;
function f<U>() {
class C { }
interface I { }
enum E { }
type T = {};
var v1: C<string>;
var v2: I<string>;
var v3: E<string>;
var v4: T<string>;
var v5: U<string>;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonInstantiatedModule.ts | TypeScript | module M {
export interface Point { x: number; y: number }
export var a = 1;
}
// primary expression
var m : typeof M;
var m = M;
var a1: number;
var a1 = M.a;
var a2: number;
var a2 = m.a;
module M2 {
export module Point {
export function Origin(): Point {
return { x: 0, y: 0 };
}
}
export interface Point {
x: number;
y: number;
}
}
var p: { x: number; y: number; };
var p: M2.Point;
var p2: { Origin() : { x: number; y: number; } };
var p2: typeof M2.Point;
module M3 {
export module Utils {
export interface Point {
x: number; y: number;
}
}
export class Utils {
name: string;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonIterableRestElement1.ts | TypeScript | var c = {};
[...c] = ["", 0]; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonIterableRestElement2.ts | TypeScript | //@target: ES6
var c = {};
[...c] = ["", 0]; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonIterableRestElement3.ts | TypeScript | var c = { bogus: 0 };
[...c] = ["", 0]; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonPrimitiveAccessProperty.ts | TypeScript | var a: object;
a.toString();
a.nonExist(); // error
var { destructuring } = a; // error
var { ...rest } = a; // ok
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonPrimitiveAndEmptyObject.ts | TypeScript | // @strict: true
// @declaration: true
// Repro from #49480
export interface BarProps {
barProp?: string;
}
export interface FooProps {
fooProps?: BarProps & object;
}
declare const foo: FooProps;
const { fooProps = {} } = foo;
fooProps.barProp;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonPrimitiveAndTypeVariables.ts | TypeScript | // @strict: true
// Repros from #23800
type A<T, V> = { [P in keyof T]: T[P] extends V ? 1 : 0; };
type B<T, V> = { [P in keyof T]: T[P] extends V | object ? 1 : 0; };
let a: A<{ a: 0 | 1 }, 0> = { a: 0 };
let b: B<{ a: 0 | 1 }, 0> = { a: 0 };
function foo<T, U>(x: T) {
let a: object = x; // Error
let b: U | object = x; // Error
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonPrimitiveAsProperty.ts | TypeScript | // @declaration: true
interface WithNonPrimitive {
foo: object
}
var a: WithNonPrimitive = { foo: {bar: "bar"} };
var b: WithNonPrimitive = {foo: "bar"}; // expect error
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonPrimitiveAssignError.ts | TypeScript | var x = {};
var y = {foo: "bar"};
var a: object;
x = a;
y = a; // expect error
a = x;
a = y;
var n = 123;
var b = true;
var s = "fooo";
a = n; // expect error
a = b; // expect error
a = s; // expect error
n = a; // expect error
b = a; // expect error
s = a; // expect error
var numObj: Number = 123;
var boolObj: Boolean = true;
var strObj: String = "string";
a = numObj; // ok
a = boolObj; // ok
a = strObj; // ok
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonPrimitiveConstraintOfIndexAccessType.ts | TypeScript | // @strict: true
// test for #15371
function f<T extends object, P extends keyof T>(s: string, tp: T[P]): void {
tp = s;
}
function g<T extends null, P extends keyof T>(s: string, tp: T[P]): void {
tp = s;
}
function h<T extends undefined, P extends keyof T>(s: string, tp: T[P]): void {
tp = s;
}
function i<T extends void, P extends keyof T>(s: string, tp: T[P]): void {
tp = s;
}
function j<T extends never, P extends keyof T>(s: string, tp: T[P]): void {
tp = s;
}
function k<T extends number, P extends keyof T>(s: string, tp: T[P]): void {
tp = s;
}
function o<T extends string, P extends keyof T>(s: string, tp: T[P]): void {
tp = s;
}
function l<T extends {}, P extends keyof T>(s: string, tp: T[P]): void {
tp = s;
}
function m<T extends { a: number }, P extends keyof T>(s: string, tp: T[P]): void {
tp = s;
}
function n<T extends { [s: string]: number }, P extends keyof T>(s: string, tp: T[P]): void {
tp = s;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonPrimitiveInFunction.ts | TypeScript | // @declaration: true
function takeObject(o: object) {}
function returnObject(): object {
return {};
}
var nonPrimitive: object;
var primitive: boolean;
takeObject(nonPrimitive);
nonPrimitive = returnObject();
takeObject(primitive); // expect error
primitive = returnObject(); // expect error
function returnError(): object {
var ret = 123;
return ret; // expect error
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonPrimitiveInGeneric.ts | TypeScript | // @declaration: true
function generic<T>(t: T) {
var o: object = t; // expect error
}
var a = {};
var b = "42";
generic<object>({});
generic<object>(a);
generic<object>(123); // expect error
generic<object>(b); // expect error
function bound<T extends object>(t: T) {
var o: object = t; // ok
}
bound({});
bound(a);
bound(123); // expect error
bound(b); // expect error
function bound2<T extends object>() {}
bound2<{}>();
bound2<Object>();
bound2<number>(); // expect error
bound2<string>(); // expect error
function bound3<T extends {}>(t: T) {
var o: object = t; // ok
}
interface Proxy<T extends object> {}
var x: Proxy<number>; // error
var y: Proxy<null>; // ok
var z: Proxy<undefined> ; // ok
interface Blah {
foo: number;
}
var u: Proxy<Blah>; // ok
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonPrimitiveIndexingWithForIn.ts | TypeScript | var a: object;
for (var key in a) {
var value = a[key];
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonPrimitiveIndexingWithForInNoImplicitAny.ts | TypeScript | // @noImplicitAny: true
var a: object;
for (var key in a) {
var value = a[key]; // error
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonPrimitiveIndexingWithForInSupressError.ts | TypeScript | // @noImplicitAny: true
// @suppressImplicitAnyIndexErrors: true
var a: object;
for (var key in a) {
var value = a[key];
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonPrimitiveNarrow.ts | TypeScript | class Narrow {
narrowed: boolean
}
var a: object
if (a instanceof Narrow) {
a.narrowed; // ok
a = 123; // error
}
if (typeof a === 'number') {
a.toFixed(); // error, never
}
var b: object | null
if (typeof b === 'object') {
b.toString(); // ok, object | null
} else {
b.toString(); // error, never
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonPrimitiveRhsSideOfInExpression.ts | TypeScript | let o: object = {};
function f(): object {
return {};
}
const b1 = "foo" in o;
const b2 = "bar" in f(); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nonPrimitiveUnionIntersection.ts | TypeScript | // @declaration: true
var a: object & string = ""; // error
var b: object | string = ""; // ok
var c: object & {} = 123; // error
a = b; // error
b = a; // ok
const foo: object & {} = {bar: 'bar'}; // ok
const bar: object & {err: string} = {bar: 'bar'}; // error
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullAssignableToEveryType.ts | TypeScript | class C {
foo: string;
}
var ac: C;
interface I {
foo: string;
}
var ai: I;
enum E { A }
var ae: E;
var b: number = null;
var c: string = null;
var d: boolean = null;
var e: Date = null;
var f: any = null;
var g: void = null;
var h: Object = null;
var i: {} = null;
var j: () => {} = null;
var k: Function = null;
var l: (x: number) => string = null;
ac = null;
ai = null;
ae = null;
var m: number[] = null;
var n: { foo: string } = null;
var o: <T>(x: T) => T = null;
var p: Number = null;
var q: String = null;
function foo<T, U, V extends Date>(x: T, y: U, z: V) {
x = null;
y = null;
z = null;
}
//function foo<T, U extends T, V extends Date>(x: T, y: U, z: V) {
// x = null;
// y = null;
// z = null;
//} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullAssignedToUndefined.ts | TypeScript | var x = undefined = null; // error
var y: typeof undefined = null; // ok, widened | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullIsSubtypeOfEverythingButUndefined.ts | TypeScript | // null is a subtype of any other types except undefined
var r0 = true ? null : null;
var r0 = true ? null : null;
var u: typeof undefined;
var r0b = true ? u : null;
var r0b = true ? null : u;
var r1 = true ? 1 : null;
var r1 = true ? null : 1;
var r2 = true ? '' : null;
var r2 = true ? null : '';
var r3 = true ? true : null;
var r3 = true ? null : true;
var r4 = true ? new Date() : null;
var r4 = true ? null : new Date();
var r5 = true ? /1/ : null;
var r5 = true ? null : /1/;
var r6 = true ? { foo: 1 } : null;
var r6 = true ? null : { foo: 1 };
var r7 = true ? () => { } : null;
var r7 = true ? null : () => { };
var r8 = true ? <T>(x: T) => { return x } : null;
var r8b = true ? null : <T>(x: T) => { return x }; // type parameters not identical across declarations
interface I1 { foo: number; }
var i1: I1;
var r9 = true ? i1 : null;
var r9 = true ? null : i1;
class C1 { foo: number; }
var c1: C1;
var r10 = true ? c1 : null;
var r10 = true ? null : c1;
class C2<T> { foo: T; }
var c2: C2<number>;
var r12 = true ? c2 : null;
var r12 = true ? null : c2;
enum E { A }
var r13 = true ? E : null;
var r13 = true ? null : E;
var r14 = true ? E.A : null;
var r14 = true ? null : E.A;
function f() { }
module f {
export var bar = 1;
}
var af: typeof f;
var r15 = true ? af : null;
var r15 = true ? null : af;
class c { baz: string }
module c {
export var bar = 1;
}
var ac: typeof c;
var r16 = true ? ac : null;
var r16 = true ? null : ac;
function f17<T>(x: T) {
var r17 = true ? x : null;
var r17 = true ? null : x;
}
function f18<T, U>(x: U) {
var r18 = true ? x : null;
var r18 = true ? null : x;
}
//function f18<T, U extends T>(x: U) {
// var r18 = true ? x : null;
// var r18 = true ? null : x;
//}
var r19 = true ? new Object() : null;
var r19 = true ? null : new Object();
var r20 = true ? {} : null;
var r20 = true ? null : {};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullOrUndefinedTypeGuardIsOrderIndependent.ts | TypeScript | // @strictNullChecks: true
function test(strOrNull: string | null, strOrUndefined: string | undefined) {
var str: string = "original";
var nil: null;
if (null === strOrNull) {
nil = strOrNull;
}
else {
str = strOrNull;
}
if (undefined !== strOrUndefined) {
str = strOrUndefined;
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullPropertyName.ts | TypeScript | // @declaration: true
function foo() {}
// properties
foo.x = 1;
foo.y = 1;
// keywords
foo.break = 1;
foo.case = 1;
foo.catch = 1;
foo.class = 1;
foo.const = 1;
foo.continue = 1;
foo.debugger = 1;
foo.default = 1;
foo.delete = 1;
foo.do = 1;
foo.else = 1;
foo.enum = 1;
foo.export = 1;
foo.extends = 1;
foo.false = 1;
foo.finally = 1;
foo.for = 1;
foo.function = 1;
foo.if = 1;
foo.import = 1;
foo.in = 1;
foo.instanceof = 1;
foo.new = 1;
foo.null = 1;
foo.return = 1;
foo.super = 1;
foo.switch = 1;
foo.this = 1;
foo.throw = 1;
foo.true = 1;
foo.try = 1;
foo.typeof = 1;
foo.var = 1;
foo.void = 1;
foo.while = 1;
foo.with = 1;
foo.implements = 1;
foo.interface = 1;
foo.let = 1;
foo.package = 1;
foo.private = 1;
foo.protected = 1;
foo.public = 1;
foo.static = 1;
foo.yield = 1;
foo.abstract = 1;
foo.as = 1;
foo.asserts = 1;
foo.any = 1;
foo.async = 1;
foo.await = 1;
foo.boolean = 1;
foo.constructor = 1;
foo.declare = 1;
foo.get = 1;
foo.infer = 1;
foo.is = 1;
foo.keyof = 1;
foo.module = 1;
foo.namespace = 1;
foo.never = 1;
foo.readonly = 1;
foo.require = 1;
foo.number = 1;
foo.object = 1;
foo.set = 1;
foo.string = 1;
foo.symbol = 1;
foo.type = 1;
foo.undefined = 1;
foo.unique = 1;
foo.unknown = 1;
foo.from = 1;
foo.global = 1;
foo.bigint = 1;
foo.of = 1;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperator1.ts | TypeScript | // @strict: true
// @allowUnreachableCode: false
declare const a1: string | undefined | null
declare const a2: string | undefined | null
declare const a3: string | undefined | null
declare const a4: string | undefined | null
declare const b1: number | undefined | null
declare const b2: number | undefined | null
declare const b3: number | undefined | null
declare const b4: number | undefined | null
declare const c1: boolean | undefined | null
declare const c2: boolean | undefined | null
declare const c3: boolean | undefined | null
declare const c4: boolean | undefined | null
interface I { a: string }
declare const d1: I | undefined | null
declare const d2: I | undefined | null
declare const d3: I | undefined | null
declare const d4: I | undefined | null
const aa1 = a1 ?? 'whatever';
const aa2 = a2 ?? 'whatever';
const aa3 = a3 ?? 'whatever';
const aa4 = a4 ?? 'whatever';
const bb1 = b1 ?? 1;
const bb2 = b2 ?? 1;
const bb3 = b3 ?? 1;
const bb4 = b4 ?? 1;
const cc1 = c1 ?? true;
const cc2 = c2 ?? true;
const cc3 = c3 ?? true;
const cc4 = c4 ?? true;
const dd1 = d1 ?? {b: 1};
const dd2 = d2 ?? {b: 1};
const dd3 = d3 ?? {b: 1};
const dd4 = d4 ?? {b: 1};
// Repro from #34635
declare function foo(): void;
const maybeBool = false;
if (!(maybeBool ?? true)) {
foo();
}
if (maybeBool ?? true) {
foo();
}
else {
foo();
}
if (false ?? true) {
foo();
}
else {
foo();
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperator10.ts | TypeScript | // @strict: true
declare function f(): string | undefined;
let gg = f() ?? 'foo'
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperator11.ts | TypeScript | // @strict: true
declare const f11: 1 | 0 | '' | null | undefined;
let g11 = f11 ?? f11.toFixed()
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperator12.ts | TypeScript | // @strict: true
// @target: ES2015
const obj: { arr: any[] } = { arr: [] };
for (const i of obj?.arr ?? []) { }
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperator2.ts | TypeScript | // @strict: true
declare const a1: 'literal' | undefined | null
declare const a2: '' | undefined | null
declare const a3: 1 | undefined | null
declare const a4: 0 | undefined | null
declare const a5: true | undefined | null
declare const a6: false | undefined | null
declare const a7: unknown | null
declare const a8: never | null
declare const a9: any | null
const aa1 = a1 ?? 'whatever'
const aa2 = a2 ?? 'whatever'
const aa3 = a3 ?? 'whatever'
const aa4 = a4 ?? 'whatever'
const aa5 = a5 ?? 'whatever'
const aa6 = a6 ?? 'whatever'
const aa7 = a7 ?? 'whatever'
const aa8 = a8 ?? 'whatever'
const aa9 = a9 ?? 'whatever' | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperator3.ts | TypeScript | // @strict: true
declare const a1: 'literal' | undefined | null
declare const a2: '' | undefined | null
declare const a3: 1 | undefined | null
declare const a4: 0 | undefined | null
declare const a5: true | undefined | null
declare const a6: false | undefined | null
const aa1 = a1 ?? a2 ?? a3 ?? a4 ?? a5 ?? a6 ?? 'whatever'
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperator4.ts | TypeScript | // @strict: true
declare const a1: 'literal' | undefined | null
const aa1 = a1 ?? a1.toLowerCase()
const aa2 = a1 || a1.toLocaleUpperCase()
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperator5.ts | TypeScript | // @strict: true
declare const a: string | undefined
declare const b: string | undefined
declare const c: string | undefined
// should be a syntax error
a ?? b || c;
// should be a syntax error
a || b ?? c;
// should be a syntax error
a ?? b && c;
// should be a syntax error
a && b ?? c;
// Valid according to spec
a ?? (b || c);
// Valid according to spec
(a ?? b) || c;
// Valid according to spec
(a || b) ?? c;
// Valid according to spec
a || (b ?? c);
// Valid according to spec
a ?? (b && c);
// Valid according to spec
(a ?? b) && c;
// Valid according to spec
(a && b) ?? c;
// Valid according to spec
a && (b ?? c);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperator6.ts | TypeScript | // @strict: true
function foo(foo: string, bar = foo ?? "bar") { }
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperator7.ts | TypeScript | // @strict: true
declare const a: string | undefined;
declare const b: string | undefined;
declare const c: string | undefined;
const foo1 = a ? 1 : 2;
const foo2 = a ?? 'foo' ? 1 : 2;
const foo3 = a ?? 'foo' ? (b ?? 'bar') : (c ?? 'baz');
function f () {
const foo4 = a ?? 'foo' ? b ?? 'bar' : c ?? 'baz';
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperator8.ts | TypeScript | // @strict: true
declare const a: { p: string | undefined, m(): string | undefined };
declare const b: { p: string | undefined, m(): string | undefined };
const n1 = a.p ?? "default";
const n2 = a.m() ?? "default";
const n3 = a.m() ?? b.p ?? b.m() ?? "default";;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperator9.ts | TypeScript | // @strict: true
declare let f: null | ((x: string) => void);
let g = f || (abc => { void abc.toLowerCase() })
let gg = f ?? (abc => { void abc.toLowerCase() })
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperatorInAsyncGenerator.ts | TypeScript | // @target: esnext,es2015,es5
// @lib: esnext
// @noEmitHelpers: true
// @noTypesAndSymbols: true
// https://github.com/microsoft/TypeScript/issues/37686
async function* f(a: { b?: number }) {
let c = a.b ?? 10;
while (c) {
yield c--;
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperatorInParameterBindingPattern.2.ts | TypeScript | // @target: esnext,es2015,es5
// @noTypesAndSymbols: true
// @noEmit: true
// https://github.com/microsoft/TypeScript/issues/36295
const a = (): string | undefined => undefined;
(({ [a() ?? "d"]: c = "" }) => { var a; })();
const x = "";
(({ [a() ?? "d"]: c = "", d = x }) => { var x; })(); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperatorInParameterBindingPattern.ts | TypeScript | // @target: esnext,es2015,es5
// @noTypesAndSymbols: true
// https://github.com/microsoft/TypeScript/issues/36295
const a = (): string | undefined => undefined;
(({ [a() ?? "d"]: c = "" }) => {})(); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperatorInParameterInitializer.2.ts | TypeScript | // @target: esnext,es2015,es5
// @noTypesAndSymbols: true
// @noEmit: true
// https://github.com/microsoft/TypeScript/issues/36295
const a = (): string | undefined => undefined;
((b = a() ?? "d") => { var a; })();
const x = "";
((b = a() ?? "d", d = x) => { var x; })(); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperatorInParameterInitializer.ts | TypeScript | // @target: esnext,es2015,es5
// @noTypesAndSymbols: true
// https://github.com/microsoft/TypeScript/issues/36295
const a = (): string | undefined => undefined;
((b = a() ?? "d") => {})(); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperator_es2020.ts | TypeScript | // @strict: true
// @target: es2020
declare const a1: 'literal' | undefined | null
declare const a2: '' | undefined | null
declare const a3: 1 | undefined | null
declare const a4: 0 | undefined | null
declare const a5: true | undefined | null
declare const a6: false | undefined | null
declare const a7: unknown | null
declare const a8: never | null
declare const a9: any | null
const aa1 = a1 ?? 'whatever'
const aa2 = a2 ?? 'whatever'
const aa3 = a3 ?? 'whatever'
const aa4 = a4 ?? 'whatever'
const aa5 = a5 ?? 'whatever'
const aa6 = a6 ?? 'whatever'
const aa7 = a7 ?? 'whatever'
const aa8 = a8 ?? 'whatever'
const aa9 = a9 ?? 'whatever'
declare let a: any, b: any, c: any;
let x1 = (a ?? b as any) || c;
let x2 = c || (a ?? b as any);
let x3 = ((a ?? b) as any) || c;
let x4 = c || ((a ?? b) as any);
let x5 = (a ?? b) as any || c;
let x6 = c || (a ?? b) as any;
let y1 = (a ?? b as any) && c;
let y2 = c && (a ?? b as any);
let y3 = ((a ?? b) as any) && c;
let y4 = c && ((a ?? b) as any);
let y5 = (a ?? b) as any && c;
let y6 = c && (a ?? b) as any;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/nullishCoalescingOperator_not_strict.ts | TypeScript | // @strict: false
declare const a1: 'literal' | undefined | null
declare const a2: '' | undefined | null
declare const a3: 1 | undefined | null
declare const a4: 0 | undefined | null
declare const a5: true | undefined | null
declare const a6: false | undefined | null
declare const a7: unknown | null
declare const a8: never | null
declare const a9: any | null
const aa1 = a1 ?? 'whatever'
const aa2 = a2 ?? 'whatever'
const aa3 = a3 ?? 'whatever'
const aa4 = a4 ?? 'whatever'
const aa5 = a5 ?? 'whatever'
const aa6 = a6 ?? 'whatever'
const aa7 = a7 ?? 'whatever'
const aa8 = a8 ?? 'whatever'
const aa9 = a9 ?? 'whatever' | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/numberAssignableToEnum.ts | TypeScript | enum E { A }
var n: number;
var e: E;
e = n;
n = e; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/numberPropertyAccess.ts | TypeScript | var x = 1;
var a = x.toExponential();
var b = x.hasOwnProperty('toFixed');
var c = x['toExponential']();
var d = x['hasOwnProperty']('toFixed'); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/numericIndexerConstrainsPropertyDeclarations.ts | TypeScript | // String indexer types constrain the types of named properties in their containing type
interface MyNumber extends Number {
foo: number;
}
class C {
[x: number]: string;
constructor() { } // ok
a: string; // ok
b: number; // ok
c: () => {} // ok
"d": string; // ok
"e": number; // ok
1.0: string; // ok
2.0: number; // error
"3.0": string; // ok
"4.0": number; // error
3.0: MyNumber // error
get X() { // ok
return '';
}
set X(v) { } // ok
foo() {
return '';
}
static sa: number; // ok
static sb: string; // ok
static foo() { } // ok
static get X() { // ok
return 1;
}
}
interface I {
[x: number]: string;
a: string; // ok
b: number; // ok
c: () => {} // ok
"d": string; // ok
"e": number; // ok
1.0: string; // ok
2.0: number; // error
(): string; // ok
(x): number // ok
foo(): string; // ok
"3.0": string; // ok
"4.0": number; // error
f: MyNumber; // error
}
var a: {
[x: number]: string;
a: string; // ok
b: number; // ok
c: () => {} // ok
"d": string; // ok
"e": number; // ok
1.0: string; // ok
2.0: number; // error
(): string; // ok
(x): number // ok
foo(): string; // ok
"3.0": string; // ok
"4.0": number; // error
f: MyNumber; // error
}
// error
var b: { [x: number]: string; } = {
a: '',
b: 1,
c: () => { },
"d": '',
"e": 1,
1.0: '',
2.0: 1,
"3.0": '',
"4.0": 1,
f: <Myn>null,
get X() {
return '';
},
set X(v) { },
foo() {
return '';
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/numericIndexerConstrainsPropertyDeclarations2.ts | TypeScript | // String indexer providing a constraint of a user defined type
class A {
foo(): string { return ''; }
}
class B extends A {
bar(): string { return ''; }
}
class Foo {
[x: number]: A;
1.0: A; // ok
2.0: B; // ok
"2.5": B // ok
3.0: number; // error
"4.0": string; // error
}
interface Foo2 {
[x: number]: A;
1.0: A; // ok
2.0: B; // ok
"2.5": B // ok
3.0: number; // error
"4.0": string; // error
}
var a: {
[x: number]: A;
1.0: A; // ok
2.0: B; // ok
"2.5": B // ok
3.0: number; // error
"4.0": string; // error
};
// error
var b: { [x: number]: A } = {
1.0: new A(),
2.0: new B(),
"2.5": new B(),
3.0: 1,
"4.0": ''
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/numericIndexingResults.ts | TypeScript | class C {
[x: number]: string;
1 = '';
"2" = ''
}
var c: C;
var r1 = c['1'];
var r2 = c['2'];
var r3 = c['3'];
var r4 = c[1];
var r5 = c[2];
var r6 = c[3];
interface I {
[x: number]: string;
1: string;
"2": string;
}
var i: I
var r1 = i['1'];
var r2 = i['2'];
var r3 = i['3'];
var r4 = i[1];
var r5 = i[2];
var r6 = i[3];
var a: {
[x: number]: string;
1: string;
"2": string;
}
var r1 = a['1'];
var r2 = a['2'];
var r3 = a['3'];
var r4 = a[1];
var r5 = a[2];
var r6 = a[3];
var b: { [x: number]: string } = { 1: '', "2": '' }
var r1a = b['1'];
var r2a = b['2'];
var r3 = b['3'];
var r4 = b[1];
var r5 = b[2];
var r6 = b[3];
var b2: { [x: number]: string; 1: string; "2": string; } = { 1: '', "2": '' }
var r1b = b2['1'];
var r2b = b2['2'];
var r3 = b2['3'];
var r4 = b2[1];
var r5 = b2[2];
var r6 = b2[3]; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/numericLiteralTypes1.ts | TypeScript | type A1 = 1;
type A2 = 1.0;
type A3 = 1e0;
type A4 = 10e-1;
type A5 = 1 | 1.0 | 1e0 | 10e-1;
function f1() {
var a: A1 = 1;
var a: A2 = 1;
var a: A3 = 1;
var a: A4 = 1;
var a: A5 = 1;
}
type B1 = -1 | 0 | 1;
type B2 = 1 | 0 | -1;
type B3 = 0 | -1 | 1;
function f2() {
var b: B1 = -1;
var b: B2 = 0;
var b: B3 = 1;
}
function f3(a: 1, b: 0 | 1 | 2) {
var x = a + b;
var x = a - b;
var x = a * b;
var x = a / b;
var x = a % b;
var x = a | b;
var x = a & b;
var x = a ^ b;
var x = -b;
var x = ~b;
var y = a == b;
var y = a != b;
var y = a === b;
var y = a !== b;
var y = a > b;
var y = a < b;
var y = a >= b;
var y = a <= b;
var y = !b;
}
function f4(a: 1, b: 0 | 1 | 2) {
a++;
b++;
}
declare function g(x: 0): string;
declare function g(x: 1): boolean;
declare function g(x: number): number;
function f5(a: 1, b: 0 | 1 | 2) {
var z1 = g(0);
var z2 = g(1);
var z3 = g(2);
var z4 = g(a);
var z5 = g(b);
}
function assertNever(x: never): never {
throw new Error("Unexpected value");
}
type Tag = 0 | 1 | 2;
function f10(x: Tag) {
switch (x) {
case 0: return "a";
case 1: return "b";
case 2: return "c";
}
}
function f11(x: Tag) {
switch (x) {
case 0: return "a";
case 1: return "b";
case 2: return "c";
}
return assertNever(x);
}
function f12(x: Tag) {
if (x) {
x;
}
else {
x;
}
}
function f13(x: Tag) {
if (x === 0 || x === 2) {
x;
}
else {
x;
}
}
function f14(x: 0 | 1 | 2, y: string) {
var a = x && y;
var b = x || y;
}
function f15(x: 0 | false, y: 1 | "one") {
var a = x && y;
var b = y && x;
var c = x || y;
var d = y || x;
var e = !x;
var f = !y;
}
type Item =
{ kind: 0, a: string } |
{ kind: 1, b: string } |
{ kind: 2, c: string };
function f20(x: Item) {
switch (x.kind) {
case 0: return x.a;
case 1: return x.b;
case 2: return x.c;
}
}
function f21(x: Item) {
switch (x.kind) {
case 0: return x.a;
case 1: return x.b;
case 2: return x.c;
}
return assertNever(x);
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/numericLiteralTypes2.ts | TypeScript | // @strictNullChecks: true
type A1 = 1;
type A2 = 1.0;
type A3 = 1e0;
type A4 = 10e-1;
type A5 = 1 | 1.0 | 1e0 | 10e-1;
function f1() {
var a: A1 = 1;
var a: A2 = 1;
var a: A3 = 1;
var a: A4 = 1;
var a: A5 = 1;
}
type B1 = -1 | 0 | 1;
type B2 = 1 | 0 | -1;
type B3 = 0 | -1 | 1;
function f2() {
var b: B1 = -1;
var b: B2 = 0;
var b: B3 = 1;
}
function f3(a: 1, b: 0 | 1 | 2) {
var x = a + b;
var x = a - b;
var x = a * b;
var x = a / b;
var x = a % b;
var x = a | b;
var x = a & b;
var x = a ^ b;
var x = -b;
var x = ~b;
var y = a == b;
var y = a != b;
var y = a === b;
var y = a !== b;
var y = a > b;
var y = a < b;
var y = a >= b;
var y = a <= b;
var y = !b;
}
function f4(a: 1, b: 0 | 1 | 2) {
a++;
b++;
}
declare function g(x: 0): string;
declare function g(x: 1): boolean;
declare function g(x: number): number;
function f5(a: 1, b: 0 | 1 | 2) {
var z1 = g(0);
var z2 = g(1);
var z3 = g(2);
var z4 = g(a);
var z5 = g(b);
}
function assertNever(x: never): never {
throw new Error("Unexpected value");
}
type Tag = 0 | 1 | 2;
function f10(x: Tag) {
switch (x) {
case 0: return "a";
case 1: return "b";
case 2: return "c";
}
}
function f11(x: Tag) {
switch (x) {
case 0: return "a";
case 1: return "b";
case 2: return "c";
}
return assertNever(x);
}
function f12(x: Tag) {
if (x) {
x;
}
else {
x;
}
}
function f13(x: Tag) {
if (x === 0 || x === 2) {
x;
}
else {
x;
}
}
function f14(x: 0 | 1 | 2, y: string) {
var a = x && y;
var b = x || y;
}
function f15(x: 0 | false, y: 1 | "one") {
var a = x && y;
var b = y && x;
var c = x || y;
var d = y || x;
var e = !x;
var f = !y;
}
type Item =
{ kind: 0, a: string } |
{ kind: 1, b: string } |
{ kind: 2, c: string };
function f20(x: Item) {
switch (x.kind) {
case 0: return x.a;
case 1: return x.b;
case 2: return x.c;
}
}
function f21(x: Item) {
switch (x.kind) {
case 0: return x.a;
case 1: return x.b;
case 2: return x.c;
}
return assertNever(x);
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/numericLiteralTypes3.ts | TypeScript | type A = 1;
type B = 2 | 3;
type C = 1 | 2 | 3;
type D = 0 | 1 | 2;
function f1(a: A, b: B, c: C, d: D) {
a = a;
a = b;
a = c;
a = d;
}
function f2(a: A, b: B, c: C, d: D) {
b = a;
b = b;
b = c;
b = d;
}
function f3(a: A, b: B, c: C, d: D) {
c = a;
c = b;
c = c;
c = d;
}
function f4(a: A, b: B, c: C, d: D) {
d = a;
d = b;
d = c;
d = d;
}
function f5(a: A, b: B, c: C, d: D) {
a = 0;
a = 1;
a = 2;
a = 3;
b = 0;
b = 1;
b = 2;
b = 3;
c = 0;
c = 1;
c = 2;
c = 3;
d = 0;
d = 1;
d = 2;
d = 3;
}
function f6(a: A, b: B, c: C, d: D) {
a === 0;
a === 1;
a === 2;
a === 3;
b === 0;
b === 1;
b === 2;
b === 3;
c === 0;
c === 1;
c === 2;
c === 3;
d === 0;
d === 1;
d === 2;
d === 3;
}
function f7(a: A, b: B, c: C, d: D) {
a === a;
a === b;
a === c;
a === d;
b === a;
b === b;
b === c;
b === d;
c === a;
c === b;
c === c;
c === d;
d === a;
d === b;
d === c;
d === d;
}
function f8(x: 0 | 2 | 4) {
switch (x) {
case 0: return;
case 1: return;
case 2: return;
case 3: return;
case 4: return;
case 5: return;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/numericStringLiteralTypes.ts | TypeScript | // @strict: true
// @declaration: true
type T0 = string & `${string}`; // string
type T1 = string & `${number}`; // `${number}
type T2 = string & `${bigint}`; // `${bigint}
type T3<T extends string> = string & `${T}`; // `${T}
type T4<T extends string> = string & `${Capitalize<`${T}`>}`; // `${Capitalize<T>}`
function f1(a: boolean[], x: `${number}`) {
let s = a[x]; // boolean
}
function f2(a: boolean[], x: number | `${number}`) {
let s = a[x]; // boolean
}
type T10 = boolean[][`${number}`]; // boolean
type T11 = boolean[][number | `${number}`]; // boolean
type T20<T extends number | `${number}`> = T;
type T21<T extends unknown[]> = { [K in keyof T]: T20<K> };
type Container<T> = {
value: T
}
type UnwrapContainers<T extends Container<unknown>[]> = { [K in keyof T]: T[K]['value'] };
declare function createContainer<T extends unknown>(value: T): Container<T>;
declare function f<T extends Container<unknown>[]>(containers: [...T], callback: (...values: UnwrapContainers<T>) => void): void;
const container1 = createContainer('hi')
const container2 = createContainer(2)
f([container1, container2], (value1, value2) => {
value1; // string
value2; // number
});
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectBindingPatternKeywordIdentifiers05.ts | TypeScript |
var { as } = { as: 1 } | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectBindingPatternKeywordIdentifiers06.ts | TypeScript |
var { as: as } = { as: 1 } | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectLiteralContextualTyping.ts | TypeScript | // In a contextually typed object literal, each property value expression is contextually typed by
// the type of the property with a matching name in the contextual type, if any, or otherwise
// for a numerically named property, the numeric index type of the contextual type, if any, or otherwise
// the string index type of the contextual type, if any.
interface Item {
name: string;
description?: string;
}
declare function foo(item: Item): string;
declare function foo(item: any): number;
var x = foo({ name: "Sprocket" });
var x: string;
var y = foo({ name: "Sprocket", description: "Bumpy wheel" });
var y: string;
var z = foo({ name: "Sprocket", description: false });
var z: number;
var w = foo({ a: 10 });
var w: number;
declare function bar<T>(param: { x?: T }): T;
var b = bar({});
var b: {};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectLiteralGettersAndSetters.ts | TypeScript | // Get and set accessor with the same name
var sameName1a = { get 'a'() { return ''; }, set a(n) { var p = n; var p: string; } };
var sameName2a = { get 0.0() { return ''; }, set 0(n) { var p = n; var p: string; } };
var sameName3a = { get 0x20() { return ''; }, set 3.2e1(n) { var p = n; var p: string; } };
var sameName4a = { get ''() { return ''; }, set ""(n) { var p = n; var p: string; } };
var sameName5a = { get '\t'() { return ''; }, set '\t'(n) { var p = n; var p: string; } };
var sameName6a = { get 'a'() { return ''; }, set a(n) { var p = n; var p: string; } };
// PropertyName CallSignature{FunctionBody} is equivalent to PropertyName:function CallSignature{FunctionBody}
var callSig1 = { num(n: number) { return '' } };
var callSig1: { num: (n: number) => string; };
var callSig2 = { num: function (n: number) { return '' } };
var callSig2: { num: (n: number) => string; };
var callSig3 = { num: (n: number) => '' };
var callSig3: { num: (n: number) => string; };
// Get accessor only, type of the property is the annotated return type of the get accessor
var getter1 = { get x(): string { return undefined; } };
var getter1: { readonly x: string; }
// Get accessor only, type of the property is the inferred return type of the get accessor
var getter2 = { get x() { return ''; } };
var getter2: { readonly x: string; }
// Set accessor only, type of the property is the param type of the set accessor
var setter1 = { set x(n: number) { } };
var setter1: { x: number };
// Set accessor only, type of the property is Any for an unannotated set accessor
var setter2 = { set x(n) { } };
var setter2: { x: any };
var anyVar: any;
// Get and set accessor with matching type annotations
var sameType1 = { get x(): string { return undefined; }, set x(n: string) { } };
var sameType2 = { get x(): Array<number> { return undefined; }, set x(n: number[]) { } };
var sameType3 = { get x(): any { return undefined; }, set x(n: typeof anyVar) { } };
var sameType4 = { get x(): Date { return undefined; }, set x(n: Date) { } };
// Type of unannotated get accessor return type is the type annotation of the set accessor param
var setParamType1 = {
set n(x: (t: string) => void) { },
get n() { return (t) => {
var p: string;
var p = t;
}
}
};
var setParamType2 = {
get n() { return (t) => {
var p: string;
var p = t;
}
},
set n(x: (t: string) => void) { }
};
// Type of unannotated set accessor parameter is the return type annotation of the get accessor
var getParamType1 = {
set n(x) {
var y = x;
var y: string;
},
get n() { return ''; }
};
var getParamType2 = {
get n() { return ''; },
set n(x) {
var y = x;
var y: string;
}
};
// Type of unannotated accessors is the inferred return type of the get accessor
var getParamType3 = {
get n() { return ''; },
set n(x) {
var y = x;
var y: string;
}
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectLiteralNormalization.ts | TypeScript | // @strict: true
// @declaration: true
// Object literals in unions are normalized upon widening
let a1 = [{ a: 0 }, { a: 1, b: "x" }, { a: 2, b: "y", c: true }][0];
a1.a; // number
a1.b; // string | undefined
a1.c; // boolean | undefined
a1 = { a: 1 };
a1 = { a: 0, b: 0 }; // Error
a1 = { b: "y" }; // Error
a1 = { c: true }; // Error
let a2 = [{ a: 1, b: 2 }, { a: "abc" }, {}][0];
a2.a; // string | number | undefined
a2.b; // number | undefined
a2 = { a: 10, b: 20 };
a2 = { a: "def" };
a2 = {};
a2 = { a: "def", b: 20 }; // Error
a2 = { a: 1 }; // Error
// Object literals containing spreads are not normalized
declare let b1: { a: string, b: string } | { b: string, c: string };
let b2 = { ...b1, z: 55 };
let b3 = { ...b2 };
// Before widening {} acts like { [x: string]: undefined }, which is a
// subtype of types with all optional properties
declare let opts: { foo?: string, bar?: string, baz?: boolean };
let c1 = !true ? {} : opts;
let c2 = !true ? opts : {};
let c3 = !true ? { a: 0, b: 0 } : {};
let c4 = !true ? {} : { a: 0, b: 0 };
// Normalization applies to nested properties
let d1 = [{ kind: 'a', pos: { x: 0, y: 0 } }, { kind: 'b', pos: !true ? { a: "x" } : { b: 0 } }][0];
d1.kind;
d1.pos;
d1.pos.x;
d1.pos.y;
d1.pos.a;
d1.pos.b;
declare function f<T>(...items: T[]): T;
declare let data: { a: 1, b: "abc", c: true };
// Object literals are inferred as a single normalized union type
let e1 = f({ a: 1, b: 2 }, { a: "abc" }, {});
let e2 = f({}, { a: "abc" }, { a: 1, b: 2 });
let e3 = f(data, { a: 2 });
let e4 = f({ a: 2 }, data);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectLiteralShorthandProperties.ts | TypeScript | // @target: es5
var a, b, c;
var x1 = {
a
};
var x2 = {
a,
}
var x3 = {
a: 0,
b,
c,
d() { },
x3,
parent: x3
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectLiteralShorthandPropertiesAssignment.ts | TypeScript | // @lib: es5
var id: number = 10000;
var name: string = "my name";
var person: { name: string; id: number } = { name, id };
function foo( obj:{ name: string }): void { };
function bar(name: string, id: number) { return { name, id }; }
function bar1(name: string, id: number) { return { name }; }
function baz(name: string, id: number): { name: string; id: number } { return { name, id }; }
foo(person);
var person1 = bar("Hello", 5);
var person2: { name: string } = bar("Hello", 5);
var person3: { name: string; id:number } = bar("Hello", 5);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectLiteralShorthandPropertiesAssignmentES6.ts | TypeScript | // @lib: es5
// @target: es6
var id: number = 10000;
var name: string = "my name";
var person: { name: string; id: number } = { name, id };
function foo(obj: { name: string }): void { };
function bar(name: string, id: number) { return { name, id }; }
function bar1(name: string, id: number) { return { name }; }
function baz(name: string, id: number): { name: string; id: number } { return { name, id }; }
foo(person);
var person1 = bar("Hello", 5);
var person2: { name: string } = bar("Hello", 5);
var person3: { name: string; id: number } = bar("Hello", 5);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectLiteralShorthandPropertiesAssignmentError.ts | TypeScript | // @lib: es5
var id: number = 10000;
var name: string = "my name";
var person: { b: string; id: number } = { name, id }; // error
var person1: { name, id }; // ok
function foo(name: string, id: number): { id: string, name: number } { return { name, id }; } // error
function bar(obj: { name: string; id: boolean }) { }
bar({ name, id }); // error
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts | TypeScript | // @lib: es5
var id: number = 10000;
var name: string = "my name";
var person: { b: string; id: number } = { name, id }; // error
function bar(name: string, id: number): { name: number, id: string } { return { name, id }; } // error
function foo(name: string, id: number): { name: string, id: number } { return { name, id }; } // error
var person1: { name, id }; // ok
var person2: { name: string, id: number } = bar("hello", 5);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectLiteralShorthandPropertiesES6.ts | TypeScript | // @target: es6
var a, b, c;
var x1 = {
a
};
var x2 = {
a,
}
var x3 = {
a: 0,
b,
c,
d() { },
x3,
parent: x3
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectLiteralShorthandPropertiesFunctionArgument.ts | TypeScript | // @lib: es5
var id: number = 10000;
var name: string = "my name";
var person = { name, id };
function foo(p: { name: string; id: number }) { }
foo(person);
var obj = { name: name, id: id }; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectLiteralShorthandPropertiesFunctionArgument2.ts | TypeScript | // @lib: es5
var id: number = 10000;
var name: string = "my name";
var person = { name, id };
function foo(p: { a: string; id: number }) { }
foo(person); // error
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectLiteralShorthandPropertiesWithModule.ts | TypeScript | // module export
module m {
export var x;
}
module m {
var z = x;
var y = {
a: x,
x
};
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectLiteralShorthandPropertiesWithModuleES6.ts | TypeScript | // @target: es6
module m {
export var x;
}
module m {
var z = x;
var y = {
a: x,
x
};
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectLiteralWidened.ts | TypeScript | // object literal properties are widened to any
var x1 = {
foo: null,
bar: undefined
}
var y1 = {
foo: null,
bar: {
baz: null,
boo: undefined
}
}
// these are not widened
var u: undefined = undefined;
var n: null = null;
var x2 = {
foo: n,
bar: u
}
var y2 = {
foo: n,
bar: {
baz: n,
boo: u
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectRest.ts | TypeScript | // @target: es2015
var o = { a: 1, b: 'no' }
var { ...clone } = o;
var { a, ...justB } = o;
var { a, b: renamed, ...empty } = o;
var { ['b']: renamed, ...justA } = o;
var { 'b': renamed, ...justA } = o;
var { b: { '0': n, '1': oooo }, ...justA } = o;
let o2 = { c: 'terrible idea?', d: 'yes' };
var { d: renamed, ...d } = o2;
let nestedrest: { x: number, n1: { y: number, n2: { z: number, n3: { n4: number } } }, rest: number, restrest: number };
var { x, n1: { y, n2: { z, n3: { ...nr } } }, ...restrest } = nestedrest;
let complex: { x: { ka, ki }, y: number };
var { x: { ka, ...nested }, y: other, ...rest } = complex;
({x: { ka, ...nested }, y: other, ...rest} = complex);
var { x, ...fresh } = { x: 1, y: 2 };
({ x, ...fresh } = { x: 1, y: 2 });
class Removable {
private x: number;
protected y: number;
set z(value: number) { }
get both(): number { return 12 }
set both(value: number) { }
m() { }
removed: string;
remainder: string;
}
interface I {
m(): void;
removed: string;
remainder: string;
}
var removable = new Removable();
var { removed, ...removableRest } = removable;
var i: I = removable;
var { removed, ...removableRest2 } = i;
let computed = 'b';
let computed2 = 'a';
var { [computed]: stillNotGreat, [computed2]: soSo, ...o } = o;
({ [computed]: stillNotGreat, [computed2]: soSo, ...o } = o);
var noContextualType = ({ aNumber = 12, ...notEmptyObject }) => aNumber + notEmptyObject.anythingGoes;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectRest2.ts | TypeScript | // @lib: es2015
// @target: es2015
// test for #12203
declare function connectionFromArray(objects: number, args: any): {};
function rootConnection(name: string) {
return {
resolve: async (context, args) => {
const { objects } = await { objects: 12 };
return {
...connectionFromArray(objects, args)
};
}
};
}
rootConnection('test');
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectRestAssignment.ts | TypeScript | // @target: es2015
let ka: any;
let nested: { ki };
let other: number;
let rest: { };
let complex: { x: { ka, ki }, y: number };
({x: { ka, ...nested }, y: other, ...rest} = complex);
// should be:
let overEmit: { a: { ka: string, x: string }[], b: { z: string, ki: string, ku: string }, ke: string, ko: string };
// var _g = overEmit.a, [_h, ...y] = _g, nested2 = __rest(_h, []), _j = overEmit.b, { z } = _j, c = __rest(_j, ["z"]), rest2 = __rest(overEmit, ["a", "b"]);
var { a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit;
({ a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectRestCatchES5.ts | TypeScript | let a = 1, b = 2;
try {} catch ({ a, ...b }) {} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectRestForOf.ts | TypeScript | // @target: es2015
let array: { x: number, y: string }[];
for (let { x, ...restOf } of array) {
[x, restOf];
}
let xx: number;
let rrestOff: { y: string };
for ({ x: xx, ...rrestOff } of array ) {
[xx, rrestOff];
}
for (const norest of array.map(a => ({ ...a, x: 'a string' }))) {
[norest.x, norest.y];
// x is now a string. who knows why.
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectRestNegative.ts | TypeScript | // @noImplicitAny: true
let o = { a: 1, b: 'no' };
var { ...mustBeLast, a } = o;
var b: string;
let notAssignable: { a: string };
({ b, ...notAssignable } = o);
function stillMustBeLast({ ...mustBeLast, a }: { a: number, b: string }): void {
}
function generic<T extends { x, y }>(t: T) {
let { x, ...rest } = t;
return rest;
}
let rest: { b: string }
({a, ...rest.b + rest.b} = o);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectRestParameter.ts | TypeScript | // @target: es2015
function cloneAgain({ a, ...clone }: { a: number, b: string }): void {
}
declare function suddenly(f: (a: { x: { z, ka }, y: string }) => void);
suddenly(({ x: a, ...rest }) => rest.y);
suddenly(({ x: { z = 12, ...nested }, ...rest } = { x: { z: 1, ka: 1 }, y: 'noo' }) => rest.y + nested.ka);
class C {
m({ a, ...clone }: { a: number, b: string}): void {
// actually, never mind, don't clone
}
set p({ a, ...clone }: { a: number, b: string}) {
// actually, never mind, don't clone
}
}
function foobar({ bar={}, ...opts }: any = {}) {
}
foobar();
foobar({ baz: 'hello' });
foobar({ bar: { greeting: 'hello' } });
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectRestParameterES5.ts | TypeScript | // @target: es5
function cloneAgain({ a, ...clone }: { a: number, b: string }): void {
}
declare function suddenly(f: (a: { x: { z, ka }, y: string }) => void);
suddenly(({ x: a, ...rest }) => rest.y);
suddenly(({ x: { z = 12, ...nested }, ...rest } = { x: { z: 1, ka: 1 }, y: 'noo' }) => rest.y + nested.ka);
class C {
m({ a, ...clone }: { a: number, b: string}): void {
// actually, never mind, don't clone
}
set p({ a, ...clone }: { a: number, b: string}) {
// actually, never mind, don't clone
}
}
function foobar({ bar={}, ...opts }: any = {}) {
}
foobar();
foobar({ baz: 'hello' });
foobar({ bar: { greeting: 'hello' } });
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectRestPropertyMustBeLast.ts | TypeScript | var {...a, x } = { x: 1 }; // Error, rest must be last property
({...a, x } = { x: 1 }); // Error, rest must be last property
var {...a, x, ...b } = { x: 1 }; // Error, rest must be last property
({...a, x, ...b } = { x: 1 }); // Error, rest must be last property
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectRestReadonly.ts | TypeScript | // #23734
type ObjType = {
foo: string
baz: string
quux: string
}
const obj: Readonly<ObjType> = {
foo: 'bar',
baz: 'qux',
quux: 'quuz',
}
const { foo, ...rest } = obj
delete rest.baz
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectSpread.ts | TypeScript | // @strictNullChecks: true
// @target: es5
let o = { a: 1, b: 'no' }
let o2 = { b: 'yes', c: true }
let swap = { a: 'yes', b: -1 };
let addAfter: { a: number, b: string, c: boolean } =
{ ...o, c: false }
let addBefore: { a: number, b: string, c: boolean } =
{ c: false, ...o }
let override: { a: number, b: string } =
{ ...o, b: 'override' }
let nested: { a: number, b: boolean, c: string } =
{ ...{ a: 3, ...{ b: false, c: 'overriden' } }, c: 'whatever' }
let combined: { a: number, b: string, c: boolean } =
{ ...o, ...o2 }
let combinedAfter: { a: number, b: string, c: boolean } =
{ ...o, ...o2, b: 'ok' }
let combinedNestedChangeType: { a: number, b: boolean, c: number } =
{ ...{ a: 1, ...{ b: false, c: 'overriden' } }, c: -1 }
let propertyNested: { a: { a: number, b: string } } =
{ a: { ... o } }
// accessors don't copy the descriptor
// (which means that readonly getters become read/write properties)
let op = { get a () { return 6 } };
let getter: { a: number, c: number } =
{ ...op, c: 7 }
getter.a = 12;
// functions result in { }
let spreadFunc = { ...(function () { }) };
type Header = { head: string, body: string, authToken: string }
function from16326(this: { header: Header }, header: Header, authToken: string): Header {
return {
...this.header,
...header,
...authToken && { authToken }
}
}
// boolean && T results in Partial<T>
function conditionalSpreadBoolean(b: boolean) : { x: number, y: number } {
let o = { x: 12, y: 13 }
o = {
...o,
...b && { x: 14 }
}
let o2 = { ...b && { x: 21 }}
return o;
}
function conditionalSpreadNumber(nt: number): { x: number, y: number } {
let o = { x: 15, y: 16 }
o = {
...o,
...nt && { x: nt }
}
let o2 = { ...nt && { x: nt }}
return o;
}
function conditionalSpreadString(st: string): { x: string, y: number } {
let o = { x: 'hi', y: 17 }
o = {
...o,
...st && { x: st }
}
let o2 = { ...st && { x: st }}
return o;
}
// any results in any
let anything: any;
let spreadAny = { ...anything };
// methods are not enumerable
class C { p = 1; m() { } }
let c: C = new C()
let spreadC: { p: number } = { ...c }
// own methods are enumerable
let cplus: { p: number, plus(): void } = { ...c, plus() { return this.p + 1; } };
cplus.plus();
// new field's type conflicting with existing field is OK
let changeTypeAfter: { a: string, b: string } =
{ ...o, a: 'wrong type?' }
let changeTypeBoth: { a: string, b: number } =
{ ...o, ...swap };
// optional
function container(
definiteBoolean: { sn: boolean },
definiteString: { sn: string },
optionalString: { sn?: string },
optionalNumber: { sn?: number }) {
let optionalUnionStops: { sn: string | number | boolean } = { ...definiteBoolean, ...definiteString, ...optionalNumber };
let optionalUnionDuplicates: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber };
let allOptional: { sn?: string | number } = { ...optionalString, ...optionalNumber };
// computed property
let computedFirst: { a: number, b: string, "before everything": number } =
{ ['before everything']: 12, ...o, b: 'yes' }
let computedAfter: { a: number, b: string, "at the end": number } =
{ ...o, b: 'yeah', ['at the end']: 14 }
}
// shortcut syntax
let a = 12;
let shortCutted: { a: number, b: string } = { ...o, a }
// non primitive
let spreadNonPrimitive = { ...<object>{}};
// generic spreads
function f<T, U>(t: T, u: U) {
return { ...t, ...u, id: 'id' };
}
let exclusive: { id: string, a: number, b: string, c: string, d: boolean } =
f({ a: 1, b: 'yes' }, { c: 'no', d: false })
let overlap: { id: string, a: number, b: string } =
f({ a: 1 }, { a: 2, b: 'extra' })
let overlapConflict: { id:string, a: string } =
f({ a: 1 }, { a: 'mismatch' })
let overwriteId: { id: string, a: number, c: number, d: string } =
f({ a: 1, id: true }, { c: 1, d: 'no' })
function genericSpread<T, U>(t: T, u: U, v: T | U, w: T | { s: string }, obj: { x: number }) {
let x01 = { ...t };
let x02 = { ...t, ...t };
let x03 = { ...t, ...u };
let x04 = { ...u, ...t };
let x05 = { a: 5, b: 'hi', ...t };
let x06 = { ...t, a: 5, b: 'hi' };
let x07 = { a: 5, b: 'hi', ...t, c: true, ...obj };
let x09 = { a: 5, ...t, b: 'hi', c: true, ...obj };
let x10 = { a: 5, ...t, b: 'hi', ...u, ...obj };
let x11 = { ...v };
let x12 = { ...v, ...obj };
let x13 = { ...w };
let x14 = { ...w, ...obj };
let x15 = { ...t, ...v };
let x16 = { ...t, ...w };
let x17 = { ...t, ...w, ...obj };
let x18 = { ...t, ...v, ...w };
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectSpreadComputedProperty.ts | TypeScript | // fixes #12200
function f() {
let n: number = 12;
let m: number = 13;
let a: any = null;
const o1 = { ...{}, [n]: n };
const o2 = { ...{}, [a]: n };
const o3 = { [a]: n, ...{}, [n]: n, ...{}, [m]: m };
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectSpreadIndexSignature.ts | TypeScript | // @strict: true
declare let indexed1: { [n: string]: number; a: number; };
declare let indexed2: { [n: string]: boolean; c: boolean; };
declare let indexed3: { [n: string]: number };
let i = { ...indexed1, b: 11 };
// only indexed has indexer, so i[101]: any
i[101];
let ii = { ...indexed1, ...indexed2 };
// both have indexer, so i[1001]: number | boolean
ii[1001];
declare const b: boolean;
indexed3 = { ...b ? indexed3 : undefined };
declare var roindex: { readonly [x:string]: number };
var writable = { ...roindex };
writable.a = 0; // should be ok.
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectSpreadNoTransform.ts | TypeScript | // @target: esnext
const y = { a: 'yes', b: 'no' };
const o = { x: 1, ...y };
var b;
var rest: any;
({ b, ...rest } = o);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectSpreadRepeatedComplexity.ts | TypeScript | // @strict: true
function f(cnd: Record<number, boolean>){
// Type is a union of 2^(n-1) members, where n is the number of spread objects
return {
// Without this one, it collapses to {} ?
...(cnd[1] &&
cnd[2] && {
prop0: 0,
}),
// With one prop each, it collapses to a single object (#34853?)
...(cnd[3] && {
prop3a: 1,
prop3b: 1,
}),
...(cnd[4] && {
prop4a: 1,
prop4b: 1,
}),
...(cnd[5] && {
prop5a: 1,
prop5b: 1,
}),
...(cnd[6] && {
prop6a: 1,
prop6b: 1,
}),
...(cnd[7] && {
prop7a: 1,
prop7b: 1,
}),
...(cnd[8] && {
prop8a: 1,
prop8b: 1,
}),
...(cnd[9] && {
prop9a: 1,
prop9b: 1,
}),
...(cnd[10] && {
prop10a: 1,
prop10b: 1,
}),
...(cnd[11] && {
prop11a: 1,
prop11b: 1,
}),
...(cnd[12] && {
prop12a: 1,
prop12b: 1,
}),
...(cnd[13] && {
prop13a: 1,
prop13b: 1,
}),
...(cnd[14] && {
prop14a: 1,
prop14b: 1,
}),
...(cnd[15] && {
prop15a: 1,
prop15b: 1,
}),
...(cnd[16] && {
prop16a: 1,
prop16b: 1,
}),
...(cnd[17] && {
prop17a: 1,
prop17b: 1,
}),
...(cnd[18] && {
prop18a: 1,
prop18b: 1,
}),
...(cnd[19] && {
prop19a: 1,
prop19b: 1,
}),
...(cnd[20] && {
prop20a: 1,
prop20b: 1,
}),
};
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/objectSpreadRepeatedNullCheckPerf.ts | TypeScript | // @strict: true
interface Props {
readonly a?: string
readonly b?: string
readonly c?: string
readonly d?: string
readonly e?: string
readonly f?: string
readonly g?: string
readonly h?: string
readonly i?: string
readonly j?: string
readonly k?: string
readonly l?: string
readonly m?: string
readonly n?: string
readonly o?: string
readonly p?: string
readonly q?: string
readonly r?: string
readonly s?: string
readonly t?: string
readonly u?: string
readonly v?: string
readonly w?: string
readonly x?: string
readonly y?: string
readonly z?: string
}
function parseWithSpread(config: Record<string, number>): Props {
return {
...config.a !== undefined && { a: config.a.toString() },
...config.b !== undefined && { b: config.b.toString() },
...config.c !== undefined && { c: config.c.toString() },
...config.d !== undefined && { d: config.d.toString() },
...config.e !== undefined && { e: config.e.toString() },
...config.f !== undefined && { f: config.f.toString() },
...config.g !== undefined && { g: config.g.toString() },
...config.h !== undefined && { h: config.h.toString() },
...config.i !== undefined && { i: config.i.toString() },
...config.j !== undefined && { j: config.j.toString() },
...config.k !== undefined && { k: config.k.toString() },
...config.l !== undefined && { l: config.l.toString() },
...config.m !== undefined && { m: config.m.toString() },
...config.n !== undefined && { n: config.n.toString() },
...config.o !== undefined && { o: config.o.toString() },
...config.p !== undefined && { p: config.p.toString() },
...config.q !== undefined && { q: config.q.toString() },
...config.r !== undefined && { r: config.r.toString() },
...config.s !== undefined && { s: config.s.toString() },
...config.t !== undefined && { t: config.t.toString() },
...config.u !== undefined && { u: config.u.toString() },
...config.v !== undefined && { v: config.v.toString() },
...config.w !== undefined && { w: config.w.toString() },
...config.x !== undefined && { x: config.x.toString() },
...config.y !== undefined && { y: config.y.toString() },
...config.z !== undefined && { z: config.z.toString() }
}
}
parseWithSpread({ a: 1, b: 2, z: 26 }) | 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.