js: |0 -> parseInt (#5703)
							parent
							
								
									9e7ba5f138
								
							
						
					
					
						commit
						cfa8e0a81a
					
				| 
						 | 
					@ -1327,6 +1327,12 @@ fn (mut g JsGen) gen_infix_expr(it ast.InfixExpr) {
 | 
				
			||||||
		g.write(g.typ(it.right_type))
 | 
							g.write(g.typ(it.right_type))
 | 
				
			||||||
		if it.op == .not_is { g.write(')') }
 | 
							if it.op == .not_is { g.write(')') }
 | 
				
			||||||
	} else {
 | 
						} 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)
 | 
							g.expr(it.left)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// in js == is non-strict & === is strict, always do strict
 | 
							// 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)
 | 
							g.expr(it.right)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Int division: 2.5 -> 2 by prepending |0
 | 
							// 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 {
 | 
							if it.op == .div && both_are_int {
 | 
				
			||||||
			g.write('|0')
 | 
								g.write(',10)')
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue