diff --git a/src/comments.js b/src/comments.js index 5b8bc1a9..aa89792e 100644 --- a/src/comments.js +++ b/src/comments.js @@ -196,6 +196,7 @@ function attach(comments, ast, text, options) { handleTemplateLiteralComments(enclosingNode, comment) || handleIfStatementComments(enclosingNode, followingNode, comment) || handleClassComments(enclosingNode, comment) || + handleLabeledStatementComments(enclosingNode, comment) || handleCallExpressionComments(precedingNode, enclosingNode, comment) || handlePropertyComments(enclosingNode, comment) || handleExportNamedDeclarationComments(enclosingNode, comment) || @@ -578,6 +579,14 @@ function handleObjectPropertyComments(enclosingNode, comment) { return false; } +function handleLabeledStatementComments(enclosingNode, comment) { + if (enclosingNode && enclosingNode.type === "LabeledStatement") { + addLeadingComment(enclosingNode, comment); + return true; + } + return false; +} + function handleCallExpressionComments(precedingNode, enclosingNode, comment) { if ( enclosingNode && diff --git a/tests/label/__snapshots__/jsfmt.spec.js.snap b/tests/label/__snapshots__/jsfmt.spec.js.snap index 2be86bcb..6677c80e 100644 --- a/tests/label/__snapshots__/jsfmt.spec.js.snap +++ b/tests/label/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`comment.js 1`] = ` +"{ + inf_leave: // goto emulation + for (;;) {} +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +{ + // goto emulation + inf_leave: for (;;) { + } +} +" +`; + exports[`empty_label.js 1`] = ` "a:; b diff --git a/tests/label/comment.js b/tests/label/comment.js new file mode 100644 index 00000000..45e9363f --- /dev/null +++ b/tests/label/comment.js @@ -0,0 +1,4 @@ +{ + inf_leave: // goto emulation + for (;;) {} +}