From 93e8b15311cc88d30eadf8a34acbc062d0965f2b Mon Sep 17 00:00:00 2001 From: Eric Sakmar Date: Mon, 27 Aug 2018 22:02:40 -0400 Subject: [PATCH] verify the precedingNode type when handling import declaration comments (#5016) --- src/language-js/comments.js | 1 + tests/import/__snapshots__/jsfmt.spec.js.snap | 20 +++++++++++++++++++ tests/import/comments.js | 5 +++++ 3 files changed, 26 insertions(+) diff --git a/src/language-js/comments.js b/src/language-js/comments.js index ecb4e2fe..dd0fcfc0 100644 --- a/src/language-js/comments.js +++ b/src/language-js/comments.js @@ -660,6 +660,7 @@ function handleImportDeclarationComments( ) { if ( precedingNode && + precedingNode.type === "ImportSpecifier" && enclosingNode && enclosingNode.type === "ImportDeclaration" && privateUtil.hasNewline(text, options.locEnd(comment)) diff --git a/tests/import/__snapshots__/jsfmt.spec.js.snap b/tests/import/__snapshots__/jsfmt.spec.js.snap index e50e887e..756d0bcf 100644 --- a/tests/import/__snapshots__/jsfmt.spec.js.snap +++ b/tests/import/__snapshots__/jsfmt.spec.js.snap @@ -95,6 +95,11 @@ import { SelectionSetNode, /* tslint:enable */ } from 'graphql'; + +import x, { + // comment + y +} from 'z'; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import { //comment1 @@ -139,6 +144,11 @@ import { /* tslint:enable */ } from "graphql"; +import x, { + // comment + y +} from "z"; + `; exports[`comments.js - flow-verify 2`] = ` @@ -182,6 +192,11 @@ import { SelectionSetNode, /* tslint:enable */ } from 'graphql'; + +import x, { + // comment + y +} from 'z'; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import { //comment1 @@ -226,6 +241,11 @@ import { /* tslint:enable */ } from "graphql"; +import x, { + // comment + y +} from "z"; + `; exports[`empty-import.js - flow-verify 1`] = ` diff --git a/tests/import/comments.js b/tests/import/comments.js index 613d4253..856785db 100644 --- a/tests/import/comments.js +++ b/tests/import/comments.js @@ -38,3 +38,8 @@ import { SelectionSetNode, /* tslint:enable */ } from 'graphql'; + +import x, { + // comment + y +} from 'z';