Stabilize comments inside of if/then/else before { (#672)

We already have the logic for fixing if/then/else comments but those ones are triggering another codepath.

Fixes #618
master
Christopher Chedeau 2017-02-13 06:55:54 -08:00 committed by James Long
parent 76e599ec97
commit abbf0b4c81
4 changed files with 119 additions and 6 deletions

View File

@ -170,12 +170,14 @@ function attach(comments, ast, text) {
addDanglingComment(ast, comment);
}
} else {
// Otherwise, text exists both before and after the comment on
// the same line. If there is both a preceding and following
// node, use a tie-breaking algorithm to determine if it should
// be attached to the next or previous node. In the last case,
// simply attach the right node;
if (precedingNode && followingNode) {
if (handleIfStatementComments(enclosingNode, followingNode, comment)) {
// We're good
} else if (precedingNode && followingNode) {
// Otherwise, text exists both before and after the comment on
// the same line. If there is both a preceding and following
// node, use a tie-breaking algorithm to determine if it should
// be attached to the next or previous node. In the last case,
// simply attach the right node;
const tieCount = tiesToBreak.length;
if (tieCount > 0) {
var lastTie = tiesToBreak[tieCount - 1];

View File

@ -0,0 +1,73 @@
exports[`test if_comments.js 1`] = `
"async function f() {
if (untrackedChoice === 0) /* Cancel */ {
return null;
} else if (untrackedChoice === 1) /* Add */ {
await repository.addAll(Array.from(untrackedChanges.keys()));
shouldAmend = true;
} else if (untrackedChoice === 2) /* Allow Untracked */ {
allowUntracked = true;
}
}
async function f() {
if (untrackedChoice === 0)
/* Cancel */ {
return null;
}
else if (untrackedChoice === 1)
/* Add */ {
await repository.addAll(Array.from(untrackedChanges.keys()));
shouldAmend = true;
}
else if (untrackedChoice === 2)
/* Allow Untracked */ {
allowUntracked = true;
}
}
async function f() {
if (untrackedChoice === 0) {
/* Cancel */ return null;
} else if (untrackedChoice === 1) {
/* Add */ await repository.addAll(Array.from(untrackedChanges.keys()));
shouldAmend = true;
} else if (untrackedChoice === 2) {
/* Allow Untracked */ allowUntracked = true;
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
async function f() {
if (untrackedChoice === 0) {
/* Cancel */ return null;
} else if (untrackedChoice === 1) {
/* Add */ await repository.addAll(Array.from(untrackedChanges.keys()));
shouldAmend = true;
} else if (untrackedChoice === 2) {
/* Allow Untracked */ allowUntracked = true;
}
}
async function f() {
if (untrackedChoice === 0) {
/* Cancel */ return null;
} else if (untrackedChoice === 1) {
/* Add */ await repository.addAll(Array.from(untrackedChanges.keys()));
shouldAmend = true;
} else if (untrackedChoice === 2) {
/* Allow Untracked */ allowUntracked = true;
}
}
async function f() {
if (untrackedChoice === 0) {
/* Cancel */ return null;
} else if (untrackedChoice === 1) {
/* Add */ await repository.addAll(Array.from(untrackedChanges.keys()));
shouldAmend = true;
} else if (untrackedChoice === 2) {
/* Allow Untracked */ allowUntracked = true;
}
}
"
`;

View File

@ -0,0 +1,37 @@
async function f() {
if (untrackedChoice === 0) /* Cancel */ {
return null;
} else if (untrackedChoice === 1) /* Add */ {
await repository.addAll(Array.from(untrackedChanges.keys()));
shouldAmend = true;
} else if (untrackedChoice === 2) /* Allow Untracked */ {
allowUntracked = true;
}
}
async function f() {
if (untrackedChoice === 0)
/* Cancel */ {
return null;
}
else if (untrackedChoice === 1)
/* Add */ {
await repository.addAll(Array.from(untrackedChanges.keys()));
shouldAmend = true;
}
else if (untrackedChoice === 2)
/* Allow Untracked */ {
allowUntracked = true;
}
}
async function f() {
if (untrackedChoice === 0) {
/* Cancel */ return null;
} else if (untrackedChoice === 1) {
/* Add */ await repository.addAll(Array.from(untrackedChanges.keys()));
shouldAmend = true;
} else if (untrackedChoice === 2) {
/* Allow Untracked */ allowUntracked = true;
}
}

View File

@ -0,0 +1 @@
run_spec(__dirname);