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

Let first getter win if one already exists. #106

merged 1 commit into from
Apr 6, 2017

Conversation

jdalton
Copy link
Contributor

@jdalton jdalton commented Mar 30, 2017

This addresses a line item of #90.

lib/entry.js Outdated
// Should this throw if hasOwn.call(this.getters, name)?
entry.getters[name] = getter;
if (hasOwn.call(this.getters, name)) {
throw new Error("A getter for " + name + " already exists");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message can be bikeshedded. I just put something in it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any preference on the error message?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it Identifier 'foo' exported more than once?

@jdalton
Copy link
Contributor Author

jdalton commented Mar 30, 2017

A follow up to this would be a unit test to ensure it throws. I'm not super up on tests here though so it may be easier for @benjamn to do the follow up test.

lib/entry.js Outdated
entry.getters[name] = getter;
if (hasOwn.call(this.getters, name)) {
throw new SyntaxError("Identifier '" + name + "' exported more than once");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

Copy link
Owner

@benjamn benjamn Apr 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we could have this error thrown only during tests, and otherwise let the first getter win (silently), I think that would be better than always throwing, since this is a runtime exception enforcing a compile-time guarantee.

@jdalton jdalton mentioned this pull request Apr 3, 2017
7 tasks
lib/entry.js Outdated
// Should this throw if hasOwn.call(this.getters, name)?
entry.getters[name] = getter;
this.getters[name] = getter;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

punted on erroring for now, opting to at least let the first getter win.

@jdalton jdalton changed the title Throw when adding a getter that already exists. Let first getter win if one already exists. Apr 6, 2017
@jdalton jdalton merged commit 18eaf43 into benjamn:master Apr 6, 2017
@jdalton jdalton deleted the add-getters branch April 6, 2017 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants