exports.flatten = flatten = (array) ->
flattened = []
for element in array
- if element instanceof Array
+ if'[object Array]'isObject::toString.call element
flattened = flattened.concat flatten element
else
flattened.push element
diff --git a/documentation/docs/lexer.html b/documentation/docs/lexer.html
index 2012a849b7..0b1174921c 100644
--- a/documentation/docs/lexer.html
+++ b/documentation/docs/lexer.html
@@ -216,6 +216,7 @@
The Lexer Class
@indents = [] # The stack of all current indentation levels.@ends = [] # The stack for pairing up tokens.@tokens = [] # Stream of parsed tokens in the form `['TYPE', value, location data]`.
+ @seenFor = no# Used to recognize FORIN and FOROF tokens.@chunkLine =
opts.line or0# The start line for the current @chunk.
diff --git a/documentation/docs/nodes.html b/documentation/docs/nodes.html
index e7243a4ba6..475684f269 100644
--- a/documentation/docs/nodes.html
+++ b/documentation/docs/nodes.html
@@ -2028,8 +2028,11 @@
Obj
',\n'
indent = if prop instanceof Comment then''else idt
indent += TAB if hasDynamic and i < dynamicIndex
- if prop instanceof Assign and prop.variable instanceof Value and prop.variable.hasProperties()
- prop.variable.error 'invalid object key'
+ if prop instanceof Assign
+ if prop.context isnt'object'
+ prop.operatorToken.error "unexpected #{prop.operatorToken.value}"
+ if prop.variable instanceof Value and prop.variable.hasProperties()
+ prop.variable.error 'invalid object key'if prop instanceof Value and prop.this
prop = new Assign prop.properties[0].name, prop, 'object'if prop notinstanceof Comment
@@ -2410,9 +2413,8 @@
Assign
exports.Assign = classAssignextendsBase
- constructor: (@variable, @value, @context, options) ->
- @param = options and options.param
- @subpattern = options and options.subpattern
+ constructor: (@variable, @value, @context, options = {}) ->
+ {@param, @subpattern, @operatorToken} = options
forbidden = (name = @variable.unwrapAll().value) in STRICT_PROSCRIBED
if forbidden and@contextisnt'object'@variable.error "variable name may not be \"#{name}\""
@@ -2471,6 +2473,7 @@
Assign
else
o.scope.find varBase.value
val = @value.compileToFragments o, LEVEL_LIST
+ @variable.front = trueif isValue and@variable.base instanceof Obj
compiledName = @variable.compileToFragments o, LEVEL_LIST
return (compiledName.concat @makeCode(": "), val) if@contextis'object'
answer = compiledName.concat @makeCode(" #{ @contextor'=' } "), val
@@ -2486,9 +2489,7 @@
Brief implementation of recursive pattern matching, when assigning array or
-object literals to a value. Peeks at their properties to assign inner names.
-See the ECMAScript Harmony Wiki
-for details.
+object literals to a value. Peeks at their properties to assign inner names.
@@ -2499,8 +2500,11 @@
Assign
unless olen = objects.length
code = value.compileToFragments o
returnif o.level >= LEVEL_OP then@wrapInBraces code else code
+ [obj] = objects
+ if olen is1and obj instanceof Expansion
+ obj.error 'Destructuring assignment has no target'
isObject = @variable.isObject()
- if top and olen is1and (obj = objects[0]) notinstanceof Splat
+ if top and olen is1and obj notinstanceof Splat
@@ -2511,27 +2515,13 @@
new Literal 0
+ acc = IDENTIFIER.test idx.unwrap().value
+ value = new Value value
+ value.properties.push new (if acc then Access else Index) idx
+ if obj.unwrap().value in RESERVED
+ obj.error "assignment to a reserved word: #{obj.compile o}"
+ value = new Op '?', value, defaultValue if defaultValue
+ returnnew Assign(obj, value, null, param: @param).compileToFragments o, LEVEL_TOP
+ vvar = value.compileToFragments o, LEVEL_LIST
+ vvarText = fragmentsToText vvar
+ assigns = []
+ expandedIdx = false
Make vvar into a simple variable if it isn’t already.
-
if obj.base instanceof Parens
- [obj, idx] = new Value(obj.unwrapAll()).cacheReference o
- else
- idx = if obj.thisthen obj.properties[0].name else obj
+
ifnot IDENTIFIER.test(vvarText) or@variable.assigns(vvarText)
+ assigns.push [@makeCode("#{ ref = o.scope.freeVariable 'ref' } = "), vvar...]
+ vvar = [@makeCode ref]
+ vvarText = ref
+ for obj, i in objects
+ idx = i
ifnot expandedIdx and obj instanceof Splat
name = obj.name.unwrap().value
obj = obj.unwrap()
@@ -2624,15 +2629,68 @@
Assign
assigns.push val.compileToFragments o, LEVEL_LIST
continueelse
- name = obj.unwrap().value
if obj instanceof Splat or obj instanceof Expansion
obj.error "multiple splats/expansions are disallowed in an assignment"
- iftypeof idx is'number'
- idx = new Literal expandedIdx or idx
- acc = no
+ defaultValue = null
+ if obj instanceof Assign and obj.context is'object'
new Literal expandedIdx or idx
+ name = obj.unwrap().value
+ acc = IDENTIFIER.test idx.unwrap().value
val = new Value new Literal(vvarText), [new (if acc then Access else Index) idx]
+ val = new Op '?', val, defaultValue if defaultValue
if name? and name in RESERVED
obj.error "assignment to a reserved word: #{obj.compile o}"
assigns.push new Assign(obj, val, null, param: @param, subpattern: yes).compileToFragments o, LEVEL_LIST
@@ -2643,11 +2701,11 @@
When compiling a conditional assignment, take care to ensure that the
operands are only evaluated once, even though we have to reference them
@@ -2661,11 +2719,11 @@
A function definition. This is the only node that creates a new Scope.
When for the purposes of walking the contents of a function body, the Code
@@ -2781,11 +2839,11 @@
Compilation creates a new scope unless explicitly asked to share with the
outer scope. Handles splat parameters in the parameter list by peeking at
@@ -2803,11 +2861,11 @@
A parameter in a function definition. Beyond a typical Javascript parameter,
these parameters can also attach themselves to the context of the function,
@@ -2925,6 +2983,9 @@
Param
constructor: (@name, @value, @splat) ->if (name = @name.unwrapAll().value) in STRICT_PROSCRIBED
@name.error "parameter name \"#{name}\" is not allowed"
+ if@nameinstanceof Obj and@name.generated
+ token = @name.objects[0].operatorToken
+ token.error "unexpected #{token.value}"children: ['name', 'value']
@@ -2951,11 +3012,11 @@
A while loop, the only sort of low-level loop exposed by CoffeeScript. From
it, all other loops can be manufactured. Useful in cases where you need more
@@ -3277,11 +3356,11 @@
The main difference from a JavaScript while is that the CoffeeScript
while can be used as a part of a larger expression — while loops may
@@ -3314,11 +3393,11 @@
Checks a variable for existence — not null and not undefined. This is
similar to .nil? in Ruby, and avoids having to consult a JavaScript truth
@@ -3861,11 +3941,11 @@
An extra set of parentheses, specified explicitly in the source. At one time
we tried to clean up the results by detecting and removing redundant
@@ -3924,11 +4004,11 @@
CoffeeScript’s replacement for the for loop is our array and object
comprehensions, that compile into for loops here. They also act as an
@@ -3972,11 +4052,11 @@
Welcome to the hairiest method in all of CoffeeScript. Handles the inner
loop, filtering, stepping, and result saving for array, object, and range
@@ -4082,11 +4162,11 @@
The CoffeeScript compiler is itself
written in CoffeeScript,
using the Jison parser generator. The
- command-line version of coffee is available as a
+ 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
@@ -285,8 +286,8 @@
npm install -g jashkenas/coffeescript
- Or, if you want to install to /usr/local, and don't want to use
- npm to manage it, open the coffee-script directory and run:
+ Or, if you want to install to /usr/local, and don't want to use
+ npm to manage it, open the coffee-script directory and run:
@@ -298,9 +299,9 @@
- Once installed, you should have access to the coffee command,
- which can execute scripts, compile .coffee files into .js,
- and provide an interactive REPL. The coffee command takes the
+ Once installed, you should have access to the coffee command,
+ which can execute scripts, compile .coffee files into .js,
+ and provide an interactive REPL. The coffee command takes the
following options:
@@ -308,7 +309,7 @@
-c, --compile
- Compile a .coffee script into a .js JavaScript file
+ Compile a .coffee script into a .js JavaScript file
of the same name.
@@ -316,21 +317,21 @@
-m, --map
Generate source maps alongside the compiled JavaScript files. Adds
- sourceMappingURL directives to the JavaScript as well.
+ sourceMappingURL directives to the JavaScript as well.
-i, --interactive
Launch an interactive CoffeeScript session to try short snippets.
- Identical to calling coffee with no arguments.
+ Identical to calling coffee with no arguments.
-o, --output [DIR]
Write out all compiled JavaScript files into the specified directory.
- Use in conjunction with --compile or --watch.
+ Use in conjunction with --compile or --watch.
@@ -360,7 +361,7 @@
Pipe in CoffeeScript to STDIN and get back JavaScript over STDOUT.
Good for use with processes written in other languages. An example:
- cat src/cake.coffee | coffee -sc
+ cat src/cake.coffee | coffee -sc
@@ -375,7 +376,7 @@
-e, --eval
Compile and print a little snippet of CoffeeScript directly from the
- command line. For example: coffee -e "console.log num for num in [10..1]"
+ command line. For example: coffee -e "console.log num for num in [10..1]"
@@ -389,7 +390,7 @@
-t, --tokens
Instead of parsing the CoffeeScript, just lex it, and print out the
- token stream: [IDENTIFIER square] [ASSIGN =] [PARAM_START (] ...
+ token stream: [IDENTIFIER square] [ASSIGN =] [PARAM_START (] ...
@@ -410,10 +411,10 @@
--nodejs
- The node executable has some useful options you can set,
- such as --debug, --debug-brk, --max-stack-size,
- and --expose-gc. Use this flag to forward options directly to Node.js.
- To pass multiple flags, use --nodejs multiple times.
+ The node executable has some useful options you can set,
+ such as --debug, --debug-brk, --max-stack-size,
+ and --expose-gc. Use this flag to forward options directly to Node.js.
+ To pass multiple flags, use --nodejs multiple times.
@@ -424,29 +425,29 @@
- Compile a directory tree of .coffee files in src into a parallel
- tree of .js files in lib:
- coffee --compile --output lib/ src/
+ Compile a directory tree of .coffee files in src into a parallel
+ tree of .js files in lib:
+ coffee --compile --output lib/ src/
Watch a file for changes, and recompile it every time the file is saved:
- coffee --watch --compile experimental.coffee
+ coffee --watch --compile experimental.coffee
Concatenate a list of files into a single script:
- coffee --join project.js --compile src/*.coffee
+ coffee --join project.js --compile src/*.coffee
Print out the compiled JS from a one-liner:
- coffee -bpe "alert i for i in [0..10]"
+ coffee -bpe "alert i for i in [0..10]"
All together now, watch and recompile an entire project as you work on it:
- coffee -o lib/ -cw src/
+ coffee -o lib/ -cw src/
- Start the CoffeeScript REPL (Ctrl-D to exit, Ctrl-Vfor multi-line):
- coffee
+ Start the CoffeeScript REPL (Ctrl-D to exit, Ctrl-Vfor multi-line):
+ coffee
@@ -458,7 +459,7 @@
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 —
+ .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.
@@ -503,11 +504,11 @@
First, the basics: CoffeeScript uses significant whitespace to delimit blocks of code.
- You don't need to use semicolons ; to terminate expressions,
+ You don't need to use semicolons ; to terminate expressions,
ending the line will do just as well (although semicolons can still
be used to fit multiple expressions onto a single line).
Instead of using curly braces
- { } to surround blocks of code in functions,
+ { } to surround blocks of code in functions,
if-statements,
switch, and try/catch,
use indentation.
@@ -516,7 +517,7 @@
You don't need to use parentheses to invoke a function if you're passing
arguments. The implicit call wraps forward to the end of the line or block expression.
- console.log sys.inspect object → console.log(sys.inspect(object));
+ console.log sys.inspect object → console.log(sys.inspect(object));
@@ -524,7 +525,7 @@
Functions
Functions are defined by an optional list of parameters in parentheses,
an arrow, and the function body. The empty function looks like this:
- ->
+ ->
square = (x) -> x * x
cube = (x) -> square(x) * x
@@ -549,16 +550,10 @@
;alert(cube(5));'>run: cube(5)
Functions may also have default values for arguments, which will be used
- if the incoming argument is missing (null or undefined).
+ if the incoming argument is missing (null or undefined).
fill = (container, liquid = "coffee") ->"Filling the #{container} with #{liquid}..."
-
-
-
-
-
-
var fill;
fill = function(container, liquid) {
@@ -567,7 +562,7 @@
}
return"Filling the " + container + " with " + liquid + "...";
};
-
load
load
load
load
run: song.join(" ... ")
- In JavaScript, you can't use reserved words, like class, as properties
+ In JavaScript, you can't use reserved words, like class, as properties
of an object, without quoting them as strings. CoffeeScript notices reserved words
used as keys in objects and quotes them for you, so you don't have to worry
about it (say, when using jQuery).
@@ -656,21 +649,19 @@
Lexical Scoping and Variable Safety
The CoffeeScript compiler takes care to make sure that all of your variables
are properly declared within lexical scope — you never need to write
- var yourself.
+ var yourself.
outer = 1changeNumbers = ->
@@ -709,7 +700,7 @@
This behavior is effectively identical to Ruby's scope for local variables.
- Because you don't have direct access to the var keyword,
+ Because you don't have direct access to the var keyword,
it's impossible to shadow an outer variable on purpose, you may only refer
to it. So be careful that you're not reusing the name of an external
variable accidentally, if you're writing a deeply nested function.
@@ -717,8 +708,8 @@
Although suppressed within this documentation for clarity, all
CoffeeScript output is wrapped in an anonymous function:
- (function(){ ... })(); This safety wrapper, combined with the
- automatic generation of the var keyword, make it exceedingly difficult
+ (function(){ ... })(); This safety wrapper, combined with the
+ automatic generation of the var keyword, make it exceedingly difficult
to pollute the global namespace by accident.
@@ -726,7 +717,7 @@
attach them as properties on window, or on the exports
object in CommonJS. The existential operator (covered below), gives you a
reliable way to figure out where to add them; if you're targeting both
- CommonJS and the browser: exports ? this
+ CommonJS and the browser: exports ? this
@@ -735,7 +726,7 @@
If/else statements can be written without the use of parentheses and
curly brackets. As with functions and other block expressions,
multi-line conditionals are delimited by indentation. There's also a handy
- postfix form, with the if or unless at the end.
+ postfix form, with the if or unless at the end.
CoffeeScript can compile if statements into JavaScript expressions,
@@ -752,9 +743,6 @@
showIt()
date = if friday then sue else jill
-
-
-
var date, mood;
if (singing) {
@@ -769,14 +757,14 @@
}
date = friday ? sue : jill;
-
load
+
load
Splats...
The JavaScript arguments object is a useful way to work with
functions that accept variable numbers of arguments. CoffeeScript provides
- splats ..., both for function definition as well as invocation,
+ splats ..., both for function definition as well as invocation,
making variable numbers of arguments a little bit more palatable.
true — or null,
+ by adding a meaningful return value — like true — or null,
to the bottom of your function.
To step through a range comprehension in fixed-size chunks,
- use by, for example:
- evens = (x for x in [0..10] by 2)
+ use by, for example:
+ evens = (x for x in [0..10] by 2)
If you don't need the current iteration value you may omit it:
- browser.closeCurrentTab() for [0...count]
+ browser.closeCurrentTab() for [0...count]
Comprehensions can also be used to iterate over the keys and values in
- an object. Use of to signal comprehension over the properties of
+ an object. Use of to signal comprehension over the properties of
an object instead of the values in an array.
If you would like to iterate over just the keys that are defined on the
- object itself, by adding a hasOwnProperty
+ object itself, by adding a hasOwnProperty
check to avoid properties that may be inherited from the prototype, use
- for own key, value of object
+ for own key, value of object
The only low-level loop that CoffeeScript provides is the while loop. The
@@ -1056,14 +1041,14 @@
"));'>run: lyrics.join("
")
- For readability, the until keyword is equivalent to while not,
- and the loop keyword is equivalent to while true.
+ For readability, the until keyword is equivalent to while not,
+ and the loop keyword is equivalent to while true.
When using a JavaScript loop to generate functions, it's common to insert
a closure wrapper in order to ensure that loop variables are closed over,
and all the generated functions don't just share the final values. CoffeeScript
- provides the do keyword, which immediately invokes a passed function,
+ provides the do keyword, which immediately invokes a passed function,
forwarding any arguments.
for filename in list
@@ -1086,8 +1071,8 @@
Array Slicing and Splicing with Ranges
Ranges can also be used to extract slices of arrays.
- With two dots (3..6), the range is inclusive (3, 4, 5, 6);
- with three dots (3...6), the range excludes the end (3, 4, 5).
+ With two dots (3..6), the range is inclusive (3, 4, 5, 6);
+ with three dots (3...6), the range excludes the end (3, 4, 5).
Slices indices have useful defaults. An omitted first index defaults to
zero and an omitted second index defaults to the size of the array.
@@ -1130,15 +1115,12 @@
return gets
+ language can be used as expressions. Watch how the return gets
pushed down into each possible branch of execution in the function
below.
@@ -1203,19 +1185,17 @@
Even though functions will always return their final value, it's both possible
and encouraged to return early from a function body writing out the explicit
- return (return value), when you know that you're done.
+ return (return value), when you know that you're done.
Because variable declarations occur at the top of scope, assignment can
be used within expressions, even for variables that haven't been seen before:
six = (one = 1) + (two = 2) + (three = 3)
-
-
var one, six, three, two;
six = (one = 1) + (two = 2) + (three = 3);
-
There are a handful of statements in JavaScript that can't be meaningfully
- converted into expressions, namely break, continue,
- and return. If you make use of them within a block of code,
+ converted into expressions, namely break, continue,
+ and return. If you make use of them within a block of code,
CoffeeScript won't try to perform the conversion.
Operators and Aliases
- Because the == operator frequently causes undesirable coercion,
+ Because the == operator frequently causes undesirable coercion,
is intransitive, and has a different meaning than in other languages,
- CoffeeScript compiles == into ===, and != into
- !==.
- In addition, is compiles into ===,
- and isnt into !==.
+ CoffeeScript compiles == into ===, and != into
+ !==.
+ In addition, is compiles into ===,
+ and isnt into !==.
- You can use not as an alias for !.
+ You can use not as an alias for !.
- For logic, and compiles to &&, and or
- into ||.
+ For logic, and compiles to &&, and or
+ into ||.
- Instead of a newline or semicolon, then can be used to separate
+ Instead of a newline or semicolon, then can be used to separate
conditions from expressions, in while,
if/else, and switch/when statements.
- As in YAML, on and yes
- are the same as boolean true, while off and no are boolean false.
+ As in YAML, on and yes
+ are the same as boolean true, while off and no are boolean false.
- unless can be used as the inverse of if.
+ unless can be used as the inverse of if.
- As a shortcut for this.property, you can use @property.
+ As a shortcut for this.property, you can use @property.
- You can use in to test for array presence, and of to
+ 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
+ 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
@@ -1347,19 +1328,19 @@
CoffeeScript
JavaScript
-
is
===
-
isnt
!==
-
not
!
-
and
&&
-
or
||
-
true, yes, on
true
-
false, no, off
false
-
@, this
this
-
of
in
-
in
no JS equivalent
-
a ** b
Math.pow(a, b)
-
a // b
Math.floor(a / b)
-
a %% b
(a % b + b) % b
+
is
===
+
isnt
!==
+
not
!
+
and
&&
+
or
||
+
true, yes, on
true
+
false, no, off
false
+
@, this
this
+
of
in
+
in
no JS equivalent
+
a ** b
Math.pow(a, b)
+
a // b
Math.floor(a / b)
+
a %% b
(a % b + b) % b
launch() if ignition ison
@@ -1401,13 +1382,13 @@
The Existential Operator
It's a little difficult to check for the existence of a variable in
- JavaScript. if (variable) ... comes close, but fails for zero,
- the empty string, and false. CoffeeScript's existential operator ? returns true unless
+ JavaScript. if (variable) ... comes close, but fails for zero,
+ the empty string, and false. CoffeeScript's existential operator ? returns true unless
a variable is null or undefined, which makes it analogous
- to Ruby's nil?
+ to Ruby's nil?
- It can also be used for safer conditional assignment than ||=
+ It can also be used for safer conditional assignment than ||=
provides, for cases where you may be handling numbers or strings.
var footprints, solipsism, speed;
if ((typeof mind !== "undefined" && mind !== null) && (typeof world === "undefined" || world === null)) {
solipsism = true;
@@ -1435,7 +1410,7 @@
- The accessor variant of the existential operator ?. can be used to soak
+ The accessor variant of the existential operator ?. can be used to soak
up null references in a chain of properties. Use it instead
- of the dot accessor . in cases where the base value may be null
+ of the dot accessor . in cases where the base value may be null
or undefined. If all of the properties exist then you'll get the expected
result, if the chain is broken, undefined is returned instead of
the TypeError that would be raised otherwise.
@@ -1486,13 +1461,13 @@
Instead of repetitively attaching functions to a prototype, CoffeeScript
- provides a basic class structure that allows you to name your class,
+ 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".
+ In the first class in the example below, this.constructor.name is "Animal".
var Animal, Horse, Snake, sam, tom,
extend = function(child, parent) {for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } functionctor() {this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
@@ -1575,7 +1546,7 @@
sam.move();
tom.move();
-
load
load
run
If structuring your prototypes classically isn't your cup of tea, CoffeeScript
- provides a couple of lower-level conveniences. The extends operator
+ provides a couple of lower-level conveniences. The extends operator
helps with proper prototype setup, and can be used to create an inheritance
- chain between any pair of constructor functions; :: gives you
- quick access to an object's prototype; and super()
+ chain between any pair of constructor functions; :: gives you
+ quick access to an object's prototype; and super()
is converted into a call against the immediate ancestor's method of the same name.
Finally, class definitions are blocks of executable code, which make for interesting
metaprogramming possibilities. Because in the context of a class definition,
- this is the class object itself (the constructor function), you
- can assign static properties by using @property: value, and call
- functions defined in parent classes: @attr 'title', type: 'text'
+ this is the class object itself (the constructor function), you
+ can assign static properties by using @property: value, and call
+ functions defined in parent classes: @attr 'title', type: 'text'
Destructuring Assignment
- To make extracting values from complex arrays and objects more convenient,
- CoffeeScript implements ECMAScript Harmony's proposed
- destructuring assignment
+ Just like JavaScript (since ES2015), CoffeeScript has destructuring assignment
syntax. When you assign an array or object literal to a value, CoffeeScript
breaks up and matches both sides against each other, assigning the values
on the right to the variables on the left. In the simplest case, it can be
@@ -1673,18 +1641,14 @@
+ The above example also demonstrates that if properties are missing in the
+ destructured object or array, you can, just like in JavaScript, provide
+ defaults. The difference with JavaScript is that CoffeeScript, as always,
+ treats both null and undefined the same.
+
Bound Functions, Generator Functions
- In JavaScript, the this keyword is dynamically scoped to mean the
+ In JavaScript, the this keyword is dynamically scoped to mean the
object that the current function is attached to. If you pass a function as
- a callback or attach it to a different object, the original value of this
+ a callback or attach it to a different object, the original value of this
will be lost. If you're not familiar with this behavior,
this Digital Web article
gives a good overview of the quirks.
- The fat arrow => can be used to both define a function, and to bind
- it to the current value of this, right on the spot. This is helpful
+ The fat arrow => can be used to both define a function, and to bind
+ it to the current value of this, right on the spot. This is helpful
when using callback-based libraries like Prototype or jQuery, for creating
- iterator functions to pass to each, or event-handler functions
- to use with on. Functions created with the fat arrow are able to access
- properties of the this where they're defined.
+ iterator functions to pass to each, or event-handler functions
+ to use with on. Functions created with the fat arrow are able to access
+ properties of the this where they're defined.
- If we had used -> in the callback above, @customer would
+ 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.
+ 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
@@ -1897,7 +1854,7 @@
CoffeeScript functions also support
ES6 generator functions
- through the yield keyword. There's no function*(){}
+ through the yield keyword. There's no function*(){}
nonsense — a generator in CoffeeScript is simply a function that yields.
- yield* is called yield from, and yield return
+ yield* is called yield from, and yield return
may be used if you need to force a generator that doesn't yield.
var html;
html = "<strong>\n cup of coffeescript\n</strong>";
-
load
load
run: html
@@ -2191,8 +2135,8 @@
Block Regular Expressions
Similar to block strings and comments, CoffeeScript supports block regexes —
extended regular expressions that ignore internal whitespace and can contain
- comments and interpolation. Modeled after Perl's /x modifier, CoffeeScript's
- block regexes are delimited by /// and go a long way towards making complex
+ comments and interpolation. Modeled after Perl's /x modifier, CoffeeScript's
+ block regexes are delimited by /// and go a long way towards making complex
regular expressions readable. To quote from the CoffeeScript source:
OPERATOR = /// ^ (
@@ -2204,12 +2148,10 @@
| \?\. # soak access
| \.{2,3} # range or splat
) ///
-
-
var OPERATOR;
OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;
-
load
+
load
@@ -2222,9 +2164,9 @@
Make and
Rake. Naturally,
it's called Cake, and is used for the tasks that build and test the CoffeeScript
- language itself. Tasks are defined in a file named Cakefile, and
- can be invoked by running cake [task] from within the directory.
- To print a list of all the tasks and options, just type cake.
+ language itself. Tasks are defined in a file named Cakefile, and
+ can be invoked by running cake [task] from within the directory.
+ To print a list of all the tasks and options, just type cake.
@@ -2232,7 +2174,7 @@
in your Cakefile. Define a task with a name, a long description, and the
function to invoke when the task is run. If your task takes a command-line
option, you can define the option with short and long flags, and it will
- be made available in the options object. Here's a task that uses
+ be made available in the options object. Here's a task that uses
the Node.js API to rebuild CoffeeScript's parser:
fs = require'fs'
@@ -2259,8 +2201,8 @@
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
+ 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
@@ -2278,7 +2220,7 @@
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.
+ pass the --map or -m flag to the compiler.
@@ -2294,10 +2236,10 @@
While it's not recommended for serious use, CoffeeScripts may be included
- directly within the browser using <script type="text/coffeescript">
+ 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, 39k when gzipped)
- as extras/coffee-script.js. Include this file on a page with
+ as extras/coffee-script.js. Include this file on a page with
inline CoffeeScript tags, and it will compile and evaluate them in order.
@@ -2305,14 +2247,14 @@
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()
+ 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.
+ functions, attach them to the window object.
@@ -2454,12 +2396,12 @@
Source Code
- Use bin/coffee to test your changes,
- bin/cake test to run the test suite,
- bin/cake build to rebuild the CoffeeScript compiler, and
- bin/cake build:parser to regenerate the Jison parser if you're
+ Use bin/coffee to test your changes,
+ bin/cake test to run the test suite,
+ bin/cake build to rebuild the CoffeeScript compiler, and
+ bin/cake build:parser to regenerate the Jison parser if you're
working on the grammar.
- git checkout lib && bin/cake build:full is a good command to run when you're working
+ git checkout lib && bin/cake build:full is a good command to run when you're working
on the core language. It'll refresh the lib directory
(in case you broke something), build your altered compiler, use that to
rebuild itself (a good sanity test) and then run all of the tests. If
@@ -2506,7 +2448,7 @@
Quick help and advice can usually be found in the CoffeeScript IRC room.
- Join #coffeescript on irc.freenode.net, or click the
+ Join #coffeescript on irc.freenode.net, or click the
button below to open a webchat session on this page.
+ CoffeeScript now supports ES6-style destructuring defaults.
+
+
+ (offsetHeight: height) -> no longer compiles. That
+ syntax was accidental and partly broken. Use ({offsetHeight:
+ height}) -> instead. Object destructuring always requires
+ braces.
+
+
+
Several minor bug fixes, including:
+
+
+ A bug where the REPL would sometimes report valid code as invalid,
+ based on what you had typed earlier.
+
+
+ A problem with multiple JS contexts in the jest test framework.
+
+
+ An error in io.js where strict mode is set on internal modules.
+
+
+ A variable name clash for the caught error in catch
+ blocks.
+
+
+
+
+
+
@@ -2536,15 +2516,15 @@
Fixed source mappings for tokens at the beginning of lines when
- compiling with the --bare option. This has the nice side
+ compiling with the --bare option. This has the nice side
effect of generating smaller source maps.
Slight formatting improvement of compiled block comments.
- Better error messages for on, off, yes and
- no.
+ Better error messages for on, off, yes and
+ no.
@@ -2561,18 +2541,18 @@
multiple files with the same filename.
- Bugfix for yield around expressions containing
- this.
+ Bugfix for yield around expressions containing
+ this.
- Added a Ruby-style -r option to the REPL, which allows
- requiring a module before execution with --eval or
- --interactive.
+ Added a Ruby-style -r option to the REPL, which allows
+ requiring a module before execution with --eval or
+ --interactive.
- In <script type="text/coffeescript"> tags, to avoid
+ In <script type="text/coffeescript"> tags, to avoid
possible duplicate browser requests for .coffee files,
- you can now use the data-src attribute instead of src.
+ you can now use the data-src attribute instead of src.
Minor bug fixes for IE8, strict ES5 regular expressions and Browserify.
@@ -2598,8 +2578,8 @@
arguments.
- Fixed a few yield-related edge cases with yield return
- and yield throw.
+ Fixed a few yield-related edge cases with yield return
+ and yield throw.
Minor bug fixes and various improvements to compiler error messages.
@@ -2616,7 +2596,7 @@
CoffeeScript now supports ES6 generators. A generator is simply a function
- that yields.
+ that yields.
More robust parsing and improved error messages for strings and regexes —
@@ -2624,8 +2604,8 @@
Changed strategy for the generation of internal compiler variable names.
- Note that this means that @example function parameters are no longer
- available as naked example variables within the function body.
+ Note that this means that @example function parameters are no longer
+ available as naked example variables within the function body.
Fixed REPL compatibility with latest versions of Node and Io.js.
@@ -2644,10 +2624,10 @@
- The --join option of the CLI is now deprecated.
+ The --join option of the CLI is now deprecated.
- Source maps now use .js.map as file extension, instead of just .map.
+ Source maps now use .js.map as file extension, instead of just .map.
The CLI now exits with the exit code 1 when it fails to write a file to disk.
@@ -2665,13 +2645,13 @@
Fixed a slight formatting error in CoffeeScript’s source map-patched stack traces.
- The %% operator now coerces its right operand only once.
+ The %% operator now coerces its right operand only once.
It is now possible to require CoffeeScript files from Cakefiles without having to register the compiler first.
- The CoffeeScript REPL is now exported and can be required using require 'coffee-script/repl'.
+ The CoffeeScript REPL is now exported and can be required using require 'coffee-script/repl'.
Fixes for the REPL in Node 0.11.
@@ -2687,7 +2667,7 @@
- Fixed a typo that broke node module lookup when running a script directly with the coffee binary.
+ Fixed a typo that broke node module lookup when running a script directly with the coffee binary.
@@ -2699,13 +2679,13 @@
- When requiring CoffeeScript files in Node you must now explicitly register the compiler. This can be done with require 'coffee-script/register' or CoffeeScript.register(). Also for configuration such as Mocha's, use coffee-script/register.
+ When requiring CoffeeScript files in Node you must now explicitly register the compiler. This can be done with require 'coffee-script/register' or CoffeeScript.register(). Also for configuration such as Mocha's, use coffee-script/register.
- Improved error messages, source maps and stack traces. Source maps now use the updated //# syntax.
+ Improved error messages, source maps and stack traces. Source maps now use the updated //# syntax.
- Leading . now closes all open calls, allowing for simpler chaining syntax.
+ Leading . now closes all open calls, allowing for simpler chaining syntax.
- Added **, // and %% operators and ... expansion in parameter lists and destructuring expressions.
+ Added **, // and %% operators and ... expansion in parameter lists and destructuring expressions.
Multiline strings are now joined by a single space and ignore all indentation. A backslash at the end of a line can denote the amount of whitespace between lines, in both strings and heredocs. Backslashes correctly escape whitespace in block regexes.
@@ -2731,16 +2709,16 @@
Closing brackets can now be indented and therefore no longer cause unexpected error.
- Several breaking compilation fixes. Non-callable literals (strings, numbers etc.) don't compile in a call now and multiple postfix conditionals compile properly. Postfix conditionals and loops always bind object literals. Conditional assignment compiles properly in subexpressions. super is disallowed outside of methods and works correctly inside for loops.
+ Several breaking compilation fixes. Non-callable literals (strings, numbers etc.) don't compile in a call now and multiple postfix conditionals compile properly. Postfix conditionals and loops always bind object literals. Conditional assignment compiles properly in subexpressions. super is disallowed outside of methods and works correctly inside for loops.
Formatting of compiled block comments has been improved.
- No more -p folders on Windows.
+ No more -p folders on Windows.
- The options object passed to CoffeeScript is no longer mutated.
+ The options object passed to CoffeeScript is no longer mutated.
@@ -2756,18 +2734,18 @@
Just like a proper REPL should.
- You can now use require in Node to load .coffee.md
+ You can now use require in Node to load .coffee.md
Literate CoffeeScript files. In the browser,
- text/literate-coffeescript script tags.
+ text/literate-coffeescript script tags.
- The old coffee --lint command has been removed. It was useful
+ The old coffee --lint command has been removed. It was useful
while originally working on the compiler, but has been surpassed by
- JSHint. You may now use -l to pass literate files in over
+ JSHint. You may now use -l to pass literate files in over
stdio.
- Bugfixes for Windows path separators, catch without naming
+ Bugfixes for Windows path separators, catch without naming
the error, and executable-class-bodies-with-
prototypal-property-attachment.
@@ -2783,7 +2761,7 @@
Source maps have been used to provide automatic line-mapping when
- running CoffeeScript directly via the coffee command, and
+ running CoffeeScript directly via the coffee command, and
for automatic line-mapping when running CoffeeScript directly in the
browser. Also, to provide better error messages for semantic errors
thrown by the compiler —
@@ -2798,8 +2776,8 @@
functions, and for Windows file path management.
- The coffee command can now correctly fork()
- both .coffee and .js files. (Requires Node.js 0.9+)
+ The coffee command can now correctly fork()
+ both .coffee and .js files. (Requires Node.js 0.9+)
@@ -2813,7 +2791,7 @@
First release of source maps. Pass the
- --map flag to the compiler, and off you go. Direct all your
+ --map flag to the compiler, and off you go. Direct all your
thanks over to Jason Walton.
@@ -2823,13 +2801,13 @@
but it still isn't good style to nest them too heavily.
- .coffee.md is now also supported as a Literate CoffeeScript
+ .coffee.md is now also supported as a Literate CoffeeScript
file extension, for existing tooling.
- .litcoffee remains the canonical one.
+ .litcoffee remains the canonical one.
Several minor fixes surrounding member properties, bound methods and
- super in class declarations.
+ super in class declarations.
@@ -2854,7 +2832,7 @@
You can now loop over an array backwards, without having to manually
- deal with the indexes: for item in list by -1
+ deal with the indexes: for item in list by -1
Source locations are now preserved in the CoffeeScript AST, although
@@ -2875,8 +2853,8 @@
exists, allowing you to compile BOM-borked source files.
- Fix Node/compiler deprecation warnings by removing registerExtension,
- and moving from path.exists to fs.exists.
+ Fix Node/compiler deprecation warnings by removing registerExtension,
+ and moving from path.exists to fs.exists.
Small tweaks to splat compilation, backticks, slicing, and the
@@ -2900,7 +2878,7 @@
Inside of a nested function inside of an instance method, it's now possible
- to call super more reliably (walks recursively up).
+ to call super more reliably (walks recursively up).
Named loop variables no longer have different scoping heuristics than
@@ -2927,27 +2905,27 @@
errors at compile time. This includes old-style octal literals,
duplicate property names in object literals, duplicate parameters in
a function definition, deleting naked variables, setting the value of
- eval or arguments, and more.
+ eval or arguments, and more.
See a full discussion at
#1547.
The REPL now has a handy new multi-line mode for entering large
blocks of code. It's useful when copy-and-pasting examples into the
- REPL. Enter multi-line mode with Ctrl-V. You may also now
+ REPL. Enter multi-line mode with Ctrl-V. You may also now
pipe input directly into the REPL.
- CoffeeScript now prints a Generated by CoffeeScript VERSION
+ CoffeeScript now prints a Generated by CoffeeScript VERSION
header at the top of each compiled file.
Conditional assignment of previously undefined variables
- a or= b is now considered a syntax error.
+ a or= b is now considered a syntax error.
- A tweak to the semantics of do, which can now be used to
- more easily simulate a namespace: do (x = 1, y = 2) -> ...
+ A tweak to the semantics of do, which can now be used to
+ more easily simulate a namespace: do (x = 1, y = 2) -> ...
Loop indices are now mutable within a loop iteration, and immutable
@@ -2958,7 +2936,7 @@
effectively creating a shallow copy of the list.
- Additional tweaks and improvements to coffee --watch under
+ Additional tweaks and improvements to coffee --watch under
Node's "new" file watching API. Watch will now beep by default
if you introduce a syntax error into a watched script. We also now
ignore hidden directories by default when watching recursively.
@@ -2974,12 +2952,12 @@
- Multiple improvements to coffee --watch and --join.
+ Multiple improvements to coffee --watch and --join.
You may now use both together, as well as add and remove
- files and directories within a --watch'd folder.
+ files and directories within a --watch'd folder.
- The throw statement can now be used as part of an expression.
+ The throw statement can now be used as part of an expression.
Block comments at the top of the file will now appear outside of the
@@ -2989,7 +2967,7 @@
Fixed a number of minor 1.1.3 regressions having to do with trailing
operators and unfinished lines, and a more major 1.1.3 regression that
caused bound functions within bound class functions to have the incorrect
- this.
+ this.
@@ -3006,26 +2984,26 @@
out and keep it readable, as you can see in the examples on this page.
- You can now call super in class level methods in class bodies,
+ You can now call super in class level methods in class bodies,
and bound class methods now preserve their correct context.
- JavaScript has always supported octal numbers 010 is 8,
- and hexadecimal numbers 0xf is 15, but CoffeeScript now
- also supports binary numbers: 0b10 is 2.
+ JavaScript has always supported octal numbers 010 is 8,
+ and hexadecimal numbers 0xf is 15, but CoffeeScript now
+ also supports binary numbers: 0b10 is 2.
The CoffeeScript module has been nested under a subdirectory to make
- it easier to require individual components separately, without
+ it easier to require individual components separately, without
having to use npm. For example, after adding the CoffeeScript
- folder to your path: require('coffee-script/lexer')
+ folder to your path: require('coffee-script/lexer')
There's a new "link" feature in Try CoffeeScript on this webpage. Use
it to get a shareable permalink for your example script.
- The coffee --watch feature now only works on Node.js 0.6.0
+ The coffee --watch feature now only works on Node.js 0.6.0
and higher, but now also works properly on Windows.
@@ -3044,7 +3022,7 @@
1.1.2 —
- Fixes for block comment formatting, ?= compilation, implicit calls
+ Fixes for block comment formatting, ?= compilation, implicit calls
against control structures, implicit invocation of a try/catch block,
variadic arguments leaking from local scope, line numbers in syntax errors
following heregexes, property access on parenthesized number literals,
@@ -3069,15 +3047,15 @@
1.1.0 —
- When running via the coffee executable, process.argv and
- friends now report coffee instead of node.
+ When running via the coffee executable, process.argv and
+ friends now report coffee instead of node.
Better compatibility with Node.js 0.4.x module lookup changes.
The output in the REPL is now colorized, like Node's is.
- Giving your concatenated CoffeeScripts a name when using --join is now mandatory.
- Fix for lexing compound division /= as a regex accidentally.
- All text/coffeescript tags should now execute in the order they're included.
+ Giving your concatenated CoffeeScripts a name when using --join is now mandatory.
+ Fix for lexing compound division /= as a regex accidentally.
+ All text/coffeescript tags should now execute in the order they're included.
Fixed an issue with extended subclasses using external constructor functions.
- Fixed an edge-case infinite loop in addImplicitParentheses.
+ Fixed an edge-case infinite loop in addImplicitParentheses.
Fixed exponential slowdown with long chains of function calls.
Globals no longer leak into the CoffeeScript REPL.
Splatted parameters are declared local to the function.
@@ -3091,10 +3069,10 @@
Fixed a lexer bug with Unicode identifiers. Updated REPL for compatibility
with Node.js 0.3.7. Fixed requiring relative paths in the REPL. Trailing
- return and return undefined are now optimized away.
- Stopped requiring the core Node.js "util" module for
+ return and return undefined are now optimized away.
+ Stopped requiring the core Node.js "util" module for
back-compatibility with Node.js 0.2.5. Fixed a case where a
- conditional return would cause fallthrough in a switch
+ conditional return would cause fallthrough in a switch
statement. Optimized empty objects in destructuring assignment.
@@ -3106,11 +3084,11 @@
CoffeeScript loops no longer try to preserve block scope when functions
are being generated within the loop body. Instead, you can use the
- do keyword to create a convenient closure wrapper.
- Added a --nodejs flag for passing through options directly
- to the node executable.
+ do keyword to create a convenient closure wrapper.
+ Added a --nodejs flag for passing through options directly
+ to the node executable.
Better behavior around the use of pure statements within expressions.
- Fixed inclusive slicing through -1, for all browsers, and splicing
+ Fixed inclusive slicing through -1, for all browsers, and splicing
with arbitrary expressions as endpoints.
@@ -3121,7 +3099,7 @@
—
The REPL now properly formats stacktraces, and stays alive through
- asynchronous exceptions. Using --watch now prints timestamps as
+ asynchronous exceptions. Using --watch now prints timestamps as
files are compiled. Fixed some accidentally-leaking variables within
plucked closure-loops. Constructors now maintain their declaration
location within a class body. Dynamic object keys were removed.
@@ -3141,11 +3119,11 @@
many contributed from satyr's Coco
dialect of CoffeeScript. Heregexes (extended regexes) were added. Functions
can now have default arguments. Class bodies are now executable code.
- Improved syntax errors for invalid CoffeeScript. undefined now
- works like null, and cannot be assigned a new value.
+ Improved syntax errors for invalid CoffeeScript. undefined now
+ works like null, and cannot be assigned a new value.
There was a precedence change with respect to single-line comprehensions:
- result = i for i in list used to parse as result = (i for i in list)
- by default ... it now parses as (result = i) for i in list.
+ result = i for i in list used to parse as result = (i for i in list)
+ by default ... it now parses as (result = i) for i in list.
@@ -3155,9 +3133,9 @@
—
CoffeeScript now uses appropriately-named temporary variables, and recycles
- their references after use. Added require.extensions support for
+ their references after use. Added require.extensions support for
Node.js 0.3. Loading CoffeeScript in the browser now adds just a
- single CoffeeScript object to global scope.
+ single CoffeeScript object to global scope.
Fixes for implicit object and block comment edge cases.
@@ -3167,11 +3145,11 @@
0.9.3 —
- CoffeeScript switch statements now compile into JS switch
- statements — they previously compiled into if/else chains
+ CoffeeScript switch statements now compile into JS switch
+ statements — they previously compiled into if/else chains
for JavaScript 1.3 compatibility.
Soaking a function invocation is now supported. Users of the RubyMine
- editor should now be able to use --watch mode.
+ editor should now be able to use --watch mode.
@@ -3180,11 +3158,11 @@
0.9.2 —
- Specifying the start and end of a range literal is now optional, eg. array[3..].
- You can now say a not instanceof b.
+ Specifying the start and end of a range literal is now optional, eg. array[3..].
+ You can now say a not instanceof b.
Fixed important bugs with nested significant and non-significant indentation (Issue #637).
- Added a --require flag that allows you to hook into the coffee command.
- Added a custom jsl.conf file for our preferred JavaScriptLint setup.
+ Added a --require flag that allows you to hook into the coffee command.
+ Added a custom jsl.conf file for our preferred JavaScriptLint setup.
Sped up Jison grammar compilation time by flattening rules for operations.
Block comments can now be used with JavaScript-minifier-friendly syntax.
Added JavaScript's compound assignment bitwise operators. Bugfixes to
@@ -3200,8 +3178,8 @@
Bugfix release for 0.9.1. Greatly improves the handling of mixed
implicit objects, implicit function calls, and implicit indentation.
- String and regex interpolation is now strictly #{ ... } (Ruby style).
- The compiler now takes a --require flag, which specifies scripts
+ String and regex interpolation is now strictly #{ ... } (Ruby style).
+ The compiler now takes a --require flag, which specifies scripts
to run before compilation.
@@ -3213,21 +3191,21 @@
The CoffeeScript 0.9 series is considered to be a release candidate
for 1.0; let's give her a shakedown cruise. 0.9.0 introduces a massive
- backwards-incompatible change: Assignment now uses =, and object
- literals use :, as in JavaScript. This allows us to have implicit
+ backwards-incompatible change: Assignment now uses =, and object
+ literals use :, as in JavaScript. This allows us to have implicit
object literals, and YAML-style object definitions. Half assignments are
- removed, in favor of +=, or=, and friends.
- Interpolation now uses a hash mark # instead of the dollar sign
- $ — because dollar signs may be part of a valid JS identifier.
+ removed, in favor of +=, or=, and friends.
+ Interpolation now uses a hash mark # instead of the dollar sign
+ $ — because dollar signs may be part of a valid JS identifier.
Downwards range comprehensions are now safe again, and are optimized to
straight for loops when created with integer endpoints.
A fast, unguarded form of object comprehension was added:
- for all key, value of object. Mentioning the super keyword
+ for all key, value of object. Mentioning the super keyword
with no arguments now forwards all arguments passed to the function,
- as in Ruby. If you extend class B from parent class A, if
- A has an extended method defined, it will be called, passing in B —
+ as in Ruby. If you extend class B from parent class A, if
+ A has an extended method defined, it will be called, passing in B —
this enables static inheritance, among other things. Cleaner output for
- functions bound with the fat arrow. @variables can now be used
+ functions bound with the fat arrow. @variables can now be used
in parameter lists, with the parameter being automatically set as a property
on the object — useful in constructors and setter functions.
Constructor functions can now take splats.
@@ -3239,7 +3217,7 @@
0.7.2 —
- Quick bugfix (right after 0.7.1) for a problem that prevented coffee
+ Quick bugfix (right after 0.7.1) for a problem that prevented coffee
command-line options from being parsed in some circumstances.
@@ -3263,15 +3241,15 @@
Official CoffeeScript variable style is now camelCase, as in JavaScript.
Reserved words are now allowed as object keys, and will be quoted for you.
- Range comprehensions now generate cleaner code, but you have to specify by -1
+ Range comprehensions now generate cleaner code, but you have to specify by -1
if you'd like to iterate downward. Reporting of syntax errors is greatly
- improved from the previous release. Running coffee with no arguments
- now launches the REPL, with Readline support. The <- bind operator
- has been removed from CoffeeScript. The loop keyword was added,
- which is equivalent to a while true loop. Comprehensions that contain
- closures will now close over their variables, like the semantics of a forEach.
+ improved from the previous release. Running coffee with no arguments
+ now launches the REPL, with Readline support. The <- bind operator
+ has been removed from CoffeeScript. The loop keyword was added,
+ which is equivalent to a while true loop. Comprehensions that contain
+ closures will now close over their variables, like the semantics of a forEach.
You can now use bound function in class definitions (bound to the instance).
- For consistency, a in b is now an array presence check, and a of b
+ For consistency, a in b is now an array presence check, and a of b
is an object-key check. Comments are no longer passed through to the generated
JavaScript.
@@ -3282,15 +3260,15 @@
0.6.2 —
- The coffee command will now preserve directory structure when
+ The coffee command will now preserve directory structure when
compiling a directory full of scripts. Fixed two omissions that were preventing
the CoffeeScript compiler from running live within Internet Explorer.
There's now a syntax for block comments, similar in spirit to CoffeeScript's heredocs.
ECMA Harmony DRY-style pattern matching is now supported, where the name
- of the property is the same as the name of the value: {name, length}: func.
- Pattern matching is now allowed within comprehension variables. unless
- is now allowed in block form. until loops were added, as the inverse
- of while loops. switch statements are now allowed without
+ of the property is the same as the name of the value: {name, length}: func.
+ Pattern matching is now allowed within comprehension variables. unless
+ is now allowed in block form. until loops were added, as the inverse
+ of while loops. switch statements are now allowed without
switch object clauses. Compatible
with Node.js v0.1.95.
@@ -3313,7 +3291,7 @@
Trailing commas are now allowed, a-la Python. Static
properties may be assigned directly within class definitions,
- using @property notation.
+ using @property notation.
@@ -3323,11 +3301,11 @@
—
Interpolation can now be used within regular expressions and heredocs, as well as
- strings. Added the <- bind operator.
- Allowing assignment to half-expressions instead of special ||=-style
+ strings. Added the <- bind operator.
+ Allowing assignment to half-expressions instead of special ||=-style
operators. The arguments object is no longer automatically converted into
- an array. After requiring coffee-script, Node.js can now directly
- load .coffee files, thanks to registerExtension. Multiple
+ an array. After requiring coffee-script, Node.js can now directly
+ load .coffee files, thanks to registerExtension. Multiple
splats can now be used in function calls, arrays, and pattern matching.
@@ -3339,8 +3317,8 @@
String interpolation, contributed by
Stan Angeloff.
- Since --run has been the default since 0.5.3, updating
- --stdio and --eval to run by default, pass --compile
+ Since --run has been the default since 0.5.3, updating
+ --stdio and --eval to run by default, pass --compile
as well if you'd like to print the result.
@@ -3350,8 +3328,8 @@
0.5.4 —
- Bugfix that corrects the Node.js global constants __filename and
- __dirname. Tweaks for more flexible parsing of nested function
+ Bugfix that corrects the Node.js global constants __filename and
+ __dirname. Tweaks for more flexible parsing of nested function
literals and improperly-indented comments. Updates for the latest Node.js API.
@@ -3363,9 +3341,9 @@
CoffeeScript now has a syntax for defining classes. Many of the core
components (Nodes, Lexer, Rewriter, Scope, Optparse) are using them.
- Cakefiles can use optparse.coffee to define options for tasks.
- --run is now the default flag for the coffee command,
- use --compile to save JavaScripts. Bugfix for an ambiguity between
+ Cakefiles can use optparse.coffee to define options for tasks.
+ --run is now the default flag for the coffee command,
+ use --compile to save JavaScripts. Bugfix for an ambiguity between
RegExp literals and chained divisions.
@@ -3376,9 +3354,9 @@
—
Added a compressed version of the compiler for inclusion in web pages as
- extras/coffee-script.js. It'll automatically run any script tags
- with type text/coffeescript for you. Added a --stdio option
- to the coffee command, for piped-in compiles.
+ extras/coffee-script.js. It'll automatically run any script tags
+ with type text/coffeescript for you. Added a --stdio option
+ to the coffee command, for piped-in compiles.
@@ -3389,8 +3367,8 @@
—
Improvements to null soaking with the existential operator, including
- soaks on indexed properties. Added conditions to while loops,
- so you can use them as filters with when, in the same manner as
+ soaks on indexed properties. Added conditions to while loops,
+ so you can use them as filters with when, in the same manner as
comprehensions.
@@ -3411,9 +3389,9 @@
0.3.2 —
- @property is now a shorthand for this.property.
+ @property is now a shorthand for this.property.
Switched the default JavaScript engine from Narwhal to Node.js. Pass
- the --narwhal flag if you'd like to continue using it.
+ the --narwhal flag if you'd like to continue using it.
@@ -3425,11 +3403,11 @@
CoffeeScript 0.3 includes major syntax changes:
The function symbol was changed to
- ->, and the bound function symbol is now =>.
+ ->, and the bound function symbol is now =>.
Parameter lists in function definitions must now be wrapped in parentheses.
- Added property soaking, with the ?. operator.
+ Added property soaking, with the ?. operator.
Made parentheses optional, when invoking functions with arguments.
@@ -3443,7 +3421,7 @@
—
Added Python-style chained comparisons, the conditional existence
- operator ?=, and some examples from Beautiful Code.
+ operator ?=, and some examples from Beautiful Code.
Bugfixes relating to statement-to-expression conversion, arguments-to-array
conversion, and the TextMate syntax highlighter.
@@ -3455,8 +3433,8 @@
—
The conditions in switch statements can now take multiple values at once —
- If any of them are true, the case will run. Added the long arrow ==>,
- which defines and immediately binds a function to this. While loops can
+ If any of them are true, the case will run. Added the long arrow ==>,
+ which defines and immediately binds a function to this. While loops can
now be used as expressions, in the same way that comprehensions can. Splats
can be used within pattern matches to soak up the rest of an array.
@@ -3478,8 +3456,8 @@
0.2.3 —
- Axed the unsatisfactory ino keyword, replacing it with of for
- object comprehensions. They now look like: for prop, value of object.
+ Axed the unsatisfactory ino keyword, replacing it with of for
+ object comprehensions. They now look like: for prop, value of object.
@@ -3488,22 +3466,22 @@
0.2.2 —
- When performing a comprehension over an object, use ino, instead
- of in, which helps us generate smaller, more efficient code at
+ When performing a comprehension over an object, use ino, instead
+ of in, which helps us generate smaller, more efficient code at
compile time.
- Added :: as a shorthand for saying .prototype.
+ Added :: as a shorthand for saying .prototype.
- The "splat" symbol has been changed from a prefix asterisk *, to
- a postfix ellipsis ...
+ The "splat" symbol has been changed from a prefix asterisk *, to
+ a postfix ellipsis ...
- Added JavaScript's in operator,
- empty return statements, and empty while loops.
+ Added JavaScript's in operator,
+ empty return statements, and empty while loops.
Constructor functions that start with capital letters now include a
safety check to make sure that the new instance of the object is returned.
- The extends keyword now functions identically to goog.inherits
+ The extends keyword now functions identically to goog.inherits
in Google's Closure Library.
@@ -3536,7 +3514,7 @@
0.1.6 —
- Bugfix for running coffee --interactive and --run
+ Bugfix for running coffee --interactive and --run
from outside of the CoffeeScript directory. Bugfix for nested
function/if-statements.
@@ -3550,8 +3528,8 @@
Array slice literals and array comprehensions can now both take Ruby-style
ranges to specify the start and end. JavaScript variable declaration is
now pushed up to the top of the scope, making all assignment statements into
- expressions. You can use \ to escape newlines.
- The coffee-script command is now called coffee.
+ expressions. You can use \ to escape newlines.
+ The coffee-script command is now called coffee.
@@ -3560,14 +3538,14 @@
0.1.4 —
- The official CoffeeScript extension is now .coffee instead of
- .cs, which properly belongs to
+ The official CoffeeScript extension is now .coffee instead of
+ .cs, which properly belongs to
C#.
- Due to popular demand, you can now also use = to assign. Unlike
- JavaScript, = can also be used within object literals, interchangeably
- with :. Made a grammatical fix for chained function calls
- like func(1)(2)(3)(4). Inheritance and super no longer use
- __proto__, so they should be IE-compatible now.
+ Due to popular demand, you can now also use = to assign. Unlike
+ JavaScript, = can also be used within object literals, interchangeably
+ with :. Made a grammatical fix for chained function calls
+ like func(1)(2)(3)(4). Inheritance and super no longer use
+ __proto__, so they should be IE-compatible now.
@@ -3576,16 +3554,16 @@
0.1.3 —
- The coffee command now includes --interactive,
- which launches an interactive CoffeeScript session, and --run,
+ The coffee command now includes --interactive,
+ which launches an interactive CoffeeScript session, and --run,
which directly compiles and executes a script. Both options depend on a
working installation of Narwhal.
- The aint keyword has been replaced by isnt, which goes
- together a little smoother with is.
+ The aint keyword has been replaced by isnt, which goes
+ together a little smoother with is.
Quoted strings are now allowed as identifiers within object literals: eg.
- {"5+5": 10}.
- All assignment operators now use a colon: +:, -:,
- *:, etc.
+ {"5+5": 10}.
+ All assignment operators now use a colon: +:, -:,
+ *:, etc.
@@ -3594,13 +3572,13 @@
0.1.2 —
- Fixed a bug with calling super() through more than one level of
- inheritance, with the re-addition of the extends keyword.
+ Fixed a bug with calling super() through more than one level of
+ inheritance, with the re-addition of the extends keyword.
Added experimental Narwhal
support (as a Tusk package), contributed by
Tom Robinson, including
bin/cs as a CoffeeScript REPL and interpreter.
- New --no-wrap option to suppress the safety function
+ New --no-wrap option to suppress the safety function
wrapper.
@@ -3610,7 +3588,7 @@
0.1.1 —
- Added instanceof and typeof as operators.
+ Added instanceof and typeof as operators.
diff --git a/lib/coffee-script/browser.js b/lib/coffee-script/browser.js
index 0f6e344ab0..abf75d3d53 100644
--- a/lib/coffee-script/browser.js
+++ b/lib/coffee-script/browser.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.9.3
+// Generated by CoffeeScript 1.10.0
(function() {
var CoffeeScript, compile, runScripts,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
diff --git a/lib/coffee-script/cake.js b/lib/coffee-script/cake.js
index bb7d24a1e1..fe227b52bc 100644
--- a/lib/coffee-script/cake.js
+++ b/lib/coffee-script/cake.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.9.3
+// Generated by CoffeeScript 1.10.0
(function() {
var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
diff --git a/lib/coffee-script/coffee-script.js b/lib/coffee-script/coffee-script.js
index 32f35e4084..1a30d49c2c 100644
--- a/lib/coffee-script/coffee-script.js
+++ b/lib/coffee-script/coffee-script.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.9.3
+// Generated by CoffeeScript 1.10.0
(function() {
var Lexer, SourceMap, base, compile, ext, formatSourcePosition, fs, getSourceMap, helpers, i, len, lexer, parser, path, ref, sourceMaps, vm, withPrettyErrors,
hasProp = {}.hasOwnProperty,
@@ -18,7 +18,7 @@
SourceMap = require('./sourcemap');
- exports.VERSION = '1.9.3';
+ exports.VERSION = '1.10.0';
exports.FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md'];
diff --git a/lib/coffee-script/command.js b/lib/coffee-script/command.js
index 1b9cd69b07..623c37cec8 100644
--- a/lib/coffee-script/command.js
+++ b/lib/coffee-script/command.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.9.3
+// Generated by CoffeeScript 1.10.0
(function() {
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, findDirectoryIndex, forkNode, fs, helpers, hidden, joinTimeout, makePrelude, mkdirp, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, ref, removeSource, removeSourceDir, silentUnlink, sourceCode, sources, spawn, timeLog, usage, useWinPathSep, version, wait, watch, watchDir, watchedDirs, writeJs,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
diff --git a/lib/coffee-script/grammar.js b/lib/coffee-script/grammar.js
index 27884ed9b7..3dc79d925b 100644
--- a/lib/coffee-script/grammar.js
+++ b/lib/coffee-script/grammar.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.9.3
+// Generated by CoffeeScript 1.10.0
(function() {
var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
diff --git a/lib/coffee-script/helpers.js b/lib/coffee-script/helpers.js
index e775c093cc..6e3d13bc42 100644
--- a/lib/coffee-script/helpers.js
+++ b/lib/coffee-script/helpers.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.9.3
+// Generated by CoffeeScript 1.10.0
(function() {
var buildLocationData, extend, flatten, ref, repeat, syntaxErrorToString;
diff --git a/lib/coffee-script/index.js b/lib/coffee-script/index.js
index d719f7afe0..bcfc8ac77a 100644
--- a/lib/coffee-script/index.js
+++ b/lib/coffee-script/index.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.9.3
+// Generated by CoffeeScript 1.10.0
(function() {
var key, ref, val;
diff --git a/lib/coffee-script/lexer.js b/lib/coffee-script/lexer.js
index 5c63e6238c..857bf29bec 100644
--- a/lib/coffee-script/lexer.js
+++ b/lib/coffee-script/lexer.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.9.3
+// Generated by CoffeeScript 1.10.0
(function() {
var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HERECOMMENT_ILLEGAL, HEREDOC_DOUBLE, HEREDOC_INDENT, HEREDOC_SINGLE, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDENTABLE_CLOSERS, INDEXABLE, INVALID_ESCAPE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LEADING_BLANK_LINE, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTI_DENT, NOT_REGEX, NUMBER, OPERATOR, POSSIBLY_DIVISION, REGEX, REGEX_FLAGS, REGEX_ILLEGAL, RELATION, RESERVED, Rewriter, SHIFT, SIMPLE_STRING_OMIT, STRICT_PROSCRIBED, STRING_DOUBLE, STRING_OMIT, STRING_SINGLE, STRING_START, TRAILING_BLANK_LINE, TRAILING_SPACES, UNARY, UNARY_MATH, VALID_FLAGS, WHITESPACE, compact, count, invertLiterate, key, locationDataToString, ref, ref1, repeat, starts, throwSyntaxError,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
diff --git a/lib/coffee-script/nodes.js b/lib/coffee-script/nodes.js
index e84131cd16..534811e50d 100644
--- a/lib/coffee-script/nodes.js
+++ b/lib/coffee-script/nodes.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.9.3
+// Generated by CoffeeScript 1.10.0
(function() {
var Access, Arr, Assign, Base, Block, Call, Class, Code, CodeFragment, Comment, Existence, Expansion, Extends, For, HEXNUM, IDENTIFIER, IS_REGEX, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, NEGATE, NO, NUMBER, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, STRICT_PROSCRIBED, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, addLocationDataFn, compact, del, ends, extend, flatten, fragmentsToText, isComplexOrAssignable, isLiteralArguments, isLiteralThis, locationDataToString, merge, multident, parseNum, ref1, ref2, some, starts, throwSyntaxError, unfoldSoak, utility,
extend1 = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
diff --git a/lib/coffee-script/optparse.js b/lib/coffee-script/optparse.js
index ccc72435bb..1790c46a24 100644
--- a/lib/coffee-script/optparse.js
+++ b/lib/coffee-script/optparse.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.9.3
+// Generated by CoffeeScript 1.10.0
(function() {
var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments, repeat;
diff --git a/lib/coffee-script/register.js b/lib/coffee-script/register.js
index 86716e24c3..14f75a1452 100644
--- a/lib/coffee-script/register.js
+++ b/lib/coffee-script/register.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.9.3
+// Generated by CoffeeScript 1.10.0
(function() {
var CoffeeScript, Module, binary, child_process, ext, findExtension, fork, helpers, i, len, loadFile, path, ref;
diff --git a/lib/coffee-script/repl.js b/lib/coffee-script/repl.js
index 7e010fefac..f4aa4ef226 100644
--- a/lib/coffee-script/repl.js
+++ b/lib/coffee-script/repl.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.9.3
+// Generated by CoffeeScript 1.10.0
(function() {
var CoffeeScript, addHistory, addMultilineHandler, fs, getCommandId, merge, nodeREPL, path, ref, replDefaults, runInContext, updateSyntaxError, vm;
diff --git a/lib/coffee-script/rewriter.js b/lib/coffee-script/rewriter.js
index b4ff0a862e..007bb870dd 100644
--- a/lib/coffee-script/rewriter.js
+++ b/lib/coffee-script/rewriter.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.9.3
+// Generated by CoffeeScript 1.10.0
(function() {
var BALANCED_PAIRS, CALL_CLOSERS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, generate, k, left, len, ref, rite,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
diff --git a/lib/coffee-script/scope.js b/lib/coffee-script/scope.js
index 925418f177..0f9835a01b 100644
--- a/lib/coffee-script/scope.js
+++ b/lib/coffee-script/scope.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.9.3
+// Generated by CoffeeScript 1.10.0
(function() {
var Scope,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
diff --git a/lib/coffee-script/sourcemap.js b/lib/coffee-script/sourcemap.js
index 8227c1b92e..ec703e15dc 100644
--- a/lib/coffee-script/sourcemap.js
+++ b/lib/coffee-script/sourcemap.js
@@ -1,4 +1,4 @@
-// Generated by CoffeeScript 1.9.3
+// Generated by CoffeeScript 1.10.0
(function() {
var LineMap, SourceMap;
diff --git a/package.json b/package.json
index fa442ca3e4..5dda687b21 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
"compiler"
],
"author": "Jeremy Ashkenas",
- "version": "1.9.3",
+ "version": "1.10.0",
"license": "MIT",
"engines": {
"node": ">=0.8.0"
diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee
index 36ca985803..69957fd930 100644
--- a/src/coffee-script.coffee
+++ b/src/coffee-script.coffee
@@ -12,7 +12,7 @@ helpers = require './helpers'
SourceMap = require './sourcemap'
# The current CoffeeScript version number.
-exports.VERSION = '1.9.3'
+exports.VERSION = '1.10.0'
exports.FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md']