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

Fix #145 - export {foo as bar}. #169

Merged
merged 2 commits into from
May 28, 2015
Merged

Fix #145 - export {foo as bar}. #169

merged 2 commits into from
May 28, 2015

Conversation

mbostock
Copy link
Contributor

Fixes #145. I’m not really sure this is the right fix, but it seemed to work?

Note: I purposely did not include the built changes to dist/. I’m assuming you’d like to test on your end, but I can include them if you want.

mbostock added a commit to d3/d3-bundler that referenced this pull request May 28, 2015
@mbostock
Copy link
Contributor Author

Related question: is there any particular reason to use getters when defining the export object, rather than just static files? Like, instead of:

var index_js = {
  get mouse () { return mouse; },
  get namespace () { return namespace; },
  get namespaces () { return namespaces; },
  get requote () { return requote; },
  get select () { return select; },
  get selectAll () { return selectAll; },
  get selection () { return Selection; },
  get touch () { return src_touch; },
  get touches () { return src_touches; }
};

You could produce:

var index_js = {
  mouse: mouse,
  namespace: namespace,
  namespaces: namespaces,
  requote: requote,
  select: select,
  selectAll: selectAll,
  selection: Selection,
  touch: src_touch,
  touches: src_touches
};

@eventualbuddha
Copy link
Contributor

@mbostock I believe it's because ES6 imports and exports are live bindings, so if you make a module object (i.e. import * as foo from 'foo') then the properties on it will need to update their values when they change. Here's an example:

// a.js
export var count = 0;
export function increment() { count++; }

// b.js
import * as a from './a';
console.log(a.count); // 0
a.increment();
console.log(b.count); // 1

@mbostock
Copy link
Contributor Author

Ah, of course: bindings, not values. Thanks! (And hi!)

@eventualbuddha
Copy link
Contributor

Hey Mike! Nice to run into you here. I'll have to check out d3-bundler.

@Rich-Harris Rich-Harris merged commit 0307e28 into esperantojs:master May 28, 2015
Rich-Harris added a commit that referenced this pull request May 28, 2015
@Rich-Harris
Copy link
Contributor

Thanks @mbostock, I've added a regression test and released this as 0.7.1. There is an _evilES3SafeReExports option which uses static values instead of getters in the case of one-to-one transformations - it could possibly be extended to cover bundles as well.

That said, I was thinking about d3-bundler on the way home and I think there might be a simpler way that sidesteps the issue... let me run a couple of experiments.

@mbostock
Copy link
Contributor Author

👍 Thanks for adding more tests. I tested against master and it still appears to work, but please npm publish when you get a chance.

@Rich-Harris
Copy link
Contributor

Oops, thought I had, sorry - it's published now

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.

export-as-from imports using the exported name
3 participants