Use the common space helper everywhere to ensure we get the smallest output possible.
This commit is contained in:
@@ -3,24 +3,24 @@ export function ClassDeclaration(node: Object) {
|
||||
this.word("class");
|
||||
|
||||
if (node.id) {
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.id, node);
|
||||
}
|
||||
|
||||
this.print(node.typeParameters, node);
|
||||
|
||||
if (node.superClass) {
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word("extends");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.superClass, node);
|
||||
this.print(node.superTypeParameters, node);
|
||||
}
|
||||
|
||||
if (node.implements) {
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word("implements");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.printList(node.implements, node);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ export function ClassProperty(node: Object) {
|
||||
|
||||
if (node.static) {
|
||||
this.word("static");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
this.print(node.key, node);
|
||||
this.print(node.typeAnnotation, node);
|
||||
@@ -69,12 +69,12 @@ export function ClassMethod(node: Object) {
|
||||
|
||||
if (node.static) {
|
||||
this.word("static");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (node.kind === "constructorCall") {
|
||||
this.word("call");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this._method(node);
|
||||
|
||||
@@ -56,7 +56,7 @@ export function ConditionalExpression(node: Object) {
|
||||
|
||||
export function NewExpression(node: Object, parent: Object) {
|
||||
this.word("new");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.callee, node);
|
||||
if (node.arguments.length === 0 && this.format.minified &&
|
||||
!t.isCallExpression(parent, { callee: node }) &&
|
||||
@@ -125,7 +125,7 @@ function buildYieldAwait(keyword: string) {
|
||||
}
|
||||
|
||||
if (node.argument) {
|
||||
this.push(" ");
|
||||
this.space();
|
||||
let terminatorState = this.startTerminatorless();
|
||||
this.print(node.argument, node);
|
||||
this.endTerminatorless(terminatorState);
|
||||
|
||||
@@ -26,17 +26,17 @@ export function NullLiteralTypeAnnotation() {
|
||||
|
||||
export function DeclareClass(node: Object) {
|
||||
this.word("declare");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word("class");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this._interfaceish(node);
|
||||
}
|
||||
|
||||
export function DeclareFunction(node: Object) {
|
||||
this.word("declare");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word("function");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.id, node);
|
||||
this.print(node.id.typeAnnotation.typeAnnotation, node);
|
||||
this.semicolon();
|
||||
@@ -44,15 +44,15 @@ export function DeclareFunction(node: Object) {
|
||||
|
||||
export function DeclareInterface(node: Object) {
|
||||
this.word("declare");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.InterfaceDeclaration(node);
|
||||
}
|
||||
|
||||
export function DeclareModule(node: Object) {
|
||||
this.word("declare");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word("module");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.id, node);
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
@@ -60,15 +60,15 @@ export function DeclareModule(node: Object) {
|
||||
|
||||
export function DeclareTypeAlias(node: Object) {
|
||||
this.word("declare");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.TypeAlias(node);
|
||||
}
|
||||
|
||||
export function DeclareVariable(node: Object) {
|
||||
this.word("declare");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word("var");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.id, node);
|
||||
this.print(node.id.typeAnnotation, node);
|
||||
this.semicolon();
|
||||
@@ -125,15 +125,15 @@ export function _interfaceish(node: Object) {
|
||||
this.print(node.id, node);
|
||||
this.print(node.typeParameters, node);
|
||||
if (node.extends.length) {
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word("extends");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.printList(node.extends, node);
|
||||
}
|
||||
if (node.mixins && node.mixins.length) {
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word("mixins");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.printList(node.mixins, node);
|
||||
}
|
||||
this.space();
|
||||
@@ -142,14 +142,14 @@ export function _interfaceish(node: Object) {
|
||||
|
||||
export function InterfaceDeclaration(node: Object) {
|
||||
this.word("interface");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this._interfaceish(node);
|
||||
}
|
||||
|
||||
function andSeparator() {
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.token("&");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
|
||||
export function IntersectionTypeAnnotation(node: Object) {
|
||||
@@ -190,13 +190,13 @@ export function TupleTypeAnnotation(node: Object) {
|
||||
|
||||
export function TypeofTypeAnnotation(node: Object) {
|
||||
this.word("typeof");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.argument, node);
|
||||
}
|
||||
|
||||
export function TypeAlias(node: Object) {
|
||||
this.word("type");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.id, node);
|
||||
this.print(node.typeParameters, node);
|
||||
this.space();
|
||||
@@ -272,7 +272,7 @@ export function ObjectTypeAnnotation(node: Object) {
|
||||
export function ObjectTypeCallProperty(node: Object) {
|
||||
if (node.static) {
|
||||
this.word("static");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
this.print(node.value, node);
|
||||
}
|
||||
@@ -280,7 +280,7 @@ export function ObjectTypeCallProperty(node: Object) {
|
||||
export function ObjectTypeIndexer(node: Object) {
|
||||
if (node.static) {
|
||||
this.word("static");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
this.token("[");
|
||||
this.print(node.id, node);
|
||||
@@ -296,7 +296,7 @@ export function ObjectTypeIndexer(node: Object) {
|
||||
export function ObjectTypeProperty(node: Object) {
|
||||
if (node.static) {
|
||||
this.word("static");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
this.print(node.key, node);
|
||||
if (node.optional) this.token("?");
|
||||
@@ -314,9 +314,9 @@ export function QualifiedTypeIdentifier(node: Object) {
|
||||
}
|
||||
|
||||
function orSeparator() {
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.token("|");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
|
||||
export function UnionTypeAnnotation(node: Object) {
|
||||
|
||||
@@ -54,18 +54,18 @@ export function JSXElement(node: Object) {
|
||||
}
|
||||
|
||||
function spaceSeparator() {
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
|
||||
export function JSXOpeningElement(node: Object) {
|
||||
this.token("<");
|
||||
this.print(node.name, node);
|
||||
if (node.attributes.length > 0) {
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.printJoin(node.attributes, node, { separator: spaceSeparator });
|
||||
}
|
||||
if (node.selfClosing) {
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.token("/>");
|
||||
} else {
|
||||
this.token(">");
|
||||
|
||||
@@ -28,12 +28,12 @@ export function _method(node: Object) {
|
||||
|
||||
if (kind === "get" || kind === "set") {
|
||||
this.word(kind);
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (node.async) {
|
||||
this.word("async");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (node.computed) {
|
||||
@@ -52,13 +52,13 @@ export function _method(node: Object) {
|
||||
export function FunctionExpression(node: Object) {
|
||||
if (node.async) {
|
||||
this.word("async");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
this.word("function");
|
||||
if (node.generator) this.token("*");
|
||||
|
||||
if (node.id) {
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.id, node);
|
||||
} else {
|
||||
this.space();
|
||||
@@ -74,7 +74,7 @@ export { FunctionExpression as FunctionDeclaration };
|
||||
export function ArrowFunctionExpression(node: Object) {
|
||||
if (node.async) {
|
||||
this.word("async");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
|
||||
if (node.params.length === 1 && t.isIdentifier(node.params[0])) {
|
||||
@@ -83,9 +83,9 @@ export function ArrowFunctionExpression(node: Object) {
|
||||
this._params(node);
|
||||
}
|
||||
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.token("=>");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ import * as t from "babel-types";
|
||||
export function ImportSpecifier(node: Object) {
|
||||
this.print(node.imported, node);
|
||||
if (node.local && node.local.name !== node.imported.name) {
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word("as");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.local, node);
|
||||
}
|
||||
}
|
||||
@@ -21,49 +21,49 @@ export function ExportDefaultSpecifier(node: Object) {
|
||||
export function ExportSpecifier(node: Object) {
|
||||
this.print(node.local, node);
|
||||
if (node.exported && node.local.name !== node.exported.name) {
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word("as");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.exported, node);
|
||||
}
|
||||
}
|
||||
|
||||
export function ExportNamespaceSpecifier(node: Object) {
|
||||
this.token("*");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word("as");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.exported, node);
|
||||
}
|
||||
|
||||
export function ExportAllDeclaration(node: Object) {
|
||||
this.word("export");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.token("*");
|
||||
if (node.exported) {
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word("as");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.exported, node);
|
||||
}
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word("from");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.source, node);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
export function ExportNamedDeclaration() {
|
||||
this.word("export");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
ExportDeclaration.apply(this, arguments);
|
||||
}
|
||||
|
||||
export function ExportDefaultDeclaration() {
|
||||
this.word("export");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word("default");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
ExportDeclaration.apply(this, arguments);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ function ExportDeclaration(node: Object) {
|
||||
} else {
|
||||
if (node.exportKind === "type") {
|
||||
this.word("type");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
|
||||
let specifiers = node.specifiers.slice(0);
|
||||
@@ -89,7 +89,7 @@ function ExportDeclaration(node: Object) {
|
||||
this.print(specifiers.shift(), node);
|
||||
if (specifiers.length) {
|
||||
this.token(",");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
@@ -107,9 +107,9 @@ function ExportDeclaration(node: Object) {
|
||||
}
|
||||
|
||||
if (node.source) {
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word("from");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.source, node);
|
||||
}
|
||||
|
||||
@@ -119,11 +119,11 @@ function ExportDeclaration(node: Object) {
|
||||
|
||||
export function ImportDeclaration(node: Object) {
|
||||
this.word("import");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
|
||||
if (node.importKind === "type" || node.importKind === "typeof") {
|
||||
this.word(node.importKind);
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
|
||||
let specifiers = node.specifiers.slice(0);
|
||||
@@ -135,7 +135,7 @@ export function ImportDeclaration(node: Object) {
|
||||
this.print(specifiers.shift(), node);
|
||||
if (specifiers.length) {
|
||||
this.token(",");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
@@ -150,9 +150,9 @@ export function ImportDeclaration(node: Object) {
|
||||
this.token("}");
|
||||
}
|
||||
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word("from");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
}
|
||||
|
||||
this.print(node.source, node);
|
||||
@@ -161,8 +161,8 @@ export function ImportDeclaration(node: Object) {
|
||||
|
||||
export function ImportNamespaceSpecifier(node: Object) {
|
||||
this.token("*");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word("as");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.local, node);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ export function IfStatement(node: Object) {
|
||||
if (node.alternate) {
|
||||
if (this.endsWith("}")) this.space();
|
||||
this.word("else");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.printAndIndentOnComments(node.alternate, node);
|
||||
}
|
||||
}
|
||||
@@ -81,9 +81,9 @@ let buildForXStatement = function (op) {
|
||||
this.keyword("for");
|
||||
this.token("(");
|
||||
this.print(node.left, node);
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.word(op);
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.right, node);
|
||||
this.token(")");
|
||||
this.printBlock(node);
|
||||
@@ -95,7 +95,7 @@ export let ForOfStatement = buildForXStatement("of");
|
||||
|
||||
export function DoWhileStatement(node: Object) {
|
||||
this.word("do");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
this.space();
|
||||
this.keyword("while");
|
||||
@@ -130,7 +130,7 @@ export let ThrowStatement = buildLabelStatement("throw", "argument");
|
||||
export function LabeledStatement(node: Object) {
|
||||
this.print(node.label, node);
|
||||
this.token(":");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ export function TryStatement(node: Object) {
|
||||
if (node.finalizer) {
|
||||
this.space();
|
||||
this.word("finally");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.finalizer, node);
|
||||
}
|
||||
}
|
||||
@@ -186,7 +186,7 @@ export function SwitchStatement(node: Object) {
|
||||
export function SwitchCase(node: Object) {
|
||||
if (node.test) {
|
||||
this.word("case");
|
||||
this.push(" ");
|
||||
this.space();
|
||||
this.print(node.test, node);
|
||||
this.token(":");
|
||||
} else {
|
||||
@@ -221,7 +221,7 @@ function constDeclarationIdent() {
|
||||
|
||||
export function VariableDeclaration(node: Object, parent: Object) {
|
||||
this.word(node.kind);
|
||||
this.push(" ");
|
||||
this.space();
|
||||
|
||||
let hasInits = false;
|
||||
// don't add whitespace to loop heads
|
||||
|
||||
@@ -9,9 +9,9 @@ export function TemplateElement(node: Object, parent: Object) {
|
||||
|
||||
let value = (isFirst ? "`" : "}") + node.value.raw + (isLast ? "`" : "${");
|
||||
|
||||
if (!isFirst) this.push(" ");
|
||||
if (!isFirst) this.space();
|
||||
this.token(value);
|
||||
if (!isLast) this.push(" ");
|
||||
if (!isLast) this.space();
|
||||
}
|
||||
|
||||
export function TemplateLiteral(node: Object) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
x=1;var {y=1}=obj;
|
||||
x=1;var{y=1}=obj;
|
||||
|
||||
@@ -1 +1 @@
|
||||
var foo=(arg1,arg2) => {arg1;arg2};var foo2=(arg1,arg2) => {arg1};var foo3=arg1 => arg1;
|
||||
var foo=(arg1,arg2)=>{arg1;arg2};var foo2=(arg1,arg2)=>{arg1};var foo3=arg1=>arg1;
|
||||
|
||||
@@ -1 +1 @@
|
||||
if(true){foo;bar2}else {foo;bar2}function fn(){foo;bar2}
|
||||
if(true){foo;bar2}else{foo;bar2}function fn(){foo;bar2}
|
||||
|
||||
@@ -1 +1 @@
|
||||
import * as foo from "foo";import {foo as bar,foo2 as bar2} from "foo";import {foo2} from "foo";export * from "foo";export {foo as bar} from "foo";export {foo} from "foo";
|
||||
import*as foo from"foo";import{foo as bar,foo2 as bar2}from"foo";import{foo2}from"foo";export*from"foo";export{foo as bar}from"foo";export{foo}from"foo";
|
||||
|
||||
Reference in New Issue
Block a user