Do not attach comments to EmptyStatements in try/catch (#763)

We skip EmptyStatement when generating the list of preceding/enclosing/following nodes but didn't do the same for the exceptions.

Fixes #695
master
Christopher Chedeau 2017-02-22 14:43:29 -08:00 committed by James Long
parent 9c558bfe71
commit 0241d97b77
4 changed files with 22 additions and 2 deletions

View File

@ -291,10 +291,11 @@ function addTrailingComment(node, comment) {
}
function addBlockStatementFirstComment(node, comment) {
if (node.body.length === 0) {
const body = node.body.filter(n => n.type !== "EmptyStatement");
if (body.length === 0) {
addDanglingComment(node, comment);
} else {
addLeadingComment(node.body[0], comment);
addLeadingComment(body[0], comment);
}
}

View File

@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`try.js 1`] = `
"try
/* missing comment */
{;}
finally {}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
try {
/* missing comment */
} finally {
}
"
`;

1
tests/try/jsfmt.spec.js Normal file
View File

@ -0,0 +1 @@
run_spec(__dirname);

4
tests/try/try.js Normal file
View File

@ -0,0 +1,4 @@
try
/* missing comment */
{;}
finally {}