Reprint printer.js

master
James Long 2017-01-04 22:27:25 -05:00
parent 835befebf5
commit f1feb24dff
1 changed files with 357 additions and 429 deletions

View File

@ -129,10 +129,10 @@ function Printer(originalOptions) {
var lines = print(FastPath.from(ast), true); var lines = print(FastPath.from(ast), true);
return new PrintResult( return new PrintResult(
lines.toString(options), lines.toString(options),
util.composeSourceMaps( util.composeSourceMaps(options.inputSourceMap, lines.getSourceMap(
options.inputSourceMap, options.sourceMapName,
lines.getSourceMap(options.sourceMapName, options.sourceRoot) options.sourceRoot
) ))
); );
}; };
@ -251,14 +251,12 @@ function genericPrintNoParens(path, options, print) {
); );
} }
parts.push( parts.push(path.call(
path.call(
function(bodyPath) { function(bodyPath) {
return printStatementSequence(bodyPath, options, print); return printStatementSequence(bodyPath, options, print);
}, },
"body" "body"
) ));
);
// Make sure the file always ends with a newline // Make sure the file always ends with a newline
parts.push(hardline); parts.push(hardline);
@ -274,33 +272,27 @@ function genericPrintNoParens(path, options, print) {
"ParenthesizedExpression": "ParenthesizedExpression":
return concat([ "(", path.call(print, "expression"), ")" ]); return concat([ "(", path.call(print, "expression"), ")" ]);
case "AssignmentExpression": case "AssignmentExpression":
return group( return group(concat([
concat(
[
path.call(print, "left"), path.call(print, "left"),
" ", " ",
n.operator, n.operator,
" ", " ",
path.call(print, "right") path.call(print, "right")
] ]));
)
);
case "BinaryExpression": case "BinaryExpression":
case "LogicalExpression": case "LogicalExpression":
return group( return group(concat([
concat(
[
path.call(print, "left"), path.call(print, "left"),
" ", " ",
n.operator, n.operator,
indent(options.tabWidth, concat([ line, path.call(print, "right") ])) indent(options.tabWidth, concat([ line, path.call(print, "right") ]))
] ]));
)
);
case "AssignmentPattern": case "AssignmentPattern":
return concat( return concat([
[ 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"));
@ -315,9 +307,11 @@ function genericPrintNoParens(path, options, print) {
return concat(parts); return concat(parts);
case "MetaProperty": case "MetaProperty":
return concat( return concat([
[ 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) {
@ -330,9 +324,11 @@ function genericPrintNoParens(path, options, print) {
case "Path": case "Path":
return fromString(".").join(n.body); return fromString(".").join(n.body);
case "Identifier": case "Identifier":
return concat( return concat([
[ n.name, (n.optional ? "?" : ""), path.call(print, "typeAnnotation") ] n.name,
); (n.optional ? "?" : ""),
path.call(print, "typeAnnotation")
]);
case "SpreadElement": case "SpreadElement":
case "SpreadElementPattern": case "SpreadElementPattern":
// Babel 6 for ObjectPattern // Babel 6 for ObjectPattern
@ -383,10 +379,10 @@ function genericPrintNoParens(path, options, print) {
) { ) {
parts.push(path.call(print, "params", 0)); parts.push(path.call(print, "params", 0));
} else { } else {
parts.push( parts.push(printFunctionParams(path, print, options), printReturnType(
printFunctionParams(path, print, options), path,
printReturnType(path, print) print
); ));
} }
parts.push(" => ", path.call(print, "body")); parts.push(" => ", path.call(print, "body"));
@ -582,12 +578,12 @@ function genericPrintNoParens(path, options, print) {
if (n.directives) { if (n.directives) {
path.each( path.each(
function(childPath) { function(childPath) {
parts.push( parts.push(indent(options.tabWidth, concat([
indent( line,
options.tabWidth, print(childPath),
concat([ line, print(childPath), ";", line ]) ";",
) line
); ])));
}, },
"directives" "directives"
); );
@ -624,9 +620,10 @@ function genericPrintNoParens(path, options, print) {
return concat(parts); return concat(parts);
case "CallExpression": case "CallExpression":
return concat( return concat([
[ path.call(print, "callee"), printArgumentsList(path, options, print) ] path.call(print, "callee"),
); printArgumentsList(path, options, print)
]);
case "ObjectExpression": case "ObjectExpression":
case "ObjectPattern": case "ObjectPattern":
case "ObjectTypeAnnotation": case "ObjectTypeAnnotation":
@ -648,43 +645,36 @@ 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(
function(childPath) { function(childPath) {
props.push(group(print(childPath))); props.push(group(print(childPath)));
}, },
field field
); );
} });
);
if (props.length === 0) { if (props.length === 0) {
return "{}"; return "{}";
} else { } else {
return multilineGroup( return multilineGroup(concat([
concat(
[
leftBrace, leftBrace,
indent( indent(options.tabWidth, concat([
options.tabWidth, (options.bracketSpacing ? line : softline),
concat([
options.bracketSpacing ? line : softline,
join(concat([ separator, line ]), props) join(concat([ separator, line ]), props)
]) ])),
), (options.bracketSpacing ? line : softline),
options.bracketSpacing ? line : softline,
rightBrace, rightBrace,
path.call(print, "typeAnnotation") path.call(print, "typeAnnotation")
] ]));
)
);
} }
case "PropertyPattern": case "PropertyPattern":
return concat( return concat([
[ path.call(print, "key"), ": ", path.call(print, "pattern") ] path.call(print, "key"),
); ": ",
path.call(print, "pattern")
]);
// Babel 6 // Babel 6
case "ObjectProperty": case "ObjectProperty":
case // Non-standard AST node type. case // Non-standard AST node type.
@ -726,26 +716,15 @@ function genericPrintNoParens(path, options, print) {
if (n.elements.length === 0) { if (n.elements.length === 0) {
parts.push("[]"); parts.push("[]");
} else { } else {
parts.push( parts.push(multilineGroup(concat([
multilineGroup(
concat(
[
"[", "[",
indent( indent(options.tabWidth, concat([
options.tabWidth,
concat(
[
line, line,
join(concat([ ",", line ]), path.map(print, "elements")) join(concat([ ",", line ]), path.map(print, "elements"))
] ])),
)
),
line, line,
"]" "]"
] ])));
)
)
);
} }
if (n.typeAnnotation) if (n.typeAnnotation)
@ -810,8 +789,7 @@ function genericPrintNoParens(path, options, print) {
return concat(parts); return concat(parts);
case "ConditionalExpression": case "ConditionalExpression":
return concat( return concat([
[
"(", "(",
path.call(print, "test"), path.call(print, "test"),
" ? ", " ? ",
@ -819,8 +797,7 @@ function genericPrintNoParens(path, options, print) {
" : ", " : ",
path.call(print, "alternate"), path.call(print, "alternate"),
")" ")"
] ]);
);
case "NewExpression": case "NewExpression":
parts.push("new ", path.call(print, "callee")); parts.push("new ", path.call(print, "callee"));
@ -844,10 +821,11 @@ function genericPrintNoParens(path, options, print) {
n.kind, n.kind,
" ", " ",
printed[0], printed[0],
indent( indent(options.tabWidth, concat(printed.slice(1).map(p => concat([
options.tabWidth, ",",
concat(printed.slice(1).map(p => concat([ ",", line, p ]))) line,
) p
]))))
]; ];
// We generally want to terminate all variable declarations with a // We generally want to terminate all variable declarations with a
@ -867,13 +845,18 @@ function genericPrintNoParens(path, options, print) {
return multilineGroup(concat(parts)); return multilineGroup(concat(parts));
case "VariableDeclarator": case "VariableDeclarator":
return (n.init ? concat( return (n.init ? concat([
[ path.call(print, "id"), " = ", path.call(print, "init") ] path.call(print, "id"),
) : path.call(print, "id")); " = ",
path.call(print, "init")
]) : path.call(print, "id"));
case "WithStatement": case "WithStatement":
return concat( return concat([
[ "with (", path.call(print, "object"), ") ", path.call(print, "body") ] "with (",
); path.call(print, "object"),
") ",
path.call(print, "body")
]);
// var con = adjustClause(path.call(print, "consequent"), options), // var con = adjustClause(path.call(print, "consequent"), options),
// parts = ["if (", path.call(print, "test"), ")", con]; // parts = ["if (", path.call(print, "test"), ")", con];
// if (n.alternate) // if (n.alternate)
@ -886,17 +869,13 @@ function genericPrintNoParens(path, options, print) {
parts = [ parts = [
"if (", "if (",
group( group(concat([
concat( indent(options.tabWidth, concat([
[ softline,
indent( path.call(print, "test")
options.tabWidth, ])),
concat([ softline, path.call(print, "test") ])
),
softline softline
] ])),
)
),
")", ")",
con con
]; ];
@ -904,25 +883,19 @@ 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"), adjustClause(
(hasBraces ? " else" : "\nelse"), path.call(print, "alternate"),
adjustClause(path.call(print, "alternate"), options) options
); ));
} }
return concat(parts); return concat(parts);
case "ForStatement": case "ForStatement":
// TODO Get the for (;;) case right. // TODO Get the for (;;) case right.
return concat( return concat([
[
"for (", "for (",
group( group(concat([
concat( indent(options.tabWidth, concat([
[
indent(
options.tabWidth,
concat(
[
softline, softline,
path.call(print, "init"), path.call(print, "init"),
";", ";",
@ -931,60 +904,47 @@ function genericPrintNoParens(path, options, print) {
";", ";",
line, line,
path.call(print, "update") path.call(print, "update")
] ])),
)
),
softline softline
] ])),
)
),
")", ")",
adjustClause(path.call(print, "body"), options) adjustClause(path.call(print, "body"), options)
] ]);
);
case "WhileStatement": case "WhileStatement":
return concat( return concat([
[
"while (", "while (",
path.call(print, "test"), path.call(print, "test"),
")", ")",
adjustClause(path.call(print, "body"), options) adjustClause(path.call(print, "body"), options)
] ]);
);
case "ForInStatement": case "ForInStatement":
// Note: esprima can't actually parse "for each (". // Note: esprima can't actually parse "for each (".
return concat( return concat([
[
(n.each ? "for each (" : "for ("), (n.each ? "for each (" : "for ("),
path.call(print, "left"), path.call(print, "left"),
" in ", " in ",
path.call(print, "right"), path.call(print, "right"),
")", ")",
adjustClause(path.call(print, "body"), options) adjustClause(path.call(print, "body"), options)
] ]);
);
case "ForOfStatement": case "ForOfStatement":
return concat( return concat([
[
"for (", "for (",
path.call(print, "left"), path.call(print, "left"),
" of ", " of ",
path.call(print, "right"), path.call(print, "right"),
")", ")",
adjustClause(path.call(print, "body"), options) adjustClause(path.call(print, "body"), options)
] ]);
);
case "ForAwaitStatement": case "ForAwaitStatement":
return concat( return concat([
[
"for await (", "for await (",
path.call(print, "left"), path.call(print, "left"),
" of ", " of ",
path.call(print, "right"), path.call(print, "right"),
")", ")",
adjustClause(path.call(print, "body"), options) adjustClause(path.call(print, "body"), options)
] ]);
);
case "DoWhileStatement": case "DoWhileStatement":
var clause = adjustClause(path.call(print, "body"), options); var clause = adjustClause(path.call(print, "body"), options);
var doBody = concat([ "do", clause ]); var doBody = concat([ "do", clause ]);
@ -1028,9 +988,12 @@ else
return concat(parts); return concat(parts);
case "LabeledStatement": case "LabeledStatement":
return concat( return concat([
[ 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"));
@ -1067,8 +1030,7 @@ else
return concat([ "throw ", path.call(print, "argument"), ";" ]); return concat([ "throw ", path.call(print, "argument"), ";" ]);
// Note: ignoring n.lexical because it has no printing consequences. // Note: ignoring n.lexical because it has no printing consequences.
case "SwitchStatement": case "SwitchStatement":
return concat( return concat([
[
"switch (", "switch (",
path.call(print, "discriminant"), path.call(print, "discriminant"),
") {", ") {",
@ -1076,8 +1038,7 @@ else
join(hardline, path.map(print, "cases")), join(hardline, path.map(print, "cases")),
hardline, hardline,
"}" "}"
] ]);
);
case "SwitchCase": case "SwitchCase":
if (n.test) if (n.test)
@ -1086,11 +1047,7 @@ else
parts.push("default:"); parts.push("default:");
if (n.consequent.length > 0) { if (n.consequent.length > 0) {
parts.push( parts.push(indent(options.tabWidth, concat([
indent(
options.tabWidth,
concat(
[
hardline, hardline,
path.call( path.call(
function(consequentPath) { function(consequentPath) {
@ -1098,10 +1055,7 @@ else
}, },
"consequent" "consequent"
) )
] ])));
)
)
);
} }
return concat(parts); return concat(parts);
@ -1119,13 +1073,13 @@ else
case "JSXIdentifier": case "JSXIdentifier":
return fromString(n.name, options); return fromString(n.name, options);
case "JSXNamespacedName": case "JSXNamespacedName":
return fromString(":").join( return fromString(
[ path.call(print, "namespace"), path.call(print, "name") ] ":"
); ).join([ path.call(print, "namespace"), path.call(print, "name") ]);
case "JSXMemberExpression": case "JSXMemberExpression":
return fromString(".").join( return fromString(
[ path.call(print, "object"), path.call(print, "property") ] "."
); ).join([ path.call(print, "object"), path.call(print, "property") ]);
case "JSXSpreadAttribute": case "JSXSpreadAttribute":
return concat([ "{...", path.call(print, "argument"), "}" ]); return concat([ "{...", path.call(print, "argument"), "}" ]);
case "JSXExpressionContainer": case "JSXExpressionContainer":
@ -1170,25 +1124,19 @@ else
var mostChildren = children.slice(0, -1); var mostChildren = children.slice(0, -1);
var closingLines = path.call(print, "closingElement"); var closingLines = path.call(print, "closingElement");
return concat( return concat([
[
openingLines, openingLines,
indent(options.tabWidth, concat(mostChildren)), indent(options.tabWidth, concat(mostChildren)),
util.getLast(children) || "", util.getLast(children) || "",
closingLines closingLines
] ]);
);
case "JSXOpeningElement": case "JSXOpeningElement":
return group( return group(concat([
concat(
[
"<", "<",
path.call(print, "name"), path.call(print, "name"),
concat(path.map(attr => concat([ " ", print(attr) ]), "attributes")), concat(path.map(attr => concat([ " ", print(attr) ]), "attributes")),
(n.selfClosing ? "/>" : ">") (n.selfClosing ? "/>" : ">")
] ]));
)
);
case "JSXClosingElement": case "JSXClosingElement":
return concat([ "</", path.call(print, "name"), ">" ]); return concat([ "</", path.call(print, "name"), ">" ]);
case "JSXText": case "JSXText":
@ -1196,22 +1144,20 @@ else
case "JSXEmptyExpression": case "JSXEmptyExpression":
return ""; return "";
case "TypeAnnotatedIdentifier": case "TypeAnnotatedIdentifier":
return concat( return concat([
[ 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("{}");
} }
return concat( return concat([
[
"{", "{",
indent( indent(options.tabWidth, concat([
options.tabWidth,
concat(
[
hardline, hardline,
path.call( path.call(
function(bodyPath) { function(bodyPath) {
@ -1219,13 +1165,10 @@ else
}, },
"body" "body"
) )
] ])),
)
),
hardline, hardline,
"}" "}"
] ]);
);
case "ClassPropertyDefinition": case "ClassPropertyDefinition":
parts.push("static ", path.call(print, "definition")); parts.push("static ", path.call(print, "definition"));
@ -1356,26 +1299,26 @@ else
case "DeclareClass": case "DeclareClass":
return printFlowDeclaration(path, printClass(path, print)); return printFlowDeclaration(path, printClass(path, print));
case "DeclareFunction": case "DeclareFunction":
return printFlowDeclaration( return printFlowDeclaration(path, [
path,
[
"function ", "function ",
path.call(print, "id"), path.call(print, "id"),
(n.predicate ? " " : ""), (n.predicate ? " " : ""),
path.call(print, "predicate"), path.call(print, "predicate"),
";" ";"
] ]);
);
case "DeclareModule": case "DeclareModule":
return printFlowDeclaration( return printFlowDeclaration(path, [
path, "module ",
[ "module ", path.call(print, "id"), " ", path.call(print, "body") ] path.call(print, "id"),
); " ",
path.call(print, "body")
]);
case "DeclareModuleExports": case "DeclareModuleExports":
return printFlowDeclaration( return printFlowDeclaration(path, [
path, "module.exports",
[ "module.exports", path.call(print, "typeAnnotation"), ";" ] path.call(print, "typeAnnotation"),
); ";"
]);
case "DeclareVariable": case "DeclareVariable":
return printFlowDeclaration(path, [ "var ", path.call(print, "id"), ";" ]); return printFlowDeclaration(path, [ "var ", path.call(print, "id"), ";" ]);
case "DeclareExportAllDeclaration": case "DeclareExportAllDeclaration":
@ -1415,18 +1358,17 @@ else
return group(concat(parts)); return group(concat(parts));
case "FunctionTypeParam": case "FunctionTypeParam":
return concat( return concat([
[
path.call(print, "name"), path.call(print, "name"),
(n.optional ? "?" : ""), (n.optional ? "?" : ""),
": ", ": ",
path.call(print, "typeAnnotation") path.call(print, "typeAnnotation")
] ]);
);
case "GenericTypeAnnotation": case "GenericTypeAnnotation":
return concat( return concat([
[ 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 ");
@ -1449,9 +1391,10 @@ else
return concat(parts); return concat(parts);
case "ClassImplements": case "ClassImplements":
case "InterfaceExtends": case "InterfaceExtends":
return concat( return concat([
[ path.call(print, "id"), path.call(print, "typeParameters") ] path.call(print, "id"),
); path.call(print, "typeParameters")
]);
case "IntersectionTypeAnnotation": case "IntersectionTypeAnnotation":
return join(" & ", path.map(print, "types")); return join(" & ", path.map(print, "types"));
case "NullableTypeAnnotation": case "NullableTypeAnnotation":
@ -1474,8 +1417,7 @@ else
case "ObjectTypeIndexer": case "ObjectTypeIndexer":
var variance = (n.variance === "plus" ? "+" : (n.variance === var variance = (n.variance === "plus" ? "+" : (n.variance ===
"minus" ? "-" : "")); "minus" ? "-" : ""));
return concat( return concat([
[
variance, variance,
"[", "[",
path.call(print, "id"), path.call(print, "id"),
@ -1483,8 +1425,7 @@ else
path.call(print, "key"), path.call(print, "key"),
"]: ", "]: ",
path.call(print, "value") path.call(print, "value")
] ]);
);
case "ObjectTypeProperty": case "ObjectTypeProperty":
var variance = (n.variance === "plus" ? "+" : (n.variance === var variance = (n.variance === "plus" ? "+" : (n.variance ===
"minus" ? "-" : "")); "minus" ? "-" : ""));
@ -1492,20 +1433,20 @@ else
// when to emit an arrow function or not. // when to emit an arrow function or not.
var isFunction = !n.variance && !n.optional && var isFunction = !n.variance && !n.optional &&
n.value.type === "FunctionTypeAnnotation"; n.value.type === "FunctionTypeAnnotation";
return concat( return concat([
[
(n.static ? "static " : ""), (n.static ? "static " : ""),
variance, variance,
path.call(print, "key"), path.call(print, "key"),
(n.optional ? "?" : ""), (n.optional ? "?" : ""),
(isFunction ? "" : ": "), (isFunction ? "" : ": "),
path.call(print, "value") path.call(print, "value")
] ]);
);
case "QualifiedTypeIdentifier": case "QualifiedTypeIdentifier":
return concat( return concat([
[ path.call(print, "qualification"), ".", path.call(print, "id") ] path.call(print, "qualification"),
); ".",
path.call(print, "id")
]);
case "StringLiteralTypeAnnotation": case "StringLiteralTypeAnnotation":
return fromString(nodeStr(n.value, options), options); return fromString(nodeStr(n.value, options), options);
case "NumberLiteralTypeAnnotation": case "NumberLiteralTypeAnnotation":
@ -1539,14 +1480,12 @@ else
return concat(parts); return concat(parts);
} }
case "TypeCastExpression": case "TypeCastExpression":
return concat( return concat([
[
"(", "(",
path.call(print, "expression"), path.call(print, "expression"),
path.call(print, "typeAnnotation"), path.call(print, "typeAnnotation"),
")" ")"
] ]);
);
case "TypeParameterDeclaration": case "TypeParameterDeclaration":
case "TypeParameterInstantiation": case "TypeParameterInstantiation":
return concat([ "<", join(", ", path.map(print, "params")), ">" ]); return concat([ "<", join(", ", path.map(print, "params")), ">" ]);
@ -1577,9 +1516,10 @@ else
return concat(parts); return concat(parts);
case "TypeofTypeAnnotation": case "TypeofTypeAnnotation":
return concat( return concat([
[ fromString("typeof ", options), path.call(print, "argument") ] fromString("typeof ", options),
); path.call(print, "argument")
]);
case "UnionTypeAnnotation": case "UnionTypeAnnotation":
return join(" | ", path.map(print, "types")); return join(" | ", path.map(print, "types"));
case "VoidTypeAnnotation": case "VoidTypeAnnotation":
@ -1644,8 +1584,7 @@ function printStatementSequence(path, options, print) {
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
@ -1677,8 +1616,7 @@ function printStatementSequence(path, options, print) {
printed.push(concat(parts)); printed.push(concat(parts));
prevAddSpacing = addSpacing; prevAddSpacing = addSpacing;
} });
);
return join(hardline, printed); return join(hardline, printed);
} }
@ -1755,34 +1693,28 @@ function printArgumentsList(path, options, print) {
const shouldBreak = printed.slice(0, -1).some(hasHardLine); const shouldBreak = printed.slice(0, -1).some(hasHardLine);
return conditionalGroup( return conditionalGroup(
[ [
concat([ concat([ "(", join(concat([ ", " ]), printed), ")" ]),
"(",
join(concat([ ", " ]), printed),
")"
]),
concat([ concat([
"(", "(",
join(concat([ ",", line ]), printed.slice(0, -1)), join(concat([ ",", line ]), printed.slice(0, -1)),
printed.length > 1 ? ", " : "", (printed.length > 1 ? ", " : ""),
group(util.getLast(printed), { shouldBreak: true }), group(util.getLast(printed), {shouldBreak: true}),
")" ")"
]), ]),
group( group(
concat([ concat([
"(", "(",
indent( indent(options.tabWidth, concat([
options.tabWidth, line,
concat([ line, join(concat([ ",", line ]), printed) ]) join(concat([ ",", line ]), printed)
), ])),
line, line,
")" ")"
]), ]),
{ shouldBreak: true } {shouldBreak: true}
), )
], ],
{ shouldBreak } {shouldBreak}
); );
} }
@ -1790,14 +1722,14 @@ function printArgumentsList(path, options, print) {
return group( return group(
concat([ concat([
"(", "(",
indent( indent(options.tabWidth, concat([
options.tabWidth, softline,
concat([ softline, join(concat([ ",", line ]), printed) ]) join(concat([ ",", line ]), printed)
), ])),
softline, softline,
")" ")"
]), ]),
{ shouldBreak } {shouldBreak}
); );
} }
@ -1826,10 +1758,10 @@ function printFunctionParams(path, print, options) {
return concat([ return concat([
"(", "(",
indent( indent(options.tabWidth, concat([
options.tabWidth, softline,
concat([ softline, join(concat([ ",", line ]), printed) ]) join(concat([ ",", line ]), printed)
), ])),
softline, softline,
")" ")"
]); ]);
@ -1943,21 +1875,20 @@ function printClass(path, print) {
} }
if (n.superClass) { if (n.superClass) {
parts.push( parts.push(" extends ", path.call(print, "superClass"), path.call(
" extends ", print,
path.call(print, "superClass"), "superTypeParameters"
path.call(print, "superTypeParameters") ));
);
} else } else
if (n.extends && n.extends.length > 0) { if (n.extends && n.extends.length > 0) {
parts.push(" extends ", join(", ", path.map(print, "extends"))); parts.push(" extends ", join(", ", path.map(print, "extends")));
} }
if (n["implements"] && n["implements"].length > 0) { if (n["implements"] && n["implements"].length > 0) {
parts.push( parts.push(" implements ", fromString(", ").join(path.map(
" implements ", print,
fromString(", ").join(path.map(print, "implements")) "implements"
); )));
} }
parts.push(" ", path.call(print, "body")); parts.push(" ", path.call(print, "body"));
@ -1984,12 +1915,9 @@ function lastNonSpaceCharacter(lines) {
} }
function swapQuotes(str) { function swapQuotes(str) {
return str.replace( return str.replace(/['"]/g, function(m) {
/['"]/g,
function(m) {
return (m === "\"" ? "'" : "\""); return (m === "\"" ? "'" : "\"");
} });
);
} }
function nodeStr(str, options) { function nodeStr(str, options) {