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

Make sure that exports \{default\} throws an error #330

Closed
wants to merge 1 commit into from

Conversation

nzakas
Copy link
Contributor

@nzakas nzakas commented Oct 9, 2015

This checks if the local name of an export specifier is a keyword or reserved word only when there's no from clause (the case with a from clause appears to already work, though I'm not sure why).

Fixes #326

@RReverser
Copy link
Member

Are you sure that such check would be enough? (compared to https://github.com/marijnh/acorn/blob/master/src/expression.js#L642-L644)

@nzakas
Copy link
Contributor Author

nzakas commented Oct 11, 2015

Based on the tests I added, I think so. parseIdent is always called first, so this code seems to be triggered already.

@RReverser
Copy link
Member

parseIdent is called with liberal === true when keyword is default so those conditions are not triggered https://github.com/marijnh/acorn/blob/master/src/statement.js#L551.

@nzakas
Copy link
Contributor Author

nzakas commented Oct 12, 2015

Yeah, that's for the form:

export default foo;

I haven't addressed that form in this PR as the bug was about non-default exports. Do you want me to look at that too?

@RReverser
Copy link
Member

No, that line with parseIdent covers exactly export { default } ....

@nzakas
Copy link
Contributor Author

nzakas commented Oct 12, 2015

Ah, I see. Still, I'm having trouble coming up with a test case that behaves incorrectly with this code. Do you have one in mind?

@RReverser
Copy link
Member

In fact you're right, there shouldn't be as default is a keyword so falls into another condition, and others are called with liberal = false anyway. It's me just being over-careful :)

@nzakas
Copy link
Contributor Author

nzakas commented Oct 12, 2015

No worries, I'd rather have you being over careful. :)

@@ -526,6 +526,13 @@ pp.parseExport = function(node) {
if (this.eatContextual("from")) {
node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected()
} else {
// check for keywords used as local names
for (let i=0; i<node.specifiers.length; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

@nzakas Can you please put some space around operators? Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@nzakas
Copy link
Contributor Author

nzakas commented Oct 13, 2015

Any other changes needed here? @marijnh

@marijnh
Copy link
Member

marijnh commented Oct 14, 2015

Nope, looks great. But this airport wifi won't allow me to push to github, and this branch isn't based on the current master, so I don't want to use github's magic merge button which I expect will introduce needless merge commits. I'll merge this when I get home later today.

@marijnh
Copy link
Member

marijnh commented Oct 14, 2015

Merged as 37efe0b!

@marijnh marijnh closed this Oct 14, 2015
@nzakas
Copy link
Contributor Author

nzakas commented Oct 14, 2015

Thanks!

@nzakas nzakas deleted the issue326 branch October 14, 2015 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants