mirror of
https://github.com/vlang/v.git
synced 2025-09-11 16:36:20 -04: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
|
#throw s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# let globalPrint;
|
||||||
|
$if js_freestanding {
|
||||||
|
# globalPrint = globalThis.print
|
||||||
|
}
|
||||||
|
|
||||||
pub fn println(s string) {
|
pub fn println(s string) {
|
||||||
$if js_freestanding {
|
$if js_freestanding {
|
||||||
#print(s.str)
|
#globalPrint(s.str)
|
||||||
} $else {
|
} $else {
|
||||||
#console.log(s.str)
|
#console.log(s.str)
|
||||||
}
|
}
|
||||||
@ -23,7 +28,7 @@ pub fn print(s string) {
|
|||||||
|
|
||||||
pub fn eprintln(s string) {
|
pub fn eprintln(s string) {
|
||||||
$if js_freestanding {
|
$if js_freestanding {
|
||||||
#print(s.str)
|
#globalPrint(s.str)
|
||||||
} $else {
|
} $else {
|
||||||
#console.error(s.str)
|
#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.stmts(it.stmts)
|
||||||
g.writeln('}')
|
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 {
|
if is_main {
|
||||||
g.write(')();')
|
g.write(')();')
|
||||||
} else if typ != .struct_method {
|
} else if typ != .struct_method {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user