Skip to content

Commit

Permalink
[systemjs] Fix: export star alongside with single export named
Browse files Browse the repository at this point in the history
  • Loading branch information
shrinktofit committed Jan 12, 2021
1 parent cba64f9 commit 85757c4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 25 deletions.
52 changes: 27 additions & 25 deletions packages/babel-plugin-transform-modules-systemjs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,36 @@ function constructExportCall(
stringSpecifiers: Set<string>,
) {
const statements = [];
if (exportNames.length === 1) {
statements.push(
t.expressionStatement(
t.callExpression(exportIdent, [
t.stringLiteral(exportNames[0]),
exportValues[0],
]),
),
);
} else if (!exportStarTarget) {
const objectProperties = [];
for (let i = 0; i < exportNames.length; i++) {
const exportName = exportNames[i];
const exportValue = exportValues[i];
objectProperties.push(
t.objectProperty(
stringSpecifiers.has(exportName)
? t.stringLiteral(exportName)
: t.identifier(exportName),
exportValue,
if (!exportStarTarget) {
if (exportNames.length === 1) {
statements.push(
t.expressionStatement(
t.callExpression(exportIdent, [
t.stringLiteral(exportNames[0]),
exportValues[0],
]),
),
);
} else {
const objectProperties = [];
for (let i = 0; i < exportNames.length; i++) {
const exportName = exportNames[i];
const exportValue = exportValues[i];
objectProperties.push(
t.objectProperty(
stringSpecifiers.has(exportName)
? t.stringLiteral(exportName)
: t.identifier(exportName),
exportValue,
),
);
}
statements.push(
t.expressionStatement(
t.callExpression(exportIdent, [t.objectExpression(objectProperties)]),
),
);
}
statements.push(
t.expressionStatement(
t.callExpression(exportIdent, [t.objectExpression(objectProperties)]),
),
);
} else {
const exportObj = path.scope.generateUid("exportObj");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { default } from 'foo';
export * from 'foo';

export { a, b } from 'bar';
export * from 'bar';
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
System.register(["foo", "bar"], function (_export, _context) {
"use strict";

return {
setters: [function (_foo) {
var _exportObj = {};

for (var _key in _foo) {
if (_key !== "default" && _key !== "__esModule") _exportObj[_key] = _foo[_key];
}

_exportObj.default = _foo.default;

_export(_exportObj);
}, function (_bar) {
var _exportObj2 = {};

for (var _key2 in _bar) {
if (_key2 !== "default" && _key2 !== "__esModule") _exportObj2[_key2] = _bar[_key2];
}

_exportObj2.a = _bar.a;
_exportObj2.b = _bar.b;

_export(_exportObj2);
}],
execute: function () {}
};
});

0 comments on commit 85757c4

Please sign in to comment.