From 9e7b02d50ec5ea933392466b46da68b4330f0a35 Mon Sep 17 00:00:00 2001 From: Lucas Azzola Date: Thu, 15 Jun 2017 20:19:01 +1000 Subject: [PATCH] Print {} in import if it's in the source, fixes #2145 (#2150) --- src/printer.js | 8 +++++++- tests/import/__snapshots__/jsfmt.spec.js.snap | 14 ++++++++++++++ tests/import/empty-import.js | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/import/empty-import.js diff --git a/src/printer.js b/src/printer.js index a4b82550..ce8ceafb 100644 --- a/src/printer.js +++ b/src/printer.js @@ -694,7 +694,13 @@ function genericPrintNoParens(path, options, print, args) { } parts.push(" ", "from "); - } else if (n.importKind && n.importKind === "type") { + } else if ( + (n.importKind && n.importKind === "type") || + // import {} from 'x' + /{\s*}/.test( + options.originalText.slice(util.locStart(n), util.locStart(n.source)) + ) + ) { parts.push("{} from "); } diff --git a/tests/import/__snapshots__/jsfmt.spec.js.snap b/tests/import/__snapshots__/jsfmt.spec.js.snap index b7055db9..ea75f73c 100644 --- a/tests/import/__snapshots__/jsfmt.spec.js.snap +++ b/tests/import/__snapshots__/jsfmt.spec.js.snap @@ -228,6 +228,20 @@ import { `; +exports[`empty-import.js 1`] = ` +import { } from '@types/googlemaps'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +import {} from "@types/googlemaps"; + +`; + +exports[`empty-import.js 2`] = ` +import { } from '@types/googlemaps'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +import {} from "@types/googlemaps"; + +`; + exports[`inline.js 1`] = ` import somethingSuperLongsomethingSuperLong from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' import {somethingSuperLongsomethingSuperLong} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' diff --git a/tests/import/empty-import.js b/tests/import/empty-import.js new file mode 100644 index 00000000..f08bd786 --- /dev/null +++ b/tests/import/empty-import.js @@ -0,0 +1 @@ +import { } from '@types/googlemaps';