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

[BugFix] Compile export default from #7309

Closed
wants to merge 1 commit into from

Conversation

nveenjain
Copy link
Contributor

@nveenjain nveenjain commented Feb 1, 2018

Q                       A
Fixed Issues? Fixes #7293
Patch: Bug Fix? Yes
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? NO
Documentation PR
Any Dependency Changes? No
License MIT

Now we check in export default statements that if from is either an assignment or from is exported then valid AST are generated, which doesn't require any sort of plugin.

@babel-bot
Copy link
Collaborator

babel-bot commented Feb 1, 2018

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

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

  1. Can you add some tests?
  2. To avoid using lookahead (which needs to clone the whole Babylon state), we can do something like this:
const declaration = this.parseMaybeAssign();
if (declaration.type === "Identifier" && declaration.value === "from" && this.state.type === tt.string) {
  // export default from "module";
} else {
  node.declaration = declaration;
  return ExportDefaultDeclaration;
}

isDefaultfrom = true;
const lookaheadState = this.lookahead();
if (
lookaheadState.value === "=" ||
Copy link
Member

Choose a reason for hiding this comment

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

What if I have another token? e.g. export default from + 2;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah Sorry, didn't consider that.. Will update the PR

@nicolo-ribaudo
Copy link
Member

I just read the spec and it looks like this is disallowed? 🤔
cc @leaves4j

https://tc39.github.io/proposal-export-default-from/#prod-ExportDeclaration

export default [lookahead ∉ { function, class, from }] AssignmentExpression[In];


> NOTE 1
The addition of from to the lookahead after export default allows for the disambiguation
of export default from "mod", which is the proposed syntactic form for exporting
"mod"'s default export as this module's default export, from export default from, which
is the potentially confusing export of a local named variable from.

@nveenjain
Copy link
Contributor Author

but since it is still in proposal, should i work on this PR or not? like first we should check whether export-default-from plugin is used or not.
Shouldn't export default from work without export-default-from plugin and don't work with export-default-from plugin enabled?

@nicolo-ribaudo
Copy link
Member

For now I think we should wait: even if it is currently allowed, we should prevent users from depending on export default from;.

Usually the spec doesn't includes breaking changes, but since people who are using modules are also using Babel (because native esm support is really new), that change wouldn't break anyone's existing code and thus I think tc39 folks could decide do make it.

cc @leebyron I'd like to know your opinion, since you are the author of the proposal 🙂

@leebyron
Copy link
Contributor

I believe @jdalton has taken over for these. I’m still in support of them, but have not been attending TC39 meetings and don’t know their status

@JLHwung
Copy link
Contributor

JLHwung commented Jun 5, 2020

@nveenjain Although this PR is closed by #11676, I want to thank you for your inspiring work here!

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Sep 5, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 5, 2020
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

Successfully merging this pull request may close these issues.

'export default from' can not be correctly compiled
5 participants