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/tsxStatelessFunctionComponents2.tsx | TypeScript (TSX) | // @filename: file.tsx
// @jsx: preserve
// @noLib: true
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
import React = require('react');
function Greet(x: {name?: string}) {
return <div>Hello, {x}</div>;
}
class BigGreeter extends React.Component<{ name?: string }, {}> {
render() {
return <div></div>;
}
greeting: string;
}
// OK
let a = <Greet />;
// OK - always valid to specify 'key'
let b = <Greet key="k" />;
// Error - not allowed to specify 'ref' on SFCs
let c = <Greet ref="myRef" />;
// OK - ref is valid for classes
let d = <BigGreeter ref={x => x.greeting.substr(10)} />;
// Error ('subtr' not on string)
let e = <BigGreeter ref={x => x.greeting.subtr(10)} />;
// Error (ref callback is contextually typed)
let f = <BigGreeter ref={x => x.notARealProperty} />;
// OK - key is always valid
let g = <BigGreeter key={100} />;
// OK - contextually typed intrinsic ref callback parameter
let h = <div ref={x => x.innerText} />;
// Error - property not on ontextually typed intrinsic ref callback parameter
let i = <div ref={x => x.propertyNotOnHtmlDivElement} />;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tsxStatelessFunctionComponents3.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');
const Foo = (props: any) => <div/>;
// Should be OK
const foo = <Foo />;
// Should be OK
var MainMenu: React.StatelessComponent<{}> = (props) => (<div>
<h3>Main Menu</h3>
</div>);
var App: React.StatelessComponent<{ children }> = ({children}) => (
<div >
<MainMenu/>
</div>
); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tsxStatelessFunctionComponentsWithTypeArguments1.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')
declare function ComponentWithTwoAttributes<K,V>(l: {key1: K, value: V}): JSX.Element;
// OK
function Baz<T,U>(key1: T, value: U) {
let a0 = <ComponentWithTwoAttributes key1={key1} value={value} />
let a1 = <ComponentWithTwoAttributes {...{key1, value: value}} key="Component" />
}
declare function Link<U>(l: {func: (arg: U)=>void}): JSX.Element;
// OK
function createLink(func: (a: number)=>void) {
let o = <Link func={func} />
}
function createLink1(func: (a: number)=>boolean) {
let o = <Link func={func} />
}
interface InferParamProp<T> {
values: Array<T>;
selectHandler: (selectedVal: T) => void;
}
declare function InferParamComponent<T>(attr: InferParamProp<T>): JSX.Element;
// OK
let i = <InferParamComponent values={[1, 2, 3, 4]} selectHandler={(val) => { }} />; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tsxStatelessFunctionComponentsWithTypeArguments2.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')
declare function ComponentSpecific1<U>(l: {prop: U, "ignore-prop": string}): JSX.Element;
declare function ComponentSpecific2<U>(l: {prop: U}): JSX.Element;
// Error
function Bar<T extends {prop: number}>(arg: T) {
let a1 = <ComponentSpecific1 {...arg} ignore-prop={10} />;
}
// Error
function Baz<T>(arg: T) {
let a0 = <ComponentSpecific1 {...arg} />
}
declare function Link<U>(l: {func: (arg: U)=>void}): JSX.Element;
// Error
function createLink(func: (a: number, b: string)=>void) {
let o = <Link func={func} />
}
interface InferParamProp<T> {
values: Array<T>;
selectHandler: (selectedVal: T) => void;
}
declare function InferParamComponent<T>(attr: InferParamProp<T>): JSX.Element;
// Error
let i = <InferParamComponent values={[1, 2, 3, 4]} selectHandler={(val: string) => { }} />;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tsxStatelessFunctionComponentsWithTypeArguments3.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')
declare function OverloadComponent<U>(): JSX.Element;
declare function OverloadComponent<U>(attr: {b: U, a?: string, "ignore-prop": boolean}): JSX.Element;
declare function OverloadComponent<T, U>(attr: {b: U, a: T}): JSX.Element;
// OK
function Baz<T extends {b: number}, U extends {a: boolean, b:string}>(arg1: T, arg2: U) {
let a0 = <OverloadComponent {...arg1} a="hello" ignore-prop />;
let a1 = <OverloadComponent {...arg2} ignore-pro="hello world" />;
let a2 = <OverloadComponent {...arg2} />;
let a3 = <OverloadComponent {...arg1} ignore-prop />;
let a4 = <OverloadComponent />;
let a5 = <OverloadComponent {...arg2} ignore-prop="hello" {...arg1} />;
let a6 = <OverloadComponent {...arg2} ignore-prop {...arg1} />;
}
declare function Link<U>(l: {func: (arg: U)=>void}): JSX.Element;
declare function Link<U>(l: {func: (arg1:U, arg2: string)=>void}): JSX.Element;
function createLink(func: (a: number)=>void) {
let o = <Link func={func} />
let o1 = <Link func={(a:number, b:string)=>{}} />;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tsxStatelessFunctionComponentsWithTypeArguments4.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')
declare function OverloadComponent<U>(): JSX.Element;
declare function OverloadComponent<U>(attr: {b: U, a: string, "ignore-prop": boolean}): JSX.Element;
declare function OverloadComponent<T, U>(attr: {b: U, a: T}): JSX.Element;
// Error
function Baz<T extends {b: number}, U extends {a: boolean, b:string}>(arg1: T, arg2: U) {
let a0 = <OverloadComponent a={arg1.b}/>
let a2 = <OverloadComponent {...arg1} ignore-prop /> // missing a
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tsxStatelessFunctionComponentsWithTypeArguments5.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')
declare function Component<U>(l: U): JSX.Element;
function createComponent<T extends { prop: number }>(arg: T) {
let a1 = <Component {...arg} />;
let a2 = <Component {...arg} prop1 />;
}
declare function ComponentSpecific<U>(l: { prop: U }): JSX.Element;
declare function ComponentSpecific1<U>(l: { prop: U, "ignore-prop": number }): JSX.Element;
function Bar<T extends { prop: number }>(arg: T) {
let a1 = <ComponentSpecific {...arg} ignore-prop="hi" />; // U is number
let a2 = <ComponentSpecific1 {...arg} ignore-prop={10} />; // U is number
let a3 = <ComponentSpecific {...arg} prop="hello" />; // U is "hello"
let a4 = <ComponentSpecific {...arg} prop1="hello" />; // U is "hello"
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tsxTypeArgumentsJsxPreserveOutput.tsx | TypeScript (TSX) | // @filename: foo.tsx
// @jsx: preserve
// @noLib: true
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
import React = require('react');
type TypeProps = { foo?: boolean; };
interface InterfaceProps { foo?: boolean; }
function Foo<T>() {
return null;
}
<>
{/* JsxSelfClosingElement */}
<Foo<unknown> />
<Foo<string> />
<Foo<boolean> />
<Foo<object> />
<Foo<null> />
<Foo<any> />
<Foo<never> />
<Foo<undefined> />
<Foo<TypeProps> />
<Foo<InterfaceProps> />
{/* JsxOpeningElement */}
<Foo<unknown>></Foo>
<Foo<string>></Foo>
<Foo<boolean>></Foo>
<Foo<object>></Foo>
<Foo<null>></Foo>
<Foo<any>></Foo>
<Foo<never>></Foo>
<Foo<undefined>></Foo>
<Foo<TypeProps>></Foo>
<Foo<InterfaceProps>></Foo>
</>
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tsxTypeErrors.tsx | TypeScript (TSX) | //@jsx: preserve
// A built-in element (OK)
var a1 = <div id="foo" />;
// A built-in element with a mistyped property (error)
var a2 = <img srce="foo.jpg" />
// A built-in element with a badly-typed attribute value (error)
var thing = { oops: 100 };
var a3 = <div id={thing} />
// Mistyped html name (error)
var e1 = <imag src="bar.jpg" />
// A custom type
class MyClass {
props: {
pt?: { x: number; y: number; };
name?: string;
reqd: boolean;
}
}
// Let's use it
// TODO: Error on missing 'reqd'
var b1 = <MyClass reqd={true} />;
// Mistyped attribute member
// sample.tsx(23,22): error TS2322: Type '{ x: number; y: string; }' is not assignable to type '{ x: number; y: number; }'.
// Types of property 'y' are incompatible.
// Type 'string' is not assignable to type 'number'.
var b2 = <MyClass pt={{x: 4, y: 'oops'}} />;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tsxUnionElementType1.tsx | TypeScript (TSX) | // @filename: file.tsx
// @jsx: react
// @noLib: true
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
import React = require('react');
function SFC1(prop: { x: number }) {
return <div>hello</div>;
};
function SFC2(prop: { x: boolean }) {
return <h1>World </h1>;
}
var SFCComp = SFC1 || SFC2;
<SFCComp x /> | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tsxUnionElementType2.tsx | TypeScript (TSX) | // @filename: file.tsx
// @jsx: react
// @noLib: true
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
import React = require('react');
function SFC1(prop: { x: number }) {
return <div>hello</div>;
};
function SFC2(prop: { x: boolean }) {
return <h1>World </h1>;
}
var SFCComp = SFC1 || SFC2;
<SFCComp x={"hi"}/> | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tsxUnionElementType3.tsx | TypeScript (TSX) | // @filename: file.tsx
// @jsx: react
// @noLib: true
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
import React = require('react');
class RC1 extends React.Component<{x : number}, {}> {
render() {
return null;
}
}
class RC2 extends React.Component<{ x: string }, {}> {
render() {
return null;
}
private method() { }
}
class RC3 extends React.Component<{}, {}> {
render() {
return null;
}
}
class RC4 extends React.Component<{}, {}> {
render() {
return null;
}
}
var EmptyRCComp = RC3 || RC4;
var PartRCComp = RC1 || RC4;
var RCComp = RC1 || RC2;
// OK
let a = <RCComp x="Hi" />;
let a1 = <EmptyRCComp />;
let a2 = <EmptyRCComp data-prop="hello" />;
let b = <PartRCComp />
let c = <PartRCComp data-extra="hello" /> | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tsxUnionElementType4.tsx | TypeScript (TSX) | // @filename: file.tsx
// @jsx: react
// @noLib: true
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
import React = require('react');
class RC1 extends React.Component<{x : number}, {}> {
render() {
return null;
}
}
class RC2 extends React.Component<{ x: string }, {}> {
render() {
return null;
}
private method() { }
}
class RC3 extends React.Component<{}, {}> {
render() {
return null;
}
}
class RC4 extends React.Component<{}, {}> {
render() {
return null;
}
}
var RCComp = RC1 || RC2;
var EmptyRCComp = RC3 || RC4;
var PartRCComp = RC1 || RC4;
// Error
let a = <RCComp x />;
let b = <PartRCComp x={10} />
let c = <EmptyRCComp prop />;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tsxUnionElementType5.tsx | TypeScript (TSX) | // @filename: file.tsx
// @jsx: react
// @noLib: true
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
import React = require('react');
function EmptySFC1() {
return <div>hello</div>;
}
function EmptySFC2() {
return <div>Hello</div>;
}
function SFC2(prop: { x: boolean }) {
return <h1>World</h1>;
}
var EmptySFCComp = EmptySFC1 || EmptySFC2;
var SFC2AndEmptyComp = SFC2 || EmptySFC1;
let a = <EmptySFCComp />
let a1 = <EmptySFCComp data-prop />
let b = <SFC2AndEmptyComp x /> | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tsxUnionElementType6.tsx | TypeScript (TSX) | // @filename: file.tsx
// @jsx: react
// @noLib: true
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
import React = require('react');
function EmptySFC1() {
return <div>Hi</div>
}
function EmptySFC2() {
return <div>Hello</div>
}
function SFC2(prop: { x: boolean }) {
return <h1>World</h1>;
}
var EmptySFCComp = EmptySFC1 || EmptySFC2;
var SFC2AndEmptyComp = SFC2 || EmptySFC1;
// Error
let a = <EmptySFCComp x />;
let b = <SFC2AndEmptyComp x="hi" />;
let c = <SFC2AndEmptyComp />;
let d = <SFC2AndEmptyComp data-prop />;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tsxUnionTypeComponent1.tsx | TypeScript (TSX) | // @filename: file.tsx
// @jsx: react
// @noLib: true
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
import React = require('react');
interface ComponentProps {
AnyComponent: React.StatelessComponent<any> | React.ComponentClass<any>;
}
class MyComponent extends React.Component<ComponentProps, {}> {
render() {
const { AnyComponent } = this.props;
return (<AnyComponent />);
}
}
// Stateless Component As Props
<MyComponent AnyComponent={() => <button>test</button>}/>
// Component Class as Props
class MyButtonComponent extends React.Component<{},{}> {
}
<MyComponent AnyComponent={MyButtonComponent} />
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tsxUnionTypeComponent2.tsx | TypeScript (TSX) | // @filename: file.tsx
// @jsx: react
// @noLib: true
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts
import React = require('react');
type Invalid1 = React.ComponentClass<any> | number;
const X: Invalid1 = 1;
<X />;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tupleElementTypes1.ts | TypeScript | var [a, b]: [number, any] = [undefined, undefined]; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tupleElementTypes2.ts | TypeScript | function f([a, b]: [number, any]) { } | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tupleElementTypes3.ts | TypeScript | var [a, b] = [0, undefined]; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tupleElementTypes4.ts | TypeScript | function f([a, b] = [0, undefined]) { } | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/tupleLengthCheck.ts | TypeScript | declare const a: [number, string]
declare const rest: [number, string, ...boolean[]]
const a1 = a[1]
const a2 = a[2]
const a3 = a[1000]
const a4 = rest[1]
const a5 = rest[2]
const a6 = rest[3]
const a7 = rest[1000]
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/twoAccessorsWithSameName2.ts | TypeScript | class C {
static get x() { return 1; }
static get x() { return 1; } // error
}
class D {
static set x(v) { }
static set x(v) { } // error
}
class E {
static get x() {
return 1;
}
static set x(v) { }
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/twoGenericInterfacesDifferingByTypeParameterName.ts | TypeScript | // type parameter names are relevant when choosing whether to merge interface declarations
interface A<T> {
x: T;
}
interface A<U> { // error
y: U;
}
interface B<T,U> {
x: U;
}
interface B<T,V> { // error
y: V;
}
module M {
interface A<T> {
x: T;
}
interface A<U> { // error
y: U;
}
interface B<T, U> {
x: U;
}
interface B<T, V> { // error
y: V;
}
}
module M2 {
interface B<T, U> {
x: U;
}
}
module M2 {
interface B<T, V> { // ok, different declaration space than other M2
y: V;
}
}
module M3 {
export interface B<T, U> {
x: U;
}
}
module M3 {
export interface B<T, V> { // error
y: V;
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/twoGenericInterfacesDifferingByTypeParameterName2.ts | TypeScript | // type parameter names are relevant when choosing whether to merge interface declarations
interface B<T, U> {
x: U;
}
interface B<U, T> { // error
y: V;
}
module M {
interface B<T, U> {
x: U;
}
interface B<U, T> { // error
y: T;
}
}
module M2 {
interface B<T, U> {
x: U;
}
}
module M2 {
interface B<U, T> { // ok, different declaration space than other M2
y: T;
}
}
module M3 {
export interface B<T, U> {
x: U;
}
}
module M3 {
export interface B<U, T> { // error
y: T;
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/twoGenericInterfacesWithDifferentConstraints.ts | TypeScript | interface A<T extends Date> {
x: T;
}
interface A<T extends Number> { // error
y: T;
}
module M {
interface B<T extends A<Date>> {
x: T;
}
interface B<T extends A<any>> { // error
y: T;
}
}
module M2 {
interface A<T extends Date> {
x: T;
}
}
module M2 {
interface A<T extends Number> { // ok, different declaration space from other M2.A
y: T;
}
}
module M3 {
export interface A<T extends Date> {
x: T;
}
}
module M3 {
export interface A<T extends Number> { // error
y: T;
}
}
interface B<T extends number> {
u: T;
v: Constraint<T>; // ok
}
interface B<T> { // ok
x: T;
y: Constraint<T>; // ok
}
interface C<T> {
x: T;
}
interface C<T extends number> { // ok
y: T;
}
interface Constraint<T extends number> {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/twoGenericInterfacesWithTheSameNameButDifferentArity.ts | TypeScript | interface A<T> {
x: T;
}
interface A<T, U> { // error
y: T;
}
module M {
interface A<T> {
x: T;
}
interface A<T, U> { // error
y: T;
}
}
module M2 {
interface A<T> {
x: T;
}
}
module M2 {
interface A<T, U> { // ok, different declaration space than other M2
y: T;
}
}
module M3 {
export interface A<T> {
x: T;
}
}
module M3 {
export interface A<T, U> { // error
y: T;
}
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/twoInterfacesDifferentRootModule.ts | TypeScript | // two interfaces with different root modules should not merge
module M {
export interface A {
foo: string;
}
export interface B<T> {
foo: T;
}
}
module M2 {
export interface A {
bar: number;
}
var a: A;
var r1 = a.foo; // error
var r2 = a.bar;
export interface B<T> {
bar: T;
}
var b: B<string>;
var r3 = b.foo; // error
var r4 = b.bar;
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/twoInterfacesDifferentRootModule2.ts | TypeScript | // two interfaces with different root modules should not merge
module M {
export interface A {
foo: string;
}
export interface B<T> {
foo: T;
}
module M2 {
export interface A {
bar: number;
}
var a: A;
var r1 = a.foo; // error
var r2 = a.bar;
export interface B<T> {
bar: T;
}
var b: B<string>;
var r3 = b.foo; // error
var r4 = b.bar;
}
var a: A;
var r1 = a.foo;
var r2 = a.bar; // error
var b: B<string>;
var r3 = b.foo;
var r4 = b.bar; // error
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/twoMergedInterfacesWithDifferingOverloads.ts | TypeScript | // interfaces that merge must not have members that conflict
interface A {
foo(x: number): number;
foo(x: string): string;
}
interface A {
foo(x: Date): Date;
}
interface B<T> {
foo(x: T): number;
foo(x: string): string;
}
interface B<T> {
foo(x: T): Date;
foo(x: Date): string;
}
var b: B<boolean>;
var r = b.foo(true); // returns Date
// add generic overload
interface C<T, U> {
foo(x: T, y: U): string;
foo(x: string, y: string): number;
}
interface C<T, U> {
foo<W>(x: W, y: W): W;
}
var c: C<boolean, Date>;
var r2 = c.foo(1, 2); // number
// add generic overload that would be ambiguous
interface D<T, U> {
a: T;
b: U;
foo<A>(x: A, y: A): U;
}
interface D<T, U> {
foo<W>(x: W, y: W): T;
}
var d: D<boolean, Date>;
var r3 = d.foo(1, 1); // boolean, last definition wins | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/twoMergedInterfacesWithDifferingOverloads2.ts | TypeScript | interface A {
(): string;
(x: number): number;
}
interface A {
(x: number, y: number): boolean;
}
var a: A;
var r = a();
var r2 = a(1);
var r3 = a(1, 2);
module G {
interface A<T> {
(): string;
(x: T): T;
}
interface A<T> {
(x: T, y: number): T;
<U>(x: U, y: T): U;
}
var a: A<boolean>;
var r = a();
var r2 = a(true);
var r3 = a(true, 2);
var r4 = a(1, true);
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeAliases.ts | TypeScript | // Writing a reference to a type alias has exactly the same effect as writing the aliased type itself.
type T1 = number;
var x1: number;
var x1: T1;
type T2 = string;
var x2: string;
var x2: T2;
type T3 = boolean;
var x3: boolean;
var x3: T3;
type T4 = void;
var x4: void;
var x4: T4;
type T5 = any;
var x5: any;
var x5: T5;
interface I6 { x : string }
type T6 = I6;
var x6: I6;
var x6: T6;
class C7 { x: boolean }
type T7 = C7;
var x7: C7;
var x7: T7;
type T8 = string | boolean;
var x8: string | boolean;
var x8: T8;
type T9 = () => string;
var x9: () => string;
var x9: T9;
type T10 = { x: number };
var x10: { x: number };
var x10: T10;
type T11 = { new(): boolean };
var x11: { new(): boolean };
var x11: T11;
interface I13 { x: string };
type T13 = I13;
var x13_1: I13;
var x13_2: T13
declare function foo13<T1 extends I13, T2 extends T13>(t1: T1, t2: T13): void;
foo13(x13_1, x13_2);
foo13(x13_2, x13_1);
type T14 = string;
var x14: T14;
declare function foo14_1(x: T14): void;
declare function foo14_2(x: "click"): void;
declare function foo14_2(x: T14): void;
type Meters = number
enum E { x = 10 }
declare function f15(a: string): boolean;
declare function f15(a: Meters): string;
f15(E.x).toLowerCase();
type StringAndBoolean = [string, boolean]
declare function f16(s: StringAndBoolean): string;
var x: [string, boolean];
f16(x);
var y: StringAndBoolean = ["1", false];
y[0].toLowerCase(); | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeAliasesDoNotMerge.ts | TypeScript | export type A = {}
type A = {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeAliasesForObjectTypes.ts | TypeScript | type T1 = { x: string }
// An interface can be named in an extends or implements clause, but a type alias for an object type literal cannot.
interface I1 extends T1 { y: string }
class C1 implements T1 {
x: string;
}
// An interface can have multiple merged declarations, but a type alias for an object type literal cannot.
type T2 = { x: string }
type T2 = { y: number }
// An interface can have type parameters, but a type alias for an object type literal cannot.
type T3<T> = { x: T }
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeAndNamespaceExportMerge.ts | TypeScript | // @strict
// @Filename: constants.ts
export const COFFEE = 0;
export const TEA = 1;
// @Filename: drink.ts
export type Drink = 0 | 1;
export * as Drink from "./constants";
// @Filename: index.ts
import { Drink } from "./drink";
// 'Drink' only refers to a type, but is being used as a value here
const x: Drink = Drink.TEA;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeArgumentInference.ts | TypeScript | // Generic call with no parameters
function noParams<T>() { }
noParams();
noParams<string>();
noParams<{}>();
// Generic call with parameters but none use type parameter type
function noGenericParams<T>(n: string) { }
noGenericParams('');
noGenericParams<number>('');
noGenericParams<{}>('');
// Generic call with multiple type parameters and only one used in parameter type annotation
function someGenerics1<T, U>(n: T, m: number) { }
someGenerics1(3, 4);
someGenerics1<number, {}>(3, 4);
// Generic call with argument of function type whose parameter is of type parameter type
function someGenerics2a<T>(n: (x: T) => void) { }
someGenerics2a((n: string) => n);
someGenerics2a<string>((n: string) => n);
someGenerics2a<string>((n) => n.substr(0));
function someGenerics2b<T, U>(n: (x: T, y: U) => void) { }
someGenerics2b((n: string, x: number) => n);
someGenerics2b<string, number>((n: string, t: number) => n);
someGenerics2b<string, number>((n, t) => n.substr(t * t));
// Generic call with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter
function someGenerics3<T>(producer: () => T) { }
someGenerics3(() => '');
someGenerics3<Date>(() => undefined);
someGenerics3<number>(() => 3);
// 2 parameter generic call with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type
function someGenerics4<T, U>(n: T, f: (x: U) => void) { }
someGenerics4(4, () => null);
someGenerics4<string, number>('', () => 3);
someGenerics4<string, number>(null, null);
// 2 parameter generic call with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type
function someGenerics5<U, T>(n: T, f: (x: U) => void) { }
someGenerics5(4, () => null);
someGenerics5<number, string>('', () => 3);
someGenerics5<string, number>(null, null);
// Generic call with multiple arguments of function types that each have parameters of the same generic type
function someGenerics6<A>(a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { }
someGenerics6(n => n, n => n, n => n);
someGenerics6<number>(n => n, n => n, n => n);
someGenerics6<number>((n: number) => n, (n: number) => n, (n: number) => n);
// Generic call with multiple arguments of function types that each have parameters of different generic type
function someGenerics7<A, B, C>(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { }
someGenerics7(n => n, n => n, n => n);
someGenerics7<number, string, number>(n => n, n => n, n => n);
someGenerics7<number, string, number>((n: number) => n, (n: string) => n, (n: number) => n);
// Generic call with argument of generic function type
function someGenerics8<T>(n: T): T { return n; }
var x = someGenerics8(someGenerics7);
x<string, string, string>(null, null, null);
// Generic call with multiple parameters of generic type passed arguments with no best common type
function someGenerics9<T>(a: T, b: T, c: T): T {
return null;
}
var a9a = someGenerics9('', 0, []);
var a9a: {};
var a9b = someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null);
var a9b: { a?: number; b?: string; };
// Generic call with multiple parameters of generic type passed arguments with multiple best common types
interface A91 {
x: number;
y?: string;
}
interface A92 {
x: number;
z?: Date;
}
var a9e = someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' });
var a9e: {};
var a9f = someGenerics9<A92>(undefined, { x: 6, z: new Date() }, { x: 6, y: '' });
var a9f: A92;
// Generic call with multiple parameters of generic type passed arguments with a single best common type
var a9d = someGenerics9({ x: 3 }, { x: 6 }, { x: 6 });
var a9d: { x: number; };
// Generic call with multiple parameters of generic type where one argument is of type 'any'
var anyVar: any;
var a = someGenerics9(7, anyVar, 4);
var a: any;
// Generic call with multiple parameters of generic type where one argument is [] and the other is not 'any'
var arr = someGenerics9([], null, undefined);
var arr: any[];
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeArgumentInferenceConstructSignatures.ts | TypeScript | // Generic call with no parameters
interface NoParams {
new <T>();
}
var noParams: NoParams;
new noParams();
new noParams<string>();
new noParams<{}>();
// Generic call with parameters but none use type parameter type
interface noGenericParams {
new <T>(n: string);
}
var noGenericParams: noGenericParams;
new noGenericParams('');
new noGenericParams<number>('');
new noGenericParams<{}>('');
// Generic call with multiple type parameters and only one used in parameter type annotation
interface someGenerics1 {
new <T, U>(n: T, m: number);
}
var someGenerics1: someGenerics1;
new someGenerics1(3, 4);
new someGenerics1<string, number>(3, 4); // Error
new someGenerics1<number, {}>(3, 4);
// Generic call with argument of function type whose parameter is of type parameter type
interface someGenerics2a {
new <T>(n: (x: T) => void);
}
var someGenerics2a: someGenerics2a;
new someGenerics2a((n: string) => n);
new someGenerics2a<string>((n: string) => n);
new someGenerics2a<string>((n) => n.substr(0));
interface someGenerics2b {
new <T, U>(n: (x: T, y: U) => void);
}
var someGenerics2b: someGenerics2b;
new someGenerics2b((n: string, x: number) => n);
new someGenerics2b<string, number>((n: string, t: number) => n);
new someGenerics2b<string, number>((n, t) => n.substr(t * t));
// Generic call with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter
interface someGenerics3 {
new <T>(producer: () => T);
}
var someGenerics3: someGenerics3;
new someGenerics3(() => '');
new someGenerics3<Window>(() => undefined);
new someGenerics3<number>(() => 3);
// 2 parameter generic call with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type
interface someGenerics4 {
new <T, U>(n: T, f: (x: U) => void);
}
var someGenerics4: someGenerics4;
new someGenerics4(4, () => null);
new someGenerics4<string, number>('', () => 3);
new someGenerics4<string, number>('', (x: string) => ''); // Error
new someGenerics4<string, number>(null, null);
// 2 parameter generic call with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type
interface someGenerics5 {
new <U, T>(n: T, f: (x: U) => void);
}
var someGenerics5: someGenerics5;
new someGenerics5(4, () => null);
new someGenerics5<number, string>('', () => 3);
new someGenerics5<number, string>('', (x: string) => ''); // Error
new someGenerics5<string, number>(null, null);
// Generic call with multiple arguments of function types that each have parameters of the same generic type
interface someGenerics6 {
new <A>(a: (a: A) => A, b: (b: A) => A, c: (c: A) => A);
}
var someGenerics6: someGenerics6;
new someGenerics6(n => n, n => n, n => n);
new someGenerics6<number>(n => n, n => n, n => n);
new someGenerics6<number>((n: number) => n, (n: string) => n, (n: number) => n); // Error
new someGenerics6<number>((n: number) => n, (n: number) => n, (n: number) => n);
// Generic call with multiple arguments of function types that each have parameters of different generic type
interface someGenerics7 {
new <A, B, C>(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C);
}
var someGenerics7: someGenerics7;
new someGenerics7(n => n, n => n, n => n);
new someGenerics7<number, string, number>(n => n, n => n, n => n);
new someGenerics7<number, string, number>((n: number) => n, (n: string) => n, (n: number) => n);
// Generic call with argument of generic function type
interface someGenerics8 {
new <T>(n: T): T;
}
var someGenerics8: someGenerics8;
var x = new someGenerics8(someGenerics7);
new x<string, string, string>(null, null, null);
// Generic call with multiple parameters of generic type passed arguments with no best common type
interface someGenerics9 {
new <T>(a: T, b: T, c: T): T;
}
var someGenerics9: someGenerics9;
var a9a = new someGenerics9('', 0, []);
var a9a: {};
var a9b = new someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null);
var a9b: { a?: number; b?: string; };
// Generic call with multiple parameters of generic type passed arguments with multiple best common types
interface A91 {
x: number;
y?: string;
}
interface A92 {
x: number;
z?: Window;
}
var a9e = new someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' });
var a9e: {};
var a9f = new someGenerics9<A92>(undefined, { x: 6, z: window }, { x: 6, y: '' });
var a9f: A92;
// Generic call with multiple parameters of generic type passed arguments with a single best common type
var a9d = new someGenerics9({ x: 3 }, { x: 6 }, { x: 6 });
var a9d: { x: number; };
// Generic call with multiple parameters of generic type where one argument is of type 'any'
var anyVar: any;
var a = new someGenerics9(7, anyVar, 4);
var a: any;
// Generic call with multiple parameters of generic type where one argument is [] and the other is not 'any'
var arr = new someGenerics9([], null, undefined);
var arr: any[];
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeArgumentInferenceErrors.ts | TypeScript | // Generic call with multiple type parameters and only one used in parameter type annotation
function someGenerics1<T, U>(n: T, m: number) { }
someGenerics1<string, number>(3, 4); // Error
// 2 parameter generic call with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type
function someGenerics4<T, U>(n: T, f: (x: U) => void) { }
someGenerics4<string, number>('', (x: string) => ''); // Error
// 2 parameter generic call with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type
function someGenerics5<U, T>(n: T, f: (x: U) => void) { }
someGenerics5<number, string>('', (x: string) => ''); // Error
// Generic call with multiple arguments of function types that each have parameters of the same generic type
function someGenerics6<A>(a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { }
someGenerics6<number>((n: number) => n, (n: string) => n, (n: number) => n); // Error
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeArgumentInferenceTransitiveConstraints.ts | TypeScript |
function fn<A extends Date, B extends A, C extends B>(a: A, b: B, c: C) {
return [a, b, c];
}
var d = fn(new Date(), new Date(), new Date());
var d: Date[]; // Should be OK (d should be Date[])
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeArgumentInferenceWithClassExpression1.ts | TypeScript | function foo<T>(x = class { static prop: T }): T {
return undefined;
}
foo(class { static prop = "hello" }).length; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeArgumentInferenceWithClassExpression2.ts | TypeScript | function foo<T>(x = class { prop: T }): T {
return undefined;
}
// Should not infer string because it is a static property
foo(class { static prop = "hello" }).length; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeArgumentInferenceWithClassExpression3.ts | TypeScript | function foo<T>(x = class { prop: T }): T {
return undefined;
}
foo(class { prop = "hello" }).length; | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeArgumentInferenceWithConstraints.ts | TypeScript | // Generic call with no parameters
function noParams<T extends {}>() { }
noParams();
noParams<string>();
noParams<{}>();
// Generic call with parameters but none use type parameter type
function noGenericParams<T extends number>(n: string) { }
noGenericParams(''); // Valid
noGenericParams<number>('');
noGenericParams<{}>(''); // Error
// Generic call with multiple type parameters and only one used in parameter type annotation
function someGenerics1<T, U extends T>(n: T, m: number) { }
someGenerics1(3, 4); // Valid
someGenerics1<string, number>(3, 4); // Error
someGenerics1<number, {}>(3, 4); // Error
someGenerics1<number, number>(3, 4);
// Generic call with argument of function type whose parameter is of type parameter type
function someGenerics2a<T extends string>(n: (x: T) => void) { }
someGenerics2a((n: string) => n);
someGenerics2a<string>((n: string) => n);
someGenerics2a<string>((n) => n.substr(0));
function someGenerics2b<T extends string, U extends number>(n: (x: T, y: U) => void) { }
someGenerics2b((n: string, x: number) => n);
someGenerics2b<string, number>((n: string, t: number) => n);
someGenerics2b<string, number>((n, t) => n.substr(t * t));
// Generic call with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter
function someGenerics3<T extends Window>(producer: () => T) { }
someGenerics3(() => ''); // Error
someGenerics3<Window>(() => undefined);
someGenerics3<number>(() => 3); // Error
// 2 parameter generic call with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type
function someGenerics4<T, U extends number>(n: T, f: (x: U) => void) { }
someGenerics4(4, () => null); // Valid
someGenerics4<string, number>('', () => 3);
someGenerics4<string, number>('', (x: string) => ''); // Error
someGenerics4<string, number>(null, null);
// 2 parameter generic call with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type
function someGenerics5<U extends number, T>(n: T, f: (x: U) => void) { }
someGenerics5(4, () => null); // Valid
someGenerics5<number, string>('', () => 3);
someGenerics5<number, string>('', (x: string) => ''); // Error
someGenerics5<string, number>(null, null); // Error
// Generic call with multiple arguments of function types that each have parameters of the same generic type
function someGenerics6<A extends number>(a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { }
someGenerics6(n => n, n => n, n => n); // Valid
someGenerics6<number>(n => n, n => n, n => n);
someGenerics6<number>((n: number) => n, (n: string) => n, (n: number) => n); // Error
someGenerics6<number>((n: number) => n, (n: number) => n, (n: number) => n);
// Generic call with multiple arguments of function types that each have parameters of different generic type
function someGenerics7<A, B extends string, C>(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { }
someGenerics7(n => n, n => n, n => n); // Valid, types of n are <any, string, any> respectively
someGenerics7<number, string, number>(n => n, n => n, n => n);
someGenerics7<number, string, number>((n: number) => n, (n: string) => n, (n: number) => n);
// Generic call with argument of generic function type
function someGenerics8<T extends string>(n: T): T { return n; }
var x = someGenerics8<string>(someGenerics7); // Error
x<string, string, string>(null, null, null); // Error
// Generic call with multiple parameters of generic type passed arguments with no best common type
function someGenerics9<T extends any>(a: T, b: T, c: T): T {
return null;
}
var a9a = someGenerics9('', 0, []);
var a9a: {};
var a9b = someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null);
var a9b: { a?: number; b?: string; };
// Generic call with multiple parameters of generic type passed arguments with multiple best common types
interface A91 {
x: number;
y?: string;
}
interface A92 {
x: number;
z?: Window;
}
var a9e = someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' });
var a9e: {};
var a9f = someGenerics9<A92>(undefined, { x: 6, z: window }, { x: 6, y: '' });
var a9f: A92;
// Generic call with multiple parameters of generic type passed arguments with a single best common type
var a9d = someGenerics9({ x: 3 }, { x: 6 }, { x: 6 });
var a9d: { x: number; };
// Generic call with multiple parameters of generic type where one argument is of type 'any'
var anyVar: any;
var a = someGenerics9(7, anyVar, 4);
var a: any;
// Generic call with multiple parameters of generic type where one argument is [] and the other is not 'any'
var arr = someGenerics9([], null, undefined);
var arr: any[];
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeArgumentInferenceWithObjectLiteral.ts | TypeScript | interface Computed<T> {
read(): T;
write(value: T);
}
function foo<T>(x: Computed<T>) { }
var s: string;
// Calls below should infer string for T and then assign that type to the value parameter
foo({
read: () => s,
write: value => s = value
});
foo({
write: value => s = value,
read: () => s
});
enum E1 { X }
enum E2 { X }
// Check that we infer from both a.r and b before fixing T in a.w
declare function f1<T, U>(a: { w: (x: T) => U; r: () => T; }, b: T): U;
var v1: number;
var v1 = f1({ w: x => x, r: () => 0 }, 0);
var v1 = f1({ w: x => x, r: () => 0 }, E1.X);
var v1 = f1({ w: x => x, r: () => E1.X }, 0);
var v2: E1;
var v2 = f1({ w: x => x, r: () => E1.X }, E1.X);
var v3 = f1({ w: x => x, r: () => E1.X }, E2.X); // Error
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeArgumentsWithStringLiteralTypes01.ts | TypeScript | // @declaration: true
declare function randBool(): boolean;
declare function takeReturnString(str: string): string;
declare function takeReturnHello(str: "Hello"): "Hello";
declare function takeReturnHelloWorld(str: "Hello" | "World"): "Hello" | "World";
function fun1<T>(x: T, y: T) {
return randBool() ? x : y;
}
function fun2<T, U>(x: T, y: U) {
return randBool() ? x : y;
}
function fun3<T>(...args: T[]): T {
return args[+randBool()];
}
namespace n1 {
// The following should all come back as strings.
// They should be assignable to/from something of a type 'string'.
// They should not be assignable to either "Hello" or "World".
export let a = fun1("Hello", "World");
export let b = fun1("Hello", "Hello");
export let c = fun2("Hello", "World");
export let d = fun2("Hello", "Hello");
export let e = fun3("Hello", "Hello", "World", "Foo");
// Should be valid
a = takeReturnString(a);
b = takeReturnString(b);
c = takeReturnString(c);
d = takeReturnString(d);
e = takeReturnString(e);
// Passing these as arguments should cause an error.
a = takeReturnHello(a);
b = takeReturnHello(b);
c = takeReturnHello(c);
d = takeReturnHello(d);
e = takeReturnHello(e);
// Passing these as arguments should cause an error.
a = takeReturnHelloWorld(a);
b = takeReturnHelloWorld(b);
c = takeReturnHelloWorld(c);
d = takeReturnHelloWorld(d);
e = takeReturnHelloWorld(e);
}
namespace n2 {
// The following (regardless of errors) should come back typed
// as "Hello" (or "Hello" | "Hello").
export let a = fun1<"Hello">("Hello", "Hello");
export let b = fun1<"Hello">("Hello", "World");
export let c = fun2<"Hello", "Hello">("Hello", "Hello");
export let d = fun2<"Hello", "Hello">("Hello", "World");
export let e = fun3<"Hello">("Hello", "World");
// Assignment from the returned value should cause an error.
a = takeReturnString(a);
b = takeReturnString(b);
c = takeReturnString(c);
d = takeReturnString(d);
e = takeReturnString(e);
// Should be valid
a = takeReturnHello(a);
b = takeReturnHello(b);
c = takeReturnHello(c);
d = takeReturnHello(d);
e = takeReturnHello(e);
// Assignment from the returned value should cause an error.
a = takeReturnHelloWorld(a);
b = takeReturnHelloWorld(b);
c = takeReturnHelloWorld(c);
d = takeReturnHelloWorld(d);
e = takeReturnHelloWorld(e);
}
namespace n3 {
// The following (regardless of errors) should come back typed
// as "Hello" | "World" (or "World" | "Hello").
export let a = fun2<"Hello", "World">("Hello", "World");
export let b = fun2<"Hello", "World">("World", "Hello");
export let c = fun2<"World", "Hello">("Hello", "Hello");
export let d = fun2<"World", "Hello">("World", "World");
export let e = fun3<"Hello" | "World">("Hello", "World");
// Assignment from the returned value should cause an error.
a = takeReturnString(a);
b = takeReturnString(b);
c = takeReturnString(c);
d = takeReturnString(d);
e = takeReturnString(e);
// Passing these as arguments should cause an error.
a = takeReturnHello(a);
b = takeReturnHello(b);
c = takeReturnHello(c);
d = takeReturnHello(d);
e = takeReturnHello(e);
// Both should be valid.
a = takeReturnHelloWorld(a);
b = takeReturnHelloWorld(b);
c = takeReturnHelloWorld(c);
d = takeReturnHelloWorld(d);
e = takeReturnHelloWorld(e);
} | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeAssertionsWithIntersectionTypes01.ts | TypeScript | interface I1 {
p1: number
}
interface I2 extends I1 {
p2: number;
}
interface I3 {
p3: number;
}
var x = { p1: 10, p2: 20, p3: 30 };
var y: I1 & I3 = x;
var z: I2 = x;
var a = <I1 & I3>z;
var b = <I3>z;
var c = <I2>z;
var d = <I1>y;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeAssertionsWithUnionTypes01.ts | TypeScript | interface I1 {
p1: number
}
interface I2 extends I1 {
p2: number;
}
var x = { p1: 10, p2: 20 };
var y: number | I2 = x;
var z: I1 = x;
var a = <number | I2>z;
var b = <number>z;
var c = <I2>z;
var d = <I1>y;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromContextualThisType.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @strict: true
// @Filename: bug25926.js
/** @type {{ a(): void; b?(n: number): number; }} */
const o1 = {
a() {
this.b = n => n;
}
};
/** @type {{ d(): void; e?(n: number): number; f?(n: number): number; g?: number }} */
const o2 = {
d() {
this.e = this.f = m => this.g || m;
}
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromJSConstructor.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @strictNullChecks: true
// @noImplicitAny: true
// @Filename: a.js
function Installer () {
// arg: number
this.arg = 0
// unknown: string | boolean | null
this.unknown = null
// twice: string | undefined
this.twice = undefined
this.twice = 'hi'
// twices: any[] | null
this.twices = []
this.twices = null
}
Installer.prototype.first = function () {
this.arg = 'hi' // error
this.unknown = 'hi' // ok
this.newProperty = 1 // ok: number | boolean
this.twice = undefined // ok
this.twice = 'hi' // ok
}
Installer.prototype.second = function () {
this.arg = false // error
this.unknown = false // ok
this.newProperty = false // ok
this.twice = null // error
this.twice = false // error
this.twices.push(1) // error: Object is possibly null
if (this.twices != null) {
this.twices.push('hi')
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromJSInitializer.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @strictNullChecks: true
// @noImplicitAny: true
// @Filename: a.js
function A () {
// should get any on this-assignments in constructor
this.unknown = null
this.unknowable = undefined
this.empty = []
}
var a = new A()
a.unknown = 1
a.unknown = true
a.unknown = {}
a.unknown = 'hi'
a.unknowable = 1
a.unknowable = true
a.unknowable = {}
a.unknowable = 'hi'
a.empty.push(1)
a.empty.push(true)
a.empty.push({})
a.empty.push('hi')
/** @type {number | undefined} */
var n;
// should get any on parameter initialisers
function f(a = null, b = n, l = []) {
// a should be null in strict mode
a = undefined
a = null
a = 1
a = true
a = {}
a = 'ok'
// b should be number | undefined, not any
b = 1
b = undefined
b = 'error'
// l should be any[]
l.push(1)
l.push('ok')
}
// should get any on variable initialisers
var u = undefined;
var l = [];
u = undefined
u = 1
u = true
u = {}
u = 'ok'
l.push('ok')
/** @type {(v: unknown) => v is undefined} */
const isUndef = v => v === undefined;
const e = [1, undefined];
// should be undefined[]
const g = e.filter(isUndef);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromJSInitializer2.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @strictNullChecks: true
// @noImplicitAny: true
// @Filename: a.js
/** @type {() => undefined} */
function f1() {
return undefined;
}
const a = f1()
/** @type {() => null} */
function f2() {
return null;
}
const b = f2()
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromJSInitializer3.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @strictNullChecks: false
// @noImplicitAny: true
// @Filename: a.js
/** @type {() => undefined} */
function f1() {
return undefined;
}
const a = f1()
/** @type {() => null} */
function f2() {
return null;
}
const b = f2()
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromJSInitializer4.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @strictNullChecks: false
// @noImplicitAny: true
// @Filename: a.js
/** @type {number | undefined} */
var n;
// should get any on parameter initialisers
function f(a = null, b = n, l = []) {
// a should be any
a = undefined
a = null
a = 1
a = true
a = {}
a = 'ok'
// b should be number | undefined, not any
b = 1
b = undefined
b = 'error'
// l should be any[]
l.push(1)
l.push('ok')
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromParamTagForFunction.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @module: commonjs
// @filename: node.d.ts
declare function require(id: string): any;
declare var module: any, exports: any;
// @filename: a-ext.js
exports.A = function () {
this.x = 1;
};
// @filename: a.js
const { A } = require("./a-ext");
/** @param {A} p */
function a(p) { p.x; }
// @filename: b-ext.js
exports.B = class {
constructor() {
this.x = 1;
}
};
// @filename: b.js
const { B } = require("./b-ext");
/** @param {B} p */
function b(p) { p.x; }
// @filename: c-ext.js
export function C() {
this.x = 1;
}
// @filename: c.js
const { C } = require("./c-ext");
/** @param {C} p */
function c(p) { p.x; }
// @filename: d-ext.js
export var D = function() {
this.x = 1;
};
// @filename: d.js
const { D } = require("./d-ext");
/** @param {D} p */
function d(p) { p.x; }
// @filename: e-ext.js
export class E {
constructor() {
this.x = 1;
}
}
// @filename: e.js
const { E } = require("./e-ext");
/** @param {E} p */
function e(p) { p.x; }
// @filename: f.js
var F = function () {
this.x = 1;
};
/** @param {F} p */
function f(p) { p.x; }
// @filename: g.js
function G() {
this.x = 1;
}
/** @param {G} p */
function g(p) { p.x; }
// @filename: h.js
class H {
constructor() {
this.x = 1;
}
}
/** @param {H} p */
function h(p) { p.x; } | willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPrivatePropertyAssignment.ts | TypeScript | // @target: esnext
type Foo = { foo?: string };
class C {
#a?: Foo;
#b?: Foo;
m() {
const a = this.#a || {};
this.#b = this.#b || {};
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPrivatePropertyAssignmentJs.ts | TypeScript | // @target: esnext
// @allowJs: true
// @checkJs: true
// @outDir: ./out
// @filename: typeFromPrivatePropertyAssignmentJs.js
// @filename: a.js
class C {
/** @type {{ foo?: string } | undefined } */
#a;
/** @type {{ foo?: string } | undefined } */
#b;
m() {
const a = this.#a || {};
this.#b = this.#b || {};
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: a.js
var Outer = class O {
m(x, y) { }
}
Outer.Inner = class I {
n(a, b) { }
}
/** @type {Outer} */
var si
si.m
/** @type {Outer.Inner} */
var oi
oi.n
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment10.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @target: es6
// @Filename: module.js
var Outer = Outer || {};
Outer.app = Outer.app || {};
// @Filename: someview.js
Outer.app.SomeView = (function () {
var SomeView = function() {
var me = this;
}
return SomeView;
})();
Outer.app.Inner = class {
constructor() {
/** @type {number} */
this.y = 12;
}
}
var example = new Outer.app.Inner();
example.y;
/** @param {number} k */
Outer.app.statische = function (k) {
return k ** k;
}
// @Filename: application.js
Outer.app.Application = (function () {
/**
* Application main class.
* Will be instantiated & initialized by HTML page
*/
var Application = function () {
var me = this;
me.view = new Outer.app.SomeView();
};
return Application;
})();
// @Filename: main.js
var app = new Outer.app.Application();
var inner = new Outer.app.Inner();
inner.y;
/** @type {Outer.app.Inner} */
var x;
x.y;
Outer.app.statische(101); // Infinity, duh
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment10_1.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @target: esnext
// @Filename: module.js
var Outer = Outer ?? {};
Outer.app = Outer.app ?? {};
// @Filename: someview.js
Outer.app.SomeView = (function () {
var SomeView = function() {
var me = this;
}
return SomeView;
})();
Outer.app.Inner = class {
constructor() {
/** @type {number} */
this.y = 12;
}
}
var example = new Outer.app.Inner();
example.y;
/** @param {number} k */
Outer.app.statische = function (k) {
return k ** k;
}
// @Filename: application.js
Outer.app.Application = (function () {
/**
* Application main class.
* Will be instantiated & initialized by HTML page
*/
var Application = function () {
var me = this;
me.view = new Outer.app.SomeView();
};
return Application;
})();
// @Filename: main.js
var app = new Outer.app.Application();
var inner = new Outer.app.Inner();
inner.y;
/** @type {Outer.app.Inner} */
var x;
x.y;
Outer.app.statische(101); // Infinity, duh
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment11.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @target: es6
// @Filename: module.js
var Inner = function() {}
Inner.prototype = {
m() { },
i: 1
}
// incremental assignments still work
Inner.prototype.j = 2
/** @type {string} */
Inner.prototype.k;
var inner = new Inner()
inner.m()
inner.i
inner.j
inner.k
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment12.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @target: es6
// @Filename: module.js
var Outer = function(element, config) {};
// @Filename: usage.js
/** @constructor */
Outer.Pos = function (line, ch) {};
/** @type {number} */
Outer.Pos.prototype.line;
var pos = new Outer.Pos(1, 'x');
pos.line;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment13.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @target: es6
// @Filename: module.js
var Outer = {}
Outer.Inner = function() {}
Outer.Inner.prototype = {
m() { },
i: 1
}
// incremental assignments still work
Outer.Inner.prototype.j = 2
/** @type {string} */
Outer.Inner.prototype.k;
var inner = new Outer.Inner()
inner.m()
inner.i
inner.j
inner.k
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment14.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: def.js
var Outer = {};
// @Filename: work.js
Outer.Inner = function () {}
Outer.Inner.prototype = {
x: 1,
m() { }
}
// @Filename: use.js
/** @type {Outer.Inner} */
var inner
inner.x
inner.m()
var inno = new Outer.Inner()
inno.x
inno.m()
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment15.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: a.js
var Outer = {};
Outer.Inner = class {
constructor() {
this.x = 1
}
m() { }
}
/** @type {Outer.Inner} */
var inner
inner.x
inner.m()
var inno = new Outer.Inner()
inno.x
inno.m()
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment16.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: a.js
var Outer = {};
Outer.Inner = function () {}
Outer.Inner.prototype = {
x: 1,
m() { }
}
/** @type {Outer.Inner} */
var inner
inner.x
inner.m()
var inno = new Outer.Inner()
inno.x
inno.m()
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment17.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: types.d.ts
declare var require: any;
declare var module: any;
// @Filename: minimatch.js
/// <reference path='./types.d.ts'/>
module.exports = minimatch
minimatch.M = M
minimatch.filter = filter
function filter() {
return minimatch()
}
function minimatch() {
}
M.defaults = function (def) {
return def
}
M.prototype.m = function () {
}
function M() {
}
// @Filename: use.js
/// <reference path='./types.d.ts'/>
var mini = require('./minimatch')
mini.M.defaults()
var m = new mini.M()
m.m()
mini.filter()
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment18.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: a.js
var GLOBSTAR = m.GLOBSTAR = {}
function m() {
}
GLOBSTAR.p = 1
m.GLOBSTAR.q = 2
GLOBSTAR.p
GLOBSTAR.q
m.GLOBSTAR.p
m.GLOBSTAR.q
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment19.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: types.d.ts
declare var require: any;
declare var module: any;
// @Filename: semver.js
/// <reference path='./types.d.ts'/>
exports = module.exports = C
C.f = n => n + 1
function C() {
this.p = 1
}
// @filename: index.js
/// <reference path='./types.d.ts'/>
const C = require("./semver")
var two = C.f(1)
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment2.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: a.js
function Outer() {
this.y = 2
}
Outer.Inner = class I {
constructor() {
this.x = 1
}
}
/** @type {Outer} */
var ok
ok.y
/** @type {Outer.Inner} */
var oc
oc.x
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment20.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: bluebird.js
!function outer (f) { return f }(
function inner () {
function Async() {
this._trampolineEnabled = true;
}
Async.prototype.disableTrampolineIfNecessary = function dtin(b) {
if (b) {
this._trampolineEnabled = false;
}
};
})
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment21.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @lib: dom, es5
// @Filename: chrome-devtools-DOMExtension.js
// Extend that DOM! (doesn't work, but shouldn't crash)
Event.prototype.removeChildren = function () {
this.textContent = 'nope, not going to happen'
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment22.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @noEmit: true
// @strictNullChecks: true
// @Filename: npm-install.js
function Installer () {
this.args = 0
}
Installer.prototype.loadArgMetadata = function (next) {
// ArrowFunction isn't treated as a this-container
(args) => {
this.args = 'hi'
this.newProperty = 1
}
}
var i = new Installer()
i.newProperty = i.args // ok, number ==> number | undefined
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment23.ts | TypeScript | // @noEmit: true
// @checkJs: true
// @allowJs: true
// @Filename: a.js
class B {
constructor () {
this.n = 1
}
foo() {
}
}
class C extends B { }
// this override should be fine (even if it's a little odd)
C.prototype.foo = function() {
}
class D extends B { }
D.prototype.foo = () => {
this.n = 'not checked, so no error'
}
// post-class prototype assignments are trying to show that these properties are abstract
class Module {
}
Module.prototype.identifier = undefined
Module.prototype.size = null
class NormalModule extends Module {
identifier() {
return 'normal'
}
size() {
return 0
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment24.ts | TypeScript | // @noEmit: true
// @checkJs: true
// @allowJs: true
// @Filename: usage.js
// note that usage is first in the compilation
Outer.Inner.Message = function() {
};
var y = new Outer.Inner()
y.name
/** @type {Outer.Inner} should be instance type, not static type */
var x;
x.name
// @Filename: def.js
var Outer = {}
Outer.Inner = class {
name() {
return 'hi'
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment25.ts | TypeScript | // @noEmit: true
// @checkJs: true
// @allowJs: true
// @Filename: bug24703.js
var Common = {};
Common.I = class {
constructor() {
this.i = 1
}
}
Common.O = class extends Common.I {
constructor() {
super()
this.o = 2
}
}
var o = new Common.O()
var i = new Common.I()
o.i
o.o
i.i
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment26.ts | TypeScript | // @noEmit: true
// @noImplicitAny: true
// @checkJs: true
// @allowJs: true
// @Filename: bug24730.js
var UI = {}
UI.TreeElement = class {
constructor() {
this.treeOutline = 12
}
};
UI.context = new UI.TreeElement()
class C extends UI.TreeElement {
onpopulate() {
this.doesNotExist
this.treeOutline.doesntExistEither()
}
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment27.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: a.js
// mixed prototype-assignment+function declaration
function C() { this.p = 1; }
C.prototype = { q: 2 };
const c = new C()
c.p
c.q
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment28.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: a.js
// mixed prototype-assignment+class declaration
class C { constructor() { this.p = 1; } }
// Property assignment does nothing.
// You have to use Object.defineProperty(C, "prototype", { q: 2 })
// and that only works on classes with no superclass.
// (Object.defineProperty isn't recognised as a JS special assignment right now.)
C.prototype = { q: 2 };
const c = new C()
c.p
c.q
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment29.ts | TypeScript | // @declaration: true
function ExpandoDecl(n: number) {
return n.toString();
}
ExpandoDecl.prop = 2
ExpandoDecl.m = function(n: number) {
return n + 1;
}
var n = ExpandoDecl.prop + ExpandoDecl.m(12) + ExpandoDecl(101).length
const ExpandoExpr = function (n: number) {
return n.toString();
}
ExpandoExpr.prop = { x: 2 }
ExpandoExpr.prop = { y: "" }
ExpandoExpr.m = function(n: number) {
return n + 1;
}
var n = (ExpandoExpr.prop.x || 0) + ExpandoExpr.m(12) + ExpandoExpr(101).length
const ExpandoArrow = (n: number) => n.toString();
ExpandoArrow.prop = 2
ExpandoArrow.m = function(n: number) {
return n + 1;
}
function ExpandoNested(n: number) {
const nested = function (m: number) {
return n + m;
};
nested.total = n + 1_000_000;
return nested;
}
ExpandoNested.also = -1;
function ExpandoMerge(n: number) {
return n * 100;
}
ExpandoMerge.p1 = 111
namespace ExpandoMerge {
export var p2 = 222;
}
namespace ExpandoMerge {
export var p3 = 333;
}
var n = ExpandoMerge.p1 + ExpandoMerge.p2 + ExpandoMerge.p3 + ExpandoMerge(1);
namespace Ns {
function ExpandoNamespace(): void {}
ExpandoNamespace.p6 = 42;
export function foo() {
return ExpandoNamespace;
}
}
// Should not work in Typescript -- must be const
var ExpandoExpr2 = function (n: number) {
return n.toString();
}
ExpandoExpr2.prop = 2
ExpandoExpr2.m = function(n: number) {
return n + 1;
}
var n = ExpandoExpr2.prop + ExpandoExpr2.m(12) + ExpandoExpr2(101).length
// Should not work in typescript -- classes already have statics
class ExpandoClass {
n = 1001;
}
ExpandoClass.prop = 2
ExpandoClass.m = function(n: number) {
return n + 1;
}
var n = ExpandoClass.prop + ExpandoClass.m(12) + new ExpandoClass().n
// Class expressions shouldn't work in typescript either
var ExpandoExpr3 = class {
n = 10001;
}
ExpandoExpr3.prop = 3
ExpandoExpr3.m = function(n: number) {
return n + 1;
}
var n = ExpandoExpr3.prop + ExpandoExpr3.m(13) + new ExpandoExpr3().n
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment3.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: a.js
var Outer = function O() {
this.y = 2
}
Outer.Inner = class I {
constructor() {
this.x = 1
}
}
/** @type {Outer} */
var ja
ja.y
/** @type {Outer.Inner} */
var da
da.x
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment30.ts | TypeScript | interface Combo {
(): number;
p?: { [s: string]: number };
}
const c: Combo = () => 1
// should not be an expando object, but contextually typed by Combo.p
c.p = {}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment31.ts | TypeScript | function ExpandoMerge(n: number) {
return n;
}
ExpandoMerge.p1 = 111
ExpandoMerge.m = function(n: number) {
return n + 1;
}
namespace ExpandoMerge {
export var p2 = 222;
}
ExpandoMerge.p4 = 44444; // ok
ExpandoMerge.p6 = 66666; // ok
ExpandoMerge.p8 = false; // type error
namespace ExpandoMerge {
export var p3 = 333;
export var p4 = 4;
export var p5 = 5;
export let p6 = 6;
export let p7 = 7;
export var p8 = 6;
export let p9 = 7;
}
ExpandoMerge.p5 = 555555; // ok
ExpandoMerge.p7 = 777777; // ok
ExpandoMerge.p9 = false; // type error
var n = ExpandoMerge.p1 + ExpandoMerge.p2 + ExpandoMerge.p3 + ExpandoMerge.p4 + ExpandoMerge.p5 + ExpandoMerge.p6 + ExpandoMerge.p7 + ExpandoMerge.p8 + ExpandoMerge.p9 + ExpandoMerge.m(12) + ExpandoMerge(1001);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment32.ts | TypeScript | // @Filename: expando.ts
function ExpandoMerge(n: number) {
return n;
}
ExpandoMerge.p1 = 111
ExpandoMerge.m = function(n: number) {
return n + 1;
}
ExpandoMerge.p4 = 44444;
ExpandoMerge.p5 = 555555;
ExpandoMerge.p6 = 66666;
ExpandoMerge.p7 = 777777;
ExpandoMerge.p8 = false; // type error
ExpandoMerge.p9 = false; // type error
var n = ExpandoMerge.p1 + ExpandoMerge.p2 + ExpandoMerge.p3 + ExpandoMerge.p4 + ExpandoMerge.p5 + ExpandoMerge.p6 + ExpandoMerge.p7 + ExpandoMerge.p8 + ExpandoMerge.p9 + ExpandoMerge.m(12) + ExpandoMerge(1001);
// @Filename: ns.ts
namespace ExpandoMerge {
export var p3 = 333;
export var p4 = 4;
export var p5 = 5;
export let p6 = 6;
export let p7 = 7;
export var p8 = 6;
export let p9 = 7;
}
namespace ExpandoMerge {
export var p2 = 222;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment33.ts | TypeScript | // @Filename: ns.ts
namespace ExpandoMerge {
export var p3 = 333;
export var p4 = 4;
export var p5 = 5;
export let p6 = 6;
export let p7 = 7;
export var p8 = 6;
export let p9 = 7;
}
namespace ExpandoMerge {
export var p2 = 222;
}
// @Filename: expando.ts
function ExpandoMerge(n: number) {
return n;
}
ExpandoMerge.p1 = 111
ExpandoMerge.m = function(n: number) {
return n + 1;
}
ExpandoMerge.p4 = 44444;
ExpandoMerge.p5 = 555555;
ExpandoMerge.p6 = 66666;
ExpandoMerge.p7 = 777777;
ExpandoMerge.p8 = false; // type error
ExpandoMerge.p9 = false; // type error
var n = ExpandoMerge.p1 + ExpandoMerge.p2 + ExpandoMerge.p3 + ExpandoMerge.p4 + ExpandoMerge.p5 + ExpandoMerge.p6 + ExpandoMerge.p7 + ExpandoMerge.p8 + ExpandoMerge.p9 + ExpandoMerge.m(12) + ExpandoMerge(1001);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment34.ts | TypeScript | // @noEmit: true
// @allowjs: true
// @checkjs: true
// @Filename: file1.js
var N = {};
N.commands = {};
// @Filename: file2.js
N.commands.a = 111;
N.commands.b = function () { };
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment35.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: bug26877.js
/** @param {Emu.D} x */
function ollKorrect(x) {
x._model
const y = new Emu.D()
const z = Emu.D._wrapperInstance;
}
Emu.D = class {
constructor() {
this._model = 1
}
}
// @Filename: second.js
var Emu = {}
/** @type {string} */
Emu.D._wrapperInstance;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment36.ts | TypeScript | // @strict: true
function f(b: boolean) {
function d() {
}
d.e = 12
d.e
if (b) {
d.q = false
}
// error d.q might not be assigned
d.q
if (b) {
d.q = false
}
else {
d.q = true
}
d.q
if (b) {
d.r = 1
}
else {
d.r = 2
}
d.r
if (b) {
d.s = 'hi'
}
return d
}
// OK to access possibly-unassigned properties outside the initialising scope
var test = f(true).s
function d() {
}
d.e = 12
d.e
if (!!false) {
d.q = false
}
d.q
if (!!false) {
d.q = false
}
else {
d.q = true
}
d.q
if (!!false) {
d.r = 1
}
else {
d.r = 2
}
d.r
// test function expressions too
const g = function() {
}
if (!!false) {
g.expando = 1
}
g.expando // error
if (!!false) {
g.both = 'hi'
}
else {
g.both = 0
}
g.both
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment37.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: mod.js
const util = exports = module.exports = {}
if (!!false) {
util.existy = function () { }
}
// @Filename: use.js
const util = require('./mod')
function n() {
util.existy // no error
}
util.existy // no error
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment38.ts | TypeScript | // @noEmit: true
// @strict: true
// @declaration: true
function F() {}
F["prop"] = 3;
const f = function () {};
f["prop"] = 3;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment39.ts | TypeScript | // @allowJs: true
// @checkJs: true
// @strict: true
// @emitDeclarationOnly: true
// @declaration: true
// @Filename: a.js
const foo = {};
foo["baz"] = {};
foo["baz"]["blah"] = 3;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment4.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: def.js
var Outer = {};
// @Filename: a.js
Outer.Inner = class {
constructor() {
/** @type {number} */
this.y = 12
}
}
/** @type {Outer.Inner} */
var local
local.y
var inner = new Outer.Inner()
inner.y
// @Filename: b.js
/** @type {Outer.Inner} */
var x
x.y
var z = new Outer.Inner()
z.y
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment40.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: typeFromPropertyAssignment40.js
function Outer() {
var self = this
self.y = 2
}
/** @type {Outer} */
var ok
ok.y
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment5.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: a.js
// @target: es6
export default function MyClass() {
}
MyClass.bar = class C {
}
MyClass.bar
// @Filename: b.js
import MC from './a'
MC.bar
/** @type {MC.bar} */
var x
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment6.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @target: es6
// @Filename: def.js
class Outer {}
// @Filename: a.js
Outer.Inner = class I {
messages() { return [] }
}
/** @type {!Outer.Inner} */
Outer.i
// @Filename: b.js
var msgs = Outer.i.messages()
/** @param {Outer.Inner} inner */
function x(inner) {
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment7.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @target: es6
// @Filename: a.js
var obj = {};
obj.method = function (hunch) {
return true;
}
var b = obj.method();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment8.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @target: es6
// @lib: es6,dom
// @Filename: a.js
var my = my || {};
my.app = my.app || {};
my.app.Application = (function () {
var Application = function () {
//...
};
return Application;
})();
my.app.Application()
// @Filename: b.js
var min = window.min || {};
min.app = min.app || {};
min.app.Application = (function () {
var Application = function () {
//...
};
return Application;
})();
min.app.Application()
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment8_1.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @target: esnext
// @lib: es6,dom
// @Filename: a.js
var my = my ?? {};
my.app = my.app ?? {};
my.app.Application = (function () {
var Application = function () {
//...
};
return Application;
})();
my.app.Application()
// @Filename: b.js
var min = window.min ?? {};
min.app = min.app ?? {};
min.app.Application = (function () {
var Application = function () {
//...
};
return Application;
})();
min.app.Application()
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment9.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @target: es6
// @Filename: a.js
var my = my || {};
/** @param {number} n */
my.method = function(n) {
return n + 1;
}
my.number = 1;
my.object = {};
my.predicate = my.predicate || {};
my.predicate.query = function () {
var me = this;
me.property = false;
};
var q = new my.predicate.query();
my.predicate.query.another = function () {
return 1;
}
my.predicate.query.result = 'none'
/** @param {number} first
* @param {number} second
*/
my.predicate.sort = my.predicate.sort || function (first, second) {
return first > second ? first : second;
}
my.predicate.type = class {
m() { return 101; }
}
// global-ish prefixes
var min = window.min || {};
min.nest = this.min.nest || function () { };
min.nest.other = self.min.nest.other || class { };
min.property = global.min.property || {};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignment9_1.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @target: esnext
// @Filename: a.js
var my = my ?? {};
/** @param {number} n */
my.method = function(n) {
return n + 1;
}
my.number = 1;
my.object = {};
my.predicate = my.predicate ?? {};
my.predicate.query = function () {
var me = this;
me.property = false;
};
var q = new my.predicate.query();
my.predicate.query.another = function () {
return 1;
}
my.predicate.query.result = 'none'
/** @param {number} first
* @param {number} second
*/
my.predicate.sort = my.predicate.sort ?? function (first, second) {
return first > second ? first : second;
}
my.predicate.type = class {
m() { return 101; }
}
// global-ish prefixes
var min = window.min ?? {};
min.nest = this.min.nest ?? function () { };
min.nest.other = self.min.nest.other ?? class { };
min.property = global.min.property ?? {};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_parser/tests/tsc/typeFromPropertyAssignmentOutOfOrder.ts | TypeScript | // @noEmit: true
// @allowJs: true
// @checkJs: true
// @target: es5
// @filename: index.js
First.Item = class I {}
Common.Object = class extends First.Item {}
Workspace.Object = class extends Common.Object {}
/** @type {Workspace.Object} */
var am;
// @filename: roots.js
var First = {};
var Common = {};
var Workspace = {};
| 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.