瀏覽代碼

fixed bug with js operator priority.

Nicolas Cannasse 19 年之前
父節點
當前提交
13932c8076
共有 1 個文件被更改,包括 14 次插入5 次删除
  1. 14 5
      genjs.ml

+ 14 - 5
genjs.ml

@@ -170,6 +170,15 @@ let rec gen_call ctx e el =
 		concat ctx "," (gen_value ctx) el;
 		spr ctx ")"
 
+and gen_value_op ctx e =
+	match e.eexpr with
+	| TBinop (op,_,_) when op = Ast.OpAnd || op = Ast.OpOr || op = Ast.OpXor ->
+		spr ctx "(";
+		gen_value ctx e;
+		spr ctx ")";
+	| _ ->
+		gen_value ctx e
+
 and gen_expr ctx e =
 	match e.eexpr with
 	| TConst c -> gen_constant ctx e.epos c
@@ -182,14 +191,14 @@ and gen_expr ctx e =
 		gen_value ctx e2;
 		spr ctx "]";
 	| TBinop (op,{ eexpr = TField (e1,s) },e2) ->
-		gen_value ctx e1;
+		gen_value_op ctx e1;
 		spr ctx (field s);
 		print ctx " %s " (Ast.s_binop op);
-		gen_value ctx e2;
-	| TBinop (op,e1,e2) ->
-		gen_value ctx e1;
+		gen_value_op ctx e2;
+	| TBinop (op,e1,e2) ->		
+		gen_value_op ctx e1;
 		print ctx " %s " (Ast.s_binop op);
-		gen_value ctx e2;
+		gen_value_op ctx e2;
 	| TField (x,s) ->
 		(match follow e.etype with
 		| TFun _ ->