From 83699b696d77ec903ad469aef0e6646f5a177efb Mon Sep 17 00:00:00 2001 From: Patryk Tomczyk <13100280+patzick@users.noreply.github.com> Date: Fri, 23 Feb 2024 17:27:26 +0100 Subject: [PATCH] fix(parseStaticImport): omit empty import names (#232) --- src/analyze.ts | 2 +- test/imports.test.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/analyze.ts b/src/analyze.ts index 89b8c8e..c09d1ff 100644 --- a/src/analyze.ts +++ b/src/analyze.ts @@ -128,7 +128,7 @@ export function parseStaticImport( const _match = namedImport.match(/^\s*(\S*) as (\S*)\s*$/); const source = _match?.[1] || namedImport.trim(); const importName = _match?.[2] || source; - if (!TYPE_RE.test(source)) { + if (source && !TYPE_RE.test(source)) { namedImports[source] = importName; } } diff --git a/test/imports.test.ts b/test/imports.test.ts index f7bf13f..3a83575 100644 --- a/test/imports.test.ts +++ b/test/imports.test.ts @@ -49,6 +49,12 @@ const staticTests: Record< member3: "alias3", }, }, + 'import { memberFormattedWithPrettier, } from "module-name";': { + specifier: "module-name", + namedImports: { + memberFormattedWithPrettier: "memberFormattedWithPrettier", + }, + }, 'import { member1, /* member0point5, */ member2 as alias2, member3 as alias3 } from "module-name";': { specifier: "module-name",