| 1 | import v.gen.js.tests.hello as hl |
| 2 | import v.gen.js.tests.hello.hello1 as hl1 |
| 3 | |
| 4 | const i_am_a_const = 21214 |
| 5 | const super = 'amazing keyword' |
| 6 | |
| 7 | struct Foo { |
| 8 | mut: |
| 9 | a hl.Aaa |
| 10 | } |
| 11 | |
| 12 | struct Companies { |
| 13 | google int |
| 14 | amazon bool |
| 15 | yahoo string |
| 16 | } |
| 17 | |
| 18 | enum POSITION { |
| 19 | go_back |
| 20 | dont_go_back |
| 21 | } |
| 22 | |
| 23 | fn class(extends string, instanceof int) { |
| 24 | delete := instanceof |
| 25 | _ = delete |
| 26 | } |
| 27 | |
| 28 | fn main() { |
| 29 | println('Hello from V.js!') |
| 30 | println(JS.Math.atan2(1, 0)) |
| 31 | non := JS.eval("console.log('Hello!')".str) |
| 32 | if isnil(non) { |
| 33 | println('non=nil') |
| 34 | } |
| 35 | ren := int(JS.eval('3'.str)) |
| 36 | if ren != 0 { |
| 37 | println('ren=${ren}') |
| 38 | } |
| 39 | res := string(JS.eval('"3"'.str)) |
| 40 | if res != '' { |
| 41 | println('res=${res}') |
| 42 | } |
| 43 | mut a := 1 |
| 44 | a *= 2 |
| 45 | a += 3 |
| 46 | println(a) |
| 47 | mut b := hl.Aaa{} |
| 48 | b.update('an update') |
| 49 | println(b) |
| 50 | mut c := Foo{hl.Aaa{}} |
| 51 | c.a.update('another update') |
| 52 | println(c) |
| 53 | println('int(1.5) == "${int(1.5)}"') |
| 54 | d := int(10) + f32(127) |
| 55 | println('typeof (int + f32) == "${typeof(d).name}"') |
| 56 | _ = 'done' |
| 57 | { |
| 58 | _ = 'block' |
| 59 | } |
| 60 | _ = POSITION.go_back |
| 61 | _ = hl.Ccc.a |
| 62 | debugger := 'JS keywords' |
| 63 | // TODO: Implement interpolation |
| 64 | await := '${super}: ${debugger}' |
| 65 | mut finally := 'implemented' |
| 66 | println('${await} ${finally}') |
| 67 | dun := i_am_a_const * 20 + 2 |
| 68 | dunn := hl.hello // External constant |
| 69 | _ = hl1.nested() |
| 70 | for i := 0; i < 10; i++ { |
| 71 | } |
| 72 | for i, x in 'hello' { |
| 73 | } |
| 74 | mut evens := []int{} |
| 75 | for x in 1 .. 10 { |
| 76 | y := error_if_even(x) or { x + 1 } |
| 77 | evens << y |
| 78 | } |
| 79 | println(evens) |
| 80 | arr := [1, 2, 3, 4, 5] |
| 81 | for i in arr { |
| 82 | } |
| 83 | ma := { |
| 84 | 'str': 'done' |
| 85 | 'ddo': 'baba' |
| 86 | } |
| 87 | // panic('foo') |
| 88 | for m, n in ma { |
| 89 | iss := m |
| 90 | } |
| 91 | spawn async(0, 'hello') |
| 92 | fn_in_var := fn (number int) { |
| 93 | println('number: ${number}') |
| 94 | } |
| 95 | hl.debugger() |
| 96 | anon_consumer(hl.excited(), fn (message string) { |
| 97 | println(message) |
| 98 | }) |
| 99 | hl.raw_js_log() |
| 100 | propagation() or { println(err) } |
| 101 | } |
| 102 | |
| 103 | fn anon_consumer(greeting string, anon fn (string)) { |
| 104 | anon(greeting) |
| 105 | } |
| 106 | |
| 107 | fn async(num int, def string) { |
| 108 | } |
| 109 | |
| 110 | @[deprecated; inline] |
| 111 | fn hello(game_on int, dummy ...string) (int, int) { |
| 112 | defer { |
| 113 | do := 'not' |
| 114 | } |
| 115 | for dd in dummy { |
| 116 | l := dd |
| 117 | } |
| 118 | return game_on + 2, 221 |
| 119 | } |
| 120 | |
| 121 | fn (it Companies) method() int { |
| 122 | ss := Companies{ |
| 123 | google: 2 |
| 124 | amazon: true |
| 125 | yahoo: 'hello' |
| 126 | } |
| 127 | a, b := hello(2, 'google', 'not google') |
| 128 | glue := if a > 2 { |
| 129 | 'more_glue' |
| 130 | } else if a > 5 { |
| 131 | 'more glueee' |
| 132 | } else { |
| 133 | 'less glue' |
| 134 | } |
| 135 | if a != 2 { |
| 136 | } |
| 137 | return 0 |
| 138 | } |
| 139 | |
| 140 | fn error_if_even(num int) !int { |
| 141 | if num % 2 == 0 { |
| 142 | return error('number is even') |
| 143 | } |
| 144 | return num |
| 145 | } |
| 146 | |
| 147 | fn propagation() ! { |
| 148 | println('Propagation test:') |
| 149 | return error('"Task failed successfully" - Windows XP') |
| 150 | } |
| 151 | |