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

master
Lucas Azzola 2017-05-27 13:47:48 +10:00 committed by Christopher Chedeau
parent b265713763
commit 934216d852
4 changed files with 90 additions and 0 deletions

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;

View File

@ -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 {

View File

@ -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);

View File

@ -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;
}