js: fix int division (#5701)

pull/5703/head
Leah Lundqvist 2020-07-06 15:24:24 +02:00 committed by GitHub
parent 6b2777e681
commit 659aa8db3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -1339,6 +1339,11 @@ 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')
}
}
}