fix V.js methods and duplicate .str() in arrays

pull/2356/head
Alexander Medvednikov 2019-10-25 22:09:23 +03:00
parent b6fa252fc9
commit 8d2111169a
3 changed files with 9 additions and 3 deletions

View File

@ -272,6 +272,9 @@ fn (p mut Parser) comptime_method_call(typ Type) {
} }
fn (p mut Parser) gen_array_str(typ Type) { fn (p mut Parser) gen_array_str(typ Type) {
if typ.has_method('str') {
return
}
p.add_method(typ.name, Fn{ p.add_method(typ.name, Fn{
name: 'str' name: 'str'
typ: 'string' typ: 'string'

View File

@ -888,7 +888,7 @@ fn (p mut Parser) fn_call_args(f mut Fn) {
// Receiver is the first arg // Receiver is the first arg
// Skip the receiver, because it was already generated in the expression // Skip the receiver, because it was already generated in the expression
if i == 0 && f.is_method { if i == 0 && f.is_method {
if f.args.len > 1 && !p.is_js { if f.args.len > 1 { // && !p.is_js {
p.gen(',') p.gen(',')
} }
continue continue

View File

@ -28,7 +28,8 @@ fn (p mut Parser) gen_fn_decl(f Fn, typ, _str_args string) {
} }
name := p.table.fn_gen_name(f) name := p.table.fn_gen_name(f)
if f.is_method { if f.is_method {
p.genln('\n${f.receiver_typ}.prototype.${name} = function($str_args) {') //p.genln('\n${f.receiver_typ}.prototype.${name} = function($str_args) {')
p.genln('function ${f.receiver_typ}_$name($str_args) {')
} else { } else {
p.genln('/** @return { $typ } **/\nfunction $name($str_args) {') p.genln('/** @return { $typ } **/\nfunction $name($str_args) {')
} }
@ -100,7 +101,9 @@ fn (p mut Parser) gen_method_call(receiver &Var, receiver_type string,
//mut cgen_name := p.table.fn_gen_name(f) //mut cgen_name := p.table.fn_gen_name(f)
//mut method_call := cgen_name + '(' //mut method_call := cgen_name + '('
p.gen('.' + cgen_name.all_after('_') + '(') //p.gen('/*2*/.' + cgen_name.all_after('_') + '(')
t := receiver_type.replace('*', '')
p.cgen.set_placeholder(method_ph, '${t}_$cgen_name(')
//p.cgen.set_placeholder(method_ph, '$cast kKE $method_call') //p.cgen.set_placeholder(method_ph, '$cast kKE $method_call')
//return method_call //return method_call
} }