UNPKG

1.22 kBtext/coffeescriptView Raw
1suite 'Optimisations', ->
2
3 # by definition, anything that is optimised away will not be detectable at
4 # runtime, so we will have to do tests on the AST structure
5
6 suite 'Non-optimisations', ->
7
8 test 'do not optimise away indirect eval', ->
9 do -> (1; eval) 'var thisShouldBeInTheGlobalScope = 0'
10 eq 'number', typeof thisShouldBeInTheGlobalScope
11 delete global.thisShouldBeInTheGlobalScope
12
13 test 'do not optimise away declarations in conditionals', ->
14 if 0 then a = 0
15 eq undefined, a
16 if 1 then 0 else b = 0
17 eq undefined, b
18
19 test 'do not optimise away declarations in while loops', ->
20 while 0 then a = 0
21 eq undefined, a
22
23 test 'do not optimise away declarations in for-in loops', ->
24 for a in [] then b = 0
25 eq undefined, a
26 eq undefined, b
27
28 test 'do not optimise away declarations in for-of loops', ->
29 for own a of {} then b = 0
30 eq undefined, a
31 eq undefined, b
32
33 test 'do not optimise away declarations in logical not ops', ->
34 not (a = 0)
35 eq 0, a
36
37 test '#71: assume JS literals have side effects, do not eliminate them', ->
38 nonce = {}
39 a = null
40 `a = nonce`
41 eq nonce, a