1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/documentation/sections/coffeescript_2.md
Geoffrey Booth d20f54967e [CS2] 2.0.0-beta1 docs (#4494)
* Update package versions; remove marked

* Revise docs to use Markdown-It: tables are now GitHub-Flavored Markdown tables, avoid hack of blockquoted code blocks

* Add anchors for sub-sections

* Add syntax highlighting to uneducable code blocks; fix missing italics variant for comments font

* Update docs about breaking changes in Literate CoffeeScript, move Breaking Changes section below Literate CoffeeScript section

* Update docs regarding destructuring default values breaking change

* Update changelog, with spitball release date for beta1

* Fix highlight function return statement
2017-04-09 23:07:58 -07:00

2.4 KiB
Raw Blame History

CoffeeScript 2

Why CoffeeScript When Theres ES2015+?

CoffeeScript introduced many new features to the JavaScript world, such as => and destructuring and classes. We are happy that ECMA has seen their utility and adopted them into ECMAScript.

CoffeeScripts intent, however, was never to be a superset of JavaScript. One of the guiding principles of CoffeeScript has been simplicity: not just removing JavaScripts “bad parts,” but providing a cleaner, terser syntax that uses less punctuation and enforces indentation, to make code easier to read and reason about. Increased clarity leads to increased quality, and fewer bugs. This benefit of CoffeeScript remains, even in an ES2015+ world.

ES2015+ Output

CoffeeScript 2 supports many of the latest ES2015+ features, output using ES2015+ syntax. If youre looking for a single tool that takes CoffeeScript input and generates JavaScript output that runs in any JavaScript runtime, assuming you opt out of certain newer features, stick to the CoffeeScript 1.x branch. CoffeeScript 2 breaks compatibility with certain CoffeeScript 1.x features in order to conform with the ES2015+ specifications, and generate more idiomatic output (a CoffeeScript => becomes an ES =>; a CoffeeScript class becomes an ES class; and so on).

Since the CoffeeScript 2 compiler outputs ES2015+ syntax, it is your responsibility to either ensure that your target JavaScript runtime(s) support all these features, or that you pass the output through another transpiler like Babel, Rollup or Traceur Compiler. In general, CoffeeScript 2s output is supported as is by Node.js 7.6+, except for modules which require transpilation.

There are many great task runners for setting up JavaScript build chains, such as Gulp, Webpack, Grunt and Broccoli. If youre looking for a very minimal solution to get started, you can use babel-preset-env and the command line:

npm install --global coffeescript@next
npm install --save-dev coffeescript@next babel-cli babel-preset-env
coffee -p *.coffee | babel --presets env > app.js