Skip to content

Commit

Permalink
feat: simplified get module export
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Jan 9, 2024
1 parent a92b445 commit 6a759c7
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/loader/built-in/module/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { BaseError } from 'ebec';
import { hasOwnProperty, isObject } from '../../../utils';
import type { LoaderFilterFn, ModuleExport } from './type';

export function isJestRuntimeEnvironment() : boolean {
Expand Down Expand Up @@ -38,28 +37,19 @@ export function getModuleExport(
throw new BaseError('Cannot find specific module export.');
}

let value: any;

if (
hasOwnProperty(data, '__esModule') &&
// eslint-disable-next-line no-underscore-dangle
!!data.__esModule &&
hasOwnProperty(data, 'default')
) {
value = data.default;
} else {
value = data;
}

if (
isObject(value) &&
hasOwnProperty(value, 'default')
typeof data.__esModule !== 'undefined' &&
typeof data.default !== 'undefined'
) {
value = value.default;
return {
key: 'default',
value: data.default,
};
}

return {
key: 'default',
value,
value: data,
};
}

0 comments on commit 6a759c7

Please sign in to comment.