Skip to content
satyr edited this page Nov 24, 2011 · 27 revisions
$ coffee -v
CoffeeScript version 1.1.3

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 -bpe '([{)]}'
[{}];

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 -ne '{"#{k}": v}'
Error: Parse error on line 1: Unexpected '('

$ 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
  }
});

$ coffee -e '@k: v'

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

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