From 121c201214582efd87440e757972b75e5c84ebdc Mon Sep 17 00:00:00 2001 From: Nicolas Cannasse Date: Sun, 23 Nov 2008 14:22:46 +0000 Subject: [PATCH] added -D check-js-packages --- doc/CHANGES.txt | 1 + genjs.ml | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/doc/CHANGES.txt b/doc/CHANGES.txt index 5a2a87bc63e..c18bb5dd467 100644 --- a/doc/CHANGES.txt +++ b/doc/CHANGES.txt @@ -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 diff --git a/genjs.ml b/genjs.ml index 9f16e10a121..839f4f3e46a 100644 --- a/genjs.ml +++ b/genjs.ml @@ -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; @@ -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 @@ -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 = [];