Browse Source

Ensure that TField with lhs as an int/float is generated like
(number).field instead of the invalid JS number.field

Luca Deltodesco 12 years ago
parent
commit
cf853bb178
1 changed files with 8 additions and 1 deletions
  1. 8 1
      genjs.ml

+ 8 - 1
genjs.ml

@@ -420,13 +420,20 @@ let rec gen_call ctx e el in_value =
 		concat ctx "," (gen_value ctx) el;
 		concat ctx "," (gen_value ctx) el;
 		spr ctx ")"
 		spr ctx ")"
 
 
+and gen_object_value ctx e = match e.eexpr with
+	| TConst (TInt _) | TConst (TFloat _) ->
+		spr ctx "(";
+		gen_value ctx e;
+		spr ctx ")"
+	| _ -> gen_value ctx e
+
 and gen_expr ctx e =
 and gen_expr ctx e =
 	add_mapping ctx e;
 	add_mapping ctx e;
 	match e.eexpr with
 	match e.eexpr with
 	| TConst c -> gen_constant ctx e.epos c
 	| TConst c -> gen_constant ctx e.epos c
 	| TLocal v -> spr ctx (ident v.v_name)
 	| TLocal v -> spr ctx (ident v.v_name)
 	| TArray (e1,{ eexpr = TConst (TString s) }) when valid_js_ident s ->
 	| TArray (e1,{ eexpr = TConst (TString s) }) when valid_js_ident s ->
-		gen_value ctx e1;
+		gen_object_value ctx e1;
 		spr ctx (field s)
 		spr ctx (field s)
 	| TArray (e1,e2) ->
 	| TArray (e1,e2) ->
 		gen_value ctx e1;
 		gen_value ctx e1;