Browse Source

removed --js-namespace
use var p = p || {} notation

Nicolas Cannasse 14 years ago
parent
commit
656b7dfd23
6 changed files with 6 additions and 50 deletions
  1. 0 2
      common.ml
  2. 4 4
      doc/CHANGES.txt
  3. 2 19
      genjs.ml
  4. 0 5
      main.ml
  5. 0 6
      std/js/Boot.hx
  6. 0 14
      std/js/_std/Type.hx

+ 0 - 2
common.ml

@@ -60,7 +60,6 @@ type context = {
 	mutable package_rules : (string,package_rule) PMap.t;
 	mutable error : string -> pos -> unit;
 	mutable warning : string -> pos -> unit;
-	mutable js_namespace : string option;
 	mutable load_extern_type : (path -> pos -> Ast.package option) list; (* allow finding types which are not in sources *)
 	mutable filters : (unit -> unit) list;
 	(* output *)
@@ -108,7 +107,6 @@ let create v =
 		php_front = None;
 		php_lib = None;
 		swf_libs = [];
-		js_namespace = None;
 		php_prefix = None;
 		js_gen = None;
 		load_extern_type = [];

+ 4 - 4
doc/CHANGES.txt

@@ -4,7 +4,7 @@
 	all : fixed some issue with completion
 	flash9 : fixed -D swfprotected with swc output
 	neko : added ~ implementation
-	js : upgraded jquery version
+	js : upgraded jquery version, more api overloads
 	sys : added "in" operator for spod macros, added relation access in expressions
 	macro : added ECheckType
 	macro : added TLazy for not-yet-typed class fields
@@ -12,10 +12,10 @@
 	all : added Std.format
 	js : trace() output fallback on console.log if no id="haxe:trace"
 	all : ensure that Std.is(2.0,Int) returns true on all platforms
-	js : replaced $closure by function.$bind + change in output format
+	js : replaced $closure by function.$bind + changes in output format
 	all : allowed @:extern on static methods (no generate + no closure + force inlining)
-	all : added documentation in --display infos
-	all : display overloads in completion
+	all : added documentation in --display infos + display overloads in completion
+	js : removed --js-namespace
 
 2011-09-25: 2.08
 	js : added js.JQuery

+ 2 - 19
genjs.ml

@@ -24,7 +24,6 @@ type ctx = {
 	buf : Buffer.t;
 	packages : (string list,unit) Hashtbl.t;
 	stack : Codegen.stack_context;
-	namespace : string option;
 	mutable current : tclass;
 	mutable statics : (tclass * string * texpr) list;
 	mutable inits : texpr list;
@@ -38,12 +37,7 @@ type ctx = {
 	mutable separator : bool;
 }
 
-let s_path ctx = function
-	| ([],p) ->
-		(match ctx.namespace with
-		| None -> p
-		| Some ns -> ns ^ "." ^ p)
-	| p -> Ast.s_type_path p
+let s_path ctx = Ast.s_type_path
 
 let kwds =
 	let h = Hashtbl.create 0 in
@@ -646,7 +640,7 @@ let generate_package_create ctx (p,_) =
 			Hashtbl.add ctx.packages (p :: acc) ();
 			(match acc with
 			| [] ->
-				print ctx "if(typeof %s=='undefined') var %s = {}" p p;
+				print ctx "var %s = %s || {}" p p;
 			| _ ->
 				let p = String.concat "." (List.rev acc) ^ (field p) in
 		        print ctx "if(!%s) %s = {}" p p);
@@ -798,7 +792,6 @@ let alloc_ctx com =
 		stack = Codegen.stack_init com false;
 		buf = Buffer.create 16000;
 		packages = Hashtbl.create 0;
-		namespace = com.js_namespace;
 		statics = [];
 		inits = [];
 		current = null_class;
@@ -838,19 +831,9 @@ function $extend(from, fields) {
 	return proto;
 }";
 	newline ctx;
-	(match ctx.namespace with
-		| None -> ()
-		| Some ns ->
-			print ctx "if(typeof %s=='undefined') var %s = {}" ns ns;
-			newline ctx);
 	List.iter (generate_type ctx) com.types;
 	print ctx "js.Boot.__res = {}";
 	newline ctx;
-	(match ctx.namespace with
-		| None -> ()
-		| Some ns ->
-			print ctx "js.Boot.__ns = '%s'" ns;
-			newline ctx);
 	if com.debug then begin
 		print ctx "%s = []" ctx.stack.Codegen.stack_var;
 		newline ctx;

+ 0 - 5
main.ml

@@ -500,11 +500,6 @@ try
 			com.php_prefix <- Some f;
 			Common.define com "php_prefix";
 		),"<name> : prefix all classes with given name");
-		("--js-namespace",Arg.String (fun f ->
-			if com.js_namespace <> None then raise (Arg.Bad "Multiple --js-namespace");
-			com.js_namespace <- Some f;
-			Common.define com "js_namespace";
-		),"<namespace> : create a namespace where root types are defined");
 		("--remap", Arg.String (fun s ->
 			let pack, target = (try ExtString.String.split s ":" with _ -> raise (Arg.Bad "Invalid format")) in
 			com.package_rules <- PMap.add pack (Remap target) com.package_rules;

+ 0 - 6
std/js/Boot.hx

@@ -183,12 +183,6 @@ class Boot {
 		untyped {
 			Lib.isIE = (__js__("typeof document!='undefined'") && document.all != null && __js__("typeof window!='undefined'") && window.opera == null );
 			Lib.isOpera = (__js__("typeof window!='undefined'") && window.opera != null );
-#if js_namespace
-			__js__("eval(js.Boot.__ns).Array = Array");
-			__js__("eval(js.Boot.__ns).String = String");
-			__js__("eval(js.Boot.__ns).Math = Math");
-			__js__("eval(js.Boot.__ns).Date = Date");
-#end
 			Array.prototype.copy = Array.prototype.slice;
 			Array.prototype.insert = function(i,x) {
 				__this__.splice(i,0,x);

+ 0 - 14
std/js/_std/Type.hx

@@ -69,14 +69,7 @@ enum ValueType {
 	public static function resolveClass( name : String ) : Class<Dynamic> untyped {
 		var cl : Class<Dynamic>;
 		try {
-			#if js_namespace
-			if (name.indexOf('.') < 0)
-				cl = eval(js.Boot.__ns + '.' + name);
-			else
-				cl = eval(name);
-			#else
 			cl = eval(name);
-			#end
 		} catch( e : Dynamic ) {
 			cl = null;
 		}
@@ -89,14 +82,7 @@ enum ValueType {
 	public static function resolveEnum( name : String ) : Enum<Dynamic> untyped {
 		var e : Dynamic;
 		try {
-			#if js_namespace
-			if (name.indexOf('.') < 0)
-				e = eval(js.Boot.__ns + '.' + name);
-			else
-				e = eval(name);
-			#else
 			e = eval(name);
-			#end
 		} catch( err : Dynamic ) {
 			e = null;
 		}