@@ -4,6 +4,7 @@ const {default: babelTraverse} = require("@babel/traverse");
44const { default : generator } = require ( "@babel/generator" ) ;
55const { getRelativePath} = require ( "./files" ) ;
66const fs = require ( "fs" ) . promises ;
7+ const _ = require ( "lodash" ) ;
78
89
910function replaceRequirePaths ( code , currentPath , testFilePath ) {
@@ -52,13 +53,21 @@ async function getAstFromFilePath(filePath) {
5253}
5354
5455async 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