-
Notifications
You must be signed in to change notification settings - Fork 111
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
Target ES6 #344
base: master
Are you sure you want to change the base?
Target ES6 #344
Conversation
which is sometimes a member node and other times (ArrowFunctionExpression) just a flag.
❤️ |
Conflicts: lib/parser.js src/grammar.pegcoffee
Fantastic! I'm especially interested in the default parameters. |
This makes defaults & rest work in constructors
@srb- default params are working now, for both ArrowExpressions and FunctionExpresion:
class Foo extends Bar
doIt: (a=1, b=2, c...)->
super("yay", a, b, c)
demo = (a, b=2, c...) => a + b + c.length
// Generated by CoffeeScript 2.0.0-beta9-dev-es6
var demo;
class Foo extends Bar {
doIt(a = 1, b = 2, ...c) {
return super.doIt('yay', a, b, c);
}
}
demo = (a, b = 2, ...c) => a + b + c.length; |
Very cool! Question: do you actually use this compiler in production? I was under the impression it's in a semi-abandoned state so I've been afraid to use it for real projects. |
I haven't yet, but I'm planning to use it to help me port a significant production codebase from coffeescript to ES6. This is admittedly a lower bar than getting it working as an ongoing production compiler -- I can supervise the process more closely. Overall I have been happy with the parser -- it is more conservative than the one in original coffeescript, and it forced me to disambiguate a bunch of dubious code. And some of the roughest features (like So for my use case it works, but I can understand the hesitation. You definitely have to be willing to debug the compiler to use it at this point. |
that will cover arbitrarily deep assignment patterns
This requires a recent master version of escodegen.
This test was unintentionally calling a constructor without "new". ES6 puts the smack down on that kind of bug.
Wow, I wish I'd seen this sooner. I've been working on The main reason I didn't go with the approach in this PR is that I'd lose comments and formatting. |
I have a separate tool for safely porting the comments across, using source This PR is still definitely a work in progress. It's usable to if you're
|
great works. but This branch has conflicts that must be resolved |
@ef4 what's the status of this project? EDIT: And are you looking for help to get it over the finish line? |
I had to shift focus to other things, anyone is welcome to take it and run with it. The status is the same as my last comment: it's already useful as an assistant if you're hand-porting code from coffeescript to ES2015. I wouldn't trust it to transpile a whole codebase. |
Awesome, thanks @ef4 ! Do you think you'd be willing to provide advice from time to time if someone were to pick it up? |
Sure. |
This is a work-in-progress. I'm sharing in case others are interested or have feedback. This branch creates a new option
--target-es6
that tells the compiler to emit ES6 when possible.Since many ES6 features are closely aligned with CoffeeScript, we can actually do less and emit smaller, simpler code that takes advantage of native implementations.
Why would you want this?
Here's an example of what it can already do:
$ cat sample.coffee
$ ./bin/coffee --bare --js --input sample.coffee --target-es6
For comparison, without
--target-es6
we get a lot more code:$ ./bin/coffee --bare --js --input sample.coffee
Status:
for in
tofor of
this
in constructors