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

Check exported bindings are defined #9589

Merged
merged 4 commits into from Feb 26, 2019

Conversation

@danez
Copy link
Member

commented Feb 26, 2019

Q                       A
Fixed Issues?
Patch: Bug Fix? n
Major: Breaking Change? n
Minor: New Feature? n
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This ensures that exports are always defined before exporting them. This is required according to the spec here: https://www.ecma-international.org/ecma-262/9.0/index.html#sec-module-semantics-static-semantics-early-errors

It is a Syntax Error if any element of the ExportedBindings of ModuleItemList does not also occur in either the VarDeclaredNames of ModuleItemList, or the LexicallyDeclaredNames of ModuleItemList.

@babel-bot

This comment has been minimized.

Copy link
Collaborator

commented Feb 26, 2019

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/10315/

@danez danez marked this pull request as ready for review Feb 26, 2019
@@ -489,7 +489,7 @@ suites.forEach(function(testSuite) {
const actualAst = parse(actualCode, {
filename: actual.loc,
plugins: task.options.plugins || [],
strictMode: false,

This comment has been minimized.

Copy link
@danez

danez Feb 26, 2019

Author Member

This was not really correct as sourceType:"module" should always be in strict mode, but it is needed for some of the tests.

@nicolo-ribaudo

This comment has been minimized.

Copy link
Member

commented Feb 26, 2019

Can I export { Object }?

EDIT: Ok, I can't. Can you add a test both for it and export { Object as Obj }? I don't want that someone will add an exception for builtins in the future, since this is a bit counter-intuitive.

@danez

This comment has been minimized.

Copy link
Member Author

commented Feb 26, 2019

I was wondering the same while working on it, but node does not allow to export globals either. I will add a test.

Parser: Spec Compliance, Refactoring and Performance automation moved this from In progress to Reviewed Feb 26, 2019
Copy link
Member

left a comment

In case you are wondering how much confusing it is: https://twitter.com/NicoloRibaudo/status/1100340777262166016 😛

@danez danez merged commit 43eed1a into babel:master Feb 26, 2019
5 checks passed
5 checks passed
babel/repl REPL preview is available
Details
buildsize No significant change
Details
ci/circleci Your tests passed on CircleCI!
Details
codecov/project 87% (target 80%)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Parser: Spec Compliance, Refactoring and Performance automation moved this from Reviewed to Done Feb 26, 2019
@danez danez deleted the danez:undefined-exports branch Mar 7, 2019
@shrinktofit

This comment has been minimized.

Copy link

commented Mar 22, 2019

Please take a look at #9745

@benjamn

This comment has been minimized.

Copy link
Contributor

commented Apr 8, 2019

#9720 (comment)

It's fine to use the parser to help enforce spec compliance, as long as you make the behavior configurable, but as far as I can tell there's no way to disable this new and surprising behavior.

Babel has a powerful plugin system that allows sophisticated developers to produce valid code even if it looks "wrong" when it's first parsed. If the parser just refuses to parse the code, that power is lost.

Please consider making this behavior configurable! If you're open to that idea, I would be happy to submit a PR.

@lock lock bot added the outdated label Oct 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
6 participants
You can’t perform that action at this time.