vfmt: keep JS object name (#7462)

pull/7472/head
zakuro 2020-12-22 22:32:49 +09:00 committed by GitHub
parent 178ddfe9c0
commit fb0c4556fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 5 deletions

View File

@ -43,12 +43,14 @@ pub fn (node &FnDecl) stringify(t &table.Table, cur_mod string) string {
receiver = '($node.receiver.name $m$name) '
*/
}
mut name := if node.is_anon { '' } else { node.name.after('.') }
mut name := if node.is_anon { '' } else { node.name.after_char(`.`) }
if !node.is_method {
if node.language == .c {
name = 'C.$name'
} else if node.language == .js {
name = 'JS.$name'
}
}
f.write('fn $receiver$name')
if name in ['+', '-', '*', '/', '%'] {
f.write(' ')

View File

@ -1502,6 +1502,8 @@ pub fn (mut f Fmt) call_expr(node ast.CallExpr) {
f.write_language_prefix(node.language)
if node.left is ast.AnonFn {
f.fn_decl(node.left.decl)
} else if node.language != .v {
f.write('${node.name.after_char(`.`)}')
} else {
mut name := f.short_module(node.name)
f.mark_module_as_used(name)

View File

@ -0,0 +1,7 @@
fn (v JS.String) toString() JS.String
fn JS.Math.abs(f64) f64
fn main() {
JS.Math.abs(0)
}