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/checkJsdocSatisfiesTag5.ts
TypeScript
// @noEmit: true // @allowJS: true // @checkJs: true // @filename: /a.js /** @typedef {{ move(distance: number): void }} Movable */ const car = /** @satisfies {Movable & Record<string, unknown>} */ ({ start() { }, move(d) { // d should be number }, stop() { } })
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsdocSatisfiesTag6.ts
TypeScript
// @noEmit: true // @allowJS: true // @checkJs: true // @filename: /a.js /** * @typedef {Object} Point2d * @property {number} x * @property {number} y */ // Undesirable behavior today with type annotation const a = /** @satisfies {Partial<Point2d>} */ ({ x: 10 }); // Should OK console.log(a.x.toFixed()); // Should error let p = a.y;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsdocSatisfiesTag7.ts
TypeScript
// @noEmit: true // @allowJS: true // @checkJs: true // @filename: /a.js /** @typedef {"a" | "b" | "c" | "d"} Keys */ const p = /** @satisfies {Record<Keys, unknown>} */ ({ a: 0, b: "hello", x: 8 // Should error, 'x' isn't in 'Keys' }) // Should be OK -- retain info that a is number and b is string let a = p.a.toFixed(); let b = p.b.substring(1); // Should error even though 'd' is in 'Keys' let d = p.d;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsdocSatisfiesTag8.ts
TypeScript
// @noEmit: true // @allowJS: true // @checkJs: true // @filename: /a.js /** @typedef {Object.<string, boolean>} Facts */ // Should be able to detect a failure here const x = /** @satisfies {Facts} */ ({ m: true, s: "false" })
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsdocSatisfiesTag9.ts
TypeScript
// @noEmit: true // @allowJS: true // @checkJs: true // @filename: /a.js /** * @typedef {Object} Color * @property {number} r * @property {number} g * @property {number} b */ // All of these should be Colors, but I only use some of them here. export const Palette = /** @satisfies {Record<string, Color>} */ ({ white: { r: 255, g: 255, b: 255 }, black: { r: 0, g: 0, d: 0 }, // <- oops! 'd' in place of 'b' blue: { r: 0, g: 0, b: 255 }, });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsdocTypeTag1.ts
TypeScript
// @allowJS: true // @suppressOutputPathCheck: true // @filename: 0.js // @ts-check /** @type {String} */ var S = "hello world"; /** @type {number} */ var n = 10; /** @type {*} */ var anyT = 2; anyT = "hello"; /** @type {?} */ var anyT1 = 2; anyT1 = "hi"; /** @type {Function} */ const x = (a) => a + 1; x(1); /** @type {function} */ const y = (a) => a + 1; y(1); /** @type {function (number)} */ const x1 = (a) => a + 1; x1(0); /** @type {function (number): number} */ const x2 = (a) => a + 1; x2(0); /** * @type {object} */ var props = {}; /** * @type {Object} */ var props = {};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsdocTypeTag2.ts
TypeScript
// @allowJS: true // @suppressOutputPathCheck: true // @filename: 0.js // @ts-check /** @type {String} */ var S = true; /** @type {number} */ var n = "hello"; /** @type {function (number)} */ const x1 = (a) => a + 1; x1("string"); /** @type {function (number): number} */ const x2 = (a) => a + 1; /** @type {string} */ var a; a = x2(0); /** @type {function (number): number} */ const x3 = (a) => a.concat("hi"); x3(0); /** @type {function (number): string} */ const x4 = (a) => a + 1; x4(0);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsdocTypeTag3.ts
TypeScript
// @Filename:test.js // @checkJs: true // @allowJs: true // @noEmit: true /** @type {Array<?number>} */ var nns;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsdocTypeTag4.ts
TypeScript
// @checkJs: true // @allowJs: true // @noEmit: true // @Filename: t.d.ts type A<T extends string> = { a: T } // @Filename: test.js /** Also should error for jsdoc typedefs * @template {string} U * @typedef {{ b: U }} B */ /** @type {A<number>} */ var a; /** @type {B<number>} */ var b;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsdocTypeTag5.ts
TypeScript
// @checkJs: true // @allowJs: true // @noEmit: true // @Filename: test.js // all 6 should error on return statement/expression /** @type {(x: number) => string} */ function h(x) { return x } /** @type {(x: number) => string} */ var f = x => x /** @type {(x: number) => string} */ var g = function (x) { return x } /** @type {{ (x: number): string }} */ function i(x) { return x } /** @type {{ (x: number): string }} */ var j = x => x /** @type {{ (x: number): string }} */ var k = function (x) { return x } /** @typedef {(x: 'hi' | 'bye') => 0 | 1 | 2} Argle */ /** @type {Argle} */ function blargle(s) { return 0; } /** @type {0 | 1 | 2} - assignment should not error */ var zeroonetwo = blargle('hi') /** @typedef {{(s: string): 0 | 1; (b: boolean): 2 | 3 }} Gioconda */ /** @type {Gioconda} */ function monaLisa(sb) { return typeof sb === 'string' ? 1 : 2; } /** @type {2 | 3} - overloads are not supported, so there will be an error */ var twothree = monaLisa(false);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsdocTypeTag6.ts
TypeScript
// @checkJs: true // @allowJs: true // @noEmit: true // @Filename: test.js /** @type {number} */ function f() { return 1 } /** @type {{ prop: string }} */ var g = function (prop) { } /** @type {(a: number) => number} */ function add1(a, b) { return a + b; } /** @type {(a: number, b: number) => number} */ function add2(a, b) { return a + b; } // TODO: Should be an error since signature doesn't match. /** @type {(a: number, b: number, c: number) => number} */ function add3(a, b) { return a + b; } // Confirm initializers are compatible. // They can't have more parameters than the type/context. /** @type {() => void} */ function funcWithMoreParameters(more) {} // error /** @type {() => void} */ const variableWithMoreParameters = function (more) {}; // error /** @type {() => void} */ const arrowWithMoreParameters = (more) => {}; // error ({ /** @type {() => void} */ methodWithMoreParameters(more) {}, // error });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsdocTypeTag7.ts
TypeScript
// @checkJs: true // @allowJs: true // @noEmit: true // @Filename: test.js /** * @typedef {(a: string, b: number) => void} Foo */ class C { /** @type {Foo} */ foo(a, b) {} /** @type {(optional?) => void} */ methodWithOptionalParameters() {} }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsdocTypeTagOnObjectProperty1.ts
TypeScript
// @allowJS: true // @suppressOutputPathCheck: true // @strictNullChecks: true // @filename: 0.js // @ts-check var lol = "hello Lol" const obj = { /** @type {string|undefined} */ foo: undefined, /** @type {string|undefined} */ bar: "42", /** @type {function(number): number} */ method1(n1) { return n1 + 42; }, /** @type {string} */ lol, /** @type {number} */ ['b' + 'ar1']: 42, /** @type {function(number): number} */ arrowFunc: (num) => num + 42 } obj.foo = 'string' obj.lol obj.bar = undefined; var k = obj.method1(0); obj.bar1 = "42"; obj.arrowFunc(0);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsdocTypeTagOnObjectProperty2.ts
TypeScript
// @allowJS: true // @suppressOutputPathCheck: true // @strictNullChecks: true // @filename: 0.js // @ts-check var lol; const obj = { /** @type {string|undefined} */ bar: 42, /** @type {function(number): number} */ method1(n1) { return "42"; }, /** @type {function(number): number} */ method2: (n1) => "lol", /** @type {function(number): number} */ arrowFunc: (num="0") => num + 42, /** @type {string} */ lol } lol = "string" /** @type {string} */ var s = obj.method1(0); /** @type {string} */ var s1 = obj.method2("0");
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsdocTypedefInParamTag1.ts
TypeScript
// @allowJS: true // @suppressOutputPathCheck: true // @filename: 0.js // @ts-check /** * @typedef {Object} Opts * @property {string} x * @property {string=} y * @property {string} [z] * @property {string} [w="hi"] * * @param {Opts} opts */ function foo(opts) { opts.x; } foo({x: 'abc'}); /** * @typedef {Object} AnotherOpts * @property anotherX {string} * @property anotherY {string=} * * @param {AnotherOpts} opts */ function foo1(opts) { opts.anotherX; } foo1({anotherX: "world"}); /** * @typedef {object} Opts1 * @property {string} x * @property {string=} y * @property {string} [z] * @property {string} [w="hi"] * * @param {Opts1} opts */ function foo2(opts) { opts.x; } foo2({x: 'abc'});
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsdocTypedefOnlySourceFile.ts
TypeScript
// @allowJS: true // @suppressOutputPathCheck: true // @filename: 0.js // @ts-check var exports = {}; /** * @typedef {string} */ exports.SomeName; /** @type {exports.SomeName} */ const myString = 'str';
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxChildrenCanBeTupleType.tsx
TypeScript (TSX)
// @jsx: react // @strict: true // @esModuleInterop: true /// <reference path="/.lib/react16.d.ts" /> import React from 'react' interface ResizablePanelProps { children: [React.ReactNode, React.ReactNode] } class ResizablePanel extends React.Component< ResizablePanelProps, any> {} const test = <ResizablePanel> <div /> <div /> </ResizablePanel> const testErr = <ResizablePanel> <div /> <div /> <div /> </ResizablePanel>
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxChildrenProperty1.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts import React = require('react'); interface Prop { a: number, b: string, children: string | JSX.Element } function Comp(p: Prop) { return <div>{p.b}</div>; } // OK let k = <Comp a={10} b="hi" children ="lol" />; let k1 = <Comp a={10} b="hi"> hi hi hi! </Comp>; let k2 = <Comp a={10} b="hi"> <div>hi hi hi!</div> </Comp>;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxChildrenProperty10.tsx
TypeScript (TSX)
//@filename: file.tsx //@jsx: preserve declare module JSX { interface Element { } interface ElementAttributesProperty { props: {} } interface IntrinsicElements { div: any; h2: any; h1: any; } } class Button { props: {} render() { return (<div>My Button</div>) } } // OK let k1 = <div> <h2> Hello </h2> <h1> world </h1></div>; let k2 = <div> <h2> Hello </h2> {(user: any) => <h2>{user.name}</h2>}</div>; let k3 = <div> {1} {"That is a number"} </div>; let k4 = <Button> <h2> Hello </h2> </Button>;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxChildrenProperty11.tsx
TypeScript (TSX)
//@filename: file.tsx //@jsx: preserve //@noImplicitAny: true declare module JSX { interface Element { } interface ElementAttributesProperty { props: {} } interface IntrinsicElements { div: any; h2: any; h1: any; } } class Button { props: {} render() { return (<div>My Button</div>) } } // OK let k1 = <div> <h2> Hello </h2> <h1> world </h1></div>; let k2 = <div> <h2> Hello </h2> {(user: any) => <h2>{user.name}</h2>}</div>; let k3 = <div> {1} {"That is a number"} </div>; let k4 = <Button> <h2> Hello </h2> </Button>;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxChildrenProperty12.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts import React = require('react'); interface ButtonProp { a: number, b: string, children: Button; } class Button extends React.Component<ButtonProp, any> { render() { let condition: boolean; if (condition) { return <InnerButton {...this.props} /> } else { return (<InnerButton {...this.props} > <div>Hello World</div> </InnerButton>); } } } interface InnerButtonProp { a: number } class InnerButton extends React.Component<InnerButtonProp, any> { render() { return (<button>Hello</button>); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxChildrenProperty13.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts // @strictNullChecks: true import React = require('react'); interface ButtonProp { a: number, b: string, children: Button; } class Button extends React.Component<ButtonProp, any> { render() { // Error children are specified twice return (<InnerButton {...this.props} children="hi"> <div>Hello World</div> </InnerButton>); } } interface InnerButtonProp { a: number } class InnerButton extends React.Component<InnerButtonProp, any> { render() { return (<button>Hello</button>); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxChildrenProperty14.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts import React = require('react'); interface Prop { a: number, b: string, children: JSX.Element | JSX.Element[]; } class Button extends React.Component<any, any> { render() { return (<div>My Button</div>) } } function AnotherButton(p: any) { return <h1>Just Another Button</h1>; } function Comp(p: Prop) { return <div>{p.b}</div>; } // OK let k1 = <Comp a={10} b="hi"><></><Button /><AnotherButton /></Comp>; let k2 = <Comp a={10} b="hi"><><Button /></><AnotherButton /></Comp>; let k3 = <Comp a={10} b="hi"><><Button /><AnotherButton /></></Comp>; interface SingleChildProp { a: number, b: string, children: JSX.Element; } function SingleChildComp(p: SingleChildProp) { return <div>{p.b}</div>; } // OK let k4 = <SingleChildComp a={10} b="hi"><><Button /><AnotherButton /></></SingleChildComp>; // Error let k5 = <SingleChildComp a={10} b="hi"><></><Button /><AnotherButton /></SingleChildComp>;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxChildrenProperty15.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts import React = require('react'); const Tag = (x: {}) => <div></div>; // OK const k1 = <Tag />; const k2 = <Tag></Tag>; // Not OK (excess children) const k3 = <Tag children={<div></div>} />; const k4 = <Tag key="1"><div></div></Tag>; const k5 = <Tag key="1"><div></div><div></div></Tag>;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxChildrenProperty16.tsx
TypeScript (TSX)
// @strict: true // @noEmit: true // @jsx: preserve /// <reference path="/.lib/react16.d.ts" /> // repro from #53493 import React = require('react'); export type Props = | { renderNumber?: false; children: (arg: string) => void } | { renderNumber: true; children: (arg: number) => void; }; export declare function Foo(props: Props): JSX.Element; export const Test = () => { return ( <> <Foo>{(value) => {}}</Foo> <Foo renderNumber>{(value) => {}}</Foo> <Foo children={(value) => {}} /> <Foo renderNumber children={(value) => {}} /> </> ); };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxChildrenProperty2.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts // @strictNullChecks: true import React = require('react'); interface Prop { a: number, b: string, children: string | JSX.Element } function Comp(p: Prop) { return <div>{p.b}</div>; } // Error: missing children let k = <Comp a={10} b="hi" />; let k0 = <Comp a={10} b="hi" children="Random" > hi hi hi! </Comp>; let o = { children:"Random" } let k1 = <Comp a={10} b="hi" {...o} > hi hi hi! </Comp>; // Error: incorrect type let k2 = <Comp a={10} b="hi"> <div> My Div </div> {(name: string) => <div> My name {name} </div>} </Comp>; let k3 = <Comp a={10} b="hi"> <div> My Div </div> {1000000} </Comp>; let k4 = <Comp a={10} b="hi" > <div> My Div </div> hi hi hi! </Comp>; let k5 = <Comp a={10} b="hi" > <div> My Div </div> <div> My Div </div> </Comp>;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxChildrenProperty3.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts import React = require('react'); interface IUser { Name: string; } interface IFetchUserProps { children: (user: IUser) => JSX.Element; } class FetchUser extends React.Component<IFetchUserProps, any> { render() { return this.state ? this.props.children(this.state.result) : null; } } // Ok function UserName0() { return ( <FetchUser> { user => ( <h1>{ user.Name }</h1> ) } </FetchUser> ); } function UserName1() { return ( <FetchUser> { user => ( <h1>{ user.Name }</h1> ) } </FetchUser> ); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxChildrenProperty4.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts import React = require('react'); interface IUser { Name: string; } interface IFetchUserProps { children: (user: IUser) => JSX.Element; } class FetchUser extends React.Component<IFetchUserProps, any> { render() { return this.state ? this.props.children(this.state.result) : null; } } // Error function UserName() { return ( <FetchUser> { user => ( <h1>{ user.NAme }</h1> ) } </FetchUser> ); } function UserName1() { return ( <FetchUser> { user => ( <h1>{ user.Name }</h1> ) } { user => ( <h1>{ user.Name }</h1> ) } </FetchUser> ); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxChildrenProperty5.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts import React = require('react'); interface Prop { a: number, b: string, children: Button; } class Button extends React.Component<any, any> { render() { return (<div>My Button</div>) } } function Comp(p: Prop) { return <div>{p.b}</div>; } // Error: no children specified let k = <Comp a={10} b="hi" />; // Error: JSX.element is not the same as JSX.ElementClass let k1 = <Comp a={10} b="hi"> <Button /> </Comp>; let k2 = <Comp a={10} b="hi"> {Button} </Comp>;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxChildrenProperty6.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts import React = require('react'); interface Prop { a: number, b: string, children: JSX.Element | JSX.Element[]; } class Button extends React.Component<any, any> { render() { return (<div>My Button</div>) } } function AnotherButton(p: any) { return <h1>Just Another Button</h1>; } function Comp(p: Prop) { return <div>{p.b}</div>; } // Ok let k1 = <Comp a={10} b="hi"> <Button /> <AnotherButton /> </Comp>; let k2 = <Comp a={10} b="hi"> <Button /> <AnotherButton /> </Comp>; let k3 = <Comp a={10} b="hi"><Button /> <AnotherButton /> </Comp>; let k4 = <Comp a={10} b="hi"><Button /></Comp>;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxChildrenProperty7.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts import React = require('react'); interface Prop { a: number, b: string, children: JSX.Element | JSX.Element[]; } class Button extends React.Component<any, any> { render() { return (<div>My Button</div>) } } function AnotherButton(p: any) { return <h1>Just Another Button</h1>; } function Comp(p: Prop) { return <div>{p.b}</div>; } // Error: whitespaces matters let k1 = <Comp a={10} b="hi"><Button /> <AnotherButton /></Comp>; let k2 = <Comp a={10} b="hi"><Button /> <AnotherButton /> </Comp>; let k3 = <Comp a={10} b="hi"> <Button /> <AnotherButton /></Comp>;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxChildrenProperty8.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts import React = require('react'); interface Prop { a: number, b: string, children: string | JSX.Element | (string | JSX.Element)[]; } class Button extends React.Component<any, any> { render() { return (<div>My Button</div>) } } function AnotherButton(p: any) { return <h1>Just Another Button</h1>; } function Comp(p: Prop) { return <div>{p.b}</div>; } // OK let k1 = <Comp a={10} b="hi"><Button /> <AnotherButton /></Comp>; let k2 = <Comp a={10} b="hi"><Button /> <AnotherButton /> </Comp>; let k3 = <Comp a={10} b="hi"> <Button /> <AnotherButton /></Comp>; let k4 = <Comp a={10} b="hi"><Button /> </Comp>;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxChildrenProperty9.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts import React = require('react'); // OK let k1 = <div> <h2> Hello </h2> <h1> world </h1></div>; let k2 = <div> <h2> Hello </h2> {(user: any) => <h2>{user.name}</h2>}</div>; let k3 = <div> {1} {"That is a number"} </div>;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxGenericTagHasCorrectInferences.tsx
TypeScript (TSX)
// @filename: file.tsx // @jsx: preserve // @noLib: true // @skipLibCheck: true // @libFiles: react.d.ts,lib.d.ts import * as React from "react"; interface BaseProps<T> { initialValues: T; nextValues: (cur: T) => T; } declare class GenericComponent<Props = {}, Values = object> extends React.Component<Props & BaseProps<Values>, {}> { iv: Values; } let a = <GenericComponent initialValues={{ x: "y" }} nextValues={a => a} />; // No error let b = <GenericComponent initialValues={12} nextValues={a => a} />; // No error - Values should be reinstantiated with `number` (since `object` is a default, not a constraint) let c = <GenericComponent initialValues={{ x: "y" }} nextValues={a => ({ x: a.x })} />; // No Error let d = <GenericComponent initialValues={{ x: "y" }} nextValues={a => a.x} />; // Error - `string` is not assignable to `{x: string}`
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxIntersectionElementPropsType.tsx
TypeScript (TSX)
// @jsx: preserve // @strict: true declare namespace JSX { interface ElementAttributesProperty { props: {}; } } declare class Component<P> { constructor(props: Readonly<P>); readonly props: Readonly<P>; } class C<T> extends Component<{ x?: boolean; } & T> {} const y = new C({foobar: "example"}); const x = <C foobar="example" />
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxSubtleSkipContextSensitiveBug.tsx
TypeScript (TSX)
// @strict: true // @jsx: react // @lib: es6 // @skipLibCheck: true /// <reference path="/.lib/react16.d.ts" /> import * as React from "react"; interface ErrorResult { error: true } interface AsyncLoaderProps<TResult> { readonly prop1: () => Promise<TResult>; readonly prop2: (result: Exclude<TResult, ErrorResult>) => any; } class AsyncLoader<TResult> extends React.Component<AsyncLoaderProps<TResult>> { render() { return null; } } async function load(): Promise<{ success: true } | ErrorResult> { return { success: true }; } const loader = <AsyncLoader prop1={load} prop2={result => result} />;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkJsxUnionSFXContextualTypeInferredCorrectly.tsx
TypeScript (TSX)
// @jsx: react // @strict: true // @esModuleInterop: true /// <reference path="/.lib/react16.d.ts" /> import React from 'react'; interface PS { multi: false value: string | undefined onChange: (selection: string | undefined) => void } interface PM { multi: true value: string[] onChange: (selection: string[]) => void } export function ComponentWithUnion(props: PM | PS) { return <h1></h1>; } // Usage with React tsx export function HereIsTheError() { return ( <ComponentWithUnion multi={false} value={'s'} onChange={val => console.log(val)} // <- this throws an error /> ); } // Usage with pure TypeScript ComponentWithUnion({ multi: false, value: 's', onChange: val => console.log(val) // <- this works fine });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkObjectDefineProperty.ts
TypeScript
// @allowJs: true // @noEmit: true // @strict: true // @checkJs: true // @filename: index.js const x = {}; Object.defineProperty(x, "name", { value: "Charles", writable: true }); Object.defineProperty(x, "middleInit", { value: "H" }); Object.defineProperty(x, "lastName", { value: "Smith", writable: false }); Object.defineProperty(x, "zip", { get() { return 98122 }, set(_) { /*ignore*/ } }); Object.defineProperty(x, "houseNumber", { get() { return 21.75 } }); Object.defineProperty(x, "zipStr", { /** @param {string} str */ set(str) { this.zip = Number(str) } }); /** * @param {{name: string}} named */ function takeName(named) { return named.name; } takeName(x); /** * @type {number} */ var a = x.zip; /** * @type {number} */ var b = x.houseNumber; const returnExemplar = () => x; const needsExemplar = (_ = x) => void 0; const expected = /** @type {{name: string, readonly middleInit: string, readonly lastName: string, zip: number, readonly houseNumber: number, zipStr: string}} */(/** @type {*} */(null)); /** * * @param {typeof returnExemplar} a * @param {typeof needsExemplar} b */ function match(a, b) {} match(() => expected, (x = expected) => void 0); module.exports = x; // @filename: validate.ts // Validate in TS as simple validations would usually be interpreted as more special assignments import x = require("./"); x.name; x.middleInit; x.lastName; x.zip; x.houseNumber; x.zipStr; x.name = "Another"; x.zip = 98123; x.zipStr = "OK"; x.lastName = "should fail"; x.houseNumber = 12; // should also fail x.zipStr = 12; // should fail x.middleInit = "R"; // should also fail
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkOtherObjectAssignProperty.ts
TypeScript
// @allowJs: true // @noEmit: true // @strict: true // @checkJs: true // @filename: mod1.js const obj = { value: 42, writable: true }; Object.defineProperty(exports, "thing", obj); /** * @type {string} */ let str = /** @type {string} */("other"); Object.defineProperty(exports, str, { value: 42, writable: true }); const propName = "prop" Object.defineProperty(exports, propName, { value: 42, writable: true }); Object.defineProperty(exports, "bad1", { }); Object.defineProperty(exports, "bad2", { get() { return 12 }, value: "no" }); Object.defineProperty(exports, "bad3", { writable: true }); // @filename: importer.js const mod = require("./mod1"); mod.thing; mod.other; mod.prop; mod.bad1; mod.bad2; mod.bad3; mod.thing = 0; mod.other = 0; mod.prop = 0; mod.bad1 = 0; mod.bad2 = 0; mod.bad3 = 0;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/checkSpecialPropertyAssignments.ts
TypeScript
// @noEmit: true // @checkJs: true // @allowJs: true // @Filename: bug24252.js var A = {}; A.B = class { m() { /** @type {string[]} */ var x = []; /** @type {number[]} */ var y; y = x; } };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/circular1.ts
TypeScript
// @noEmit: true // @Filename: /a.ts export type { A } from './b'; // @Filename: /b.ts export type { A } from './a';
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/circular2.ts
TypeScript
// @noEmit: true // @Filename: /a.ts import type { B } from './b'; export type A = B; // @Filename: /b.ts import type { A } from './a'; export type B = A;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/circular3.ts
TypeScript
// @noEmit: true // @Filename: /a.ts import type { A } from './b'; export type { A as B }; // @Filename: /b.ts import type { B } from './a'; export type { B as A };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/circular4.ts
TypeScript
// @noEmit: true // @Filename: /a.ts import type { ns2 } from './b'; export namespace ns1 { export namespace nested { export type T = ns2.nested.T; } } // @Filename: /b.ts import type { ns1 } from './a'; export namespace ns2 { export namespace nested { export type T = ns1.nested.T; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/circularImportAlias.ts
TypeScript
// expected no error module B { export import a = A; export class D extends a.C { id: number; } } module A { export class C { name: string } export import b = B; } var c: { name: string }; var c = new B.a.C();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/circularIndexedAccessErrors.ts
TypeScript
// @declaration: true type T1 = { x: T1["x"]; // Error }; type T2<K extends "x" | "y"> = { x: T2<K>[K]; // Error y: number; } declare let x2: T2<"x">; let x2x = x2.x; interface T3<T extends T3<T>> { x: T["x"]; } interface T4<T extends T4<T>> { x: T4<T>["x"]; // Error } class C1 { x: C1["x"]; // Error } class C2 { x: this["y"]; y: this["z"]; z: this["x"]; } // Repro from #12627 interface Foo { hello: boolean; } function foo<T extends Foo | T["hello"]>() { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/circularMultipleAssignmentDeclaration.ts
TypeScript
// @filename:circularMultipleAssignmentDeclaration.js // @allowJs: true // @checkJs: true // @noEmit: true ns.next = ns.next || { shared: {} }; ns.next.shared.mymethod = {};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/circularReference.ts
TypeScript
// @Filename: foo1.ts import foo2 = require('./foo2'); export module M1 { export class C1 { m1: foo2.M1.C1; x: number; constructor(){ this.m1 = new foo2.M1.C1(); this.m1.y = 10; // OK this.m1.x = 20; // Error } } } // @Filename: foo2.ts import foo1 = require('./foo1'); export module M1 { export class C1 { m1: foo1.M1.C1; y: number constructor(){ this.m1 = new foo1.M1.C1(); this.m1.y = 10; // Error this.m1.x = 20; // OK var tmp = new M1.C1(); tmp.y = 10; // OK tmp.x = 20; // Error } } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/circularTypeAliasForUnionWithClass.ts
TypeScript
var v0: T0; type T0 = string | I0; class I0 { x: T0; } var v3: T3; type T3 = string | I3; class I3 { [x: number]: T3; } var v4: T4; type T4 = string | I4; class I4 { [x: string]: T4; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/circularTypeAliasForUnionWithInterface.ts
TypeScript
var v0: T0; type T0 = string | I0; interface I0 { x: T0; } var v1: T1; type T1 = string | I1; interface I1 { (): T1; } var v2: T2; type T2 = string | I2; interface I2 { new (): T2; } var v3: T3; type T3 = string | I3; interface I3 { [x: number]: T3; } var v4: T4; type T4 = string | I4; interface I4 { [x: string]: T4; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/circularTypeofWithVarOrFunc.ts
TypeScript
type typeAlias1 = typeof varOfAliasedType1; var varOfAliasedType1: typeAlias1; var varOfAliasedType2: typeAlias2; type typeAlias2 = typeof varOfAliasedType2; function func(): typeAlias3 { return null; } var varOfAliasedType3 = func(); type typeAlias3 = typeof varOfAliasedType3; // Repro from #26104 interface Input { a: number; b: number; } type R = ReturnType<typeof mul>; function mul(input: Input): R { return input.a * input.b; } // Repro from #26104 type R2 = ReturnType<typeof f>; function f(): R2 { return 0; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/cjsImportInES2015.ts
TypeScript
// @module: es2015 // @moduleResolution: node // @Filename: /project/node_modules/cjs-dep/index.d.ts declare class SpecialError extends Error {} export = SpecialError; // @Filename: /project/index.ts import type SpecialError = require("cjs-dep"); function handleError(err: SpecialError) {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAbstractAsIdentifier.ts
TypeScript
class abstract { foo() { return 1; } } new abstract;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAbstractAssignabilityConstructorFunction.ts
TypeScript
abstract class A { } // var AA: typeof A; var AAA: new() => A; // AA = A; // okay AAA = A; // error. AAA = "asdf";
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAbstractClinterfaceAssignability.ts
TypeScript
interface I { x: number; } interface IConstructor { new (): I; y: number; prototype: I; } var I: IConstructor; abstract class A { x: number; static y: number; } var AA: typeof A; AA = I; var AAA: typeof I; AAA = A;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAbstractConstructorAssignability.ts
TypeScript
class A {} abstract class B extends A {} class C extends B {} var AA : typeof A = B; var BB : typeof B = A; var CC : typeof C = B; new AA; new BB; new CC;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAbstractFactoryFunction.ts
TypeScript
class A {} abstract class B extends A {} function NewA(Factory: typeof A) { return new A; } function NewB(Factory: typeof B) { return new B; } NewA(A); NewA(B); NewB(A); NewB(B);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAbstractImportInstantiation.ts
TypeScript
module M { export abstract class A {} new A; } import myA = M.A; new myA;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAbstractInAModule.ts
TypeScript
module M { export abstract class A {} export class B extends A {} } new M.A; new M.B;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAbstractInstantiations1.ts
TypeScript
// // Calling new with (non)abstract classes. // abstract class A {} class B extends A {} abstract class C extends B {} new A; new A(1); // should report 1 error new B; new C; var a : A; var b : B; var c : C; a = new B; b = new B; c = new B;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAbstractMergedDeclaration.ts
TypeScript
abstract class CM {} module CM {} module MC {} abstract class MC {} abstract class CI {} interface CI {} interface IC {} abstract class IC {} abstract class CC1 {} class CC1 {} class CC2 {} abstract class CC2 {} declare abstract class DCI {} interface DCI {} interface DIC {} declare abstract class DIC {} declare abstract class DCC1 {} declare class DCC1 {} declare class DCC2 {} declare abstract class DCC2 {} new CM; new MC; new CI; new IC; new CC1; new CC2; new DCI; new DIC; new DCC1; new DCC2;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAbstractOverloads.ts
TypeScript
abstract class A { abstract foo(); abstract foo() : number; abstract foo(); abstract bar(); bar(); abstract bar(); abstract baz(); baz(); abstract baz(); baz() {} qux(); } abstract class B { abstract foo() : number; abstract foo(); x : number; abstract foo(); abstract foo(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAbstractSingleLineDecl.ts
TypeScript
abstract class A {} abstract class B {} abstract class C {} new A; new B; new C;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAbstractSuperCalls.ts
TypeScript
class A { foo() { return 1; } } abstract class B extends A { abstract foo(); bar() { super.foo(); } baz() { return this.foo; } } class C extends B { foo() { return 2; } qux() { return super.foo() || super.foo; } // 2 errors, foo is abstract norf() { return super.bar(); } } class AA { foo() { return 1; } bar() { return this.foo(); } } abstract class BB extends AA { abstract foo(); // inherits bar. But BB is abstract, so this is OK. }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAbstractUsingAbstractMethod1.ts
TypeScript
abstract class A { abstract foo() : number; } class B extends A { foo() { return 1; } } abstract class C extends A { abstract foo() : number; } var a = new B; a.foo(); a = new C; // error, cannot instantiate abstract class. a.foo();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAndInterfaceMerge.d.ts
TypeScript
interface C { } declare class C { } interface C { } interface C { } declare module M { interface C1 { } class C1 { } interface C1 { } interface C1 { } export class C2 { } } declare module M { export interface C2 { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAndInterfaceMergeConflictingMembers.ts
TypeScript
declare class C1 { public x : number; } interface C1 { x : number; } declare class C2 { protected x : number; } interface C2 { x : number; } declare class C3 { private x : number; } interface C3 { x : number; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAndInterfaceWithSameName.ts
TypeScript
class C { foo: string; } interface C { foo: string; } module M { class D { bar: string; } interface D { bar: string; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAndVariableWithSameName.ts
TypeScript
class C { foo: string; } // error var C = ''; // error module M { class D { // error bar: string; } var D = 1; // error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classAppearsToHaveMembersOfObject.ts
TypeScript
class C { foo: string; } var c: C; var r = c.toString(); var r2 = c.hasOwnProperty(''); var o: Object = c; var o2: {} = c;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classCanExtendConstructorFunction.ts
TypeScript
// @noEmit: true // @allowJs: true // @checkJs: true // @Filename: first.js /** * @constructor * @param {number} numberOxen */ function Wagon(numberOxen) { this.numberOxen = numberOxen } /** @param {Wagon[]=} wagons */ Wagon.circle = function (wagons) { return wagons ? wagons.length : 3.14; } /** @param {*[]=} supplies - *[]= is my favourite type */ Wagon.prototype.load = function (supplies) { } /** @param {*[]=} supplies - Yep, still a great type */ Wagon.prototype.weight = supplies => supplies ? supplies.length : -1 Wagon.prototype.speed = function () { return this.numberOxen / this.weight() } // ok class Sql extends Wagon { constructor() { super(); // error: not enough arguments this.foonly = 12 } /** * @param {Array.<string>} files * @param {"csv" | "json" | "xmlolololol"} format * This is not assignable, so should have a type error */ load(files, format) { if (format === "xmlolololol") { throw new Error("please do not use XML. It was a joke."); } else { super.speed() // run faster if (super.weight() < 0) { // ???????????????????????? } } } } var db = new Sql(); db.numberOxen = db.foonly // error, can't extend a TS constructor function class Drakkhen extends Dragon { } // @Filename: second.ts /** * @constructor */ function Dragon(numberEaten: number) { this.numberEaten = numberEaten } // error! class Firedrake extends Dragon { constructor() { super(); } } // ok class Conestoga extends Wagon { constructor(public drunkOO: true) { // error: wrong type super('nope'); } // should error since others is not optional static circle(others: (typeof Wagon)[]) { return others.length } } var c = new Conestoga(true); c.drunkOO c.numberOxen // @Filename: generic.js /** * @template T * @param {T} flavour */ function Soup(flavour) { this.flavour = flavour } /** @extends {Soup<{ claim: "ignorant" | "malicious" }>} */ class Chowder extends Soup { log() { return this.flavour } } var soup = new Soup(1); soup.flavour var chowder = new Chowder({ claim: "ignorant" }); chowder.flavour.claim var errorNoArgs = new Chowder(); var errorArgType = new Chowder(0);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classConstructorAccessibility.ts
TypeScript
// @declaration: true class C { public constructor(public x: number) { } } class D { private constructor(public x: number) { } } class E { protected constructor(public x: number) { } } var c = new C(1); var d = new D(1); // error var e = new E(1); // error module Generic { class C<T> { public constructor(public x: T) { } } class D<T> { private constructor(public x: T) { } } class E<T> { protected constructor(public x: T) { } } var c = new C(1); var d = new D(1); // error var e = new E(1); // error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classConstructorAccessibility2.ts
TypeScript
// @declaration: true class BaseA { public constructor(public x: number) { } createInstance() { new BaseA(1); } } class BaseB { protected constructor(public x: number) { } createInstance() { new BaseB(2); } } class BaseC { private constructor(public x: number) { } createInstance() { new BaseC(3); } static staticInstance() { new BaseC(4); } } class DerivedA extends BaseA { constructor(public x: number) { super(x); } createInstance() { new DerivedA(5); } createBaseInstance() { new BaseA(6); } static staticBaseInstance() { new BaseA(7); } } class DerivedB extends BaseB { constructor(public x: number) { super(x); } createInstance() { new DerivedB(7); } createBaseInstance() { new BaseB(8); } // ok static staticBaseInstance() { new BaseB(9); } // ok } class DerivedC extends BaseC { // error constructor(public x: number) { super(x); } createInstance() { new DerivedC(9); } createBaseInstance() { new BaseC(10); } // error static staticBaseInstance() { new BaseC(11); } // error } var ba = new BaseA(1); var bb = new BaseB(1); // error var bc = new BaseC(1); // error var da = new DerivedA(1); var db = new DerivedB(1); var dc = new DerivedC(1);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classConstructorAccessibility3.ts
TypeScript
// @declaration: true class Foo { constructor(public x: number) { } } class Bar { public constructor(public x: number) { } } class Baz { protected constructor(public x: number) { } } class Qux { private constructor(public x: number) { } } // b is public let a = Foo; a = Bar; a = Baz; // error Baz is protected a = Qux; // error Qux is private // b is protected let b = Baz; b = Foo; b = Bar; b = Qux; // error Qux is private // c is private let c = Qux; c = Foo; c = Bar; c = Baz;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classConstructorAccessibility4.ts
TypeScript
// @declaration: true class A { private constructor() { } method() { class B { method() { new A(); // OK } } class C extends A { // OK } } } class D { protected constructor() { } method() { class E { method() { new D(); // OK } } class F extends D { // OK } } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classConstructorAccessibility5.ts
TypeScript
class Base { protected constructor() { } } class Derived extends Base { static make() { new Base() } // ok } class Unrelated { static fake() { new Base() } // error }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classConstructorOverloadsAccessibility.ts
TypeScript
// @declaration: true class A { public constructor(a: boolean) // error protected constructor(a: number) // error private constructor(a: string) private constructor() { } } class B { protected constructor(a: number) // error constructor(a: string) constructor() { } } class C { protected constructor(a: number) protected constructor(a: string) protected constructor() { } } class D { constructor(a: number) constructor(a: string) public constructor() { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classConstructorParametersAccessibility.ts
TypeScript
class C1 { constructor(public x: number) { } } var c1: C1; c1.x // OK class C2 { constructor(private p: number) { } } var c2: C2; c2.p // private, error class C3 { constructor(protected p: number) { } } var c3: C3; c3.p // protected, error class Derived extends C3 { constructor(p: number) { super(p); this.p; // OK } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classConstructorParametersAccessibility2.ts
TypeScript
class C1 { constructor(public x?: number) { } } var c1: C1; c1.x // OK class C2 { constructor(private p?: number) { } } var c2: C2; c2.p // private, error class C3 { constructor(protected p?: number) { } } var c3: C3; c3.p // protected, error class Derived extends C3 { constructor(p: number) { super(p); this.p; // OK } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classConstructorParametersAccessibility3.ts
TypeScript
class Base { constructor(protected p: number) { } } class Derived extends Base { constructor(public p: number) { super(p); this.p; // OK } } var d: Derived; d.p; // public, OK
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classDeclarationLoop.ts
TypeScript
const arr = []; for (let i = 0; i < 10; ++i) { class C { prop = i; } arr.push(C); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classDoesNotDependOnBaseTypes.ts
TypeScript
type StringTree = string | StringTreeCollection; class StringTreeCollectionBase { [n: number]: StringTree; } class StringTreeCollection extends StringTreeCollectionBase { } var x: StringTree; if (typeof x !== "string") { x[0] = ""; x[0] = new StringTreeCollection; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classDoesNotDependOnPrivateMember.ts
TypeScript
//@declaration: true module M { interface I { } export class C { private x: I; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classExpression.ts
TypeScript
var x = class C { } var y = { foo: class C2 { } } module M { var z = class C4 { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classExpression1.ts
TypeScript
var v = class C {};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classExpression2.ts
TypeScript
class D { } var v = class C extends D {};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classExpression3.ts
TypeScript
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 }; let c = new C(); c.a; c.b; c.c;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classExpression4.ts
TypeScript
let C = class { foo() { return new C(); } }; let x = (new C).foo();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classExpression5.ts
TypeScript
new class { hi() { return "Hi!"; } }().hi();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classExpressionES61.ts
TypeScript
// @target: es6 var v = class C {};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classExpressionES62.ts
TypeScript
// @target: es6 class D { } var v = class C extends D {};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classExpressionES63.ts
TypeScript
// @target: es6 let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 }; let c = new C(); c.a; c.b; c.c;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classExpressionLoop.ts
TypeScript
let arr = []; for (let i = 0; i < 10; ++i) { arr.push(class C { prop = i; }); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classExtendingBuiltinType.ts
TypeScript
class C1 extends Object { } class C2 extends Function { } class C3 extends String { } class C4 extends Boolean { } class C5 extends Number { } class C6 extends Date { } class C7 extends RegExp { } class C8 extends Error { } class C9 extends Array { } class C10 extends Array<number> { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classExtendingClass.ts
TypeScript
class C { foo: string; thing() { } static other() { } } class D extends C { bar: string; } var d: D; var r = d.foo; var r2 = d.bar; var r3 = d.thing(); var r4 = D.other(); class C2<T> { foo: T; thing(x: T) { } static other<T>(x: T) { } } class D2<T> extends C2<T> { bar: string; } var d2: D2<string>; var r5 = d2.foo; var r6 = d2.bar; var r7 = d2.thing(''); var r8 = D2.other(1);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classExtendingClassLikeType.ts
TypeScript
interface Base<T, U> { x: T; y: U; } // Error, no Base constructor function class D0 extends Base<string, string> { } interface BaseConstructor { new (x: string, y: string): Base<string, string>; new <T>(x: T): Base<T, T>; new <T>(x: T, y: T): Base<T, T>; new <T, U>(x: T, y: U): Base<T, U>; } declare function getBase(): BaseConstructor; class D1 extends getBase() { constructor() { super("abc", "def"); this.x = "x"; this.y = "y"; } } class D2 extends getBase() <number> { constructor() { super(10); super(10, 20); this.x = 1; this.y = 2; } } class D3 extends getBase() <string, number> { constructor() { super("abc", 42); this.x = "x"; this.y = 2; } } // Error, no constructors with three type arguments class D4 extends getBase() <string, string, string> { } interface BadBaseConstructor { new (x: string): Base<string, string>; new (x: number): Base<number, number>; } declare function getBadBase(): BadBaseConstructor; // Error, constructor return types differ class D5 extends getBadBase() { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classExtendingNonConstructor.ts
TypeScript
var x: {}; function foo() { this.x = 1; } class C1 extends undefined { } class C2 extends true { } class C3 extends false { } class C4 extends 42 { } class C5 extends "hello" { } class C6 extends x { } class C7 extends foo { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classExtendingNull.ts
TypeScript
class C1 extends null { } class C2 extends (null) { } class C3 extends null { x = 1; } class C4 extends (null) { x = 1; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classExtendingOptionalChain.ts
TypeScript
namespace A { export class B {} } // ok class C1 extends A?.B {} // error class C2 implements A?.B {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/classExtendsItself.ts
TypeScript
class C extends C { } // error class D<T> extends D<T> { } // error class E<T> extends E<string> { } // error
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University