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

Default Exports #9

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Default Exports #9

wants to merge 5 commits into from

Conversation

juliankrispel
Copy link
Owner

@juliankrispel juliankrispel commented Aug 22, 2016

So in light of the issues discovered in this pr I'm now changing the exports mod to be much simpler. cc @yofreke

Here's what I'm doing:

  • Keep the exports variable.
  • Instantiate the exports object if there isn't one yet.
  • export the exports object as the default export.

So basically this:

exports = Hello;
exports.foo = 'dwq';

becomes this:

var exports = Hello;
exports.foo = 'dwq';
export default exports;

@juliankrispel juliankrispel self-assigned this Aug 22, 2016
@yofreke
Copy link
Contributor

yofreke commented Aug 23, 2016

This es6 seems unintuitive at first glance. What are your thoughts on something like:

export default Hello;
exports.default.foo = 'dwq';

I don't like overwriting exports, and while yours is not, it is also not very clear what is happening until the end, since exports is already defined in the module scope.

@juliankrispel
Copy link
Owner Author

I think mounting on exports.default is wrong because it's implementation specific to the compiler.

How about just renaming exports to defaultExport

Julian Krispel-Samsel
rainforestqa.com
goodafternoon.co

On Aug 23, 2016, at 9:12 PM, Joe Brown notifications@github.com wrote:

This es6 seems unintuitive at first glance. What are your thoughts on something like:

export default Hello;
exports.default.foo = 'dwq';
I don't like overwriting exports, and while yours is not, it is also not very clear what is happening until the end, since exports is already defined in the module scope.


You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub, or mute the thread.

@yofreke
Copy link
Contributor

yofreke commented Aug 23, 2016

ty es6

I suppose that is true, since we haven't settled on a compiler yet. What about the following:

const defaultExport = Hello;
export default defaultExport;
defaultExport.foo = 'dwq';

That way any references to exports in the file will still work as intended.

@juliankrispel
Copy link
Owner Author

Ok cool. It seems to me like it's pretty conventional to put the export statement at the bottom of a file but if you have a good reason for having that at the top that seems fine. I don't really care too mucg either way tbh.

Whaddayasay

Julian Krispel-Samsel
rainforestqa.com
goodafternoon.co

On Aug 23, 2016, at 11:56 PM, Joe Brown notifications@github.com wrote:

ty es6

I suppose that is true, since we haven't settled on a compiler yet. What about the following:

const defaultExport = Hello;
export default defaultExport;
defaultExport.foo = 'dwq';
That way any references to exports in the file will still work as intended.


You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub, or mute the thread.

@juliankrispel
Copy link
Owner Author

That seems to work for me though. The thing about not being compiler specific is not just about us choosing a compiler but also user-land. Ideally this should work with whatever other peeps are using. Whether that's webpack or browseriify or whatever else

Julian Krispel-Samsel
rainforestqa.com
goodafternoon.co

On Aug 23, 2016, at 11:56 PM, Joe Brown notifications@github.com wrote:

ty es6

I suppose that is true, since we haven't settled on a compiler yet. What about the following:

const defaultExport = Hello;
export default defaultExport;
defaultExport.foo = 'dwq';
That way any references to exports in the file will still work as intended.


You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub, or mute the thread.

@juliankrispel
Copy link
Owner Author

@yofreke also bear in mind you can define exports as a normal variable and babel will adjust to prevent any collisions at compile time - here's and example

var exports = null

export default {}

will compile to

"use strict";

exports.__esModule = true;
var _exports = null;

exports.default = {};

Alpha = exports = function() { console.log('boom'); }
Beta = exports.boing = yoyoyo;
export default exports;
var defaultExports;
Copy link
Contributor

Choose a reason for hiding this comment

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

let

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.

2 participants