Skip to content

Instantly share code, notes, and snippets.

@deathcap
Last active August 29, 2015 14:15
Show Gist options
  • Save deathcap/3eb80f28b4545345f084 to your computer and use it in GitHub Desktop.
Save deathcap/3eb80f28b4545345f084 to your computer and use it in GitHub Desktop.
Notes on converting CoffeeScript to ES6

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, or const 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 with for (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 operator x ? y : z
  • replace class Foo with class Foo {
  • replace method declarations m: () -> with m() {
  • replace class method declaration @m: () -> with static m() {
  • replace class variable declaration @x = y with static property getter static get x() { return y; }
  • replace @ instance variables with this.
  • replace and with &&, or with ||, not with !
  • replace x ? y existential operator with typeof(x) !== 'undefined' : x : y
  • replace coffeeify browserify transform with babelify
  • ...

note: these are simplified shortcuts, use with caution. references:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment