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

Let first getter win if one already exists. #106

Merged
merged 1 commit into from
Apr 6, 2017
Merged
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
25 changes: 11 additions & 14 deletions lib/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ function makeUniqueKey() {
}

Ep.addSetters = function (parent, setters, key) {
var entry = this;

if (typeof key === "undefined") {
// If no key was provided, make a new unique key that won't collide
// with any other keys.
Expand All @@ -57,15 +55,14 @@ Ep.addSetters = function (parent, setters, key) {
// Ignore any requests for the exports.__esModule property."
name !== "__esModule") {
setter.parent = parent;
(entry.setters[name] =
entry.setters[name] || Object.create(null)
(this.setters[name] =
this.setters[name] || Object.create(null)
)[key] = setter;
}
}
};

Ep.addGetters = function (getters) {
var entry = this;
var names = Object.keys(getters);
var nameCount = names.length;

Expand All @@ -74,9 +71,10 @@ Ep.addGetters = function (getters) {
var getter = getters[name];
if (typeof getter === "function" &&
// Ignore any requests for the exports.__esModule property."
name !== "__esModule") {
// Should this throw if hasOwn.call(this.getters, name)?
entry.getters[name] = getter;
name !== "__esModule" &&
// Should this throw if hasOwn.call(this.getters, name)?
! hasOwn.call(this.getters, name)) {
this.getters[name] = getter;
}
}
};
Expand All @@ -94,12 +92,11 @@ function runModuleGetters(module) {
}

Ep.runModuleGetters = function (module) {
var entry = this;
var names = Object.keys(entry.getters);
var names = Object.keys(this.getters);
var nameCount = names.length;

for (var i = 0; i < nameCount; ++i) {
entry.runGetter(module, names[i]);
this.runGetter(module, names[i]);
}
};

Expand All @@ -123,14 +120,14 @@ Ep.runGetter = function (module, name) {
// setters associated with the newly exported values.
Ep.runModuleSetters = function (module) {
var entry = this;
var names = Object.keys(entry.setters);
var names = Object.keys(this.setters);

// Make sure module.exports is up to date before we call
// module.getExportByName(name).
entry.runModuleGetters(module);
this.runModuleGetters(module);

if (names.length === 0) {
++entry.runCount;
++this.runCount;
return;
}

Expand Down