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

don't rename default exports unnecessarily #166

Merged
merged 1 commit into from
May 11, 2015
Merged

Conversation

Rich-Harris
Copy link
Contributor

This scratches an itch I've had for quite some time. Due to the way esperanto avoids variable name conflicts, something like this...

var foo = 42;
export default foo;

...gets transpiled to this inside a bundle:

var foo = 42;
var _foo = foo;

A large enough codebase will be littered with this sort of thing. Or, if foo.js is inside a directory, say utils, it will come out as var utils__foo = foo, or something like that.

Clearly it's unnecessary - we should just use foo throughout. The one exception is where foo is updated or assigned to after it has been exported, since IIRC default bindings aren't live, like regular bindings (can't find the reference now, spotty wifi - correct me if I'm wrong!).

In other words, this...

var foo = 42;
export default foo;
foo++;

...should become this:

var foo = 42;
var _foo = foo;
foo++;

That edge case is dealt with, at the cost of some pretty funky code, which I might try and clean up a little before merging this in.

I've tried this out on a few examples and the difference is huge - the code looks handwritten rather than generated, and is accordingly much easier to read in its bundled state.

Rich-Harris added a commit that referenced this pull request May 11, 2015
don't rename default exports unnecessarily
@Rich-Harris Rich-Harris merged commit 5735d26 into master May 11, 2015
@Rich-Harris Rich-Harris deleted the saner-defaults branch May 11, 2015 15:13
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.

1 participant