Skip to content

Commit

Permalink
Support ESM named imports
Browse files Browse the repository at this point in the history
Closes #776
  • Loading branch information
Manuel Mujica committed Jul 6, 2017
1 parent 0145daa commit ed49d46
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 11 deletions.
9 changes: 2 additions & 7 deletions lib/node/slim/make_shim_template.js
Expand Up @@ -24,7 +24,7 @@ module.exports = function(options) {
function stealRequire(moduleId) {
if (loadedModules[moduleId]) {
return stealRequire.esm(loadedModules[moduleId].exports);
return loadedModules[moduleId].exports;
}
${options.plugins ? slimPluginsPartial : ""}
Expand All @@ -40,14 +40,9 @@ module.exports = function(options) {
stealModule
);
return stealRequire.esm(stealModule.exports);
return stealModule.exports;
}
stealRequire.esm = function(stealExports) {
return stealExports && stealExports.__esModule ?
stealExports.default : stealExports;
};
${options.progressive ? progressivePartial : ""}
// import the main module
Expand Down
2 changes: 1 addition & 1 deletion test/slim/basics/main-size.snap
@@ -1 +1 @@
module.exports = 291;
module.exports = 252;
2 changes: 1 addition & 1 deletion test/slim/cache/util.js
@@ -1,4 +1,4 @@
export default function(prop) {
module.exports = function(prop) {
var _props = window._props || {};
_props[prop] = prop;
window._props = _props;
Expand Down
10 changes: 10 additions & 0 deletions test/slim/esm_named_imports/index.html
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script src="./dist/bundles/main.js"></script>
</body>
</html>
3 changes: 3 additions & 0 deletions test/slim/esm_named_imports/main.js
@@ -0,0 +1,3 @@
import { sum } from "./sum";

window.result = sum(1, 1);
3 changes: 3 additions & 0 deletions test/slim/esm_named_imports/stealconfig.js
@@ -0,0 +1,3 @@
steal.config({
main: "main"
});
3 changes: 3 additions & 0 deletions test/slim/esm_named_imports/sum.js
@@ -0,0 +1,3 @@
export function sum(a, b) {
return a + b;
}
2 changes: 1 addition & 1 deletion test/slim/plugins/main-size.snap
@@ -1 +1 @@
module.exports = 337;
module.exports = 301;
2 changes: 1 addition & 1 deletion test/slim/progressive/main-size.snap
@@ -1 +1 @@
module.exports = 897;
module.exports = 864;
23 changes: 23 additions & 0 deletions test/slim_build_test.js
Expand Up @@ -408,4 +408,27 @@ describe("slim builds", function() {
});
});
});

it("ESM named imports work", function() {
var base = path.join(__dirname, "slim", "esm_named_imports");
var config = { config: path.join(base, "stealconfig.js") };

// allow `find` to reject before mocha timeout kicks in
this.timeout(3000);

return rmdir(path.join(base, "dist"))
.then(function() {
return optimize(config, { minify: false, quiet: true });
})
.then(function() {
return open(path.join("test", "slim", "esm_named_imports", "index.html"));
})
.then(function(args) {
return Promise.all([args.close, find(args.browser, "result")]);
})
.then(function(data) {
assert.equal(data[1], 2, "should work");
data[0](); // close();
});
});
});

0 comments on commit ed49d46

Please sign in to comment.