Stabilize label comments (#1179)

Fixes #1160
master
Christopher Chedeau 2017-04-10 11:22:35 -07:00 committed by GitHub
parent 45796601c4
commit da7c97e0bb
3 changed files with 27 additions and 0 deletions

View File

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

View File

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

4
tests/label/comment.js Normal file
View File

@ -0,0 +1,4 @@
{
inf_leave: // goto emulation
for (;;) {}
}