diff --git a/src/comments.js b/src/comments.js index 4897381e..54be8dd8 100644 --- a/src/comments.js +++ b/src/comments.js @@ -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); } } diff --git a/tests/try/__snapshots__/jsfmt.spec.js.snap b/tests/try/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 00000000..089c262f --- /dev/null +++ b/tests/try/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`try.js 1`] = ` +"try +/* missing comment */ +{;} +finally {} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +try { + /* missing comment */ +} finally { +} +" +`; diff --git a/tests/try/jsfmt.spec.js b/tests/try/jsfmt.spec.js new file mode 100644 index 00000000..989047bc --- /dev/null +++ b/tests/try/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname); diff --git a/tests/try/try.js b/tests/try/try.js new file mode 100644 index 00000000..8bc21ad0 --- /dev/null +++ b/tests/try/try.js @@ -0,0 +1,4 @@ +try +/* missing comment */ +{;} +finally {}