Skip to content

Commit

Permalink
refactor: code (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Jun 11, 2020
1 parent 44944a2 commit bed32ac
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ function resolveExports(type, item) {
result = {
syntax: splittedItem[0],
name: splittedItem[1],
// eslint-disable-next-line no-undefined
alias: splittedItem[2] ? splittedItem[2] : undefined,
alias:
// eslint-disable-next-line no-undefined
typeof splittedItem[2] !== 'undefined' ? splittedItem[2] : undefined,
};
}
} else {
Expand Down Expand Up @@ -70,16 +71,16 @@ function resolveExports(type, item) {
}

function getExports(type, exports) {
let result = [];
let result;

if (typeof exports === 'string') {
result.push(resolveExports(type, exports));
if (Array.isArray(exports)) {
result = exports.map((item) => resolveExports(type, item));
} else {
result = [].concat(exports).map((item) => resolveExports(type, item));
result = [resolveExports(type, exports)];
}

const hasMultipleDefault = result.filter(
(item) => item.syntax === 'default' || item.syntax === 'single'
({ syntax }) => syntax === 'default' || syntax === 'single'
);

if (hasMultipleDefault.length > 1) {
Expand All @@ -97,10 +98,10 @@ function renderExports(loaderContext, type, exports) {
let code = '';

const defaultExport = exports.filter(
(item) => item.syntax === 'default' || item.syntax === 'single'
({ syntax }) => syntax === 'default' || syntax === 'single'
);
const namedExports = exports.filter(
(item) => item.syntax === 'named' || item.syntax === 'multiple'
({ syntax }) => syntax === 'named' || syntax === 'multiple'
);

if (defaultExport.length > 0) {
Expand Down

0 comments on commit bed32ac

Please sign in to comment.