Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
$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.
  • Loading branch information
deltaluca committed Apr 7, 2014
1 parent 72707e2 commit 762ff49
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions genjs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1223,26 +1223,22 @@ let generate com =

(* Wrap output in a closure *)
if (anyExposed && (Common.defined com Define.ShallowExpose)) then (
print ctx "var $hx_exports = {}";
print ctx "var $hx_exports = $hx_exports || {}";
ctx.separator <- true;
newline ctx
);
print ctx "(function (";
if (anyExposed && not (Common.defined com Define.ShallowExpose)) then print ctx "$hx_exports";
print ctx ") { \"use strict\"";
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
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;

(* TODO: fix $estr *)
Expand Down

0 comments on commit 762ff49

Please sign in to comment.