Explorar o código

[php] cleaner output for string concat and Array.push()

Aleksandr Kuzmenko %!s(int64=5) %!d(string=hai) anos
pai
achega
0247aaaf32
Modificáronse 2 ficheiros con 11 adicións e 7 borrados
  1. 9 5
      src/generators/genphp7.ml
  2. 2 2
      std/php/_std/Array.hx

+ 9 - 5
src/generators/genphp7.ml

@@ -2103,11 +2103,15 @@ class code_writer (ctx:php_generator_context) hx_type_path php_name =
 					|| is_php_class_const expr
 				then
 					self#write_expr expr
-				else begin
-					self#write "(";
-					self#write_expr expr;
-					self#write "??'null')"
-				end
+				else
+					match (reveal_expr expr).eexpr with
+					| TConst TNull -> self#write "'null'"
+					| TBinop _ | TUnop _ -> self#write_expr (parenthesis expr)
+					| TParenthesis { eexpr = (TBinop _ | TUnop _) } -> self#write_expr expr
+					| _ ->
+						self#write "(";
+						self#write_expr expr;
+						self#write "??'null')"
 			and write_binop ?writer ?right_writer str =
 				let write_left = match writer with None -> self#write_expr | Some writer -> writer in
 				let write_right = match right_writer with None -> write_left | Some writer -> writer

+ 2 - 2
std/php/_std/Array.hx

@@ -120,8 +120,8 @@ final class Array<T> implements ArrayAccess<Int, T> {
 	}
 
 	public inline function push(x:T):Int {
-		arr[length] = x;
-		return ++length;
+		arr[length++] = x;
+		return length;
 	}
 
 	public function remove(x:T):Bool {