JS backend not supporting [export] attribute
V version: V 0.2.4 227d12f OS: macOS 10.15
What did you do?
$ cat hello.v
[export: 'TIC']
__global tic = fn (a int) int {
println('hello')
return 3
}
fn main() {
mut a := 32
a += tic(a)
}
What did you expect to see?
I expect to have a global function named TIC externally, but at the same time being usable from inside as in lowercase.
What did you see instead?
the C backend fails because of https://github.com/vlang/v/issues/11373 and https://github.com/vlang/v/issues/11374
and the JS backend just ignores that and doesnt exports TIC.
There are several problems here:
- GlobalDecl doesnt have [attr]
- AnonFn doesnt have [attr] either
- export is not supported in the JS backend
export is not supported in the JS backend
Should be fixed by https://github.com/vlang/v/pull/11377
This works in the C backend:
[export: 'TIC']
fn tic(a int) int {
println('hello')
return 3
}
fn main() {
mut a := 32
a += tic(a)
}
Should be allow exporting global anonymous functions? we can probably forbid this and just suggest to use the [export] attribute instead, which works for C and JS after 11377 gets merged