Skip to content

Commit

Permalink
fix: mfsu none export when only has __esModule export (umijs#7101)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc authored Aug 2, 2021
1 parent 6c21641 commit e16476e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,25 @@ exports.Foo = void 0;
).toEqual(`export * from 'foo';`);
});

test('__esModule only', async () => {
expect(
// ref: @%INNER_SCOPE%/radiant-util
await getDepReExportContent({
content: `
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./constant"), exports);
tslib_1.__exportStar(require("./number/math"), exports);
tslib_1.__exportStar(require("./number/format"), exports);
tslib_1.__exportStar(require("./date"), exports);
tslib_1.__exportStar(require("./collection/transform"), exports);
`,
importFrom: 'foo',
}),
).toEqual(`import _ from 'foo';\nexport default _;\nexport * from 'foo';`);
});

test('cjs mode esm parser', () => {
const file = `
Object.defineProperty(exports, "__esModule", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ export default _;`.trim();
}

if (!hasExports) {
ret.push(`import '${opts.importFrom}';`);
// 只有 __esModule 的全量导出
if (exports.includes('__esModule')) {
ret.push(`import _ from '${opts.importFrom}';`);
ret.push(`export default _;`);
ret.push(`export * from '${opts.importFrom}';`);
} else {
ret.push(`import '${opts.importFrom}';`);
}
}

return ret.join('\n');
Expand Down

0 comments on commit e16476e

Please sign in to comment.