Selaa lähdekoodia

[js][es6] still use $ for `length` and `name` var fields (#8185)

Alexander Kuzmenko 6 vuotta sitten
vanhempi
commit
a26e77a545
2 muutettua tiedostoa jossa 20 lisäystä ja 5 poistoa
  1. 12 4
      src/generators/genjs.ml
  2. 8 1
      tests/display/src/cases/Issue8185.hx

+ 12 - 4
src/generators/genjs.ml

@@ -135,11 +135,19 @@ let check_var_declaration v = if Hashtbl.mem kwds2 v.v_name then v.v_name <- "$"
 
 let anon_field s = if Hashtbl.mem kwds s || not (valid_js_ident s) then "'" ^ s ^ "'" else s
 let static_field ctx c s =
-	if get_es_version ctx.com >= 6 then
-		field s
-	else
 		match s with
-		| "length" | "name" when not c.cl_extern || Meta.has Meta.HxGen c.cl_meta-> ".$" ^ s
+		| "length" | "name" when not c.cl_extern || Meta.has Meta.HxGen c.cl_meta->
+			let with_dollar = ".$" ^ s in
+			if get_es_version ctx.com >= 6 then
+				try
+					let f = PMap.find s c.cl_statics in
+					match f.cf_kind with
+					| Method _ -> "." ^ s
+					| _ -> with_dollar
+				with Not_found ->
+					with_dollar
+			else
+				with_dollar
 		| s -> field s
 
 let has_feature ctx = Common.has_feature ctx.com

+ 8 - 1
tests/display/src/cases/Issue8185.hx

@@ -3,9 +3,16 @@ package cases;
 class Issue8185 extends DisplayTestCase {
 	function test() {
 		eq(1, length());
-		eq(1, name());
+		eq(2, name());
+		eq(1, TestVar.length);
+		eq(2, TestVar.name);
 	}
 
 	static function length() return 1;
 	static function name() return 2;
 }
+
+private class TestVar {
+	static public var length = 1;
+	static public var name = 2;
+}