1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

js: |0 -> parseInt (#5703)

This commit is contained in:
Leah Lundqvist 2020-07-06 18:09:54 +02:00 committed by GitHub
parent 9e7ba5f138
commit cfa8e0a81a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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