Browse Source

resolved #2855.

$hx_exports initializers are now exploded, with each unique field
assigned with || {} to avoid overwriting any potential existing value.

For -D shallow_expose, the outside declared $hx_exports is similarly
exploded.
Luca Deltodesco 11 years ago
parent
commit
762ff49598
1 changed files with 7 additions and 11 deletions
  1. 7 11
      genjs.ml

+ 7 - 11
genjs.ml

@@ -1223,7 +1223,7 @@ let generate com =
 
 
 		(* Wrap output in a closure *)
 		(* Wrap output in a closure *)
 		if (anyExposed && (Common.defined com Define.ShallowExpose)) then (
 		if (anyExposed && (Common.defined com Define.ShallowExpose)) then (
-			print ctx "var $hx_exports = {}";
+			print ctx "var $hx_exports = $hx_exports || {}";
 			ctx.separator <- true;
 			ctx.separator <- true;
 			newline ctx
 			newline ctx
 		);
 		);
@@ -1231,18 +1231,14 @@ let generate com =
 		if (anyExposed && not (Common.defined com Define.ShallowExpose)) then print ctx "$hx_exports";
 		if (anyExposed && not (Common.defined com Define.ShallowExpose)) then print ctx "$hx_exports";
 		print ctx ") { \"use strict\"";
 		print ctx ") { \"use strict\"";
 		newline ctx;
 		newline ctx;
-		let rec print_obj { os_fields = fields } = (
-			print ctx "{";
-			concat ctx "," (fun ({ os_name = name } as f) -> print ctx "%s" (name ^ ":"); print_obj f) fields;
-			print ctx "}";
+		let rec print_obj f root = (
+			print ctx "%s.%s = %s.%s || {}" root f.os_name root f.os_name;
+			ctx.separator <- true;
+			newline ctx;
+			concat ctx ";" (fun g -> print_obj g (root ^ "." ^ f.os_name)) f.os_fields
 		)
 		)
 		in
 		in
-		List.iter (fun f ->
-			print ctx "$hx_exports.%s = " f.os_name;
-			print_obj f;
-			ctx.separator <- true;
-			newline ctx
-		) exposedObject.os_fields;
+		List.iter (fun f -> print_obj f "$hx_exports") exposedObject.os_fields;
 	end;
 	end;
 
 
 	(* TODO: fix $estr *)
 	(* TODO: fix $estr *)