js: |0 -> parseInt (#5703)

pull/5710/head
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
1 changed files with 8 additions and 2 deletions

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