Some quick notes on hand-converting from CoffeeScript to ES6/ECMAScript 2015 (e.g. for use with bablejs):
- add
'use strict';
to beginning of file - add
let
before new variable assignments, orconst
if they are constant - add semicolons to end of statements (optional)
- add commas between elements of multi-line array literals
- add parenthesizes around function calls
- add braces around blocks
- replace
(args) =>
with(args) => {
arrow functions - replace
for x in a
withfor (let x of a) {
- replace
#
with//
comments - replace
==
with===
and!=
with!==
strict equality comparison - replace
"#{x}"
with backquote template strings
`${x}`
- replace suffixed if/unless with prefixed if
- replace expression
if x then y else z
with ternary operatorx ? y : z
- replace
class Foo
withclass Foo {
- replace method declarations
m: () ->
withm() {
- replace class method declaration
@m: () ->
withstatic m() {
- replace class variable declaration
@x = y
with static property getterstatic get x() { return y; }
- replace
@
instance variables withthis.
- replace
and
with&&
,or
with||
,not
with!
- replace
x ? y
existential operator withtypeof(x) !== 'undefined' : x : y
- replace coffeeify browserify transform with babelify
- ...
note: these are simplified shortcuts, use with caution. references: