Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take chunk export mode into account when reexporting default #2727

Merged
merged 1 commit into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 39 additions & 33 deletions src/finalisers/shared/getExportBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,42 +49,48 @@ export default function getExportBlock(
}
});

dependencies.forEach(({ name, imports, reexports, isChunk }) => {
if (reexports && namedExportsMode) {
reexports.forEach(specifier => {
if (specifier.imported === 'default' && !isChunk) {
const exportsNamesOrNamespace =
(imports &&
imports.some(
specifier => specifier.imported === '*' || specifier.imported !== 'default'
)) ||
(reexports &&
reexports.some(
specifier => specifier.imported !== 'default' && specifier.imported !== '*'
));
dependencies.forEach(
({ name, imports, reexports, isChunk, namedExportsMode: depNamedExportsMode }) => {
if (reexports && namedExportsMode) {
reexports.forEach(specifier => {
if (specifier.imported === 'default' && !isChunk) {
const exportsNamesOrNamespace =
(imports &&
imports.some(
specifier => specifier.imported === '*' || specifier.imported !== 'default'
)) ||
(reexports &&
reexports.some(
specifier => specifier.imported !== 'default' && specifier.imported !== '*'
));

const reexportsDefaultAsDefault =
reexports &&
reexports.some(
specifier => specifier.imported === 'default' && specifier.reexported === 'default'
);
const reexportsDefaultAsDefault =
reexports &&
reexports.some(
specifier => specifier.imported === 'default' && specifier.reexported === 'default'
);

if (exportBlock && !compact) exportBlock += '\n';
if (exportsNamesOrNamespace || reexportsDefaultAsDefault)
exportBlock += `exports.${specifier.reexported}${_}=${_}${name}${
interop !== false ? '__default' : '.default'
};`;
else exportBlock += `exports.${specifier.reexported}${_}=${_}${name};`;
} else if (specifier.imported !== '*') {
if (exportBlock && !compact) exportBlock += '\n';
exportBlock += `exports.${specifier.reexported}${_}=${_}${name}.${specifier.imported};`;
} else if (specifier.reexported !== '*') {
if (exportBlock && !compact) exportBlock += '\n';
exportBlock += `exports.${specifier.reexported}${_}=${_}${name};`;
}
});
if (exportBlock && !compact) exportBlock += '\n';
if (exportsNamesOrNamespace || reexportsDefaultAsDefault)
exportBlock += `exports.${specifier.reexported}${_}=${_}${name}${
interop !== false ? '__default' : '.default'
};`;
else exportBlock += `exports.${specifier.reexported}${_}=${_}${name};`;
} else if (specifier.imported !== '*') {
if (exportBlock && !compact) exportBlock += '\n';
const importName =
specifier.imported === 'default' && !depNamedExportsMode
? name
: `${name}.${specifier.imported}`;
exportBlock += `exports.${specifier.reexported}${_}=${_}${importName};`;
} else if (specifier.reexported !== '*') {
if (exportBlock && !compact) exportBlock += '\n';
exportBlock += `exports.${specifier.reexported}${_}=${_}${name};`;
}
});
}
}
});
);

exports.forEach(expt => {
const lhs = `exports.${expt.exported}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ define(['exports', './m2.js'], function (exports, m2) { 'use strict';
m2: m2
});

exports.m2 = m2.default;
exports.m2 = m2;
exports.ms = ms;

});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ define(['exports', './m2.js', './generated-m1.js'], function (exports, m2, m1) {



exports.m2 = m2.default;
exports.m2 = m2;

Object.defineProperty(exports, '__esModule', { value: true });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ var ms = /*#__PURE__*/Object.freeze({
m2: m2
});

exports.m2 = m2.default;
exports.m2 = m2;
exports.ms = ms;
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ require('./generated-m1.js');



exports.m2 = m2.default;
exports.m2 = m2;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
description: 'correctly imports the default from an entry point',
options: {
input: ['main', 'dep']
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
define(function () { 'use strict';

var dep = 42;

return dep;

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
define(['exports', './dep.js'], function (exports, dep) { 'use strict';



exports.value = dep;

Object.defineProperty(exports, '__esModule', { value: true });

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

var dep = 42;

module.exports = dep;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var dep = require('./dep.js');



exports.value = dep;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var dep = 42;

export default dep;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as value } from './dep.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
System.register([], function (exports, module) {
'use strict';
return {
execute: function () {

var dep = exports('default', 42);

}
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
System.register(['./dep.js'], function (exports, module) {
'use strict';
return {
setters: [function (module) {
exports('value', module.default);
}],
execute: function () {



}
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 42;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default as value} from './dep';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const assert = require('assert');

module.exports = {
description: 'correctly imports the default from an entry point',
options: {
input: ['main', 'dep']
},
exports(exports) {
assert.deepStrictEqual(exports, {
value: 42
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 42;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default as value} from './dep';