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 #618master
parent
76e599ec97
commit
abbf0b4c81
|
@ -170,12 +170,14 @@ function attach(comments, ast, text) {
|
||||||
addDanglingComment(ast, comment);
|
addDanglingComment(ast, comment);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, text exists both before and after the comment on
|
if (handleIfStatementComments(enclosingNode, followingNode, comment)) {
|
||||||
// the same line. If there is both a preceding and following
|
// We're good
|
||||||
// node, use a tie-breaking algorithm to determine if it should
|
} else if (precedingNode && followingNode) {
|
||||||
// be attached to the next or previous node. In the last case,
|
// Otherwise, text exists both before and after the comment on
|
||||||
// simply attach the right node;
|
// the same line. If there is both a preceding and following
|
||||||
if (precedingNode && followingNode) {
|
// 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;
|
const tieCount = tiesToBreak.length;
|
||||||
if (tieCount > 0) {
|
if (tieCount > 0) {
|
||||||
var lastTie = tiesToBreak[tieCount - 1];
|
var lastTie = tiesToBreak[tieCount - 1];
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"
|
||||||
|
`;
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
run_spec(__dirname);
|
Loading…
Reference in New Issue