diff --git a/README.md b/README.md index e4b71cee..4b85bc6d 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ coffee -c /path/to/script.coffee For documentation, usage, and examples, see: http://coffeescript.org/ -To suggest a feature or report a bug: http://github.com/jashkenas/coffeescript/issues +To suggest a feature or report a bug: https://github.com/jashkenas/coffeescript/issues If you’d like to chat, drop by #coffeescript on Freenode IRC. @@ -54,4 +54,4 @@ The source repository: https://github.com/jashkenas/coffeescript.git Changelog: http://coffeescript.org/#changelog -Our lovely and talented contributors are listed here: http://github.com/jashkenas/coffeescript/contributors +Our lovely and talented contributors are listed here: https://github.com/jashkenas/coffeescript/contributors diff --git a/docs/v1/annotated-source/cake.html b/docs/v1/annotated-source/cake.html index 98f29fb1..c085fcaf 100644 --- a/docs/v1/annotated-source/cake.html +++ b/docs/v1/annotated-source/cake.html @@ -116,7 +116,7 @@

cake is a simplified version of Make -(Rake, Jake) +(Rake, Jake) for CoffeeScript. You define tasks with names and descriptions in a Cakefile, and can call them from the command line, or invoke them from other tasks.

Running cake with no arguments will print out a list of all the tasks in the diff --git a/docs/v1/annotated-source/grammar.html b/docs/v1/annotated-source/grammar.html index eb724d82..ab1f3ad1 100644 --- a/docs/v1/annotated-source/grammar.html +++ b/docs/v1/annotated-source/grammar.html @@ -115,17 +115,17 @@

-

The CoffeeScript parser is generated by Jison +

The CoffeeScript parser is generated by Jison from this grammar file. Jison is a bottom-up parser generator, similar in style to Bison, implemented in JavaScript. -It can recognize LALR(1), LR(0), SLR(1), and LR(1) +It can recognize LALR(1), LR(0), SLR(1), and LR(1) type grammars. To create the Jison parser, we list the pattern to match on the left-hand side, and the action to take (usually the creation of syntax tree nodes) on the right. As the parser runs, it shifts tokens from our token stream, from left to right, and -attempts to match +attempts to match the token sequence against the rules below. When a match can be made, it -reduces into the nonterminal +reduces into the nonterminal (the enclosing name at the top), and we proceed from there.

If you run the cake build:parser command, Jison constructs a parse table from our rules and saves it into lib/parser.js.

@@ -199,7 +199,7 @@ wrapper and just returning the value directly.

Our handy DSL for Jison grammar generation, thanks to -Tim Caswell. For every rule in the grammar, +Tim Caswell. For every rule in the grammar, we pass the pattern-defining string, the action to run, and extra options, optionally. If no action is specified, we simply pass the value of the previous nonterminal.

diff --git a/docs/v1/annotated-source/lexer.html b/docs/v1/annotated-source/lexer.html index 6ae28040..bd843b65 100644 --- a/docs/v1/annotated-source/lexer.html +++ b/docs/v1/annotated-source/lexer.html @@ -121,7 +121,7 @@ a token is produced, we consume the match, and start again. Tokens are in the form:

[tag, value, locationData]
 

where locationData is {first_line, first_column, last_line, last_column}, which is a -format that can be fed directly into Jison. These +format that can be fed directly into Jison. These are read by jison in the parser.lexer function defined in coffee-script.coffee.

diff --git a/docs/v1/annotated-source/nodes.html b/docs/v1/annotated-source/nodes.html index 22f350c2..f980a12c 100644 --- a/docs/v1/annotated-source/nodes.html +++ b/docs/v1/annotated-source/nodes.html @@ -3941,7 +3941,7 @@ CoffeeScript operations into their JavaScript equivalents.

Am I capable of -Python-style comparison chaining?

+Python-style comparison chaining?

diff --git a/docs/v1/annotated-source/sourcemap.html b/docs/v1/annotated-source/sourcemap.html index 67525c1b..4b9ac673 100644 --- a/docs/v1/annotated-source/sourcemap.html +++ b/docs/v1/annotated-source/sourcemap.html @@ -406,7 +406,7 @@ column for the current line:

Note that SourceMap VLQ encoding is “backwards”. MIDI-style VLQ encoding puts the most-significant-bit (MSB) from the original value into the MSB of the VLQ -encoded value (see Wikipedia). +encoded value (see Wikipedia). SourceMap VLQ does things the other way around, with the least significat four bits of the original value encoded into the first byte of the VLQ encoded value.

diff --git a/docs/v1/index.html b/docs/v1/index.html index 22c352bd..de27322e 100644 --- a/docs/v1/index.html +++ b/docs/v1/index.html @@ -591,18 +591,18 @@ pre .xml .cdata { Annotated Source @@ -612,7 +612,7 @@ pre .xml .cdata {

CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque patina, JavaScript has always had a gorgeous heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.

The golden rule of CoffeeScript is: “It’s just JavaScript”. The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime. You can use any existing JavaScript library seamlessly from CoffeeScript (and vice-versa). The compiled output is readable, pretty-printed, and tends to run as fast or faster than the equivalent handwritten JavaScript.

The CoffeeScript compiler goes to great lengths to generate output JavaScript that runs in every JavaScript runtime, but there are exceptions. Use generator functions, for…from, or tagged template literals only if you know that your target runtimes can support them. If you use modules, you will need to use an additional tool to resolve them.

-

Latest Version: 1.12.5

+

Latest Version: 1.12.5

npm install -g coffee-script
 

CoffeeScript 2 is coming! It adds support for ES2015 classes, async/await, and generates JavaScript using ES2015+ syntax. Learn more.

@@ -738,8 +738,8 @@ cubes = (function() { ;alert(cubes);">run: cubes

Installation

-

The command-line version of 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).

-

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:

+

The command-line version of 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).

+

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:

npm install --global coffee-script
 

When you need CoffeeScript as a dependency of a project, within that project’s folder you can install it locally:

@@ -842,8 +842,7 @@ cubes = (function() {

Literate CoffeeScript

Besides being used as an ordinary programming language, CoffeeScript may also be written in “literate” mode. If you name your file with a .litcoffee extension, you can write it as a Markdown document — a document that also happens to be executable CoffeeScript code. The compiler will treat any indented blocks (Markdown’s way of indicating source code) as code, and ignore the rest as comments.

-

Just for kicks, a little bit of the compiler is currently implemented in this fashion: See it as a document, raw, and properly highlighted in a text editor.

-

I’m fairly excited about this direction for the language, and am looking forward to writing (and more importantly, reading) more programs in this style. More information about Literate CoffeeScript, including an example program, are available in this blog post.

+

Just for kicks, a little bit of the compiler is currently implemented in this fashion: See it as a document, raw, and properly highlighted in a text editor.

Language Reference

@@ -1470,7 +1469,7 @@ alert((function() {

unless can be used as the inverse of if.

As a shortcut for this.property, you can use @property.

You can use in to test for array presence, and of to test for JavaScript object-key presence.

-

To simplify math expressions, ** can be used for exponentiation and // performs integer division. % works just like in JavaScript, while %% provides “dividend dependent modulo”:

+

To simplify math expressions, ** can be used for exponentiation and // performs integer division. % works just like in JavaScript, while %% provides “dividend dependent modulo”:

-7 % 5 == -2 # The remainder of 7 / 5
 -7 %% 5 == 3 # n %% 5 is always between 0 and 4
 
@@ -1625,7 +1624,7 @@ zip = typeof lottery.drawWinner === 
       

Classes, Inheritance, and Super

-

JavaScript’s prototypal inheritance has always been a bit of a brain-bender, with a whole family tree of libraries that provide a cleaner syntax for classical inheritance on top of JavaScript’s prototypes: Base2, Prototype.js, JS.Class, etc. The libraries provide syntactic sugar, but the built-in inheritance would be completely usable if it weren’t for a couple of small exceptions: it’s awkward to call super (the prototype object’s implementation of the current function), and it’s awkward to correctly set the prototype chain.

+

JavaScript’s prototypal inheritance has always been a bit of a brain-bender, with a whole family tree of libraries that provide a cleaner syntax for classical inheritance on top of JavaScript’s prototypes: Base2, Prototype.js, JS.Class, etc. The libraries provide syntactic sugar, but the built-in inheritance would be completely usable if it weren’t for a couple of small exceptions: it’s awkward to call super (the prototype object’s implementation of the current function), and it’s awkward to correctly set the prototype chain.

Instead of repetitively attaching functions to a prototype, CoffeeScript provides a basic class structure that allows you to name your class, set the superclass, assign prototypal properties, and define the constructor, in a single assignable expression.

Constructor functions are named, to better support helpful stack traces. In the first class in the example below, this.constructor.name is "Animal".

class Animal
@@ -1950,6 +1949,7 @@ Account = function(
load

If we had used -> in the callback above, @customer would have referred to the undefined “customer” property of the DOM element, and trying to call purchase() on it would have raised an exception.

When used in a class definition, methods declared with the fat arrow will be automatically bound to each instance of the class when the instance is constructed.

+

CoffeeScript functions also support ES2015 generator functions through the yield keyword. There’s no function*(){} nonsense — a generator in CoffeeScript is simply a function that yields.

perfectSquares = ->
   num = 0
@@ -1984,6 +1984,7 @@ perfectSquares = function*() {
 
 window.ps || (window.ps = perfectSquares());
 ;alert(ps.next().value);">run: ps.next().value

yield* is called yield from, and yield return may be used if you need to force a generator that doesn’t yield.

+

You can iterate over a generator function using for…from.

fibonacci = ->
   [previous, current] = [1, 1]
@@ -2184,7 +2185,7 @@ grade = (function(
load

Chained Comparisons

-

CoffeeScript borrows chained comparisons from Python — making it easy to test if a value falls within a certain range.

+

CoffeeScript borrows chained comparisons from Python — making it easy to test if a value falls within a certain range.

cholesterol = 127
 
 healthy = 200 > cholesterol > 60
@@ -2405,7 +2406,8 @@ OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>&g
   max,
   min
 } from 'underscore';
-
load

Note that the CoffeeScript compiler does not resolve modules; writing an import or export statement in CoffeeScript will produce an import or export statement in the resulting output. It is your responsibility attach another transpiler, such as Traceur Compiler, Babel or Rollup, to convert this ES2015 syntax into code that will work in your target runtimes.

+
load

+

Note that the CoffeeScript compiler does not resolve modules; writing an import or export statement in CoffeeScript will produce an import or export statement in the resulting output. It is your responsibility attach another transpiler, such as Traceur Compiler, Babel or Rollup, to convert this ES2015 syntax into code that will work in your target runtimes.

Also note that any file with an import or export statement will be output without a top-level function safety wrapper; in other words, importing or exporting modules will automatically trigger bare mode for that file. This is because per the ES2015 spec, import or export statements must occur at the topmost scope.

@@ -2434,16 +2436,16 @@ task('build:parser', 'rebuild t dir = options.output || 'lib'; return fs.writeFile(dir + "/parser.js", code); }); -
load

If you need to invoke one task before another — for example, running 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.

+
load

If you need to invoke one task before another — for example, running 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.

Source Maps

CoffeeScript 1.6.1 and above include support for generating source maps, a way to tell your JavaScript engine what part of your CoffeeScript program matches up with the code being evaluated. Browsers that support it can automatically use source maps to show your original source code in the debugger. To generate source maps alongside your JavaScript files, pass the --map or -m flag to the compiler.

-

For a full introduction to source maps, how they work, and how to hook them up in your browser, read the HTML5 Tutorial.

+

For a full introduction to source maps, how they work, and how to hook them up in your browser, read the HTML5 Tutorial.

“text/coffeescript” Script Tags

-

While it’s not recommended for serious use, CoffeeScripts may be included directly within the browser using <script type="text/coffeescript"> tags. The source includes a compressed and minified version of the compiler (Download current version here, 51k when gzipped) as v1/browser-compiler/coffee-script.js. Include this file on a page with inline CoffeeScript tags, and it will compile and evaluate them in order.

+

While it’s not recommended for serious use, CoffeeScripts may be included directly within the browser using <script type="text/coffeescript"> tags. The source includes a compressed and minified version of the compiler (Download current version here, 51k when gzipped) as v1/browser-compiler/coffee-script.js. Include this file on a page with inline CoffeeScript tags, and it will compile and evaluate them in order.

In fact, the little bit of glue script that runs “Try CoffeeScript” above, as well as the jQuery for the menu, 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 CoffeeScript.compile() so you can pop open Firebug and try compiling some strings.

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 window object.

@@ -2451,22 +2453,22 @@ task('build:parser', 'rebuild t

Books

There are a number of excellent resources to help you get started with CoffeeScript, some of which are freely available online.

Screencasts

@@ -2474,10 +2476,9 @@ task('build:parser', 'rebuild t

Examples

The best list of open-source CoffeeScript examples can be found on GitHub. But just to throw out a few more: