js: support `[export: 'AnotherName']` for FnDecl codegen (#11377)

pull/11383/head
playX 2021-09-03 13:00:24 +03:00 committed by GitHub
parent 67ab5b858b
commit a4df418a68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -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)
}

View File

@ -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 {