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

Consider building as ES6 modules. #38

Closed
tomek-he-him opened this issue Dec 20, 2014 · 4 comments
Closed

Consider building as ES6 modules. #38

tomek-he-him opened this issue Dec 20, 2014 · 4 comments

Comments

@tomek-he-him
Copy link
Contributor

Why

You've reached a conclusion in #17, that AMD is fairly compatible with CommonJS – you can use one within the other or transpile one to the other. That's not the case with ES6 modules. They are designed to be statically analysable (without executing the code) – so there are things impossible to transpile. Such as:

if (hasToGo) require('car').driveHome();
// ...or:
module.exports = something || somethingElse;
How

Looking by the simplicity of your modules, it should be easy to copy each file to 101/es6/, replacing:

  • module.exports = a; with export default a;, and
  • var b = require('./b'); with import b from './b';.

I've had a very rough go at this, because I needed two modules in an ES6 project. A simple search-and-replace did it in my case: tomekwi/101-es6.

The only problem

The problem is dependency on CommonJS modules (clone, keypather and deep-eql – we should be able to replace extend with 101/assign).

Possible solutions:

  1. Implement these ourselves (I guess it can be out of the question at the moment)
  2. Compile only non-dependent modules to ES6
  3. Compile everything as-it-is (just import clone from 'clone';). Some compilers (6to5) can handle this as a temporary ES5-ES6 brigde.
@tjmehta
Copy link
Owner

tjmehta commented Dec 20, 2014

Awesome, I think this a great idea. I'll try to hack it out next week


Sent from Mailbox

On Sat, Dec 20, 2014 at 1:30 PM, Tomek Wiszniewski
notifications@github.com wrote:

Why

You've reached a conclusion in #17, that AMD is fairly compatible with CommonJS – you can use one within the other or transpile one to the other. That's not the case with ES6 modules. They are designed to be statically analysable (without executing the code) – so there are things impossible to transpile. Such as:

if (hasToGo) require('car').driveHome();
// ...or:
module.exports = something || somethingElse;
How

Looking by the simplicity of your modules, it should be fairly easy to copy each file to 101/es6/, replacing:

  • module.exports = a; with export default a;, and
  • var b = require('./b'); with import b from './b';.
    I've had a very rough go at this, because I needed two modules in an ES6 project. A simple search-and-replace did it in my case: tomekwi/101-es6.
    The only problem
    The problem is dependency on CommonJS modules (clone, keypather and deep-eql – we should be able to replace extend with 101/assign).
    Possible solutions:
  • Implement these ourselves (I guess it's out of the question at the moment)
  • Compile only non-dependent modules to ES6

3. Compile everything as-it-is (just import clone from 'clone';). Some compilers (6to5) can handle this as a temporary ES5-ES6 brigde.

Reply to this email directly or view it on GitHub:
#38

@stoeffel
Copy link
Contributor

I would close this in favour of #42. I think a complete move to es6 using 6to5 or traceur would be cleaner.

@tjmehta
Copy link
Owner

tjmehta commented Feb 25, 2015

I am punting on this for now. I know ES6 traction is picking up fast. Let's revisit this idea after a few months. Long answer here: #62

@tjmehta tjmehta closed this as completed Feb 25, 2015
@stoeffel
Copy link
Contributor

Let's revisit this idea after a few months

Sure will do 😸

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

No branches or pull requests

3 participants