babel-generator: Add TypeScript support (#5896)

* babel-generator: Add TypeScript support

* Remove type declarations; not published from babylon

* Remove TODOs

* Consistently use `this.word` for tokens that are words
This commit is contained in:
Andy
2017-07-28 13:07:05 -07:00
committed by Henry Zhu
parent f83c83d49c
commit c1d07fd6db
284 changed files with 1450 additions and 51 deletions

View File

@@ -0,0 +1 @@
(x: number): number => x;

View File

@@ -0,0 +1 @@
(x: number): number => x;

View File

@@ -0,0 +1,2 @@
async < 1;
async<T>() == 0;

View File

@@ -0,0 +1,2 @@
async < 1;
async<T>() == 0;

View File

@@ -0,0 +1 @@
async <T>(a: T): T => a;

View File

@@ -0,0 +1 @@
async <T>(a: T): T => a;

View File

@@ -0,0 +1 @@
async (x?: number): any => x;

View File

@@ -0,0 +1 @@
async (x?: number): any => x;

View File

@@ -0,0 +1 @@
(x: number = 0) => 0;

View File

@@ -0,0 +1 @@
(x: number = 0) => 0;

View File

@@ -0,0 +1 @@
({ a = 0 }) => 0;

View File

@@ -0,0 +1,3 @@
({
a = 0
}) => 0;

View File

@@ -0,0 +1,2 @@
// Same as `generic`. Verify that JSX doesn't change things.
<T>(a: T): T => a;

View File

@@ -0,0 +1,2 @@
// Same as `generic`. Verify that JSX doesn't change things.
<T>(a: T): T => a;

View File

@@ -0,0 +1,3 @@
{
"plugins": ["jsx", "typescript"]
}

View File

@@ -0,0 +1 @@
<T>(a: T): T => a;

View File

@@ -0,0 +1 @@
<T>(a: T): T => a;

View File

@@ -0,0 +1 @@
(x?: number): any => x;

View File

@@ -0,0 +1 @@
(x?: number): any => x;

View File

@@ -0,0 +1 @@
(x: any): x is string => true;

View File

@@ -0,0 +1 @@
(x: any): x is string => true;

View File

@@ -0,0 +1,4 @@
x as T;
x < y as boolean; // (x < y) as boolean;
x === 1 as number; // x === (1 as number);
x as any as T;

View File

@@ -0,0 +1,6 @@
(x as T);
(x < y as boolean); // (x < y) as boolean;
x === (1 as number); // x === (1 as number);
((x as any) as T);

View File

@@ -0,0 +1 @@
f(x < 0, /a/);

View File

@@ -0,0 +1 @@
f(x < 0, /a/);

View File

@@ -0,0 +1,3 @@
(<T> x).y;
(x as T).y;
x!.y;

View File

@@ -0,0 +1,3 @@
(<T> x).y;
(x as T).y;
x!.y;

View File

@@ -0,0 +1 @@
x!;

View File

@@ -0,0 +1 @@
x!;

View File

@@ -0,0 +1 @@
1 + <number> 1;

View File

@@ -0,0 +1 @@
1 + (<number> 1);

View File

@@ -0,0 +1 @@
<number> 1 + 1;

View File

@@ -0,0 +1 @@
(<number> 1) + 1;

View File

@@ -0,0 +1 @@
<number> 1;

View File

@@ -0,0 +1 @@
(<number> 1);

View File

@@ -0,0 +1,6 @@
abstract class C {}
declare abstract class C {}
export abstract class C {}
// `export abstract class { }` is not valid.
// `export default abstract class C { }` is not valid.
// `abstract class` is not valid as an expression.

View File

@@ -0,0 +1,7 @@
abstract class C {}
declare abstract class C {}
export abstract class C {} // `export abstract class { }` is not valid.
// `export default abstract class C { }` is not valid.
// `abstract class` is not valid as an expression.

View File

@@ -0,0 +1,5 @@
class C {
constructor(x: number, y: number);
constructor(x: string, y: string);
constructor(x: any, y: any) {}
}

View File

@@ -0,0 +1,7 @@
class C {
constructor(x: number, y: number);
constructor(x: string, y: string);
constructor(x: any, y: any) {}
}

View File

@@ -0,0 +1,7 @@
declare class C {
[x: string]: any;
x;
x: number;
f();
f(): void;
}

View File

@@ -0,0 +1,7 @@
declare class C {
[x: string]: any;
x;
x: number;
f();
f(): void;
}

View File

@@ -0,0 +1,2 @@
(class extends f()<T> implements X.Y<T> {});
(class C extends f()<T> implements X.Y<T> {});

View File

@@ -0,0 +1,3 @@
(class extends f()<T> implements X.Y<T> {});
(class C extends f()<T> implements X.Y<T> {});

View File

@@ -0,0 +1,2 @@
(class extends f()<T> {});
(class C extends f()<T> {});

View File

@@ -0,0 +1,3 @@
(class extends f()<T> {});
(class C extends f()<T> {});

View File

@@ -0,0 +1,2 @@
(class<T> {});
(class C<T> {});

View File

@@ -0,0 +1,3 @@
(class<T> {});
(class C<T> {});

View File

@@ -0,0 +1,2 @@
(class implements X.Y<T> {});
(class C implements X.Y<T> {});

View File

@@ -0,0 +1,3 @@
(class implements X.Y<T> {});
(class C implements X.Y<T> {});

View File

@@ -0,0 +1 @@
class C extends f()<T> implements X.Y<T> {}

View File

@@ -0,0 +1 @@
class C extends f()<T> implements X.Y<T> {}

View File

@@ -0,0 +1 @@
class C extends f()<T> {}

View File

@@ -0,0 +1 @@
class C extends f()<T> {}

View File

@@ -0,0 +1 @@
class C<T extends object = { x: number }> {}

View File

@@ -0,0 +1,3 @@
class C<T extends object = {
x: number;
}> {}

View File

@@ -0,0 +1,3 @@
declare class C {
get<T>(): void;
}

View File

@@ -0,0 +1,3 @@
declare class C {
get<T>(): void;
}

View File

@@ -0,0 +1 @@
class C implements X.Y<T> {}

View File

@@ -0,0 +1 @@
class C implements X.Y<T> {}

View File

@@ -0,0 +1,4 @@
class C {
[x: string]: any;
readonly [x: string]: any;
}

View File

@@ -0,0 +1,4 @@
class C {
[x: string]: any;
readonly [x: string]: any;
}

View File

@@ -0,0 +1,6 @@
class C {
public(): void;
public static(): void;
readonly = 0;
async<T>(): void;
}

View File

@@ -0,0 +1,6 @@
class C {
public(): void;
public static(): void;
readonly = 0;
async<T>(): void;
}

View File

@@ -0,0 +1,3 @@
class C {
public delete(): void;
}

View File

@@ -0,0 +1,3 @@
class C {
public delete(): void;
}

View File

@@ -0,0 +1,4 @@
class C {
[Symbol.iterator](): void;
[Symbol.iterator]?(): void;
}

View File

@@ -0,0 +1,4 @@
class C {
[Symbol.iterator](): void;
[Symbol.iterator]?(): void;
}

View File

@@ -0,0 +1,4 @@
class C {
f<T>(a: T, b?: T, ...c: T[]): T {}
[Symbol.iterator]<T>(): T {}
}

View File

@@ -0,0 +1,6 @@
class C {
f<T>(a: T, b?: T, ...c: T[]): T {}
[Symbol.iterator]<T>(): T {}
}

View File

@@ -0,0 +1,4 @@
class C {
f();
f(): void;
}

View File

@@ -0,0 +1,4 @@
class C {
f();
f(): void;
}

View File

@@ -0,0 +1,3 @@
class C {
m?(): void {}
}

View File

@@ -0,0 +1,4 @@
class C {
m?(): void {}
}

View File

@@ -0,0 +1,3 @@
class C {
f(): void {}
}

View File

@@ -0,0 +1,4 @@
class C {
f(): void {}
}

View File

@@ -0,0 +1,6 @@
class C
{
m()
{
}
}

View File

@@ -0,0 +1,4 @@
class C {
m() {}
}

View File

@@ -0,0 +1,5 @@
class C
{
m()
n()
}

View File

@@ -0,0 +1,4 @@
class C {
m();
n();
}

View File

@@ -0,0 +1,11 @@
// Copy of modifiers-methods with 'get'
abstract class C {
abstract get a();
static get s() { return 0; }
public abstract get pua();
public static get pus() { return 0; }
public get pu() { return 0; }
protected get po() { return 0; }
private get pi() { return 0; }
}

View File

@@ -0,0 +1,27 @@
// Copy of modifiers-methods with 'get'
abstract class C {
abstract get a();
static get s() {
return 0;
}
public abstract get pua();
public static get pus() {
return 0;
}
public get pu() {
return 0;
}
protected get po() {
return 0;
}
private get pi() {
return 0;
}
}

View File

@@ -0,0 +1,11 @@
// Copy of modifiers-methods with 'async'
abstract class C {
abstract async a();
static async s() {}
public abstract async pua();
public static async pus() {}
public async pu() {}
protected async po() {}
private async pi() {}
}

View File

@@ -0,0 +1,17 @@
// Copy of modifiers-methods with 'async'
abstract class C {
abstract async a();
static async s() {}
public abstract async pua();
public static async pus() {}
public async pu() {}
protected async po() {}
private async pi() {}
}

View File

@@ -0,0 +1,21 @@
abstract class C {
readonly r;
readonly r2?: number;
abstract a;
static s;
public pu;
protected po;
private pi;
readonly abstract ra;
abstract readonly ar;
static readonly sr;
public readonly pur;
public abstract pua;
public static pus;
public readonly abstract pura;
public abstract readonly puar;
public static readonly pusr;
}

View File

@@ -0,0 +1,18 @@
abstract class C {
readonly r;
readonly r2?: number;
abstract a;
static s;
public pu;
protected po;
private pi;
abstract readonly ra;
abstract readonly ar;
static readonly sr;
public readonly pur;
public abstract pua;
public static pus;
public abstract readonly pura;
public abstract readonly puar;
public static readonly pusr;
}

View File

@@ -0,0 +1,3 @@
class C {
constructor(@foo readonly x: number) {}
}

View File

@@ -0,0 +1,5 @@
class C {
constructor(@foo
readonly x: number) {}
}

View File

@@ -0,0 +1,3 @@
{
"plugins": ["typescript", "decorators"]
}

View File

@@ -0,0 +1,11 @@
class C {
constructor(
readonly r,
public pu: number,
protected po?,
private pi?: number,
public readonly pur,
// Also works on AssignmentPattern
readonly x = 0,
public y?: number = 0) {}
}

View File

@@ -0,0 +1,5 @@
class C {
constructor(readonly r, public pu: number, protected po?, private pi?: number, public readonly pur, // Also works on AssignmentPattern
readonly x = 0, public y?: number = 0) {}
}

View File

@@ -0,0 +1,6 @@
class C {
x;
x?;
x: number;
x: number = 1;
}

View File

@@ -0,0 +1,6 @@
class C {
x;
x?;
x: number;
x: number = 1;
}

View File

@@ -0,0 +1,4 @@
class C {
[Symbol.iterator]: number;
[Symbol.iterator]?: number;
}

View File

@@ -0,0 +1,4 @@
class C {
[Symbol.iterator]: number;
[Symbol.iterator]?: number;
}

View File

@@ -0,0 +1,6 @@
class C {
static f();
public static f();
protected static f();
private static f();
}

View File

@@ -0,0 +1,6 @@
class C {
static f();
public static f();
protected static f();
private static f();
}

View File

@@ -0,0 +1 @@
const x: number;

View File

@@ -0,0 +1 @@
const x: number;

Some files were not shown because too many files have changed in this diff Show More