Reprint printer.js

This commit is contained in:
James Long committed 2016-12-31 14:38:58 -05:00
1 parent 5efa13a10c
commit de4d7ac799
1 file changed
+86 -86
+86 -86
View File
@@ -61,7 +61,7 @@ function Printer(originalOptions) {
var explicitTabWidth = originalOptions && originalOptions.tabWidth; var explicitTabWidth = originalOptions && originalOptions.tabWidth;
var options = normalizeOptions(originalOptions); var options = normalizeOptions(originalOptions);
assert.notStrictEqual(options, originalOptions); assert.notStrictEqual(options, originalOptions);
// It's common for client code to pass the same options into both // It's common for client code to pass the same options into both
@@ -84,12 +84,12 @@ function Printer(originalOptions) {
if (!explicitTabWidth) { if (!explicitTabWidth) {
var oldTabWidth = options.tabWidth; var oldTabWidth = options.tabWidth;
var loc = path.getNode().loc; var loc = path.getNode().loc;
if (loc && loc.lines && loc.lines.guessTabWidth) { if (loc && loc.lines && loc.lines.guessTabWidth) {
options.tabWidth = loc.lines.guessTabWidth(); options.tabWidth = loc.lines.guessTabWidth();
var lines = maybeReprint(path); var lines = maybeReprint(path);
options.tabWidth = oldTabWidth; options.tabWidth = oldTabWidth;
return lines; return lines;
@@ -142,14 +142,14 @@ function Printer(originalOptions) {
var path = FastPath.from(ast); var path = FastPath.from(ast);
var oldReuseWhitespace = options.reuseWhitespace; var oldReuseWhitespace = options.reuseWhitespace;
// Do not reuse whitespace (or anything else, for that matter) // Do not reuse whitespace (or anything else, for that matter)
// when printing generically. // when printing generically.
options.reuseWhitespace = false; options.reuseWhitespace = false;
var res = printGenerically(path); var res = printGenerically(path);
var pr = new PrintResult(pp.print(options.wrapColumn, res)); var pr = new PrintResult(pp.print(options.wrapColumn, res));
options.reuseWhitespace = oldReuseWhitespace; options.reuseWhitespace = oldReuseWhitespace;
return pr; return pr;
@@ -169,7 +169,7 @@ function genericPrint(path, options, printPath) {
var parts = []; var parts = [];
var needsParens = false; var needsParens = false;
var linesWithoutParens = genericPrintNoParens(path, options, printPath); var linesWithoutParens = genericPrintNoParens(path, options, printPath);
if (!node || isEmpty(linesWithoutParens)) { if (!node || isEmpty(linesWithoutParens)) {
return linesWithoutParens; return linesWithoutParens;
} }
@@ -221,7 +221,7 @@ function genericPrint(path, options, printPath) {
function genericPrintNoParens(path, options, print) { function genericPrintNoParens(path, options, print) {
var n = path.getValue(); var n = path.getValue();
if (!n) { if (!n) {
return fromString(""); return fromString("");
} }
@@ -239,7 +239,7 @@ function genericPrintNoParens(path, options, print) {
case "File": case "File":
return path.call(print, "program"); return path.call(print, "program");
case "Program": case "Program":
// Babel 6 // Babel 6
if (n.directives) { if (n.directives) {
path.each( path.each(
@@ -301,11 +301,11 @@ function genericPrintNoParens(path, options, print) {
[ path.call(print, "left"), " = ", path.call(print, "right") ] [ path.call(print, "left"), " = ", path.call(print, "right") ]
); );
case "MemberExpression": case "MemberExpression":
parts.push(path.call(print, "object")); parts.push(path.call(print, "object"));
var property = path.call(print, "property"); var property = path.call(print, "property");
if (n.computed) { if (n.computed) {
parts.push("[", property, "]"); parts.push("[", property, "]");
} else { } else {
@@ -318,7 +318,7 @@ function genericPrintNoParens(path, options, print) {
[ path.call(print, "meta"), ".", path.call(print, "property") ] [ path.call(print, "meta"), ".", path.call(print, "property") ]
); );
case "BindExpression": case "BindExpression":
if (n.object) { if (n.object) {
parts.push(path.call(print, "object")); parts.push(path.call(print, "object"));
} }
@@ -342,7 +342,7 @@ function genericPrintNoParens(path, options, print) {
return concat([ "...", path.call(print, "argument") ]); return concat([ "...", path.call(print, "argument") ]);
case "FunctionDeclaration": case "FunctionDeclaration":
case "FunctionExpression": case "FunctionExpression":
if (n.async) if (n.async)
parts.push("async "); parts.push("async ");
@@ -377,7 +377,7 @@ function genericPrintNoParens(path, options, print) {
return group(concat(parts)); return group(concat(parts));
case "ArrowFunctionExpression": case "ArrowFunctionExpression":
if (n.async) if (n.async)
parts.push("async "); parts.push("async ");
@@ -406,7 +406,7 @@ function genericPrintNoParens(path, options, print) {
return concat(parts); return concat(parts);
case "MethodDefinition": case "MethodDefinition":
if (n.static) { if (n.static) {
parts.push("static "); parts.push("static ");
} }
@@ -415,7 +415,7 @@ function genericPrintNoParens(path, options, print) {
return concat(parts); return concat(parts);
case "YieldExpression": case "YieldExpression":
parts.push("yield"); parts.push("yield");
if (n.delegate) if (n.delegate)
@@ -426,7 +426,7 @@ function genericPrintNoParens(path, options, print) {
return concat(parts); return concat(parts);
case "AwaitExpression": case "AwaitExpression":
parts.push("await"); parts.push("await");
if (n.all) if (n.all)
@@ -437,7 +437,7 @@ function genericPrintNoParens(path, options, print) {
return concat(parts); return concat(parts);
case "ModuleDeclaration": case "ModuleDeclaration":
parts.push("module", path.call(print, "id")); parts.push("module", path.call(print, "id"));
if (n.source) { if (n.source) {
@@ -450,7 +450,7 @@ function genericPrintNoParens(path, options, print) {
return fromString(" ").join(parts); return fromString(" ").join(parts);
case "ImportSpecifier": case "ImportSpecifier":
if (n.imported) { if (n.imported) {
parts.push(path.call(print, "imported")); parts.push(path.call(print, "imported"));
@@ -468,7 +468,7 @@ function genericPrintNoParens(path, options, print) {
return concat(parts); return concat(parts);
case "ExportSpecifier": case "ExportSpecifier":
if (n.local) { if (n.local) {
parts.push(path.call(print, "local")); parts.push(path.call(print, "local"));
@@ -488,7 +488,7 @@ function genericPrintNoParens(path, options, print) {
case "ExportBatchSpecifier": case "ExportBatchSpecifier":
return fromString("*"); return fromString("*");
case "ImportNamespaceSpecifier": case "ImportNamespaceSpecifier":
parts.push("* as "); parts.push("* as ");
if (n.local) { if (n.local) {
@@ -500,7 +500,7 @@ function genericPrintNoParens(path, options, print) {
return concat(parts); return concat(parts);
case "ImportDefaultSpecifier": case "ImportDefaultSpecifier":
if (n.local) { if (n.local) {
return path.call(print, "local"); return path.call(print, "local");
} }
@@ -511,7 +511,7 @@ function genericPrintNoParens(path, options, print) {
case "ExportNamedDeclaration": case "ExportNamedDeclaration":
return printExportDeclaration(path, options, print); return printExportDeclaration(path, options, print);
case "ExportAllDeclaration": case "ExportAllDeclaration":
parts.push("export *"); parts.push("export *");
if (n.exported) { if (n.exported) {
@@ -526,7 +526,7 @@ function genericPrintNoParens(path, options, print) {
case "ExportDefaultSpecifier": case "ExportDefaultSpecifier":
return path.call(print, "exported"); return path.call(print, "exported");
case "ImportDeclaration": case "ImportDeclaration":
parts.push("import "); parts.push("import ");
if (n.importKind && n.importKind !== "value") { if (n.importKind && n.importKind !== "value") {
@@ -535,17 +535,17 @@ function genericPrintNoParens(path, options, print) {
if (n.specifiers && n.specifiers.length > 0) { if (n.specifiers && n.specifiers.length > 0) {
var foundImportSpecifier = false; var foundImportSpecifier = false;
path.each( path.each(
function(specifierPath) { function(specifierPath) {
var i = specifierPath.getName(); var i = specifierPath.getName();
if (i > 0) { if (i > 0) {
parts.push(", "); parts.push(", ");
} }
var value = specifierPath.getValue(); var value = specifierPath.getValue();
if ( if (
namedTypes.ImportDefaultSpecifier.check(value) || namedTypes.ImportDefaultSpecifier.check(value) ||
namedTypes.ImportNamespaceSpecifier.check(value) namedTypes.ImportNamespaceSpecifier.check(value)
@@ -583,7 +583,7 @@ function genericPrintNoParens(path, options, print) {
}, },
"body" "body"
); );
// If there are no contents, return a simple block // If there are no contents, return a simple block
if (!getFirstString(naked)) { if (!getFirstString(naked)) {
return "{}"; return "{}";
@@ -612,11 +612,11 @@ function genericPrintNoParens(path, options, print) {
return concat(parts); return concat(parts);
case "ReturnStatement": case "ReturnStatement":
parts.push("return"); parts.push("return");
var arg = path.call(print, "argument"); var arg = path.call(print, "argument");
if (n.argument) { if (n.argument) {
if ( if (
namedTypes.JSXElement && namedTypes.JSXElement.check(n.argument) && namedTypes.JSXElement && namedTypes.JSXElement.check(n.argument) &&
@@ -649,7 +649,7 @@ function genericPrintNoParens(path, options, print) {
var fields = []; var fields = [];
var leftBrace = (n.exact ? "{|" : "{"); var leftBrace = (n.exact ? "{|" : "{");
var rightBrace = (n.exact ? "|}" : "}"); var rightBrace = (n.exact ? "|}" : "}");
if (isTypeAnnotation) { if (isTypeAnnotation) {
fields.push("indexers", "callProperties"); fields.push("indexers", "callProperties");
} }
@@ -658,7 +658,7 @@ function genericPrintNoParens(path, options, print) {
var i = 0; var i = 0;
var props = []; var props = [];
fields.forEach( fields.forEach(
function(field) { function(field) {
path.each( path.each(
@@ -697,7 +697,7 @@ function genericPrintNoParens(path, options, print) {
case "ObjectProperty": case "ObjectProperty":
case // Non-standard AST node type. case // Non-standard AST node type.
"Property": "Property":
if (n.method || n.kind === "get" || n.kind === "set") { if (n.method || n.kind === "get" || n.kind === "set") {
return printMethod(path, options, print); return printMethod(path, options, print);
} }
@@ -715,7 +715,7 @@ function genericPrintNoParens(path, options, print) {
return concat(parts); return concat(parts);
case // Babel 6 case // Babel 6
"ClassMethod": "ClassMethod":
if (n.static) { if (n.static) {
parts.push("static "); parts.push("static ");
} }
@@ -730,7 +730,7 @@ function genericPrintNoParens(path, options, print) {
return concat([ "@", path.call(print, "expression") ]); return concat([ "@", path.call(print, "expression") ]);
case "ArrayExpression": case "ArrayExpression":
case "ArrayPattern": case "ArrayPattern":
if (n.elements.length === 0) { if (n.elements.length === 0) {
parts.push("[]"); parts.push("[]");
} else { } else {
@@ -779,7 +779,7 @@ function genericPrintNoParens(path, options, print) {
// Babel 6 Literal split // Babel 6 Literal split
case "StringLiteral": case "StringLiteral":
case "Literal": case "Literal":
if (typeof n.value !== "string") if (typeof n.value !== "string")
return fromString(n.value, options); return fromString(n.value, options);
@@ -791,7 +791,7 @@ function genericPrintNoParens(path, options, print) {
"DirectiveLiteral": "DirectiveLiteral":
return fromString(nodeStr(n.value, options)); return fromString(nodeStr(n.value, options));
case "ModuleSpecifier": case "ModuleSpecifier":
if (n.local) { if (n.local) {
throw new Error("The ESTree ModuleSpecifier type should be abstract"); throw new Error("The ESTree ModuleSpecifier type should be abstract");
} }
@@ -800,7 +800,7 @@ function genericPrintNoParens(path, options, print) {
// Literal identifying the imported-from module. // Literal identifying the imported-from module.
return fromString(nodeStr(n.value, options), options); return fromString(nodeStr(n.value, options), options);
case "UnaryExpression": case "UnaryExpression":
parts.push(n.operator); parts.push(n.operator);
if (/[a-z]$/.test(n.operator)) if (/[a-z]$/.test(n.operator))
@@ -810,7 +810,7 @@ function genericPrintNoParens(path, options, print) {
return concat(parts); return concat(parts);
case "UpdateExpression": case "UpdateExpression":
parts.push(path.call(print, "argument"), n.operator); parts.push(path.call(print, "argument"), n.operator);
if (n.prefix) if (n.prefix)
@@ -830,11 +830,11 @@ function genericPrintNoParens(path, options, print) {
] ]
); );
case "NewExpression": case "NewExpression":
parts.push("new ", path.call(print, "callee")); parts.push("new ", path.call(print, "callee"));
var args = n.arguments; var args = n.arguments;
if (args) { if (args) {
parts.push(printArgumentsList(path, options, print)); parts.push(printArgumentsList(path, options, print));
} }
@@ -847,7 +847,7 @@ function genericPrintNoParens(path, options, print) {
}, },
"declarations" "declarations"
); );
parts = [ parts = [
n.kind, n.kind,
" ", " ",
@@ -861,7 +861,7 @@ function genericPrintNoParens(path, options, print) {
// We generally want to terminate all variable declarations with a // We generally want to terminate all variable declarations with a
// semicolon, except when they are children of for loops. // semicolon, except when they are children of for loops.
var parentNode = path.getParentNode(); var parentNode = path.getParentNode();
if ( if (
!namedTypes.ForStatement.check(parentNode) && !namedTypes.ForStatement.check(parentNode) &&
!namedTypes.ForInStatement.check(parentNode) && !namedTypes.ForInStatement.check(parentNode) &&
@@ -891,7 +891,7 @@ function genericPrintNoParens(path, options, print) {
// return concat(parts); // return concat(parts);
case "IfStatement": case "IfStatement":
const con = adjustClause(path.call(print, "consequent"), options); const con = adjustClause(path.call(print, "consequent"), options);
parts = [ parts = [
"if (", "if (",
group( group(
@@ -911,7 +911,7 @@ function genericPrintNoParens(path, options, print) {
if (n.alternate) { if (n.alternate) {
const hasBraces = getFirstString(con) === "{"; const hasBraces = getFirstString(con) === "{";
parts.push( parts.push(
(hasBraces ? " else" : "\nelse"), (hasBraces ? " else" : "\nelse"),
adjustClause(path.call(print, "alternate"), options) adjustClause(path.call(print, "alternate"), options)
@@ -998,7 +998,7 @@ function genericPrintNoParens(path, options, print) {
var doBody = concat([ "do", clause ]); var doBody = concat([ "do", clause ]);
var parts = [ doBody ]; var parts = [ doBody ];
const hasBraces = getFirstString(clause) === "{"; const hasBraces = getFirstString(clause) === "{";
if (hasBraces) if (hasBraces)
parts.push(" while"); parts.push(" while");
else else
@@ -1016,7 +1016,7 @@ else
); );
return concat([ "do {\n", statements.indent(options.tabWidth), "\n}" ]); return concat([ "do {\n", statements.indent(options.tabWidth), "\n}" ]);
case "BreakStatement": case "BreakStatement":
parts.push("break"); parts.push("break");
if (n.label) if (n.label)
@@ -1026,7 +1026,7 @@ else
return concat(parts); return concat(parts);
case "ContinueStatement": case "ContinueStatement":
parts.push("continue"); parts.push("continue");
if (n.label) if (n.label)
@@ -1040,7 +1040,7 @@ else
[ path.call(print, "label"), ":", hardline, path.call(print, "body") ] [ path.call(print, "label"), ":", hardline, path.call(print, "body") ]
); );
case "TryStatement": case "TryStatement":
parts.push("try ", path.call(print, "block")); parts.push("try ", path.call(print, "block"));
if (n.handler) { if (n.handler) {
@@ -1061,7 +1061,7 @@ else
return concat(parts); return concat(parts);
case "CatchClause": case "CatchClause":
parts.push("catch (", path.call(print, "param")); parts.push("catch (", path.call(print, "param"));
if (n.guard) if (n.guard)
@@ -1087,7 +1087,7 @@ else
] ]
); );
case "SwitchCase": case "SwitchCase":
if (n.test) if (n.test)
parts.push("case ", path.call(print, "test"), ":"); parts.push("case ", path.call(print, "test"), ":");
else else
@@ -1117,7 +1117,7 @@ else
case "DebuggerStatement": case "DebuggerStatement":
return fromString("debugger;"); return fromString("debugger;");
case "JSXAttribute": case "JSXAttribute":
parts.push(path.call(print, "name")); parts.push(path.call(print, "name"));
if (n.value) if (n.value)
@@ -1140,7 +1140,7 @@ else
return concat([ "{", path.call(print, "expression"), "}" ]); return concat([ "{", path.call(print, "expression"), "}" ]);
case "JSXElement": case "JSXElement":
var openingLines = path.call(print, "openingElement"); var openingLines = path.call(print, "openingElement");
if (n.openingElement.selfClosing) { if (n.openingElement.selfClosing) {
assert.ok(!n.closingElement); assert.ok(!n.closingElement);
@@ -1148,18 +1148,18 @@ else
} }
var children = []; var children = [];
path.map( path.map(
function(childPath) { function(childPath) {
var child = childPath.getValue(); var child = childPath.getValue();
if ( if (
namedTypes.Literal.check(child) && typeof child.value === "string" namedTypes.Literal.check(child) && typeof child.value === "string"
) { ) {
if (/\S/.test(child.value)) { if (/\S/.test(child.value)) {
const beginBreak = child.value.match(/^\s*\n/); const beginBreak = child.value.match(/^\s*\n/);
const endBreak = child.value.match(/\n\s*$/); const endBreak = child.value.match(/\n\s*$/);
children.push( children.push(
(beginBreak ? hardline : ""), (beginBreak ? hardline : ""),
child.value.replace(/^\s+|\s+$/g, ""), child.value.replace(/^\s+|\s+$/g, ""),
@@ -1209,7 +1209,7 @@ else
[ path.call(print, "annotation"), " ", path.call(print, "identifier") ] [ path.call(print, "annotation"), " ", path.call(print, "identifier") ]
); );
case "ClassBody": case "ClassBody":
if (n.body.length === 0) { if (n.body.length === 0) {
return fromString("{}"); return fromString("{}");
} }
@@ -1236,7 +1236,7 @@ else
] ]
); );
case "ClassPropertyDefinition": case "ClassPropertyDefinition":
parts.push("static ", path.call(print, "definition")); parts.push("static ", path.call(print, "definition"));
if (!namedTypes.MethodDefinition.check(n.definition)) if (!namedTypes.MethodDefinition.check(n.definition))
@@ -1244,12 +1244,12 @@ else
return concat(parts); return concat(parts);
case "ClassProperty": case "ClassProperty":
if (n.static) if (n.static)
parts.push("static "); parts.push("static ");
var key = path.call(print, "key"); var key = path.call(print, "key");
if (n.computed) { if (n.computed) {
key = concat([ "[", key, "]" ]); key = concat([ "[", key, "]" ]);
} else } else
@@ -1278,13 +1278,13 @@ else
return join(literalline, n.value.raw.split("\n")); return join(literalline, n.value.raw.split("\n"));
case "TemplateLiteral": case "TemplateLiteral":
var expressions = path.map(print, "expressions"); var expressions = path.map(print, "expressions");
parts.push("`"); parts.push("`");
path.each( path.each(
function(childPath) { function(childPath) {
var i = childPath.getName(); var i = childPath.getName();
parts.push(print(childPath)); parts.push(print(childPath));
if (i < expressions.length) { if (i < expressions.length) {
@@ -1332,7 +1332,7 @@ else
// Type Annotations for Facebook Flow, typically stripped out or // Type Annotations for Facebook Flow, typically stripped out or
// transformed away before printing. // transformed away before printing.
case "TypeAnnotation": case "TypeAnnotation":
if (n.typeAnnotation) { if (n.typeAnnotation) {
if (n.typeAnnotation.type !== "FunctionTypeAnnotation") { if (n.typeAnnotation.type !== "FunctionTypeAnnotation") {
parts.push(": "); parts.push(": ");
@@ -1403,7 +1403,7 @@ else
namedTypes.DeclareFunction.check(path.getParentNode(2))); namedTypes.DeclareFunction.check(path.getParentNode(2)));
var needsColon = isArrowFunctionTypeAnnotation && var needsColon = isArrowFunctionTypeAnnotation &&
namedTypes.TypeAnnotation.check(parent); namedTypes.TypeAnnotation.check(parent);
if (needsColon) { if (needsColon) {
parts.push(": "); parts.push(": ");
} }
@@ -1437,11 +1437,11 @@ else
[ path.call(print, "id"), path.call(print, "typeParameters") ] [ path.call(print, "id"), path.call(print, "typeParameters") ]
); );
case "DeclareInterface": case "DeclareInterface":
parts.push("declare "); parts.push("declare ");
case "InterfaceDeclaration": case "InterfaceDeclaration":
parts.push( parts.push(
fromString("interface ", options), fromString("interface ", options),
path.call(print, "id"), path.call(print, "id"),
@@ -1472,7 +1472,7 @@ else
case "NumberTypeAnnotation": case "NumberTypeAnnotation":
return fromString("number", options); return fromString("number", options);
case "ObjectTypeCallProperty": case "ObjectTypeCallProperty":
if (n.static) { if (n.static) {
parts.push("static "); parts.push("static ");
} }
@@ -1518,7 +1518,7 @@ else
case "StringLiteralTypeAnnotation": case "StringLiteralTypeAnnotation":
return fromString(nodeStr(n.value, options), options); return fromString(nodeStr(n.value, options), options);
case "NumberLiteralTypeAnnotation": case "NumberLiteralTypeAnnotation":
assert.strictEqual(typeof n.value, "number"); assert.strictEqual(typeof n.value, "number");
return fromString("" + n.value, options); return fromString("" + n.value, options);
@@ -1528,7 +1528,7 @@ else
case "TypeAlias": case "TypeAlias":
{ {
const parent = path.getParentNode(1); const parent = path.getParentNode(1);
if ( if (
n.type === "DeclareTypeAlias" || n.type === "DeclareTypeAlias" ||
parent && parent.type === "DeclareModule" parent && parent.type === "DeclareModule"
@@ -1562,18 +1562,18 @@ else
case "TypeParameter": case "TypeParameter":
switch (n.variance) { switch (n.variance) {
case "plus": case "plus":
parts.push("+"); parts.push("+");
break; break;
case "minus": case "minus":
parts.push("-"); parts.push("-");
break; break;
default: default:
} }
parts.push(path.call(print, "name")); parts.push(path.call(print, "name"));
if (n.bound) { if (n.bound) {
@@ -1652,11 +1652,11 @@ function printStatementSequence(path, options, print) {
namedTypes.ClassBody.check(path.getParentNode()); namedTypes.ClassBody.check(path.getParentNode());
let printed = []; let printed = [];
let prevAddSpacing = false; let prevAddSpacing = false;
path.map( path.map(
function(stmtPath, i) { function(stmtPath, i) {
var stmt = stmtPath.getValue(); var stmt = stmtPath.getValue();
// Just in case the AST has been modified to contain falsy // Just in case the AST has been modified to contain falsy
// "statements," it's safer simply to skip them. // "statements," it's safer simply to skip them.
if (!stmt) { if (!stmt) {
@@ -1672,7 +1672,7 @@ function printStatementSequence(path, options, print) {
const addSpacing = shouldAddSpacing(stmt); const addSpacing = shouldAddSpacing(stmt);
const stmtPrinted = print(stmtPath); const stmtPrinted = print(stmtPath);
const parts = []; const parts = [];
if (!prevAddSpacing && addSpacing && !isFirstStatement(stmtPath)) { if (!prevAddSpacing && addSpacing && !isFirstStatement(stmtPath)) {
parts.push(hardline); parts.push(hardline);
} }
@@ -1696,7 +1696,7 @@ function printMethod(path, options, print) {
var node = path.getNode(); var node = path.getNode();
var kind = node.kind; var kind = node.kind;
var parts = []; var parts = [];
if (node.type === "ObjectMethod" || node.type === "ClassMethod") { if (node.type === "ObjectMethod" || node.type === "ClassMethod") {
node.value = node; node.value = node;
} else { } else {
@@ -1718,7 +1718,7 @@ function printMethod(path, options, print) {
} }
var key = path.call(print, "key"); var key = path.call(print, "key");
if (node.computed) { if (node.computed) {
key = concat([ "[", key, "]" ]); key = concat([ "[", key, "]" ]);
} }
@@ -1746,7 +1746,7 @@ function printArgumentsList(path, options, print) {
var printed = path.map(print, "arguments"); var printed = path.map(print, "arguments");
var trailingComma = util.isTrailingCommaEnabled(options, "parameters"); var trailingComma = util.isTrailingCommaEnabled(options, "parameters");
var args; var args;
if (printed.length === 0) { if (printed.length === 0) {
args = ""; args = "";
} else } else
@@ -1773,13 +1773,13 @@ function printFunctionParams(path, print) {
var fun = path.getValue(); var fun = path.getValue();
// namedTypes.Function.assert(fun); // namedTypes.Function.assert(fun);
var printed = path.map(print, "params"); var printed = path.map(print, "params");
if (fun.defaults) { if (fun.defaults) {
path.each( path.each(
function(defExprPath) { function(defExprPath) {
var i = defExprPath.getName(); var i = defExprPath.getName();
var p = printed[i]; var p = printed[i];
if (p && defExprPath.getValue()) { if (p && defExprPath.getValue()) {
printed[i] = concat([ p, " = ", print(defExprPath) ]); printed[i] = concat([ p, " = ", print(defExprPath) ]);
} }
@@ -1798,7 +1798,7 @@ function printFunctionParams(path, print) {
function printObjectMethod(path, options, print) { function printObjectMethod(path, options, print) {
var objMethod = path.getValue(); var objMethod = path.getValue();
var parts = []; var parts = [];
if (objMethod.async) if (objMethod.async)
parts.push("async "); parts.push("async ");
@@ -1812,7 +1812,7 @@ function printObjectMethod(path, options, print) {
} }
var key = path.call(print, "key"); var key = path.call(print, "key");
if (objMethod.computed) { if (objMethod.computed) {
parts.push("[", key, "]"); parts.push("[", key, "]");
} else { } else {
@@ -1834,7 +1834,7 @@ function printObjectMethod(path, options, print) {
function printReturnType(path, print) { function printReturnType(path, print) {
const n = path.getValue(); const n = path.getValue();
const parts = [ path.call(print, "returnType") ]; const parts = [ path.call(print, "returnType") ];
if (n.predicate) { if (n.predicate) {
// The return type will already add the colon, but otherwise we // The return type will already add the colon, but otherwise we
// need to do it ourselves // need to do it ourselves
@@ -1848,7 +1848,7 @@ function printExportDeclaration(path, options, print) {
var decl = path.getValue(); var decl = path.getValue();
var parts = [ "export " ]; var parts = [ "export " ];
var shouldPrintSpaces = options.objectCurlySpacing; var shouldPrintSpaces = options.objectCurlySpacing;
namedTypes.Declaration.assert(decl); namedTypes.Declaration.assert(decl);
if (decl["default"] || decl.type === "ExportDefaultDeclaration") { if (decl["default"] || decl.type === "ExportDefaultDeclaration") {
@@ -1883,7 +1883,7 @@ function printExportDeclaration(path, options, print) {
function printFlowDeclaration(path, parts) { function printFlowDeclaration(path, parts) {
var parentExportDecl = util.getParentExportDeclaration(path); var parentExportDecl = util.getParentExportDeclaration(path);
if (parentExportDecl) { if (parentExportDecl) {
assert.strictEqual(parentExportDecl.type, "DeclareExportDeclaration"); assert.strictEqual(parentExportDecl.type, "DeclareExportDeclaration");
} else { } else {
@@ -1899,7 +1899,7 @@ function printFlowDeclaration(path, parts) {
function printClass(path, print) { function printClass(path, print) {
const n = path.getValue(); const n = path.getValue();
const parts = [ "class" ]; const parts = [ "class" ];
if (n.id) { if (n.id) {
parts.push(" ", path.call(print, "id"), path.call(print, "typeParameters")); parts.push(" ", path.call(print, "id"), path.call(print, "typeParameters"));
} }
@@ -1939,7 +1939,7 @@ function lastNonSpaceCharacter(lines) {
var pos = lines.lastPos(); var pos = lines.lastPos();
do { do {
var ch = lines.charAt(pos); var ch = lines.charAt(pos);
if (/\S/.test(ch)) if (/\S/.test(ch))
return ch; return ch;
} while (lines.prevPos(pos)); } while (lines.prevPos(pos));