Skip to content

Commit

Permalink
added -D check-js-packages
Browse files Browse the repository at this point in the history
  • Loading branch information
ncannasse committed Nov 23, 2008
1 parent a5ba902 commit 121c201
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
flash9 : use target file path for Boot unique ID instead of random number
as3 : fixed bug when anonymous field was a reserved identifier
flash9 : added flash.Lib.vectorOfArray and vectorConvert for flash10
added -D check-js-packages to allow several haxe-generated js files in same page

2008-10-04: 2.01
fixed php.Sys
Expand Down
10 changes: 7 additions & 3 deletions genjs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type ctx = {
buf : Buffer.t;
packages : (string list,unit) Hashtbl.t;
stack : Codegen.stack_context;
check_package : bool;
mutable current : tclass;
mutable statics : (tclass * string * texpr) list;
mutable inits : texpr list;
Expand Down Expand Up @@ -587,9 +588,11 @@ let generate_package_create ctx (p,_) =
Hashtbl.add ctx.packages (p :: acc) ();
(match acc with
| [] ->
print ctx "%s = {}" p;
| _ ->
print ctx "%s%s = {}" (String.concat "." (List.rev acc)) (field p));
if ctx.check_package then print ctx "try { if( %s == null ) %s = {}; } catch(_) { %s = {}; } " p p p else print ctx "%s = {}" p;
| _ ->
let p = String.concat "." (List.rev acc) ^ (field p) in
if ctx.check_package then print ctx "if( !%s ) " p;
print ctx "%s = {}" p);
newline ctx;
loop (p :: acc) l
in
Expand Down Expand Up @@ -703,6 +706,7 @@ let generate com =
com = com;
stack = Codegen.stack_init com false;
buf = Buffer.create 16000;
check_package = Common.defined com "check-js-packages";
packages = Hashtbl.create 0;
statics = [];
inits = [];
Expand Down

0 comments on commit 121c201

Please sign in to comment.