mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
js: support [export: 'AnotherName']
for FnDecl codegen (#11377)
This commit is contained in:
parent
67ab5b858b
commit
a4df418a68
@ -5,9 +5,14 @@ pub fn js_throw(s any) {
|
||||
#throw s
|
||||
}
|
||||
|
||||
# let globalPrint;
|
||||
$if js_freestanding {
|
||||
# globalPrint = globalThis.print
|
||||
}
|
||||
|
||||
pub fn println(s string) {
|
||||
$if js_freestanding {
|
||||
#print(s.str)
|
||||
#globalPrint(s.str)
|
||||
} $else {
|
||||
#console.log(s.str)
|
||||
}
|
||||
@ -23,7 +28,7 @@ pub fn print(s string) {
|
||||
|
||||
pub fn eprintln(s string) {
|
||||
$if js_freestanding {
|
||||
#print(s.str)
|
||||
#globalPrint(s.str)
|
||||
} $else {
|
||||
#console.error(s.str)
|
||||
}
|
||||
|
@ -1452,7 +1452,14 @@ fn (mut g JsGen) gen_method_decl(it ast.FnDecl, typ FnGenType) {
|
||||
|
||||
g.stmts(it.stmts)
|
||||
g.writeln('}')
|
||||
|
||||
for attr in it.attrs {
|
||||
match attr.name {
|
||||
'export' {
|
||||
g.writeln('globalThis.$attr.arg = ${g.js_name(it.name)};')
|
||||
}
|
||||
else {}
|
||||
}
|
||||
}
|
||||
if is_main {
|
||||
g.write(')();')
|
||||
} else if typ != .struct_method {
|
||||
|
Loading…
Reference in New Issue
Block a user