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

Target ES6 #344

Open
wants to merge 69 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
c783dc4
Add super syntax
mizchi May 22, 2014
0dc48d5
Add find helper
mizchi May 22, 2014
5ad09f6
Implement super
mizchi May 22, 2014
bb9fa6b
Generate
mizchi May 22, 2014
9a16e21
Activate jashkenas/coffeescript tests
mizchi May 22, 2014
97d9061
update to newest escodegen
ef4 May 24, 2015
c4f332e
targetES6: rest args
ef4 May 25, 2015
6b6b730
targetES6: arrow function expression
ef4 May 25, 2015
1583ff2
render arrow function expression bodies as expressions
ef4 May 25, 2015
ceccb92
fix accidental reuse of 'expression' property
ef4 May 25, 2015
8ad3511
Respect syntax error offset location
ef4 May 25, 2015
044b562
avoid a crash when no raw
ef4 May 27, 2015
9829c15
Merge branch 'missing-raw'
ef4 May 27, 2015
42b6e6c
Merge remote-tracking branch 'super/redux-super'
ef4 May 27, 2015
1558183
class support
ef4 May 27, 2015
1858513
handle empty class bodies
ef4 May 27, 2015
45b9a36
targetES6: default args for both ArrowExpression and FunctionExpression
ef4 May 27, 2015
fa9f139
extend FunctionDeclration to support defaults
ef4 May 27, 2015
eaa1517
targetES6: array destructuring
ef4 May 27, 2015
fbacb64
smarter declaration detection
ef4 May 27, 2015
08771f4
arrow function expressions have their own scope
ef4 May 27, 2015
3042c9f
recursive array assignment patterns
ef4 May 27, 2015
6814292
added RestElement
ef4 May 28, 2015
2923e2b
making functional helpers follow modern CJS conventions
ef4 May 28, 2015
f409dfb
Fix duplicate vars at top level
ef4 May 28, 2015
dd5d527
Merge branch 'map-child-nodes'
ef4 May 28, 2015
3550280
Merge branch 'fix-duplicate-vars'
ef4 May 28, 2015
f598369
destructuring patterns inside args
ef4 May 28, 2015
ae5f802
es6 test support
ef4 May 28, 2015
9b9ad6c
Merge branch 'toplevel-gensyms'
ef4 May 28, 2015
84be770
merged lib
ef4 May 28, 2015
681515d
finish removing non-strict-mode compatible exports
ef4 May 28, 2015
7c780a6
static methods
ef4 May 29, 2015
22b5f38
anonymous classes & external constructors
ef4 May 29, 2015
d2bfb5c
punt on classes with complex assignee's for now
ef4 May 29, 2015
2ee35e5
use mapChildNodes
ef4 May 29, 2015
c785e29
don't drop nulls from child node lists
ef4 May 29, 2015
c71e98b
only emit ES6 RestElement in final position
ef4 May 29, 2015
e3e71b6
support ES6 methods that equal language keywords
ef4 May 29, 2015
bdda1e2
clarify ClassExpressions vs ClassDeclarations
ef4 May 29, 2015
75fc57f
enforce ES6 rules for constructor super
ef4 May 29, 2015
46d20ad
fix Class scoping
ef4 May 29, 2015
3aac70a
avoid mutating original constructor bodies
ef4 May 30, 2015
a4a3163
preserve semantics of 'arguments' keyword in bound functions
ef4 May 30, 2015
f130d07
fix empty node case
ef4 May 30, 2015
230a7c9
allow class declarations to be converted back to class expressions
ef4 May 30, 2015
063b938
handle "(@foo...) ->"
ef4 May 30, 2015
4d23872
handle class properties whose name happen to be keywords
ef4 May 31, 2015
477d75a
don't try to convert classes that extend expressions
ef4 May 31, 2015
33805a9
only rewrite super when we're inside ES6 classes
ef4 May 31, 2015
e9a35e9
fix missing declarations
ef4 May 31, 2015
09fbe63
make test work in strict mode
ef4 May 31, 2015
9120377
match coffeescript destructuring semantics for empty patterns
ef4 May 31, 2015
34ad7a4
rest param between default params
ef4 May 31, 2015
cb08bfd
don't try to transpile classes with bound members
ef4 May 31, 2015
1c6dcb8
added a macro
ef4 Jun 1, 2015
1a734f9
documenting possible semantic differences
ef4 Jun 1, 2015
b9fcea0
minor docs edit
ef4 Jun 1, 2015
ae17c55
let CS classes extend ES6 classes
ef4 Jun 1, 2015
bec2447
fix a broken (in master) test
ef4 Jun 1, 2015
48104af
disabling some tests that can't work with ES6 classes
ef4 Jun 1, 2015
a96514d
use SpreadElement in function application
ef4 Jun 1, 2015
4865d69
use SpreadElement in array initializer
ef4 Jun 1, 2015
6190214
use spread element for invoking default super arguments
ef4 Jun 1, 2015
93690f6
object destructure
ef4 Jun 1, 2015
d2baf92
ObjectPattern keys don't create local bindings
ef4 Jun 1, 2015
9e88982
support nested patterns inside object patterns
ef4 Jun 1, 2015
69966f0
transpile some ForIn to ForOf
ef4 Jun 1, 2015
b4ead4c
support arbitrary patterns for ForIn value patterns
ef4 Jun 1, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ LIBMIN = $(LIB:lib/%.js=lib/%.min.js)
TEST = $(wildcard test/*.coffee | sort)
ROOT = $(shell pwd)

COFFEE = bin/coffee --js --bare
PEGJS = node_modules/.bin/pegjs --cache --plugin ./lib/pegjs-coffee-plugin
MOCHA = node_modules/.bin/mocha --compilers coffee:./register -u tdd
NODE = $(if ${ES6}, babel-node, node)
COFFEE = ${NODE} bin/coffee --js --bare $(if ${ES6}, --target-es6)
PEGJS = ${NODE} node_modules/.bin/pegjs --cache --plugin ./lib/pegjs-coffee-plugin
MOCHA = ${NODE} node_modules/.bin/mocha --compilers coffee:./register -u tdd
CJSIFY = node_modules/.bin/cjsify --export CoffeeScript
MINIFIER = node_modules/.bin/esmangle

Expand Down
84 changes: 84 additions & 0 deletions README-ES6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Notes for ES6 Mode

The compiler option `--target-es6` enables opportunistic use of ES6
features. This is useful if you are targeting a runtime wiht native
ES6 support, or if you are migrating a codebase from CoffeeScript to
ES6.

Original PR: https://github.com/michaelficarra/CoffeeScriptRedux/pull/344

## What is eligible for ES6 tranpilation?

The following describes the stuff we can convert to ES6. Anything that
is not convertible falls back to the normal CoffeeScript compilation
path.

- Most classes are eligible for conversion directly into ES6
classes. If you have a class that is not being converted, run the
compiler with the environment variable `DEBUG=es6` to see why yours
is being rejected. ES6 is significantly more strict than
CoffeeScript about what's legal in a class definition.

- if you have a constructor, it needs to be a function expression
directly in the class definition. No "external constructors"
like:

class Foo
constructor: someFunctionDeclaredElsewhere

- we don't deal with compound class names like:

class X.Foo

You can get the same effect with assignment, like `X.Foo =
class ...`.

- we don't deal with arbitrary expressions for the parent class
(even though ES6 does support this pattern, it has not been
implemented here):

class X extends someFunctionThatRetunsAClass()

- in ES6, a derived class's constructor *must* call `super()` and
it must do it before referencing `this`. We will automatically
insert a leading `super()` if you weren't manually calling
super at all, but if you already call `super` and you do it
after referencing `this`, we will not transpile your class.

- if you have arbitrary expressions in your class body that do
not translate directly into methods, static methods, prototype
properties, or class properties we will ignore your class.

- Array destructuring is eligible for conversion, with one exception:
ES6 only allows rest parameters at the end of an array pattern, not
in the middle. So `[a, b, c...]` gets converted to `[a, b, ...c]`
but `[a, b..., c]` will not be converted.

- CoffeeScript bound functions (the fat arrow `=>`) are almost
completely analogous to ES6 arrow function expressions, except for
the meaning of the `arguments` keyword. We can safely rewrite every
practical case, but if you are using both positional arguments and
referencing the `arguments` keyword we will give up and fall back
to normal CoffeeScript compilation.


## Semantic Differences

There are some differences in semantics that the compiler does not try
to patch over.

- `super` is required in derived class constructors. If you don't
already call super, we will insert a `super()` call to make your
class legal.

- if you call `super` in a function that's not inside a class
definition, and try to attach that function to a class and use it,
the `super` is not going to work.

- In CoffeeScript, a parameter's default value is used if the given
value is `null` or `undefined`. In ES6, a parameter's default value
is only used if the given value is `undefined`.

- The methods on an ES6 class are non-enumerable. The methods on a
CoffeeScript class are enumerable.

12 changes: 8 additions & 4 deletions lib/browser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 36 additions & 17 deletions lib/cli.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading