Fix unstable comments in assignment pattern (#1055)

* Add handleAssignmentPatternComments print function.

* Add new test cases.
master
Davy Duperron 2017-03-21 02:49:42 +01:00 committed by Christopher Chedeau
parent 553966345a
commit 389d9d0fad
3 changed files with 84 additions and 1 deletions

View File

@ -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;

View File

@ -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
) => {};
"
`;

View File

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