-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathdeclaration.ls
More file actions
112 lines (95 loc) · 2.02 KB
/
declaration.ls
File metadata and controls
112 lines (95 loc) · 2.02 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
### `export`
out = exports ? this
{random} = Math
a = random!
export a
eq out.a, a
eq do
export b = random!
out.b
export class C
@d = random!
export @d, @e = random!
ok new out.C instanceof C
eq out.d, C.d
eq out.e, C.e
export function f
g
export
function g then h
function h then f
eq out.f!, g
eq out.g!, h
eq out.h!, f
export
I: i = random!
J: j = random!
eq out.I, i
eq out.J, j
o = k: random!
export do -> o
eq out.k, o.k
### `const`
let
const a = 1
const b = 2, c = 3
const
d = 4
[e, f] = [5, 6]
export const g = 7
export
const h = 8
const i = 9
eq '1,2,3,4,5,6,7,8,9' ''+[a, b, c, d, e, f, g, h, i]
eq out.g, g
eq out.h, h
eq out.i, i
compileThrows 'redeclaration of constant "a"' 2 '''
const a = 0
a = 1
'''
compileThrows 'redeclaration of constant "a"' 2 '''
a = 2
const a = 3
'''
compileThrows 'redeclaration of constant "a"' 2 '''
const a = 4
function a then 5
'''
compileThrows 'assignment to constant "a"' 2 '''
const a = 6
-> a := 7
'''
compileThrows 'increment of constant "a"' 2 '''
const a = 8
++a
'''
compileThrows 'invalid constant variable declaration' 2 'const\n a'
### `var`
let
var a
var b, c
var
d
e
ok a is b is c is d is e is void
eq void var f
compileThrows 'invalid variable declaration' 2 'var\n 0'
compileThrows 'redeclaration of "a"' 2 '(a) ->\n var a'
compileThrows 'empty var' 2 '\nvar'
### with const flag
throws 'redeclaration of constant "z" on line 2' ->
LiveScript.compile 'z = 1\nz = 2' {+\const}
throws 'increment of constant "z" on line 2' ->
LiveScript.compile 'z = 9\nz++' {+\const}
throws 'assignment to constant "z" on line 2' ->
LiveScript.compile 'z = 1\nz := 2' {+\const}
eq '''(function(n){
n == null && (n = 2);
return n + 1;
});''' LiveScript.compile '(n = 2) -> n + 1' {+\const, +bare,-header}
eq '''var ref$;
1 < 2 && 2 === (ref$ = 4 / 2) && ref$ > 0;''' LiveScript.compile '1 < 2 == 4/2 > 0' {+\const, +bare,-header}
### former reserved words
where = 1
eq 1 where