componentjs / builder-es6-module-to-cjs

builder plugin to convert ES6 modules to CJS
5 stars 1 forks source link

es6 modules #1

Open queckezz opened 10 years ago

queckezz commented 10 years ago

So I tried to use the es6 syntax today and I ran into multiple issues with it.

I know that you reported some of the issues to es6-module-transpiler but they don't seem very active. What do you think of using https://github.com/andreypopp/es6-module-jstransform? This resolves all the above issues. A downside though is that it compiles to pretty ugly code:

var mod$0 = require("./mod.js");
module.exports.x = mod$0.x;
var mod$1 = require("./mod.js");
module.exports.x = mod$1.x;
module.exports.y = mod$1.y;
var mod$2 = require("./mod.js");
module.exports.y = mod$2.x;
var mod$3 = require("./mod.js");
module.exports.y = mod$3.x;
module.exports.b = mod$3.y;

But for me not really a problem since it's just the build output anyway.

jonathanong commented 10 years ago

+1. thank for putting in the time to find actual cases that fail! i don't really care about which transpiler we use, but adding test cases for every issue we find would be useful. doesn't help that ES6 modules aren't standardized yet =/

don't really care about the build output.

andreypopp commented 10 years ago

Hi,

I've released 0.1.3 which preserves line info and doesn't generate unneeded vars when there's only single specifier to export/import, so the output above looks like now:

module.exports.x = require("./mod.js").x;
var mod$0 = require("./mod.js");module.exports.x = mod$0.x;module.exports.y = mod$0.y;
module.exports.y = require("./mod.js").x;
var mod$1 = require("./mod.js");module.exports.y = mod$1.x;module.exports.b = mod$1.y;

Also, I developed this transform to be compatible with CommonJS modules but I'm not sure yet I did this aspect right because I didn't put this transform to production use yet.

jonathanong commented 10 years ago

so far, it's better than square's transpiler in that it actually works :D

jonathanong commented 10 years ago

btw is there a cjs -> es6 module compiler?

bodokaiser commented 10 years ago

+1 on this too.

Currently debugging is real pain. You either get syntax error on line 1 (what fucking file??) or just undefined. I guess this would be solved too by using a different transformer.

timaschew commented 9 years ago

related to #2