Skip to content
This repository

leaky Ruby emulations

unmatched unindentations

$ coffee -s
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

(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

(un)safe loops

$ coffee -e 'console.log i for i in [3..1]'
3
2
1

$ coffee -e 'console.log i for i in [3..1] by 1'

$ coffee -e 'console.log i for i in ([3..1]) by 1'
3
2
1

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

object literal quirks

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

post-conditional associativity

$ coffee -bce 'a if b if c'
// Generated by CoffeeScript 1.3.3

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 = /+/'
// Generated by CoffeeScript 1.3.3
var invalid;

invalid = /+/;

cf.

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

$ node -e '/+/'

undefined:1

^
SyntaxError: Invalid regular expression: /+/: Nothing to repeat

complex comments

$ coffee -bce '# 1'
// Generated by CoffeeScript 1.3.3

$ coffee -bce '## 2'
// Generated by CoffeeScript 1.3.3

$ coffee -bce '### 3'
// Generated by CoffeeScript 1.3.3
/* 3
*/

$ coffee -bce '#### 4'
// Generated by CoffeeScript 1.3.3

$ coffee -bce '###*/ 5'
SyntaxError: block comment cannot contain "*/", starting on line 1
...

$ coffee -bce '6 ### ###'
Error: Parse error on line 1: Unexpected 'HERECOMMENT'
...
Something went wrong with that request. Please try again.