Skip to content
Permalink
Browse files

Properly skip "default" exports in `export * from "module"`.

  • Loading branch information
benjamn committed Jul 11, 2017
1 parent 64807cf commit 8defc645e556429283e0b522fd3afababf6525ea
Showing with 22 additions and 24 deletions.
  1. +9 −3 lib/runtime/index.js
  2. +0 −20 lib/runtime/utils.js
  3. +1 −1 test/export/all.js
  4. +1 −0 test/export/def.js
  5. +5 −0 test/misc-tests.js
  6. +6 −0 test/misc/export-all.js
@@ -112,11 +112,17 @@ function runSetters(valueToPassThrough) {
}

// Returns a function that takes a namespace object and copies the
// properties of the namespace to module.exports, which is useful for
// implementing `export * from "module"` syntax.
// properties of the namespace to module.exports, excluding any "default"
// property, which is useful for implementing `export * from "module"`.
function moduleMakeNsSetter() {
var module = this;
// Discussion of why the "default" property is skipped:
// https://github.com/tc39/ecma262/issues/948
return function (namespace) {
utils.assign(module.exports, namespace);
Object.keys(namespace).forEach(function (key) {
if (key !== "default") {
utils.copyKey(key, module.exports, namespace);
}
});
};
}
@@ -15,26 +15,6 @@ var useGetOwnPropDesc =
typeof Object.getOwnPropertyDescriptor === "function";
var hasOwn = Object.prototype.hasOwnProperty;

exports.assign = function (target) {
var argCount = arguments.length;
var sourcesByKey = Object.create(null);

for (var i = 0; i < argCount; ++i) {
var source = arguments[i];
if (isObjectLike(source)) {
Object.keys(source).forEach(function (key) {
sourcesByKey[key] = source;
});
}
}

Object.keys(sourcesByKey).forEach(function (key) {
copyKey(key, target, sourcesByKey[key]);
});

return target;
};

function copyKey(key, target, source) {
if (useGetOwnPropDesc) {
var desc = Object.getOwnPropertyDescriptor(source, key);
@@ -1,2 +1,2 @@
export * from "../misc/abc";
export default "default";
export * from "../misc/abc";
@@ -1,3 +1,4 @@
export const d = "d";
export const e = "e";
export const f = "f";
export default "default";
@@ -19,6 +19,11 @@ describe("spec compliance", () => {
import value from "./export/cycle-a";
assert.equal(value, true);
});

it("should not export the default binding of namespace exports", () => {
import * as ns from "./misc/export-all.js";
ns.check();
});
});

describe("built-in modules", () => {
@@ -0,0 +1,6 @@
import assert from "assert"
import * as ns from "../export/all-multiple.js"

export function check() {
assert.ok(! ("default" in ns))
}

0 comments on commit 8defc64

Please sign in to comment.
You can’t perform that action at this time.