浏览代码

Generate dotted aliases for static fields.

...this static field flattening probably isn't going to work out.
Unfortunately it doesn't work so great with Dynamic, even with this
commit. I'm not sure how to handle code like this:

	class Evil {
		public static var staticMember :Int = 1;
	}
	var evil :Dynamic = new Evil();
	evil.staticMember = 2;

Package flattening on the other hand has been pretty solid, and is more
bang for the buck anyways.
Bruno Garcia 12 年之前
父节点
当前提交
5dac20067b
共有 1 个文件被更改,包括 12 次插入2 次删除
  1. 12 2
      genjs.ml

+ 12 - 2
genjs.ml

@@ -878,7 +878,12 @@ let gen_class_static_field ctx c f =
 			ctx.id_counter <- 0;
 			ctx.id_counter <- 0;
 			if ctx.js_flatten then
 			if ctx.js_flatten then
 				print ctx "var ";
 				print ctx "var ";
-			print ctx "%s = " path;
+			print ctx "%s" path;
+			if ctx.js_flatten then
+				(* Also generate the dotted field under js_flatten, so calls on
+				 * Dynamic and reflection work. *)
+				print ctx " = %s%s" (s_path ctx c.cl_path) (static_field ctx true f.cf_name);
+			print ctx " = ";
 			gen_value ctx e;
 			gen_value ctx e;
 			ctx.separator <- false;
 			ctx.separator <- false;
 			newline ctx;
 			newline ctx;
@@ -1017,7 +1022,12 @@ let generate_enum ctx e =
 		let enum_var = p ^ (static_field ctx false f.ef_name) in
 		let enum_var = p ^ (static_field ctx false f.ef_name) in
 		if ctx.js_flatten then
 		if ctx.js_flatten then
 			print ctx "var ";
 			print ctx "var ";
-		print ctx "%s = " enum_var;
+		print ctx "%s" enum_var;
+		if ctx.js_flatten then
+			(* Also generate the dotted field under js_flatten, so calls on
+			 * Dynamic and reflection work. *)
+			print ctx " = %s%s" p (static_field ctx true f.ef_name);
+		print ctx " = ";
 		(match f.ef_type with
 		(match f.ef_type with
 		| TFun (args,_) ->
 		| TFun (args,_) ->
 			let sargs = String.concat "," (List.map (fun (n,_,_) -> ident n) args) in
 			let sargs = String.concat "," (List.map (fun (n,_,_) -> ident n) args) in