diff --git a/Cakefile b/Cakefile index b28c85b307..44c37011c9 100644 --- a/Cakefile +++ b/Cakefile @@ -403,11 +403,6 @@ runTests = (CoffeeScript) -> # Run every test in the `test` folder, recording failures. files = fs.readdirSync 'test' - # Ignore async test file if async/await is not available - asyncSupported = parseInt(process.versions.node.split('.')[0]) >= 7 and - ('--harmony' in process.execArgv or '--harmony-async-await' in process.execArgv) - files.splice files.indexOf('async.coffee'), 1 unless asyncSupported - for file in files when helpers.isCoffee file literate = helpers.isLiterate file currentFile = filename = path.join 'test', file diff --git a/docs/v2/index.html b/docs/v2/index.html index ac13408095..76e5d7e7a0 100644 --- a/docs/v2/index.html +++ b/docs/v2/index.html @@ -607,6 +607,9 @@
CoffeeScript on the top
CoffeeScript 2 generates JavaScript that uses the latest ES2015+ features. It is your responsibility to 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 2’s output is fully supported by Node.js 7+, although async functions require the If you’re 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 CoffeeScript introduced many new features to the JavaScript world, such as CoffeeScript’s intent, however, was never to be a superset of JavaScript. One of the guiding principles of CoffeeScript has been simplicity: not just removing JavaScript’s “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. CoffeeScript 2 supports many of the latest ES2015+ features, output using ES2015+ syntax. If you’re 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 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 2’s 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 you’re looking for a very minimal solution to get started, you can use babel-preset-env and the command line: The command-line version of The command-line version of To install, first make sure you have a working copy of the latest stable version of Node.js. You can then install CoffeeScript globally with npm: Hopefully, you’ll never need to use it, but if
There are a few ECMAScript features that CoffeeScript intentionally doesn’t support. When CoffeeScript was designed, Keep in mind that This is to avoid grammatical ambiguity, since in CoffeeScript such a construct looks identical to a function call (e.g. CoffeeScript 2 aims to output as much idiomatic ES2015+ syntax as possible with as few breaking changes from CoffeeScript 1.x as possible. Some breaking changes, unfortunately, were unavoidable. Per the ES2015 spec regarding default parameters, default values are only applied when a parameter value is missing or CoffeeScript includes a (very) simple build syste
- If you need to invoke one task before another — for example, running If you need to invoke one task before another — for example, running While it’s not recommended for serious use, CoffeeScripts may be included directly within the browser using While it’s not recommended for serious use, CoffeeScripts may be included directly within the browser using In fact, the little bit of glue script that runs Try CoffeeScript, as well as the code examples and other interactive parts of this site, is implemented in just this way. View source and look at the bottom of the page to see the example. Including the script also gives you access to The usual caveats about CoffeeScript apply — your inline scripts will run within a closure wrapper, so if you want to expose global variables or functions, attach them to the You can browse the CoffeeScript 2.0.0-alpha1 source
Contributions are welcome! Feel free to fork the repo and submit a pull request. Some features of ECMAScript are intentionally unsupported. Please review both the open and closed issues on GitHub to see if the feature you’re looking for has already been discussed. As a general rule, we don’t support ECMAScript syntax for features that aren’t yet finalized (at Stage 4 in the proposal approval process). For more resources on adding to CoffeeScript, please see the Wiki, especially How The Parser Works. There are several things you can do to increase your odds of having your pull request accepted: Of course, it’s entirely possible that you have a great addition, but it doesn’t fit within these constraints. Feel free to roll your own solution; you will have plenty of company.CoffeeScript 2
--harmony or --harmony-async-await flags; and ES2015 modules require an additional transpiler. Output JavaScript intended for browsers generally requires additional transpilation.=> becomes an ES =>; a CoffeeScript class becomes an ES class; and so on).CoffeeScript 2
Why CoffeeScript When There’s ES2015+?
=> and destructuring and classes. We are happy that ECMA has seen their utility and adopted them into ECMAScript.ES2015+ Output
=> becomes an ES =>; a CoffeeScript class becomes an ES class; and so on).
+
npm install --global coffeescript@next
+npm install --save-dev coffeescript@next babel-cli babel-preset-env
+coffee -p *.coffee | babel --presets env > app.jsInstallation
coffee is available as a Node.js utility. The core compiler however, does not depend on Node, and can be run in any JavaScript environment, or in the browser (see Try CoffeeScript).Installation
coffee is available as a Node.js utility. The core compiler however, does not depend on Node, and can be run in any JavaScript environment, or in the browser (see Try CoffeeScript).
@@ -2994,6 +3007,60 @@ npm install --global coffeescript@nextEmbedded JavaScript
Unsupported ECMAScript Features
let and const: Block-Scoped and Reassignment-Protected Variablesvar was intentionally omitted. This was to spare developers the mental housekeeping of needing to worry about variable declaration (var foo) as opposed to variable assignment (foo = 1). The CoffeeScript compiler automatically takes care of declaration for you, by generating var statements at the top of every function scope. This makes it impossible to accidentally declare a global variable.let and const add a useful ability to JavaScript in that you can use them to declare variables within a block scope, for example within an if statement body or a for loop body, whereas var always declares variables in the scope of an entire function. When CoffeeScript 2 was designed, there was much discussion of whether this functionality was useful enough to outweigh the simplicity offered by never needing to consider variable declaration in CoffeeScript. In the end, it was decided that the simplicity was more valued. In CoffeeScript there remains only one type of variable.const only protects you from reassigning a variable; it doesn’t prevent the variable’s value from changing, the way constants usually do in other languages:
+
+const obj = {foo: 'bar'};
+obj.foo = 'baz'; // Allowed!
+obj = {}; // Throws errorget and set Keyword Shorthand Syntaxget and set, as keywords preceding functions or class methods, are intentionally unimplemented in CoffeeScript.get(function foo() {})); and because there is an alternate syntax that is slightly more verbose but just as effective:Breaking Changes From CoffeeScript 1.x to 2
Function parameter default values
undefined. In CoffeeScript 1.x, the default value would be applied in those cases but also if the parameter value was null.Cake, and Cakefiles
build before test, you can use the invoke function: invoke 'build'. Cake tasks are a minimal way to expose your CoffeeScript functions to the command line, so don’t expect any fanciness built-in. If you need dependencies, or async callbacks, it’s best to put them in your code itself — not the cake task.build before test, you can use the invoke function: invoke 'build'. Cake tasks are a minimal way to expose your CoffeeScript functions to the command line, so don’t expect any fanciness built-in. If you need dependencies, or async callbacks, it’s best to put them in your code itself — not the cake task."text/coffeescript" Script Tags<script type="text/coffeescript"> tags. The source includes a compressed and minified version of the compiler (Download current version here, 51k when gzipped) as v2/browser-compiler/coffeescript.js. Include this file on a page with inline CoffeeScript tags, and it will compile and evaluate them in order."text/coffeescript" Script Tags<script type="text/coffeescript"> tags. The source includes a compressed and minified version of the compiler (Download current version here, 51k when gzipped) as v2/browser-compiler/coffeescript.js. Include this file on a page with inline CoffeeScript tags, and it will compile and evaluate them in order.CoffeeScript.compile() so you can pop open your JavaScript console and try compiling some strings.window object.Annotated Source
Contributing
+
+
MINIFY=false cake build:browser.Error.prepareStackTrace has been removed.
@@ -3373,7 +3454,7 @@
for…from syntax for outputting ES2015 for…of. (Sorry they couldn’t match, but we came up with for…of first for something else.) This allows iterating over generators or any other iterable object. Note that using for…from in your code makes you responsible for ensuring that either your runtime supports for…of or that you transpile the output JavaScript further to a version your target runtime(s) support.```) allow the creation of embedded JavaScript blocks where escaping single backticks is not required, which should improve interoperability with ES2015 template literals and with Markdown.\`.imports and exports are now ignored.