Skip to content
satyr edited this page May 11, 2011 · 27 revisions
$ coffee -v
CoffeeScript version 1.1.0

unmatched unindentations

$ coffee -se
if 0
  if 0
    console.log 1
   console.log  2
  console.log   3

3

cf.

$ python <<_
> if 0:
>   if 0:
>     print(1)
>    print(2)
>   print(3)
> _
  File "<stdin>", line 4
    print(2)
           ^
IndentationError: unindent does not match any outer indentation level

global leak

$ coffee -bce 'a ?= 1'
typeof a != "undefined" && a !== null ? a : a = 1;

(un)nested comprehensions

$ coffee -e 'console.log(i+j for j in [3..4] for i in [1..2])'
[ [ 4, 5 ], [ 5, 6 ] ]

cf.

js> uneval([i+j for each(i in [1,2]) for each(j in [3,4])])
[4, 5, 5, 6]

implicit object quirks

$ coffee -ne 'f a: b, 2 * c'
Error: Parse error on line 1: Unexpected 'MATH'

$ coffee -ne 'a: f b: c'
Error: Parse error on line 1: Unexpected ':'

$ coffee -bsp
a: b: c
d: e

({
  a: {
    b: c,
    d: e
  }
});

regex quirks

$ coffee -e 'spaces = / +/'
Error: Parse error on line 1: Unexpected 'MATH'
...

$ coffee -bce 'invalid = /+/'
var invalid;
invalid = /+/;

cf.

$ node -e '/ +/'
/ +/

$ node -e '/+/'

undefined:1

^
SyntaxError: Invalid regular expression: /+/: Nothing to repeat
Clone this wiki locally