add support for outputting flow types - fixes #665
This commit is contained in:
@@ -24,7 +24,7 @@ exports.esvalid = function (ast, code, loc) {
|
||||
if (errors.length) {
|
||||
var msg = [];
|
||||
_.each(errors, function (err) {
|
||||
msg.push(err.message + " - " + JSON.stringify(err.node));
|
||||
msg.push(err.message + " - " + util.inspect(err.node));
|
||||
});
|
||||
throw new Error(loc + ": " + msg.join(". ") + "\n" + code);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ var run = function (task, done) {
|
||||
if (!execCode || actualCode) {
|
||||
result = transform(actualCode, getOpts(actual));
|
||||
checkAst(result, actual);
|
||||
actualCode = result.code;
|
||||
actualCode = result.code.trim();
|
||||
|
||||
try {
|
||||
chai.expect(actualCode).to.be.equal(expectCode, actual.loc + " !== " + expect.loc);
|
||||
|
||||
6
test/fixtures/generation/flow/array-types/actual.js
vendored
Normal file
6
test/fixtures/generation/flow/array-types/actual.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
var a: number[];
|
||||
var a: ?number[];
|
||||
var a: (?number)[];
|
||||
var a: () => number[];
|
||||
var a: (() => number)[];
|
||||
var a: typeof A[];
|
||||
6
test/fixtures/generation/flow/array-types/expected.js
vendored
Normal file
6
test/fixtures/generation/flow/array-types/expected.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
var a: number[];
|
||||
var a: ?number[];
|
||||
var a: (?number)[];
|
||||
var a: () => number[];
|
||||
var a: (() => number)[];
|
||||
var a: typeof A[];
|
||||
5
test/fixtures/generation/flow/call-properties/actual.js
vendored
Normal file
5
test/fixtures/generation/flow/call-properties/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var a: { (): number };
|
||||
var a: { (): number; };
|
||||
var a: { (): number; y: string; (x: string): string };
|
||||
var a: { <T>(x: T): number; };
|
||||
interface A { (): number; };
|
||||
5
test/fixtures/generation/flow/call-properties/expected.js
vendored
Normal file
5
test/fixtures/generation/flow/call-properties/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var a: { (): number };
|
||||
var a: { (): number };
|
||||
var a: { y: string; (): number; (x: string): string };
|
||||
var a: { <T>(x: T): number };
|
||||
interface A { (): number };
|
||||
5
test/fixtures/generation/flow/declare-module/actual.js
vendored
Normal file
5
test/fixtures/generation/flow/declare-module/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
declare module A {}
|
||||
declare module "./a/b.js" {}
|
||||
declare module A { declare var x: number; }
|
||||
declare module A { declare function foo(): number; }
|
||||
declare module A { declare class B { foo(): number; } }
|
||||
11
test/fixtures/generation/flow/declare-module/expected.js
vendored
Normal file
11
test/fixtures/generation/flow/declare-module/expected.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
declare module A {}
|
||||
declare module "./a/b.js" {}
|
||||
declare module A {
|
||||
declare var x: number;
|
||||
}
|
||||
declare module A {
|
||||
declare function foo(): number;
|
||||
}
|
||||
declare module A {
|
||||
declare class B { foo(): number }
|
||||
}
|
||||
11
test/fixtures/generation/flow/declare-statements/actual.js
vendored
Normal file
11
test/fixtures/generation/flow/declare-statements/actual.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
declare var foo
|
||||
declare var foo;
|
||||
declare function foo(): void
|
||||
declare function foo(): void;
|
||||
declare function foo<T>(): void;
|
||||
declare function foo(x: number, y: string): void;
|
||||
declare class A {}
|
||||
declare class A<T> extends B<T> { x: number }
|
||||
declare class A { static foo(): number; static x : string }
|
||||
declare class A { static [ indexer: number]: string }
|
||||
declare class A { static () : number }
|
||||
11
test/fixtures/generation/flow/declare-statements/expected.js
vendored
Normal file
11
test/fixtures/generation/flow/declare-statements/expected.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
declare var foo;
|
||||
declare var foo;
|
||||
declare function foo(): void;
|
||||
declare function foo(): void;
|
||||
declare function foo<T>(): void;
|
||||
declare function foo(x: number, y: string): void;
|
||||
declare class A {}
|
||||
declare class A<T> extends B<T> { x: number }
|
||||
declare class A { static foo(): number; static x: string }
|
||||
declare class A { static [indexer: number]: string }
|
||||
declare class A { static (): number }
|
||||
9
test/fixtures/generation/flow/interfaces-module-and-script/actual.js
vendored
Normal file
9
test/fixtures/generation/flow/interfaces-module-and-script/actual.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
interface A {};
|
||||
interface A extends B {};
|
||||
interface A<T> extends B<T>, C<T> {};
|
||||
interface A { foo: () => number; };
|
||||
interface Dictionary { [index: string]: string; length: number; };
|
||||
class Foo implements Bar {}
|
||||
class Foo extends Bar implements Bat, Man<number> {}
|
||||
class Foo extends class Bar implements Bat {} {}
|
||||
class Foo extends class Bar implements Bat {} implements Man {}
|
||||
9
test/fixtures/generation/flow/interfaces-module-and-script/expected.js
vendored
Normal file
9
test/fixtures/generation/flow/interfaces-module-and-script/expected.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
interface A {};
|
||||
interface A extends B {};
|
||||
interface A<T> extends B<T>, C<T> {};
|
||||
interface A { foo(): number };
|
||||
interface Dictionary { length: number; [index: string]: string };
|
||||
class Foo implements Bar {}
|
||||
class Foo extends Bar implements Bat, Man<number> {}
|
||||
class Foo extends class Bar implements Bat {} {}
|
||||
class Foo extends class Bar implements Bat {} implements Man {}
|
||||
4
test/fixtures/generation/flow/qualified-generic-type/actual.js
vendored
Normal file
4
test/fixtures/generation/flow/qualified-generic-type/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var a: A.B;
|
||||
var a: A.B.C;
|
||||
var a: A.B<T>;
|
||||
var a: typeof A.B<T>;
|
||||
4
test/fixtures/generation/flow/qualified-generic-type/expected.js
vendored
Normal file
4
test/fixtures/generation/flow/qualified-generic-type/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var a: A.B;
|
||||
var a: A.B.C;
|
||||
var a: A.B<T>;
|
||||
var a: typeof A.B<T>;
|
||||
2
test/fixtures/generation/flow/string-literal-types/actual.js
vendored
Normal file
2
test/fixtures/generation/flow/string-literal-types/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
function createElement(tagName: "div"): HTMLDivElement {}
|
||||
function createElement(tagName: 'div'): HTMLDivElement {}
|
||||
2
test/fixtures/generation/flow/string-literal-types/expected.js
vendored
Normal file
2
test/fixtures/generation/flow/string-literal-types/expected.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
function createElement(tagName: "div"): HTMLDivElement {}
|
||||
function createElement(tagName: "div"): HTMLDivElement {}
|
||||
4
test/fixtures/generation/flow/tuples/actual.js
vendored
Normal file
4
test/fixtures/generation/flow/tuples/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var a: [] = [];
|
||||
var a: [Foo<T>] = [foo];
|
||||
var a: [number,] = [123,];
|
||||
var a: [number, string] = [123, "duck"];
|
||||
4
test/fixtures/generation/flow/tuples/expected.js
vendored
Normal file
4
test/fixtures/generation/flow/tuples/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var a: [] = [];
|
||||
var a: [Foo<T>] = [foo];
|
||||
var a: [number] = [123];
|
||||
var a: [number, string] = [123, "duck"];
|
||||
3
test/fixtures/generation/flow/type-alias/actual.js
vendored
Normal file
3
test/fixtures/generation/flow/type-alias/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
type FBID = number;
|
||||
type Foo<T> = Bar<T>
|
||||
export type Foo = number;
|
||||
3
test/fixtures/generation/flow/type-alias/expected.js
vendored
Normal file
3
test/fixtures/generation/flow/type-alias/expected.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
type FBID = number;
|
||||
type Foo<T> = Bar<T>;
|
||||
export type Foo = number;
|
||||
97
test/fixtures/generation/flow/type-annotations/actual.js
vendored
Normal file
97
test/fixtures/generation/flow/type-annotations/actual.js
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
function foo(numVal: any) {}
|
||||
function foo(numVal: number) {}
|
||||
function foo(numVal: number, strVal: string) {}
|
||||
function foo(numVal: number, untypedVal) {}
|
||||
function foo(untypedVal, numVal: number) {}
|
||||
function foo(nullableNum: ?number) {}
|
||||
function foo(callback: () => void) {}
|
||||
function foo(callback: () => number) {}
|
||||
function foo(callback: (_: bool) => number) {}
|
||||
function foo(callback: (_1: bool, _2: string) => number) {}
|
||||
function foo(callback: (_1: bool, ...foo: Array<number>) => number) {}
|
||||
function foo(): number{}
|
||||
function foo():() => void {}
|
||||
function foo():(_:bool) => number{}
|
||||
function foo():(_?:bool) => number{}
|
||||
function foo(): {} {}
|
||||
function foo<T>() {}
|
||||
function foo<T,S>() {}
|
||||
a = function<T,S>() {};
|
||||
a = { set fooProp(value: number) {} };
|
||||
a = { set fooProp(value: number): void {} };
|
||||
a = { get fooProp():number{} };
|
||||
a = { id<T>(x: T): T {} };
|
||||
a = { *id<T>(x: T): T {} };
|
||||
a = { async id<T>(x: T): T {} };
|
||||
a = { 123<T>(x: T): T {} };
|
||||
class Foo {
|
||||
set fooProp(value: number) {}
|
||||
}
|
||||
class Foo {
|
||||
set fooProp(value: number): void {}
|
||||
}
|
||||
class Foo {
|
||||
get fooProp(): number {}
|
||||
}
|
||||
var numVal: number;
|
||||
var numVal: number = otherNumVal;
|
||||
var a: { numVal: number };
|
||||
var a: { numVal: number; };
|
||||
var a: { numVal: number; [indexer: string]: number };
|
||||
var a: ?{ numVal: number };
|
||||
var a: { numVal: number; strVal: string }
|
||||
var a: { subObj: {strVal: string} }
|
||||
var a: { subObj: ?{strVal: string} }
|
||||
var a: { param1: number; param2: string }
|
||||
var a: { param1: number; param2?: string }
|
||||
var a: { [a: number]: string; [b: number]: string; };
|
||||
var a: { add(x: number, ...y: Array<string>): void };
|
||||
var a: { id<T>(x: T): T; };
|
||||
var a:Array<number> = [1, 2, 3]
|
||||
a = class Foo<T> {}
|
||||
a = class Foo<T> extends Bar<T> {}
|
||||
class Foo<T> {}
|
||||
class Foo<T> extends Bar<T> {}
|
||||
class Foo<T> extends mixin(Bar) {}
|
||||
class Foo<T> {
|
||||
bar<U>():number { return 42; }
|
||||
}
|
||||
class Foo {
|
||||
"bar"<T>() {}
|
||||
}
|
||||
function foo(requiredParam, optParam?) {}
|
||||
class Foo {
|
||||
prop1: string;
|
||||
prop2: number;
|
||||
}
|
||||
class Foo {
|
||||
static prop1: string;
|
||||
prop2: number;
|
||||
}
|
||||
var x: number | string = 4;
|
||||
class Array { concat(items:number | string) {}; }
|
||||
var x: () => number | () => string = fn;
|
||||
var x: typeof Y = Y;
|
||||
var x: typeof Y | number = Y;
|
||||
var {x}: {x: string; } = { x: "hello" };
|
||||
var {x}: {x: string } = { x: "hello" };
|
||||
var [x]: Array<string> = [ "hello" ];
|
||||
function foo({x}: { x: string; }) {}
|
||||
function foo([x]: Array<string>) {}
|
||||
function foo(...rest: Array<number>) {}
|
||||
(function (...rest: Array<number>) {});
|
||||
((...rest: Array<number>) => rest);
|
||||
var a: Map<string, Array<string> >
|
||||
var a: Map<string, Array<string>>
|
||||
var a: number[]
|
||||
var a: ?string[]
|
||||
var a: Promise<bool>[]
|
||||
var a:(...rest:Array<number>) => number
|
||||
var identity: <T>(x: T) => T
|
||||
var identity: <T>(x: T, ...y:T[]) => T
|
||||
import type foo from "bar";
|
||||
import type { foo, bar } from "baz";
|
||||
import type { foo as bar } from "baz";
|
||||
import type from "foo";
|
||||
import type, { foo } from "bar";
|
||||
import type * as namespace from "bar";
|
||||
101
test/fixtures/generation/flow/type-annotations/expected.js
vendored
Normal file
101
test/fixtures/generation/flow/type-annotations/expected.js
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
function foo(numVal: any) {}
|
||||
function foo(numVal: number) {}
|
||||
function foo(numVal: number, strVal: string) {}
|
||||
function foo(numVal: number, untypedVal) {}
|
||||
function foo(untypedVal, numVal: number) {}
|
||||
function foo(nullableNum: ?number) {}
|
||||
function foo(callback: () => void) {}
|
||||
function foo(callback: () => number) {}
|
||||
function foo(callback: (_: bool) => number) {}
|
||||
function foo(callback: (_1: bool, _2: string) => number) {}
|
||||
function foo(callback: (_1: bool, ...foo: Array<number>) => number) {}
|
||||
function foo(): number {}
|
||||
function foo(): () => void {}
|
||||
function foo(): (_: bool) => number {}
|
||||
function foo(): (_?: bool) => number {}
|
||||
function foo(): {} {}
|
||||
function foo<T>() {}
|
||||
function foo<T, S>() {}
|
||||
a = function <T, S>() {};
|
||||
a = { set fooProp(value: number) {} };
|
||||
a = { set fooProp(value: number): void {} };
|
||||
a = { get fooProp(): number {} };
|
||||
a = { id<T>(x: T): T {} };
|
||||
a = { *id<T>(x: T): T {} };
|
||||
a = { async id<T>(x: T): T {} };
|
||||
a = { 123<T>(x: T): T {} };
|
||||
class Foo {
|
||||
set fooProp(value: number) {}
|
||||
}
|
||||
class Foo {
|
||||
set fooProp(value: number): void {}
|
||||
}
|
||||
class Foo {
|
||||
get fooProp(): number {}
|
||||
}
|
||||
var numVal: number;
|
||||
var numVal: number = otherNumVal;
|
||||
var a: { numVal: number };
|
||||
var a: { numVal: number };
|
||||
var a: { numVal: number; [indexer: string]: number };
|
||||
var a: ?{ numVal: number };
|
||||
var a: { numVal: number; strVal: string };
|
||||
var a: { subObj: { strVal: string } };
|
||||
var a: { subObj: ?{ strVal: string } };
|
||||
var a: { param1: number; param2: string };
|
||||
var a: { param1: number; param2?: string };
|
||||
var a: { [a: number]: string; [b: number]: string };
|
||||
var a: { add(x: number, ...y: Array<string>): void };
|
||||
var a: { id<T>(x: T): T };
|
||||
var a: Array<number> = [1, 2, 3];
|
||||
a = class Foo<T> {};
|
||||
a = class Foo<T> extends Bar<T> {};
|
||||
class Foo<T> {}
|
||||
class Foo<T> extends Bar<T> {}
|
||||
class Foo<T> extends mixin(Bar) {}
|
||||
class Foo<T> {
|
||||
bar<U>(): number {
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
class Foo {
|
||||
"bar"<T>() {}
|
||||
}
|
||||
function foo(requiredParam, optParam?) {}
|
||||
class Foo {
|
||||
prop1: string;
|
||||
prop2: number;
|
||||
}
|
||||
class Foo {
|
||||
static prop1: string;
|
||||
prop2: number;
|
||||
}
|
||||
var x: number | string = 4;
|
||||
class Array {
|
||||
concat(items: number | string) {}
|
||||
}
|
||||
var x: () => number | () => string = fn;
|
||||
var x: typeof Y = Y;
|
||||
var x: typeof Y | number = Y;
|
||||
var { x }: { x: string } = { x: "hello" };
|
||||
var { x }: { x: string } = { x: "hello" };
|
||||
var [x]: Array<string> = ["hello"];
|
||||
function foo({ x }: { x: string }) {}
|
||||
function foo([x]: Array<string>) {}
|
||||
function foo(...rest: Array<number>) {}
|
||||
(function (...rest: Array<number>) {});
|
||||
(...rest: Array<number>) => rest;
|
||||
var a: Map<string, Array<string>>;
|
||||
var a: Map<string, Array<string>>;
|
||||
var a: number[];
|
||||
var a: ?string[];
|
||||
var a: Promise<bool>[];
|
||||
var a: (...rest: Array<number>) => number;
|
||||
var identity: <T>(x: T) => T;
|
||||
var identity: <T>(x: T, ...y: T[]) => T;
|
||||
import type foo from "bar";
|
||||
import type { foo, bar } from "baz";
|
||||
import type { foo as bar } from "baz";
|
||||
import type from "foo";
|
||||
import type, { foo } from "bar";
|
||||
import type * as namespace from "bar";
|
||||
4
test/fixtures/generation/flow/typecasts/actual.js
vendored
Normal file
4
test/fixtures/generation/flow/typecasts/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
(xxx: number);
|
||||
({ xxx: 0, yyy: "hey" }: { xxx: number; yyy: string });
|
||||
(xxx => xxx + 1: (xxx: number) => number);
|
||||
((xxx: number), (yyy: string));
|
||||
4
test/fixtures/generation/flow/typecasts/expected.js
vendored
Normal file
4
test/fixtures/generation/flow/typecasts/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
(xxx: number);
|
||||
({ xxx: 0, yyy: "hey" }: { xxx: number; yyy: string });
|
||||
(xxx => xxx + 1: (xxx: number) => number);
|
||||
(xxx: number), (yyy: string);
|
||||
5
test/fixtures/transformation/flow/options.json
vendored
Normal file
5
test/fixtures/transformation/flow/options.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"experimental": true,
|
||||
"whitelist": ["flow"],
|
||||
"noCheckAst": true
|
||||
}
|
||||
6
test/fixtures/transformation/flow/strip-array-types/actual.js
vendored
Normal file
6
test/fixtures/transformation/flow/strip-array-types/actual.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
var a: number[];
|
||||
var a: ?number[];
|
||||
var a: (?number)[];
|
||||
var a: () => number[];
|
||||
var a: (() => number)[];
|
||||
var a: typeof A[];
|
||||
6
test/fixtures/transformation/flow/strip-array-types/expected.js
vendored
Normal file
6
test/fixtures/transformation/flow/strip-array-types/expected.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
5
test/fixtures/transformation/flow/strip-call-properties/actual.js
vendored
Normal file
5
test/fixtures/transformation/flow/strip-call-properties/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var a: { (): number };
|
||||
var a: { (): number; };
|
||||
var a: { (): number; y: string; (x: string): string };
|
||||
var a: { <T>(x: T): number; };
|
||||
interface A { (): number; }
|
||||
4
test/fixtures/transformation/flow/strip-call-properties/expected.js
vendored
Normal file
4
test/fixtures/transformation/flow/strip-call-properties/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
5
test/fixtures/transformation/flow/strip-declare-module/actual.js
vendored
Normal file
5
test/fixtures/transformation/flow/strip-declare-module/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
declare module A {}
|
||||
declare module "./a/b.js" {}
|
||||
declare module A { declare var x: number; }
|
||||
declare module A { declare function foo(): number; }
|
||||
declare module A { declare class B { foo(): number; } }
|
||||
11
test/fixtures/transformation/flow/strip-declare-statements/actual.js
vendored
Normal file
11
test/fixtures/transformation/flow/strip-declare-statements/actual.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
declare var foo
|
||||
declare var foo;
|
||||
declare function foo(): void
|
||||
declare function foo(): void;
|
||||
declare function foo<T>(): void;
|
||||
declare function foo(x: number, y: string): void;
|
||||
declare class A {}
|
||||
declare class A<T> extends B<T> { x: number }
|
||||
declare class A { static foo(): number; static x : string }
|
||||
declare class A { static [ indexer: number]: string }
|
||||
declare class A { static () : number }
|
||||
9
test/fixtures/transformation/flow/strip-interfaces-module-and-script/actual.js
vendored
Normal file
9
test/fixtures/transformation/flow/strip-interfaces-module-and-script/actual.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
interface A {}
|
||||
interface A extends B {}
|
||||
interface A<T> extends B<T>, C<T> {}
|
||||
interface A { foo: () => number; }
|
||||
interface Dictionary { [index: string]: string; length: number; }
|
||||
class Foo implements Bar {}
|
||||
class Foo2 extends Bar implements Bat, Man<number> {}
|
||||
class Foo3 extends class Bar implements Bat {} {}
|
||||
class Foo4 extends class Bar implements Bat {} implements Man {}
|
||||
4
test/fixtures/transformation/flow/strip-interfaces-module-and-script/expected.js
vendored
Normal file
4
test/fixtures/transformation/flow/strip-interfaces-module-and-script/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
class Foo {}
|
||||
class Foo2 extends Bar {}
|
||||
class Foo3 extends class Bar {} {}
|
||||
class Foo4 extends class Bar {} {}
|
||||
4
test/fixtures/transformation/flow/strip-qualified-generic-type/actual.js
vendored
Normal file
4
test/fixtures/transformation/flow/strip-qualified-generic-type/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var a: A.B;
|
||||
var a: A.B.C;
|
||||
var a: A.B<T>;
|
||||
var a: typeof A.B<T>;
|
||||
4
test/fixtures/transformation/flow/strip-qualified-generic-type/expected.js
vendored
Normal file
4
test/fixtures/transformation/flow/strip-qualified-generic-type/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
2
test/fixtures/transformation/flow/strip-string-literal-types/actual.js
vendored
Normal file
2
test/fixtures/transformation/flow/strip-string-literal-types/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
function createElement(tagName: "div"): HTMLDivElement {}
|
||||
function createElement(tagName: 'div'): HTMLDivElement {}
|
||||
2
test/fixtures/transformation/flow/strip-string-literal-types/expected.js
vendored
Normal file
2
test/fixtures/transformation/flow/strip-string-literal-types/expected.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
function createElement(tagName) {}
|
||||
function createElement(tagName) {}
|
||||
4
test/fixtures/transformation/flow/strip-tuples/actual.js
vendored
Normal file
4
test/fixtures/transformation/flow/strip-tuples/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var a: [] = [];
|
||||
var a: [Foo<T>] = [foo];
|
||||
var a: [number,] = [123,];
|
||||
var a: [number, string] = [123, "duck"];
|
||||
4
test/fixtures/transformation/flow/strip-tuples/expected.js
vendored
Normal file
4
test/fixtures/transformation/flow/strip-tuples/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var a = [];
|
||||
var a = [foo];
|
||||
var a = [123];
|
||||
var a = [123, "duck"];
|
||||
3
test/fixtures/transformation/flow/strip-type-alias/actual.js
vendored
Normal file
3
test/fixtures/transformation/flow/strip-type-alias/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
type FBID = number;
|
||||
type Foo<T> = Bar<T>
|
||||
export type Foo = number;
|
||||
97
test/fixtures/transformation/flow/strip-type-annotations/actual.js
vendored
Normal file
97
test/fixtures/transformation/flow/strip-type-annotations/actual.js
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
function foo(numVal: any) {}
|
||||
function foo(numVal: number) {}
|
||||
function foo(numVal: number, strVal: string) {}
|
||||
function foo(numVal: number, untypedVal) {}
|
||||
function foo(untypedVal, numVal: number) {}
|
||||
function foo(nullableNum: ?number) {}
|
||||
function foo(callback: () => void) {}
|
||||
function foo(callback: () => number) {}
|
||||
function foo(callback: (_: bool) => number) {}
|
||||
function foo(callback: (_1: bool, _2: string) => number) {}
|
||||
function foo(callback: (_1: bool, ...foo: Array<number>) => number) {}
|
||||
function foo(): number{}
|
||||
function foo():() => void {}
|
||||
function foo():(_:bool) => number{}
|
||||
function foo():(_?:bool) => number{}
|
||||
function foo(): {} {}
|
||||
function foo<T>() {}
|
||||
function foo<T,S>() {}
|
||||
a = function<T,S>() {};
|
||||
a = { set fooProp(value: number) {} };
|
||||
a = { set fooProp(value: number): void {} };
|
||||
a = { get fooProp():number{} };
|
||||
a = { id<T>(x: T): T {} };
|
||||
a = { *id<T>(x: T): T {} };
|
||||
a = { async id<T>(x: T): T {} };
|
||||
a = { 123<T>(x: T): T {} };
|
||||
class Foo {
|
||||
set fooProp(value: number) {}
|
||||
}
|
||||
class Foo2 {
|
||||
set fooProp(value: number): void {}
|
||||
}
|
||||
class Foo3 {
|
||||
get fooProp(): number {}
|
||||
}
|
||||
var numVal: number;
|
||||
var numVal: number = otherNumVal;
|
||||
var a: { numVal: number };
|
||||
var a: { numVal: number; };
|
||||
var a: { numVal: number; [indexer: string]: number };
|
||||
var a: ?{ numVal: number };
|
||||
var a: { numVal: number; strVal: string }
|
||||
var a: { subObj: {strVal: string} }
|
||||
var a: { subObj: ?{strVal: string} }
|
||||
var a: { param1: number; param2: string }
|
||||
var a: { param1: number; param2?: string }
|
||||
var a: { [a: number]: string; [b: number]: string; };
|
||||
var a: { add(x: number, ...y: Array<string>): void };
|
||||
var a: { id<T>(x: T): T; };
|
||||
var a:Array<number> = [1, 2, 3]
|
||||
a = class Foo<T> {}
|
||||
a = class Foo<T> extends Bar<T> {}
|
||||
class Foo4<T> {}
|
||||
class Foo5<T> extends Bar<T> {}
|
||||
class Foo6<T> extends mixin(Bar) {}
|
||||
class Foo7<T> {
|
||||
bar<U>():number { return 42; }
|
||||
}
|
||||
class Foo8 {
|
||||
"bar"<T>() {}
|
||||
}
|
||||
function foo(requiredParam, optParam?) {}
|
||||
class Foo9 {
|
||||
prop1: string;
|
||||
prop2: number;
|
||||
}
|
||||
class Foo10 {
|
||||
static prop1: string;
|
||||
prop2: number;
|
||||
}
|
||||
var x: number | string = 4;
|
||||
class Array { concat(items:number | string) {}; }
|
||||
var x: () => number | () => string = fn;
|
||||
var x: typeof Y = Y;
|
||||
var x: typeof Y | number = Y;
|
||||
var {x}: {x: string; } = { x: "hello" };
|
||||
var {x}: {x: string } = { x: "hello" };
|
||||
var [x]: Array<string> = [ "hello" ];
|
||||
function foo({x}: { x: string; }) {}
|
||||
function foo([x]: Array<string>) {}
|
||||
function foo(...rest: Array<number>) {}
|
||||
(function (...rest: Array<number>) {});
|
||||
((...rest: Array<number>) => rest);
|
||||
var a: Map<string, Array<string> >
|
||||
var a: Map<string, Array<string>>
|
||||
var a: number[]
|
||||
var a: ?string[]
|
||||
var a: Promise<bool>[]
|
||||
var a:(...rest:Array<number>) => number
|
||||
var identity: <T>(x: T) => T
|
||||
var identity: <T>(x: T, ...y:T[]) => T
|
||||
import type foo from "bar";
|
||||
import type { foo2, bar } from "baz";
|
||||
import type { foo as bar2 } from "baz";
|
||||
import type from "foo";
|
||||
import type2, { foo3 } from "bar";
|
||||
import type * as namespace from "bar";
|
||||
92
test/fixtures/transformation/flow/strip-type-annotations/expected.js
vendored
Normal file
92
test/fixtures/transformation/flow/strip-type-annotations/expected.js
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
function foo(numVal) {}
|
||||
function foo(numVal) {}
|
||||
function foo(numVal, strVal) {}
|
||||
function foo(numVal, untypedVal) {}
|
||||
function foo(untypedVal, numVal) {}
|
||||
function foo(nullableNum) {}
|
||||
function foo(callback) {}
|
||||
function foo(callback) {}
|
||||
function foo(callback) {}
|
||||
function foo(callback) {}
|
||||
function foo(callback) {}
|
||||
function foo() {}
|
||||
function foo() {}
|
||||
function foo() {}
|
||||
function foo() {}
|
||||
function foo() {}
|
||||
function foo() {}
|
||||
function foo() {}
|
||||
a = function () {};
|
||||
a = { set fooProp(value) {} };
|
||||
a = { set fooProp(value) {} };
|
||||
a = { get fooProp() {} };
|
||||
a = { id(x) {} };
|
||||
a = { *id(x) {} };
|
||||
a = { async id(x) {} };
|
||||
a = { 123(x) {} };
|
||||
class Foo {
|
||||
set fooProp(value) {}
|
||||
}
|
||||
class Foo2 {
|
||||
set fooProp(value) {}
|
||||
}
|
||||
class Foo3 {
|
||||
get fooProp() {}
|
||||
}
|
||||
var numVal;
|
||||
var numVal = otherNumVal;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a = [1, 2, 3];
|
||||
a = class Foo {};
|
||||
a = class Foo extends Bar {};
|
||||
class Foo4 {}
|
||||
class Foo5 extends Bar {}
|
||||
class Foo6 extends mixin(Bar) {}
|
||||
class Foo7 {
|
||||
bar() {
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
class Foo8 {
|
||||
"bar"() {}
|
||||
}
|
||||
function foo(requiredParam, optParam?) {}
|
||||
class Foo9 {}
|
||||
class Foo10 {}
|
||||
var x = 4;
|
||||
class Array {
|
||||
concat(items) {}
|
||||
}
|
||||
var x = fn;
|
||||
var x = Y;
|
||||
var x = Y;
|
||||
var { x } = { x: "hello" };
|
||||
var { x } = { x: "hello" };
|
||||
var [x] = ["hello"];
|
||||
function foo({ x }) {}
|
||||
function foo([x]) {}
|
||||
function foo(...rest) {}
|
||||
(function (...rest) {});
|
||||
(...rest) => rest;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var identity;
|
||||
var identity;
|
||||
|
||||
import type from "foo";
|
||||
import type2, { foo3 } from "bar";
|
||||
4
test/fixtures/transformation/flow/strip-typecasts/actual.js
vendored
Normal file
4
test/fixtures/transformation/flow/strip-typecasts/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
(xxx: number);
|
||||
({ xxx: 0, yyy: "hey" }: { xxx: number; yyy: string });
|
||||
(xxx => xxx + 1: (xxx: number) => number);
|
||||
((xxx: number), (yyy: string));
|
||||
4
test/fixtures/transformation/flow/strip-typecasts/expected.js
vendored
Normal file
4
test/fixtures/transformation/flow/strip-typecasts/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
xxx;
|
||||
({ xxx: 0, yyy: "hey" });
|
||||
xxx => xxx + 1;
|
||||
xxx, yyy;
|
||||
Reference in New Issue
Block a user