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

Hoist import and export declarations to the beginning of the enclosing block #25

Closed
benjamn opened this issue Jun 6, 2016 · 2 comments
Assignees
Milestone

Comments

@benjamn
Copy link
Owner

benjamn commented Jun 6, 2016

See these failing tests for examples when hoisting import and export declarations is helpful/necessary. Thanks to @sokra for those tests.

This will require a slightly more sophisticated compilation strategy, since we're no longer just replacing import and export declarations in place, but potentially moving them around. I suspect I will end up using https://www.npmjs.com/package/magic-string, which also provides source maps.

One subtle implication of this change is that imported symbols should not be visible outside the block where they are imported, because we won't be hoisting import declarations outside the block, and the variables are likely to be undefined before the block, so they might as well not be accessible at all outside the block. In other words, this change is definitely a good idea: #17

@benjamn benjamn added this to the 0.3.0 milestone Jun 6, 2016
@benjamn benjamn self-assigned this Jun 6, 2016
@benjamn
Copy link
Owner Author

benjamn commented Jun 6, 2016

If we're hoisting export declarations, we might as well merge multiple exports into one

module.export({
  a: () => a,
  b: () => b,
  ...
});

instead of

module.export("a", () => a);
module.export("b", () => b);

@benjamn
Copy link
Owner Author

benjamn commented Jun 14, 2016

Fixed by c884634.

@benjamn benjamn closed this as completed Jun 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant