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

Multiple export defaults (T7242) #4204

Closed
babel-bot opened this issue Mar 24, 2016 · 6 comments
Closed

Multiple export defaults (T7242) #4204

babel-bot opened this issue Mar 24, 2016 · 6 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@babel-bot
Copy link
Collaborator

Issue originally made by James Whitney (whitneyit)

Bug information

  • Babel version: Babel 6.7.4
  • Node version: v5.4.0
  • npm version: v3.5.3

Input code

export default class A {
}

export default class B {
}

Description

I'm not sure if this is intended or has just been overlooked, but the above code does not produce an error.

I was able to find a few references to support this, namely a reference on [[ https://developer.mozilla.org/en/docs/web/javascript/reference/statements/export#Description | MDN]] and a post by Dr. Axel Rauschmayer's on [[ http://www.2ality.com/2014/09/es6-modules-final.html#an_overview_of_the_es6_module_syntax | 2ality ]], but I couldn't track it down specifically in the ES spec.

In addition, this is reported as an error on the [[ http://www.typescriptlang.org/Playground#src=export%20default%20class%20A%20%7B%0A%7D%0A%0Aexport%20default%20class%20B%20%7B%0A%7D| Typescript Playground]].

@babel-bot
Copy link
Collaborator Author

Comment originally made by @loganfsmyth

Good call, I don't think we have any error handling for duplicate exports at the moment.

@babel-bot
Copy link
Collaborator Author

Comment originally made by @jmm

If this is a spec violation, someone please provide a spec citation.

@babel-bot
Copy link
Collaborator Author

Comment originally made by @kaicataldo

Cross-posting from the open PR:

Thanks for the comment! I'll be up front - my experience reading the spec is limited at best at the moment, but I think this section references the error we're reporting in this PR. The relevant part seems to be the note at the bottom:

The duplicate ExportedNames rule implies that multiple export default ExportDeclaration items within a ModuleBody is a Syntax Error. Additional error conditions relating to conflicting or duplicate declarations are checked during module linking prior to evaluation of a Module. If any such errors are detected the Module is not evaluated.

Does that look right to you?

@babel-bot
Copy link
Collaborator Author

Comment originally made by @jmm

Thanks @kaicataldo! That does seem like the relevant reference. (Hmm...I'm not sure off the top of my head what they're referring to with "Additional error conditions [...]".) Actually that was kind of my bad 🤦 for forgetting that multiple export default is just a special case of attempting to export the same name multiple times in general, as indicated by that spec reference. Probably this issue should be updated or absorbed into a new issue to reflect that it's not specific to export default.

@babel-bot
Copy link
Collaborator Author

Comment originally made by @kaicataldo

I'm happy to continue working on this, and would be willing to try my hand at the relevant Babylon change, if need be - what are your thoughts on @hzoo's suggestion [[ https://github.com//pull/3518#issuecomment-225709319 | here ]]?

@babel-bot
Copy link
Collaborator Author

Comment originally made by @danez

It seems this landed in master now and for the proper fix in the parser there is already an issue.
babel/babylon#69

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 7, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

1 participant