clean up babel-generator - closes #2210
This commit is contained in:
@@ -1,25 +1,24 @@
|
||||
/* @flow */
|
||||
|
||||
import type NodePrinter from "../node/printer";
|
||||
import * as t from "babel-types";
|
||||
|
||||
export function _params(node: Object, print: NodePrinter) {
|
||||
print.plain(node.typeParameters);
|
||||
export function _params(node: Object) {
|
||||
this.print(node.typeParameters, node);
|
||||
this.push("(");
|
||||
print.list(node.params, {
|
||||
this.printList(node.params, node, {
|
||||
iterator: (node) =>{
|
||||
if (node.optional) this.push("?");
|
||||
print.plain(node.typeAnnotation);
|
||||
this.print(node.typeAnnotation, node);
|
||||
}
|
||||
});
|
||||
this.push(")");
|
||||
|
||||
if (node.returnType) {
|
||||
print.plain(node.returnType);
|
||||
this.print(node.returnType, node);
|
||||
}
|
||||
}
|
||||
|
||||
export function _method(node: Object, print: NodePrinter) {
|
||||
export function _method(node: Object) {
|
||||
let value = node.value;
|
||||
let kind = node.kind;
|
||||
let key = node.key;
|
||||
@@ -38,43 +37,43 @@ export function _method(node: Object, print: NodePrinter) {
|
||||
|
||||
if (node.computed) {
|
||||
this.push("[");
|
||||
print.plain(key);
|
||||
this.print(key, node);
|
||||
this.push("]");
|
||||
} else {
|
||||
print.plain(key);
|
||||
this.print(key, node);
|
||||
}
|
||||
|
||||
this._params(value, print);
|
||||
this._params(value);
|
||||
this.space();
|
||||
print.plain(value.body);
|
||||
this.print(value.body, value);
|
||||
}
|
||||
|
||||
export function FunctionExpression(node: Object, print: NodePrinter) {
|
||||
export function FunctionExpression(node: Object) {
|
||||
if (node.async) this.push("async ");
|
||||
this.push("function");
|
||||
if (node.generator) this.push("*");
|
||||
|
||||
if (node.id) {
|
||||
this.push(" ");
|
||||
print.plain(node.id);
|
||||
this.print(node.id, node);
|
||||
} else {
|
||||
this.space();
|
||||
}
|
||||
|
||||
this._params(node, print);
|
||||
this._params(node);
|
||||
this.space();
|
||||
print.plain(node.body);
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
export { FunctionExpression as FunctionDeclaration };
|
||||
|
||||
export function ArrowFunctionExpression(node: Object, print: NodePrinter) {
|
||||
export function ArrowFunctionExpression(node: Object) {
|
||||
if (node.async) this.push("async ");
|
||||
|
||||
if (node.params.length === 1 && t.isIdentifier(node.params[0])) {
|
||||
print.plain(node.params[0]);
|
||||
this.print(node.params[0], node);
|
||||
} else {
|
||||
this._params(node, print);
|
||||
this._params(node);
|
||||
}
|
||||
|
||||
this.push(" => ");
|
||||
@@ -85,7 +84,7 @@ export function ArrowFunctionExpression(node: Object, print: NodePrinter) {
|
||||
this.push("(");
|
||||
}
|
||||
|
||||
print.plain(node.body);
|
||||
this.print(node.body, node);
|
||||
|
||||
if (bodyNeedsParens) {
|
||||
this.push(")");
|
||||
|
||||
Reference in New Issue
Block a user