Skip to content
satyr edited this page Mar 3, 2012 · 27 revisions
$ coffee -v
CoffeeScript version 1.2.0

leaky Ruby emulations

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

fuzzy matching of parentheses

Hunted by me at 1.1.3.

$ coffee -bce '([{)]}'
[{}];

global leak

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

$ coffee -e 'do -> a ?= 1; console.log global.a'
1

$ coffee -e '"use strict"; a ?= 1'
ReferenceError: a is not defined

(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]

http://brehaut.net/blog/2011/coffeescript_comprehensions

object literal quirks

$ coffee -e '{"#{k}": v}'
Error: Parse error on line 1: Unexpected '('

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

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

$ coffee -e '@k: v'

.:3
    this.k: v
        ^
SyntaxError: Unexpected token .

$ coffee -ce 'a: b if c, d: e'
Error: Parse error on line 1: Unexpected ','

$ coffee -bsc
  a: b if c
  d: e
  _
  d: e
  a: b if c

if (c) {
  ({
    a: b
  });
}

({
  d: e
});

_;


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

post-conditional associativity

$ coffee -bce 'a if b if c'
if (c ? b : void 0) {
  a;

}

$ coffee -e 'i = 0; console.log i if i%2 while 6 > i += 1'
6

cf.

$ ruby -e 'i = 0; p i if i.odd? while 6 > i += 1'
1
3
5

regex literal 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