瀏覽代碼

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;
 			if ctx.js_flatten then
 				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;
 			ctx.separator <- false;
 			newline ctx;
@@ -1017,7 +1022,12 @@ let generate_enum ctx e =
 		let enum_var = p ^ (static_field ctx false f.ef_name) in
 		if ctx.js_flatten then
 			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
 		| TFun (args,_) ->
 			let sargs = String.concat "," (List.map (fun (n,_,_) -> ident n) args) in