js: prefix V builtin functions, so they do not overlap with JS (#11483)
parent
480fe8041a
commit
b9dfc89aa9
|
@ -2,6 +2,7 @@ module js
|
|||
|
||||
import v.ast
|
||||
import v.util
|
||||
import v.parser
|
||||
|
||||
fn (mut g JsGen) js_mname(name_ string) string {
|
||||
mut is_js := false
|
||||
|
@ -234,9 +235,9 @@ fn (mut g JsGen) method_call(node ast.CallExpr) {
|
|||
g.stmt(it.or_block.stmts.last())
|
||||
}
|
||||
.propagate {
|
||||
panicstr := '`optional not set (\${err})`'
|
||||
panicstr := '`optional not set (\${err.val.msg})`'
|
||||
if g.file.mod.name == 'main' && g.fn_decl.name == 'main.main' {
|
||||
g.writeln('return panic($panicstr)')
|
||||
g.writeln('return builtin__panic($panicstr)')
|
||||
} else {
|
||||
g.writeln('js_throw(err)')
|
||||
}
|
||||
|
@ -268,7 +269,11 @@ fn (mut g JsGen) gen_call_expr(it ast.CallExpr) {
|
|||
node := it
|
||||
g.call_stack << it
|
||||
mut name := g.js_name(it.name)
|
||||
|
||||
is_print := name in ['print', 'println', 'eprint', 'eprintln', 'panic']
|
||||
if name in parser.builtin_functions {
|
||||
name = 'builtin__$name'
|
||||
}
|
||||
print_method := name
|
||||
ret_sym := g.table.get_type_symbol(it.return_type)
|
||||
if it.language == .js && ret_sym.name in v_types && ret_sym.name != 'void' {
|
||||
|
@ -324,7 +329,7 @@ fn (mut g JsGen) gen_call_expr(it ast.CallExpr) {
|
|||
.propagate {
|
||||
panicstr := '`optional not set (\${err.val.msg})`'
|
||||
if g.file.mod.name == 'main' && g.fn_decl.name == 'main.main' {
|
||||
g.writeln('return panic($panicstr)')
|
||||
g.writeln('return builtin__panic($panicstr)')
|
||||
} else {
|
||||
g.writeln('js_throw(err)')
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import v.util.version
|
|||
import v.depgraph
|
||||
import encoding.base64
|
||||
import v.gen.js.sourcemap
|
||||
import v.parser
|
||||
|
||||
struct MutArg {
|
||||
tmp_var string
|
||||
|
@ -1101,14 +1102,14 @@ fn (mut g JsGen) gen_assert_stmt(a ast.AssertStmt) {
|
|||
metaname_fail := g.gen_assert_metainfo(a)
|
||||
g.writeln(' g_test_fails++;')
|
||||
g.writeln(' main__cb_assertion_failed($metaname_fail);')
|
||||
g.writeln(' exit(1);')
|
||||
g.writeln(' builtin__exit(1);')
|
||||
g.writeln('}')
|
||||
return
|
||||
}
|
||||
g.writeln('} else {')
|
||||
g.inc_indent()
|
||||
g.writeln('eprintln(new string("$mod_path:${a.pos.line_nr + 1}: FAIL: fn ${g.fn_decl.name}(): assert $s_assertion"));')
|
||||
g.writeln('exit(1);')
|
||||
g.writeln('builtin__eprintln(new string("$mod_path:${a.pos.line_nr + 1}: FAIL: fn ${g.fn_decl.name}(): assert $s_assertion"));')
|
||||
g.writeln('builtin__exit(1);')
|
||||
g.dec_indent()
|
||||
g.writeln('}')
|
||||
}
|
||||
|
@ -1440,7 +1441,9 @@ fn (mut g JsGen) gen_method_decl(it ast.FnDecl, typ FnGenType) {
|
|||
name = g.js_name(name)
|
||||
|
||||
name = g.generic_fn_name(g.table.cur_concrete_types, name, true)
|
||||
|
||||
if name in parser.builtin_functions {
|
||||
name = 'builtin__$name'
|
||||
}
|
||||
has_go := fn_has_go(it)
|
||||
if it.is_pub && !it.is_method {
|
||||
g.push_pub_var(name)
|
||||
|
|
|
@ -13,7 +13,7 @@ import v.errors
|
|||
import os
|
||||
import hash.fnv1a
|
||||
|
||||
const (
|
||||
pub const (
|
||||
builtin_functions = ['print', 'println', 'eprint', 'eprintln', 'isnil', 'panic', 'exit']
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue