Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderOMara committed Aug 3, 2024
1 parent 0a5c21a commit a7392dd
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
},

/**
Expand All @@ -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);
}
}
}
});

0 comments on commit a7392dd

Please sign in to comment.