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);
|
||||
}
|
||||
} 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];
|
||||
|
|
|
@ -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