Fix unstable comments in assignment pattern (#1055)
* Add handleAssignmentPatternComments print function. * Add new test cases.master
parent
553966345a
commit
389d9d0fad
|
@ -166,7 +166,8 @@ function attach(comments, ast, text, options) {
|
|||
comment
|
||||
) ||
|
||||
handleOnlyComments(enclosingNode, ast, comment, isLastComment) ||
|
||||
handleImportDeclarationComments(enclosingNode, precedingNode, comment)
|
||||
handleImportDeclarationComments(enclosingNode, precedingNode, comment) ||
|
||||
handleAssignmentPatternComments(enclosingNode, comment)
|
||||
) {
|
||||
// We're good
|
||||
} else if (followingNode) {
|
||||
|
@ -657,6 +658,14 @@ function handleImportDeclarationComments(enclosingNode, precedingNode, comment)
|
|||
return false;
|
||||
}
|
||||
|
||||
function handleAssignmentPatternComments(enclosingNode, comment) {
|
||||
if (enclosingNode && enclosingNode.type === "AssignmentPattern") {
|
||||
addLeadingComment(enclosingNode, comment);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function printComment(commentPath) {
|
||||
const comment = commentPath.getValue();
|
||||
comment.printed = true;
|
||||
|
|
|
@ -39,6 +39,22 @@ var fnString = // Comment
|
|||
|
||||
var fnString = // Comment
|
||||
'some' + 'long' + 'string';
|
||||
|
||||
let f = (
|
||||
a =
|
||||
//comment
|
||||
b
|
||||
) => {};
|
||||
|
||||
let f = (
|
||||
a = //comment
|
||||
b
|
||||
) => {};
|
||||
|
||||
let f = (
|
||||
a =
|
||||
b //comment
|
||||
) => {};
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
fnString =
|
||||
// Comment
|
||||
|
@ -88,6 +104,19 @@ var fnString = // Comment
|
|||
|
||||
var fnString = // Comment
|
||||
\\"some\\" + \\"long\\" + \\"string\\";
|
||||
|
||||
let f = (
|
||||
//comment
|
||||
a = b
|
||||
) => {};
|
||||
|
||||
let f = (
|
||||
a = b //comment
|
||||
) => {};
|
||||
|
||||
let f = (
|
||||
a = b //comment
|
||||
) => {};
|
||||
"
|
||||
`;
|
||||
|
||||
|
@ -130,6 +159,22 @@ var fnString = // Comment
|
|||
|
||||
var fnString = // Comment
|
||||
'some' + 'long' + 'string';
|
||||
|
||||
let f = (
|
||||
a =
|
||||
//comment
|
||||
b
|
||||
) => {};
|
||||
|
||||
let f = (
|
||||
a = //comment
|
||||
b
|
||||
) => {};
|
||||
|
||||
let f = (
|
||||
a =
|
||||
b //comment
|
||||
) => {};
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
fnString =
|
||||
// Comment
|
||||
|
@ -179,5 +224,18 @@ var fnString = // Comment
|
|||
|
||||
var fnString = // Comment
|
||||
\\"some\\" + \\"long\\" + \\"string\\";
|
||||
|
||||
let f = (
|
||||
//comment
|
||||
a = b
|
||||
) => {};
|
||||
|
||||
let f = (
|
||||
a = b //comment
|
||||
) => {};
|
||||
|
||||
let f = (
|
||||
a = b //comment
|
||||
) => {};
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -36,3 +36,19 @@ var fnString = // Comment
|
|||
|
||||
var fnString = // Comment
|
||||
'some' + 'long' + 'string';
|
||||
|
||||
let f = (
|
||||
a =
|
||||
//comment
|
||||
b
|
||||
) => {};
|
||||
|
||||
let f = (
|
||||
a = //comment
|
||||
b
|
||||
) => {};
|
||||
|
||||
let f = (
|
||||
a =
|
||||
b //comment
|
||||
) => {};
|
||||
|
|
Loading…
Reference in New Issue