forked from jashkenas/coffeescript
/
compilation.coffee
77 lines (59 loc) · 1.71 KB
/
compilation.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Compilation
# -----------
# helper to assert that a string should fail compilation
cantCompile = (code) ->
throws -> CoffeeScript.compile code
test "ensure that carriage returns don't break compilation on Windows", ->
doesNotThrow -> CoffeeScript.compile 'one\r\ntwo', bare: on
test "--bare", ->
eq -1, CoffeeScript.compile('x = y', bare: on).indexOf 'function'
ok 'passed' is CoffeeScript.eval '"passed"', bare: on, filename: 'test'
test "compiler emits events", ->
compileCount = 0; successCount = 0; failureCount = 0
CoffeeScript.on 'compile', -> compileCount++
CoffeeScript.on 'success', -> successCount++
CoffeeScript.on 'failure', -> failureCount++
CoffeeScript.compile('x = y')
eq compileCount, 1
eq successCount, 1
eq failureCount, 0
compileCount = 0; successCount = 0; failureCount = 0
try
CoffeeScript.compile('^@$%!') # valid Perl, no doubt
eq compileCount, 1
eq successCount, 0
eq failureCount, 1
test "multiple generated references", ->
a = {b: []}
a.b[true] = -> this == a.b
c = 0
d = []
ok a.b[0<++c<2] d...
test "splat on a line by itself is invalid", ->
cantCompile "x 'a'\n...\n"
test "Issue 750", ->
cantCompile 'f(->'
cantCompile 'a = (break)'
cantCompile 'a = (return 5 for item in list)'
cantCompile 'a = (return 5 while condition)'
cantCompile 'a = for x in y\n return 5'
test "Issue #986: Unicode identifiers", ->
λ = 5
eq λ, 5
test "don't accidentally stringify keywords", ->
ok (-> this == 'this')() is false
test "#1026", ->
cantCompile '''
if a
b
else
c
else
d
'''
test "#1050", ->
cantCompile "### */ ###"
test "#1106: __proto__ compilation", ->
object = eq
@["__proto__"] = true
ok __proto__