From cfa8e0a81a8fd0538c82388ab850220d2fb75cba Mon Sep 17 00:00:00 2001 From: Leah Lundqvist Date: Mon, 6 Jul 2020 18:09:54 +0200 Subject: [PATCH] js: |0 -> parseInt (#5703) --- vlib/v/gen/js/js.v | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/vlib/v/gen/js/js.v b/vlib/v/gen/js/js.v index 5ab8599ac6..d5e41f0268 100644 --- a/vlib/v/gen/js/js.v +++ b/vlib/v/gen/js/js.v @@ -1327,6 +1327,12 @@ fn (mut g JsGen) gen_infix_expr(it ast.InfixExpr) { g.write(g.typ(it.right_type)) if it.op == .not_is { g.write(')') } } else { + both_are_int := int(it.left_type) in table.integer_type_idxs && int(it.right_type) in table.integer_type_idxs + + if it.op == .div && both_are_int { + g.write('parseInt(') + } + g.expr(it.left) // in js == is non-strict & === is strict, always do strict @@ -1341,8 +1347,8 @@ fn (mut g JsGen) gen_infix_expr(it ast.InfixExpr) { g.expr(it.right) // Int division: 2.5 -> 2 by prepending |0 - if it.op == .div && it.left_type == table.any_int_type_idx && it.right_type == table.any_int_type_idx { - g.write('|0') + if it.op == .div && both_are_int { + g.write(',10)') } } }