Handle ContinueStatement and BreakStatement comments (#4279)

master
Lucas Duailibe 2018-04-07 13:38:37 -03:00 committed by GitHub
parent 4bc80d8c64
commit f3626611a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 1 deletions

View File

@ -135,7 +135,8 @@ function handleRemainingComment(comment, text, options, ast, isLastComment) {
precedingNode,
comment,
options
)
) ||
handleBreakAndContinueStatementComments(enclosingNode, comment)
) {
return true;
}
@ -553,6 +554,19 @@ function handleLabeledStatementComments(enclosingNode, comment) {
return false;
}
function handleBreakAndContinueStatementComments(enclosingNode, comment) {
if (
enclosingNode &&
(enclosingNode.type === "ContinueStatement" ||
enclosingNode.type === "BreakStatement") &&
!enclosingNode.label
) {
addTrailingComment(enclosingNode, comment);
return true;
}
return false;
}
function handleCallExpressionComments(precedingNode, enclosingNode, comment) {
if (
enclosingNode &&

View File

@ -82,6 +82,33 @@ exports[`blank.js 1`] = `
`;
exports[`break-continue-statements.js 1`] = `
for (;;) {
break /* comment */;
continue /* comment */;
}
loop: for (;;) {
break /* comment */ loop;
break loop /* comment */;
continue /* comment */ loop;
continue loop /* comment */;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for (;;) {
break; /* comment */
continue; /* comment */
}
loop: for (;;) {
break /* comment */ loop;
break loop /* comment */;
continue /* comment */ loop;
continue loop /* comment */;
}
`;
exports[`call_comment.js 1`] = `
render( // Warm any cache
<ChildUpdates renderAnchor={true} anchorClassOn={true} />,

View File

@ -0,0 +1,11 @@
for (;;) {
break /* comment */;
continue /* comment */;
}
loop: for (;;) {
break /* comment */ loop;
break loop /* comment */;
continue /* comment */ loop;
continue loop /* comment */;
}