瀏覽代碼

[js] consider statics of @:native("") classes when renaming local vars (closes #6448)

Dan Korostelev 8 年之前
父節點
當前提交
9e712ce50c
共有 2 個文件被更改,包括 26 次插入3 次删除
  1. 11 1
      src/optimization/filters.ml
  2. 15 2
      tests/unit/src/unit/issues/Issue6448.hx

+ 11 - 1
src/optimization/filters.ml

@@ -237,10 +237,20 @@ let collect_reserved_local_names com =
 	match com.platform with
 	| Js ->
 		let h = ref StringMap.empty in
+		let add name = h := StringMap.add name true !h in
 		List.iter (fun mt ->
 			let tinfos = t_infos mt in
 			let native_name = try fst (get_native_name tinfos.mt_meta) with Not_found -> Path.flat_path tinfos.mt_path in
-			h := StringMap.add native_name true !h
+			if native_name = "" then
+				match mt with
+				| TClassDecl c ->
+					List.iter (fun cf ->
+						let native_name = try fst (get_native_name cf.cf_meta) with Not_found -> cf.cf_name in
+						add native_name
+					) c.cl_ordered_statics;
+				| _ -> ()
+			else
+				add native_name
 		) com.types;
 		!h
 	| _ -> StringMap.empty

+ 15 - 2
tests/unit/src/unit/issues/Issue6448.hx

@@ -1,17 +1,30 @@
 package unit.issues;
 
-@:native("some")
+@:native("some6448")
 private class C {
 	public var v = true;
 	public function new() {}
 }
 
+@:native("")
+private extern class Lib {
+	@:native("___hx_returnTrue")
+	static function returnTrue():Bool;
+
+	static function __init__():Void {
+		untyped __js__("function ___hx_returnTrue() { return true; }");
+	}
+}
+
 class Issue6448 extends unit.Test {
 	#if js
 	@:analyzer(no_local_dce)
 	function test() {
-		var some = null;
+		var some6448 = null;
 		t(new C().v);
+
+		function ___hx_returnTrue() return false;
+		t(Lib.returnTrue());
 	}
 	#end
 }