Skip to content

Commit ef34fbc

Browse files
author
Zvonimir Sabljic
committed
Fix for incorrect setting the moduleType
1 parent 6eb440b commit ef34fbc

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/utils/code.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {default: babelTraverse} = require("@babel/traverse");
44
const {default: generator} = require("@babel/generator");
55
const {getRelativePath} = require("./files");
66
const fs = require("fs").promises;
7+
const _ = require("lodash");
78

89

910
function replaceRequirePaths(code, currentPath, testFilePath) {
@@ -52,13 +53,21 @@ async function getAstFromFilePath(filePath) {
5253
}
5354

5455
async function getModuleTypeFromFilePath(ast) {
55-
let moduleType = 'unknown';
56+
let moduleType = 'CommonJS';
5657

5758
babelTraverse(ast, {
5859
ImportDeclaration(path) {
5960
moduleType = 'ES6';
6061
path.stop(); // Stop traversal when an ESM statement is found
6162
},
63+
ExportNamedDeclaration(path) {
64+
moduleType = 'ES6';
65+
path.stop(); // Stop traversal when an ESM statement is found
66+
},
67+
ExportDefaultDeclaration(path) {
68+
moduleType = 'ES6';
69+
path.stop(); // Stop traversal when an ESM statement is found
70+
},
6271
CallExpression(path) {
6372
if (path.node.callee.name === 'require') {
6473
moduleType = 'CommonJS';
@@ -138,10 +147,9 @@ function getRelatedFunctions(node, ast, filePath, functionList) {
138147
}
139148
let functionFromList = functionList[requiredPath + ':' + funcName];
140149
if (functionFromList) {
141-
relatedFunctions.push({
142-
fileName: requiredPath,
143-
funcName
144-
});
150+
relatedFunctions.push(_.extend(functionFromList, {
151+
fileName: requiredPath
152+
}));
145153
}
146154
}
147155

0 commit comments

Comments
 (0)