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/contextualTypedSpecialAssignment.ts | TypeScript | // @checkJs: true
// @allowJs: true
// @noEmit: true
// @Filename: test.js
// @strict: true
/** @typedef {{
status: 'done'
m(n: number): void
}} DoneStatus */
// property assignment
var ns = {}
/** @type {DoneStatus} */
ns.x = {
status: 'done',
m(n) { }
}
ns.x = {
status: 'done',
m(n) { }
}
ns... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypeAsyncFunctionAwaitOperand.ts | TypeScript | // @target: esnext
// @noImplicitAny: true
// @noEmit: true
interface Obj { key: "value"; }
async function fn1(): Promise<Obj> {
const obj1: Obj = await { key: "value" };
const obj2: Obj = await new Promise(resolve => resolve({ key: "value" }));
return await { key: "value" };
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypeAsyncFunctionReturnType.ts | TypeScript | // @target: esnext
// @noImplicitAny: true
// @noEmit: true
interface Obj { key: "value"; }
async function fn1(): Promise<Obj> {
return { key: "value" };
}
async function fn2(): Promise<Obj> {
return new Promise(resolve => {
resolve({ key: "value" });
});
}
async function fn3(): Promise<Obj> {
... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypeCommaOperator01.ts | TypeScript | // @allowUnreachableCode: true
// @noImplicitAny: true
let x: (a: string) => string;
x = (100, a => a); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypeCommaOperator02.ts | TypeScript | // @allowUnreachableCode: true
// @noImplicitAny: true
let x: (a: string) => string;
x = (100, a => {
const b: number = a;
return b;
}); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypeCommaOperator03.ts | TypeScript | // @allowUnreachableCode: true
// @noImplicitAny: true
let x: (a: string) => string;
x = (a => a, b => b); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypeLogicalAnd01.ts | TypeScript | // @noImplicitAny: true
let x: (a: string) => string;
let y = true;
x = y && (a => a); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypeLogicalAnd02.ts | TypeScript | // @noImplicitAny: true
let x: (a: string) => string;
let y = true;
x = y && (a => {
const b: number = a;
return b;
}); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypeLogicalAnd03.ts | TypeScript | // @noImplicitAny: true
let x: (a: string) => string;
let y = true;
x = (a => a) && (b => b); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypedBindingInitializer.ts | TypeScript | // @noImplicitAny: true
interface Show {
show: (x: number) => string;
}
function f({ show = v => v.toString() }: Show) {}
function f2({ "show": showRename = v => v.toString() }: Show) {}
function f3({ ["show"]: showRename = v => v.toString() }: Show) {}
interface Nested {
nested: Show
}
function ff({ nested = ... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypedBindingInitializerNegative.ts | TypeScript | // @noImplicitAny: true
interface Show {
show: (x: number) => string;
}
function f({ show: showRename = v => v }: Show) {}
function f2({ "show": showRename = v => v }: Show) {}
function f3({ ["show"]: showRename = v => v }: Show) {}
interface Nested {
nested: Show
}
function ff({ nested: nestedRename = { show:... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypedClassExpressionMethodDeclaration01.ts | TypeScript | // @noImplicitAny: true
interface A {
numProp: number;
}
interface B {
strProp: string;
}
interface Foo {
method1(arg: A): void;
method2(arg: B): void;
}
function getFoo1(): Foo {
return class {
static method1(arg) {
arg.numProp = 10;
}
static method2(arg) {
... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypedClassExpressionMethodDeclaration02.ts | TypeScript | // @noImplicitAny: true
interface A {
numProp: number;
}
interface B {
strProp: string;
}
interface Foo {
new (): Bar;
}
interface Bar {
method1(arg: A): void;
method2(arg: B): void;
}
function getFoo1(): Foo {
return class {
method1(arg) {
arg.numProp = 10;
}
... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypedFunctionExpressionsAndReturnAnnotations.ts | TypeScript | declare function foo(x: (y: string) => (y2: number) => void);
// Contextually type the parameter even if there is a return annotation
foo((y): (y2: number) => void => {
var z = y.charAt(0); // Should be string
return null;
});
foo((y: string) => {
return y2 => {
var z = y2.toFixed(); // Should be ... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypedIife.ts | TypeScript | // arrow
(jake => { })("build");
// function expression
(function (cats) { })("lol");
// Lots of Irritating Superfluous Parentheses
(function (x) { } ("!"));
((((function (y) { }))))("-");
// multiple arguments
((a, b, c) => { })("foo", 101, false);
// default parameters
((m = 10) => m + 1)(12);
((n = 10) => n + 1)();
... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypedIifeStrict.ts | TypeScript | // @strictNullChecks: true
// arrow
(jake => { })("build");
// function expression
(function (cats) { })("lol");
// Lots of Irritating Superfluous Parentheses
(function (x) { } ("!"));
((((function (y) { }))))("-");
// multiple arguments
((a, b, c) => { })("foo", 101, false);
// default parameters
((m = 10) => m + 1)(1... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypedObjectLiteralMethodDeclaration01.ts | TypeScript | // @noImplicitAny: true
interface A {
numProp: number;
}
interface B {
strProp: string;
}
interface Foo {
method1(arg: A): void;
method2(arg: B): void;
}
function getFoo1(): Foo {
return {
method1(arg) {
arg.numProp = 10;
},
method2(arg) {
arg.str... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypedStringLiteralsInJsxAttributes01.tsx | TypeScript (TSX) | // @jsx: preserve
// @declaration: true
namespace JSX {
export interface IntrinsicElements {
span: {};
}
export interface Element {
something?: any;
}
}
const FooComponent = (props: { foo: "A" | "B" | "C" }) => <span>{props.foo}</span>;
<FooComponent foo={"A"} />;
<FooComponent foo="A" /... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/contextuallyTypedStringLiteralsInJsxAttributes02.tsx | TypeScript (TSX) | // @filename: file.tsx
// @jsx: preserve
// @module: amd
// @noLib: true
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
import React = require('react')
export interface ClickableProps {
children?: string;
className?: string;
}
export interface ButtonProps extends ClickableProps {
onClick: (k: ... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowAliasing.ts | TypeScript | // @strict: true
// @declaration: true
// Narrowing by aliased conditional expressions
function f10(x: string | number) {
const isString = typeof x === "string";
if (isString) {
let t: string = x;
}
else {
let t: number = x;
}
}
function f11(x: unknown) {
const isString = type... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowAliasingCatchVariables.ts | TypeScript | // @useUnknownInCatchVariables: true,false
try {}
catch (e) {
const isString = typeof e === 'string';
if (isString) {
e.toUpperCase(); // e string
}
if (typeof e === 'string') {
e.toUpperCase(); // e string
}
}
try {}
catch (e) {
const isString = typeof e === 'string';
e ... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowAssignmentExpression.ts | TypeScript | let x: string | boolean | number;
let obj: any;
x = "";
x = x.length;
x; // number
x = true;
(x = "", obj).foo = (x = x.length);
x; // number
// https://github.com/microsoft/TypeScript/issues/35484
type D = { done: true, value: 1 } | { done: false, value: 2 };
declare function fn(): D;
let o: D;
if ((o = fn()).done)... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowAssignmentPatternOrder.ts | TypeScript | // @target: esnext
// @noEmit: true
// https://github.com/microsoft/TypeScript/pull/41094#issuecomment-716044363
declare function f(): void;
{
let a: 0 | 1 = 0;
let b: 0 | 1 | 9;
[{ [(a = 1)]: b } = [9, a] as const] = [];
const bb: 0 = b;
}
{
let a: 0 | 1 = 1;
let b: 0 | 1 | 9;
[{ [a]: b } ... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowBinaryAndExpression.ts | TypeScript | let x: string | number | boolean;
let cond: boolean;
(x = "") && (x = 0);
x; // string | number
x = "";
cond && (x = 0);
x; // string | number
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowBinaryOrExpression.ts | TypeScript | let x: string | number | boolean;
let cond: boolean;
(x = "") || (x = 0);
x; // string | number
x = "";
cond || (x = 0);
x; // string | number
export interface NodeList {
length: number;
}
export interface HTMLCollection {
length: number;
}
declare function isNodeList(sourceObj: any): sourceObj is NodeList... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowBindingElement.ts | TypeScript | // @strictNullChecks: true
// @allowUnreachableCode: false
{
const data = { param: 'value' };
const {
param = (() => { throw new Error('param is not defined') })(),
} = data;
console.log(param); // should not trigger 'Unreachable code detected.'
}
{
const data = { param: 'value... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowBindingPatternOrder.ts | TypeScript | // @target: esnext
// @noEmit: true
// https://github.com/microsoft/TypeScript/pull/41094#issuecomment-716044363
{
let a: 0 | 1 = 0;
const [{ [(a = 1)]: b } = [9, a] as const] = [];
const bb: 0 = b;
}
{
let a: 0 | 1 = 1;
const [{ [a]: b } = [9, a = 0] as const] = [];
const bb: 9 = b;
}
{
le... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowCommaOperator.ts | TypeScript | function f(x: string | number | boolean) {
let y: string | number | boolean = false;
let z: string | number | boolean = false;
if (y = "", typeof x === "string") {
x; // string
y; // string
z; // boolean
}
else if (z = 1, typeof x === "number") {
x; // number
... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowComputedPropertyNames.ts | TypeScript | // @strict: true
// @noEmit: true
function f1(obj: Record<string, unknown>, key: string) {
if (typeof obj[key] === "string") {
obj[key].toUpperCase();
}
}
function f2(obj: Record<string, string | undefined>, key: string) {
if (obj[key] !== undefined) {
obj[key].toUpperCase();
}
let... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowConditionalExpression.ts | TypeScript | let x: string | number | boolean;
let cond: boolean;
cond ? x = "" : x = 3;
x; // string | number
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowDeleteOperator.ts | TypeScript | // @strictNullChecks: true
function f() {
let x: { a?: number | string, b: number | string } = { b: 1 };
x.a;
x.b;
x.a = 1;
x.b = 1;
x.a;
x.b;
delete x.a;
delete x.b;
x.a;
x.b;
x;
delete x; // No effect
x;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowDestructuringDeclaration.ts | TypeScript | // @strictNullChecks: true
function f1() {
let x: string | number = 1;
x;
let y: string | undefined = "";
y;
}
function f2() {
let [x]: [string | number] = [1];
x;
let [y]: [string | undefined] = [""];
y;
let [z = ""]: [string | undefined] = [undefined];
z;
}
function f3() {
... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowDoWhileStatement.ts | TypeScript | let cond: boolean;
function a() {
let x: string | number;
x = "";
do {
x; // string
} while (cond)
}
function b() {
let x: string | number;
x = "";
do {
x; // string
x = 42;
break;
} while (cond)
}
function c() {
let x: string | number;
x = "";
... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowElementAccess.ts | TypeScript | let x: { o: boolean } = { o: false }
if (x['o'] === false) {
x['o'] = true
}
const y: [number, number] = [0, 0];
if (y[0] === 0) {
y[0] = -1;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowElementAccess2.ts | TypeScript | // @strict: true
declare const config: {
[key: string]: boolean | { prop: string };
};
if (typeof config['works'] !== 'boolean') {
config.works.prop = 'test'; // ok
config['works'].prop = 'test'; // error, config['works']: boolean | { 'prop': string }
}
if (typeof config.works !== 'boolean') {
config['... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowElementAccessNoCrash1.ts | TypeScript | // @strict: true
// @noEmit: true
interface TestTscEdit {
caption: string;
commandLineArgs?: readonly string[];
}
interface TestTscCompile {
subScenario: string;
commandLineArgs: readonly string[];
}
interface VerifyTscEditDiscrepanciesInput {
index: number;
edits: readonly TestTscEdit[];
commandLineAr... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowForInStatement.ts | TypeScript | let x: string | number | boolean | RegExp | Function;
let obj: any;
let cond: boolean;
x = /a/;
for (let y in obj) {
x = y;
if (cond) {
x = 42;
continue;
}
if (cond) {
x = true;
break;
}
}
x; // RegExp | string | number | boolean
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowForInStatement2.ts | TypeScript | const keywordA = 'a';
const keywordB = 'b';
type A = { [keywordA]: number };
type B = { [keywordB]: string };
declare const c: A | B;
if ('a' in c) {
c; // narrowed to `A`
}
if (keywordA in c) {
c; // also narrowed to `A`
}
let stringB: string = 'b';
if ((stringB as 'b') in c) {
c; // narrowed to `B`
... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowForOfStatement.ts | TypeScript | let obj: number[];
let x: string | number | boolean | RegExp;
function a() {
x = true;
for (x of obj) {
x = x.toExponential();
}
x; // string | boolean
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowForStatement.ts | TypeScript | let cond: boolean;
function a() {
let x: string | number | boolean;
for (x = ""; cond; x = 5) {
x; // string | number
}
}
function b() {
let x: string | number | boolean;
for (x = 5; cond; x = x.length) {
x; // number
x = "";
}
}
function c() {
let x: string | number ... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowGenericTypes.ts | TypeScript | // @strict: true
function f1<T extends string | undefined>(x: T, y: { a: T }, z: [T]): string {
if (x) {
x;
x.length;
return x;
}
if (y.a) {
y.a.length;
return y.a;
}
if (z[0]) {
z[0].length;
return z[0];
}
return "hello";
}
function ... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowIIFE.ts | TypeScript | // @strictNullChecks: true
// @target: ES2017
declare function getStringOrNumber(): string | number;
function f1() {
let x = getStringOrNumber();
if (typeof x === "string") {
let n = function() {
return x.length;
}();
}
}
function f2() {
let x = getStringOrNumber();
if... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowIfStatement.ts | TypeScript | // @allowUnreachableCode: true
let x: string | number | boolean | RegExp;
let cond: boolean;
x = /a/;
if (x /* RegExp */, (x = true)) {
x; // boolean
x = "";
}
else {
x; // boolean
x = 42;
}
x; // string | number
function a() {
let x: string | number;
if (cond) {
x = 42;
}
els... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowInOperator.ts | TypeScript | const a = 'a';
const b = 'b';
const d = 'd';
type A = { [a]: number; };
type B = { [b]: string; };
declare const c: A | B;
if ('a' in c) {
c; // A
c['a']; // number;
}
if ('d' in c) {
c; // never
}
if (a in c) {
c; // A
c[a]; // number;
}
if (d in c) {
c; // never
}
// repro from ... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowInstanceOfGuardPrimitives.ts | TypeScript | function distinguish(thing: string | number | Date) {
if (thing instanceof Object) {
console.log("Aha!! It's a Date in " + thing.getFullYear());
} else if (typeof thing === 'string') {
console.log("Aha!! It's a string of length " + thing.length);
} else {
console.log("Aha!! It's the ... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowInstanceofExtendsFunction.ts | TypeScript | declare global {
interface Function {
now(): string;
}
}
Function.prototype.now = function () {
return "now"
}
class X {
static now() {
return {}
}
why() {
}
}
class Y {
}
console.log(X.now()) // works as expected
console.log(Y.now()) // works as expected
export const... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowIteration.ts | TypeScript | // @strictNullChecks: true
let cond: boolean;
function ff() {
let x: string | undefined;
while (true) {
if (cond) {
x = "";
}
else {
if (x) {
x.length;
}
if (x) {
x.length;
}
}
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowIterationErrors.ts | TypeScript | // @noImplicitAny: true
let cond: boolean;
function len(s: string) {
return s.length;
}
function f1() {
let x: string | number | boolean;
x = "";
while (cond) {
x = len(x);
x;
}
x;
}
function f2() {
let x: string | number | boolean;
x = "";
while (cond) {
... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowIterationErrorsAsync.ts | TypeScript | // @strict: true
// @noEmit: true
// @lib: esnext
let cond: boolean;
async function len(s: string) {
return s.length;
}
async function f1() {
let x: string | number | boolean;
x = "";
while (cond) {
x = await len(x);
x;
}
x;
}
async function f2() {
let x: string | number ... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowNoIntermediateErrors.ts | TypeScript | // @strict: true
// @noEmit: true
// Repros from #46475
function f1() {
let code: 0 | 1 | 2 = 0;
const otherCodes: (0 | 1 | 2)[] = [2, 0, 1, 0, 2, 2, 2, 0, 1, 0, 2, 1, 1, 0, 2, 1];
for (const code2 of otherCodes) {
if (code2 === 0) {
code = code === 2 ? 1 : 0;
}
... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowNullishCoalesce.ts | TypeScript | // @strict: true
// assignments in shortcutting rhs
let a: number;
o ?? (a = 1);
a.toString();
// assignment flow
declare const o: { x: number } | undefined;
let x: { x: number } | boolean;
if (x = o ?? true) {
x;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowOptionalChain.ts | TypeScript | // @strict: true
// @allowUnreachableCode: false
// assignments in shortcutting chain
declare const o: undefined | {
[key: string]: any;
[key: number]: any;
(...args: any[]): any;
};
let a: number;
o?.[a = 1];
a.toString();
let b: number;
o?.x[b = 1];
b.toString();
let c: number;
o?.(c = 1)
c.toString()... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowOptionalChain2.ts | TypeScript | // @strictNullChecks: true
type A = {
type: 'A';
name: string;
}
type B = {
type: 'B';
}
function funcTwo(arg: A | B | undefined) {
if (arg?.type === 'B') {
arg; // `B`
return;
}
arg;
arg?.name;
}
function funcThree(arg: A | B | null) {
if (arg?.type === 'B') {
arg; // `B`
return;
... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowOptionalChain3.tsx | TypeScript (TSX) | // @strict: true
// @noEmit: true
// @esModuleInterop: true
// @jsx: react
/// <reference path="/.lib/react16.d.ts" />
// https://github.com/microsoft/TypeScript/issues/56482
import React from "react";
interface Foo {
bar: boolean;
}
function test1(foo: Foo | undefined) {
if (foo?.bar === false) {
foo;
}... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowParameter.ts | TypeScript | // @strictNullChecks: true
// @allowUnreachableCode: false
function f1(
required: unknown = (() => {
throw new Error("bad");
})()
) {
console.log("ok"); // should not trigger 'Unreachable code detected.'
}
function f2(
a: number | string | undefined,
required: unknown = (() => {
a = 1;
})()
) {
a... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowStringIndex.ts | TypeScript | // @strict: true
type A = {
other: number | null;
[index: string]: number | null
};
declare const value: A;
if (value.foo !== null) {
value.foo.toExponential()
value.other // should still be number | null
value.bar // should still be number | null
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowSuperPropertyAccess.ts | TypeScript | // @strictNullChecks: true
class B {
protected m?(): void;
}
class C extends B {
body() {
super.m && super.m();
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowTruthiness.ts | TypeScript | // @strictNullChecks: true
declare function foo(): string | undefined;
function f1() {
let x = foo();
if (x) {
x; // string
}
else {
x; // string | undefined
}
}
function f2() {
let x: string | undefined;
x = foo();
if (x) {
x; // string
}
else {
... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowTypeofObject.ts | TypeScript | // @strict: true
// @declaration: true
declare function obj(x: object): void;
function f1(x: unknown) {
if (!x) {
return;
}
if (typeof x === 'object') {
obj(x);
}
}
function f2(x: unknown) {
if (x === null) {
return;
}
if (typeof x === 'object') {
obj(x);
... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowWhileStatement.ts | TypeScript | let cond: boolean;
function a() {
let x: string | number;
x = "";
while (cond) {
x; // string
}
}
function b() {
let x: string | number;
x = "";
while (cond) {
x; // string
x = 42;
break;
}
}
function c() {
let x: string | number;
x = "";
while... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/controlFlowWithTemplateLiterals.ts | TypeScript | // @strictNullChecks: true
declare const envVar: string | undefined;
if (typeof envVar === `string`) {
envVar.slice(0)
}
declare const obj: {test: string} | {}
if (`test` in obj) {
obj.test.slice(0)
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/correctlyMarkAliasAsReferences1.tsx | TypeScript (TSX) | // @target: es2017
// @jsx: react
// @moduleResolution: node
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
// @filename: declaration.d.ts
declare module "classnames";
// @filename: 0.tsx
///<reference path="declaration.d.ts" />
import * as cx from 'classnames';
import * as React from "react";
let buttonPr... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/correctlyMarkAliasAsReferences2.tsx | TypeScript (TSX) | // @target: es2017
// @jsx: react
// @moduleResolution: node
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
// @filename: declaration.d.ts
declare module "classnames";
// @filename: 0.tsx
///<reference path="declaration.d.ts" />
import * as cx from 'classnames';
import * as React from "react";
let buttonPr... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/correctlyMarkAliasAsReferences3.tsx | TypeScript (TSX) | // @target: es2017
// @jsx: react
// @moduleResolution: node
// @noImplicitAny: true
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
// @filename: declaration.d.ts
declare module "classnames";
// @filename: 0.tsx
///<reference path="declaration.d.ts" />
import * as cx from 'classnames';
import * as React fro... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/correctlyMarkAliasAsReferences4.tsx | TypeScript (TSX) | // @target: es2017
// @jsx: react
// @moduleResolution: node
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
// @filename: declaration.d.ts
declare module "classnames";
// @filename: 0.tsx
///<reference path="declaration.d.ts" />
import * as cx from 'classnames';
import * as React from "react";
let buttonPr... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/covariantCallbacks.ts | TypeScript | // @target: es2015
// @strict: true
// Test that callback parameters are related covariantly
interface P<T> {
then(cb: (value: T) => void): void;
};
interface A { a: string }
interface B extends A { b: string }
function f1(a: P<A>, b: P<B>) {
a = b;
b = a; // Error
}
function f2(a: Promise<A>, b: Prom... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/declarationEmitIdentifierPredicates01.ts | TypeScript | // @declaration: true
// @module: commonjs
export function f(x: any): x is number {
return typeof x === "number";
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/declarationEmitIdentifierPredicatesWithPrivateName01.ts | TypeScript | // @declaration: true
// @module: commonjs
interface I {
a: number;
}
export function f(x: any): x is I {
return typeof x.a === "number";
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/declarationEmitReadonly.ts | TypeScript | // @declaration: true
class C {
constructor(readonly x: number) {}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/declarationEmitThisPredicates01.ts | TypeScript | // @declaration: true
// @module: commonjs
export class C {
m(): this is D {
return this instanceof D;
}
}
export class D extends C {
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/declarationEmitThisPredicates02.ts | TypeScript | // @declaration: true
// @module: commonjs
export interface Foo {
a: string;
b: number;
c: boolean;
}
export const obj = {
m(): this is Foo {
let dis = this as {} as Foo;
return dis.a != null && dis.b != null && dis.c != null;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/declarationEmitThisPredicatesWithPrivateName01.ts | TypeScript | // @declaration: true
// @module: commonjs
export class C {
m(): this is D {
return this instanceof D;
}
}
class D extends C {
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/declarationEmitThisPredicatesWithPrivateName02.ts | TypeScript | // @declaration: true
// @module: commonjs
interface Foo {
a: string;
b: number;
c: boolean;
}
export const obj = {
m(): this is Foo {
let dis = this as {} as Foo;
return dis.a != null && dis.b != null && dis.c != null;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/declarationEmitWorkWithInlineComments.ts | TypeScript | // @declaration: true
// @stripInternal:true
export class Foo {
constructor(
/** @internal */
public isInternal1: string,
/** @internal */ public isInternal2: string, /** @internal */
public isInternal3: string,
// @internal
public isInternal4: string,
// nothing
/** @internal */
... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/declarationFileForJsonImport.ts | TypeScript | // @allowArbitraryExtensions: true
// @resolveJsonModule: true,false
// @filename: main.ts
import data from "./data.json";
let x: string = data;
// @filename: data.json
{}
// @filename: data.d.json.ts
declare var val: string;
export default val; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/declarationFiles.ts | TypeScript | // @declaration: true
class C1 {
x: this;
f(x: this): this { return undefined; }
constructor(x: this) { }
}
class C2 {
[x: string]: this;
}
interface Foo<T> {
x: T;
y: this;
}
class C3 {
a: this[];
b: [this, this];
c: this | Date;
d: this & Date;
e: (((this)));
f: (x:... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/declarationInAmbientContext.ts | TypeScript | declare var [a, b]; // Error, destructuring declaration not allowed in ambient context
declare var {c, d}; // Error, destructuring declaration not allowed in ambient context
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/declarationsAndAssignments.ts | TypeScript | function f0() {
var [] = [1, "hello"];
var [x] = [1, "hello"];
var [x, y] = [1, "hello"];
var [x, y, z] = [1, "hello"];
var [,, x] = [0, 1, 2];
var x: number;
var y: string;
}
function f1() {
var a = [1, "hello"];
var [x] = a;
var [x, y] = a;
var [x, y, z] = a;
var x: nu... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/declaredClassMergedwithSelf.ts | TypeScript |
// @Filename: file1.ts
declare class C1 {}
declare class C1 {}
declare class C2 {}
interface C2 {}
declare class C2 {}
// @Filename: file2.ts
declare class C3 { }
// @Filename: file3.ts
declare class C3 { } | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decoratedClassExportsCommonJS1.ts | TypeScript | // @target: es6
// @experimentaldecorators: true
// @emitDecoratorMetadata: true
// @module: commonjs
// @filename: a.ts
declare function forwardRef(x: any): any;
declare var Something: any;
@Something({ v: () => Testing123 })
export class Testing123 {
static prop0: string;
static prop1 = Testing123.prop0;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decoratedClassExportsCommonJS2.ts | TypeScript | // @target: es6
// @experimentaldecorators: true
// @emitDecoratorMetadata: true
// @module: commonjs
// @filename: a.ts
declare function forwardRef(x: any): any;
declare var Something: any;
@Something({ v: () => Testing123 })
export class Testing123 { } | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decoratedClassExportsSystem1.ts | TypeScript | // @target: es6
// @experimentaldecorators: true
// @emitDecoratorMetadata: true
// @module: system
// @filename: a.ts
declare function forwardRef(x: any): any;
declare var Something: any;
@Something({ v: () => Testing123 })
export class Testing123 {
static prop0: string;
static prop1 = Testing123.prop0;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decoratedClassExportsSystem2.ts | TypeScript | // @target: es6
// @experimentaldecorators: true
// @emitDecoratorMetadata: true
// @module: system
// @filename: a.ts
declare function forwardRef(x: any): any;
declare var Something: any;
@Something({ v: () => Testing123 })
export class Testing123 { } | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decoratorMetadata.ts | TypeScript | // @experimentalDecorators: true
// @emitDecoratorMetadata: true
// @target: es5
// @module: commonjs
// @filename: service.ts
export default class Service {
}
// @filename: component.ts
import Service from "./service";
declare var decorator: any;
@decorator
class MyComponent {
constructor(public Service: Service... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decoratorMetadataWithTypeOnlyImport.ts | TypeScript | // @experimentalDecorators: true
// @emitDecoratorMetadata: true
// @target: es5
// @module: commonjs
// @filename: service.ts
export class Service {
}
// @filename: component.ts
import type { Service } from "./service";
declare var decorator: any;
@decorator
class MyComponent {
constructor(public Service: Servic... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decoratorMetadataWithTypeOnlyImport2.ts | TypeScript | // @experimentalDecorators: true
// @emitDecoratorMetadata: true
// @filename: services.ts
export namespace Services {
export class Service {}
}
// @filename: index.ts
import type { Services } from './services';
declare const decorator: any;
export class Main {
@decorator()
field: Services.Service;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decoratorOnClass9.ts | TypeScript | // @target:es5
// @experimentaldecorators: true
declare var dec: any;
class A {}
// https://github.com/Microsoft/TypeScript/issues/16417
@dec
class B extends A {
static x = 1;
static y = B.x;
m() {
return B.x;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decoratorOnClassConstructor4.ts | TypeScript | // @target: es5
// @module: commonjs
// @experimentaldecorators: true
// @emitdecoratormetadata: true
declare var dec: any;
@dec
class A {
}
@dec
class B {
constructor(x: number) {}
}
@dec
class C extends A {
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decoratorOnClassMethod11.ts | TypeScript | // @target: ES5
// @experimentaldecorators: true
module M {
class C {
decorator(target: Object, key: string): void { }
@(this.decorator)
method() { }
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decoratorOnClassMethod12.ts | TypeScript | // @target: ES5
// @experimentaldecorators: true
module M {
class S {
decorator(target: Object, key: string): void { }
}
class C extends S {
@(super.decorator)
method() { }
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decoratorOnClassMethod14.ts | TypeScript | // @target: esnext
// @experimentaldecorators: true
// @emitdecoratormetadata: true
declare var decorator: any;
class Foo {
private prop = () => {
return 0;
}
@decorator
foo() {
return 0;
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decoratorOnClassMethod15.ts | TypeScript | // @target: esnext
// @experimentaldecorators: true
// @emitdecoratormetadata: true
declare var decorator: any;
class Foo {
private prop = 1
@decorator
foo() {
return 0;
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decoratorOnClassMethod16.ts | TypeScript | // @target: esnext
// @experimentaldecorators: true
// @emitdecoratormetadata: true
declare var decorator: any;
class Foo {
private prop
@decorator
foo() {
return 0;
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decoratorOnClassMethod18.ts | TypeScript | // @target: esnext
// @experimentaldecorators: true
// @emitdecoratormetadata: true
declare var decorator: any;
class Foo {
p1
@decorator()
p2;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decrementOperatorWithAnyOtherType.ts | TypeScript | // -- operator on any type
var ANY: any;
var ANY1: any;
var ANY2: any[] = ["", ""];
var obj = {x:1,y:null};
class A {
public a: any;
}
module M {
export var n: any;
}
var objA = new A();
// any type var
var ResultIsNumber1 = --ANY;
var ResultIsNumber2 = --ANY1;
var ResultIsNumber3 = ANY1--;
var ResultIsNumbe... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decrementOperatorWithEnumType.ts | TypeScript | // -- operator on enum type
enum ENUM1 { A, B, "" };
// expression
var ResultIsNumber1 = --ENUM1["A"];
var ResultIsNumber2 = ENUM1.A--;
// miss assignment operator
--ENUM1["A"];
ENUM1[A]--;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decrementOperatorWithEnumTypeInvalidOperations.ts | TypeScript | // -- operator on enum type
enum ENUM { };
enum ENUM1 { A, B, "" };
// enum type var
var ResultIsNumber1 = --ENUM;
var ResultIsNumber2 = --ENUM1;
var ResultIsNumber3 = ENUM--;
var ResultIsNumber4 = ENUM1--;
// enum type expressions
var ResultIsNumber5 = --(ENUM["A"] + ENUM.B);
var ResultIsNumber6 = (ENUM.A + ENUM["... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decrementOperatorWithNumberType.ts | TypeScript | // -- operator on number type
var NUMBER: number;
var NUMBER1: number[] = [1, 2];
class A {
public a: number;
}
module M {
export var n: number;
}
var objA = new A();
// number type var
var ResultIsNumber1 = --NUMBER;
var ResultIsNumber2 = NUMBER--;
// expressions
var ResultIsNumber3 = --objA.a;
var Result... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decrementOperatorWithNumberTypeInvalidOperations.ts | TypeScript | // -- operator on number type
var NUMBER: number;
var NUMBER1: number[] = [1, 2];
function foo(): number { return 1; }
class A {
public a: number;
static foo() { return 1; }
}
module M {
export var n: number;
}
var objA = new A();
//number type var
var ResultIsNumber1 = --NUMBER1;
var ResultIsNumber2 = ... | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/decrementOperatorWithUnsupportedBooleanType.ts | TypeScript | // -- operator on boolean type
var BOOLEAN: boolean;
function foo(): boolean { return true; }
class A {
public a: boolean;
static foo() { return true; }
}
module M {
export var n: boolean;
}
var objA = new A();
// boolean type var
var ResultIsNumber1 = --BOOLEAN;
var ResultIsNumber2 = BOOLEAN--;
// bo... | 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.