fix(typescript): allow parens with TSFunctionType and ignore empty specifiers (#1764)

This commit is contained in:
Lucas Azzola authored and Christopher Chedeau committed 2017-05-26 20:47:48 -07:00
1 parent b265713763
commit 934216d852
4 files changed
+90

No files matched your search

+18
View File
@@ -81,6 +81,24 @@ function massageAST(ast) {
};
}
// (TypeScript) ignore empty `specifiers` array
if (
ast.type === "TSNamespaceExportDeclaration" &&
ast.specifiers &&
ast.specifiers.length === 0
) {
delete newObj.specifiers;
}
// (TypeScript) allow parenthesization of TSFunctionType
if (
ast.type === "TSParenthesizedType" &&
ast.typeAnnotation.type === "TypeAnnotation" &&
ast.typeAnnotation.typeAnnotation.type === "TSFunctionType"
) {
return newObj.typeAnnotation.typeAnnotation;
}
// We convert <div></div> to <div />
if (ast.type === "JSXOpeningElement") {
delete newObj.selfClosing;
@@ -214,6 +214,21 @@ interface i2 {
`;
exports[`contextualSignatureInstantiation2.ts 1`] = `
// dot f g x = f(g(x))
var dot: <T, S>(f: (_: T) => S) => <U>(g: (_: U) => T) => (_: U) => S;
dot = <T, S>(f: (_: T) => S) => <U>(g: (_: U) => T): (r:U) => S => (x) => f(g(x));
var id: <T>(x:T) => T;
var r23 = dot(id)(id);~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// dot f g x = f(g(x))
var dot: <T, S>(f: (_: T) => S) => <U>(g: (_: U) => T) => (_: U) => S;
dot = <T, S>(f: (_: T) => S) => <U>(g: (_: U) => T): ((r: U) => S) => x =>
f(g(x));
var id: <T>(x: T) => T;
var r23 = dot(id)(id);
`;
exports[`decrementAndIncrementOperators.ts 1`] = `
var x = 0;
@@ -310,6 +325,42 @@ interface Foo {
`;
exports[`es5ExportDefaultClassDeclaration4.ts 1`] = `
// @target: es5
// @module: commonjs
// @declaration: true
declare module "foo" {
export var before: C;
export default class C {
method(): C;
}
export var after: C;
export var t: typeof C;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @target: es5
// @module: commonjs
// @declaration: true
declare module "foo" {
export var before: C;
export class C {
method(): C;
}
export var after: C;
export var t: typeof C;
}
`;
exports[`functionOverloadsOnGenericArity1.ts 1`] = `
// overloading on arity not allowed
interface C {
@@ -0,0 +1,5 @@
// dot f g x = f(g(x))
var dot: <T, S>(f: (_: T) => S) => <U>(g: (_: U) => T) => (_: U) => S;
dot = <T, S>(f: (_: T) => S) => <U>(g: (_: U) => T): (r:U) => S => (x) => f(g(x));
var id: <T>(x:T) => T;
var r23 = dot(id)(id);
@@ -0,0 +1,16 @@
// @target: es5
// @module: commonjs
// @declaration: true
declare module "foo" {
export var before: C;
export default class C {
method(): C;
}
export var after: C;
export var t: typeof C;
}