From a7392dde28a911e3e56608f57b4eb97c1112efa5 Mon Sep 17 00:00:00 2001 From: Alexander O'Mara Date: Sat, 3 Aug 2024 18:25:16 -0400 Subject: [PATCH] Code cleanup --- src/index.mjs | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/index.mjs b/src/index.mjs index bf28034..b434c6b 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -449,25 +449,9 @@ function resolveSource(src, state) { ? resolveSourceBarePath(src, state, bareImport) : resolveSourceBareMain(src, state, bareImport); } - return src; } -/** - * Visitor callback for declarations. - * - * @param {object} nodePath AST node. - * @param {object} state AST state. - */ -function visitDeclaration(nodePath, state) { - const {source} = nodePath.node; - if (!source) { - return; - } - - source.value = resolveSource(source.value, state); -} - /** * Babel plugin entry point. * @@ -482,7 +466,8 @@ export default () => ({ * @param {object} state AST state. */ ImportDeclaration(path, state) { - visitDeclaration(path, state); + const {source} = path.node; + source.value = resolveSource(source.value, state); }, /** @@ -492,17 +477,21 @@ export default () => ({ * @param {object} state AST state. */ ExportAllDeclaration(path, state) { - visitDeclaration(path, state); + const {source} = path.node; + source.value = resolveSource(source.value, state); }, /** - * Visitor callback for export names declarations. + * Visitor callback for export named declarations. * * @param {object} path AST node. * @param {object} state AST state. */ ExportNamedDeclaration(path, state) { - visitDeclaration(path, state); + const {source} = path.node; + if (source) { + source.value = resolveSource(source.value, state); + } } } });