Rely on .space and .newline behavior instead of explicit format checks.
This commit is contained in:
parent
68bc3d7dfb
commit
0e05e9f216
@ -21,7 +21,7 @@ export function BlockStatement(node: Object) {
|
||||
if (node.directives && node.directives.length) this.newline();
|
||||
|
||||
this.printSequence(node.body, node, { indent: true });
|
||||
if (!this.format.retainLines && !this.format.concise) this.removeTrailingNewline();
|
||||
this.removeTrailingNewline();
|
||||
|
||||
this.source("end", node.loc);
|
||||
this.rightBrace();
|
||||
|
||||
@ -89,6 +89,8 @@ export function Decorator(node: Object) {
|
||||
function commaSeparatorNewline() {
|
||||
this.token(",");
|
||||
this.newline();
|
||||
|
||||
if (!this.endsWith("\n")) this.space();
|
||||
}
|
||||
|
||||
export function CallExpression(node: Object) {
|
||||
@ -97,7 +99,7 @@ export function CallExpression(node: Object) {
|
||||
|
||||
this.token("(");
|
||||
|
||||
let isPrettyCall = node._prettyCall && !this.format.retainLines && !this.format.compact;
|
||||
let isPrettyCall = node._prettyCall;
|
||||
|
||||
let separator;
|
||||
if (isPrettyCall) {
|
||||
|
||||
@ -209,14 +209,14 @@ function variableDeclarationIdent() {
|
||||
// "let " or "var " indentation.
|
||||
this.token(",");
|
||||
this.newline();
|
||||
for (let i = 0; i < 4; i++) this.space(true);
|
||||
if (this.endsWith("\n")) for (let i = 0; i < 4; i++) this.space(true);
|
||||
}
|
||||
|
||||
function constDeclarationIdent() {
|
||||
// "const " indentation.
|
||||
this.token(",");
|
||||
this.newline();
|
||||
for (let i = 0; i < 6; i++) this.space(true);
|
||||
if (this.endsWith("\n")) for (let i = 0; i < 6; i++) this.space(true);
|
||||
}
|
||||
|
||||
export function VariableDeclaration(node: Object, parent: Object) {
|
||||
@ -247,7 +247,7 @@ export function VariableDeclaration(node: Object, parent: Object) {
|
||||
//
|
||||
|
||||
let separator;
|
||||
if (!this.format.compact && !this.format.concise && hasInits && !this.format.retainLines) {
|
||||
if (hasInits) {
|
||||
separator = node.kind === "const" ? constDeclarationIdent : variableDeclarationIdent;
|
||||
}
|
||||
|
||||
|
||||
@ -512,7 +512,7 @@ export default class Printer {
|
||||
|
||||
if (!this.endsWith("[") && !this.endsWith("{")) this.space();
|
||||
|
||||
let val = comment.type === "CommentLine" ? `//${comment.value}` : `/*${comment.value}*/`;
|
||||
let val = comment.type === "CommentLine" ? `//${comment.value}\n` : `/*${comment.value}*/`;
|
||||
|
||||
//
|
||||
if (comment.type === "CommentBlock" && this.format.indent.adjustMultilineComment) {
|
||||
@ -526,19 +526,13 @@ export default class Printer {
|
||||
val = val.replace(/\n(?!$)/g, `\n${repeat(" ", indentSize)}`);
|
||||
}
|
||||
|
||||
// force a newline for line comments when retainLines is set in case the next printed node
|
||||
// doesn't catch up
|
||||
if ((this.format.compact || this.format.concise || this.format.retainLines) &&
|
||||
comment.type === "CommentLine") {
|
||||
val += "\n";
|
||||
}
|
||||
|
||||
//
|
||||
this.token(val);
|
||||
|
||||
// whitespace after
|
||||
this.newline((this._whitespace ? this._whitespace.getNewlinesAfter(comment) : 0) ||
|
||||
(comment.type === "CommentLine" ? 1 : 0));
|
||||
this.newline((this._whitespace ? this._whitespace.getNewlinesAfter(comment) : 0) +
|
||||
// Subtract one to account for the line force-added above.
|
||||
(comment.type === "CommentLine" ? -1 : 0));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
function test() {}
|
||||
|
||||
// Copyright (C) 2012 Yusuke Suzuki <utatane.tea@gmail.com>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user