فهرست منبع

[js] clean up after Simn and add a test (closes #7869)

Dan Korostelev 6 سال پیش
والد
کامیت
defd505e45
4فایلهای تغییر یافته به همراه29 افزوده شده و 6 حذف شده
  1. 5 2
      src/context/common.ml
  2. 0 3
      src/generators/genjs.ml
  3. 1 1
      src/typing/macroContext.ml
  4. 23 0
      tests/unit/src/unit/issues/Issue7869.hx

+ 5 - 2
src/context/common.ml

@@ -98,7 +98,7 @@ type platform_config = {
 	pf_supports_function_equality : bool;
 	(** uses utf16 encoding with ucs2 api **)
 	pf_uses_utf16 : bool;
-	(** target supports `this` before `super` **)
+	(** target supports accessing `this` before calling `super(...)` **)
 	pf_this_before_super : bool;
 }
 
@@ -241,6 +241,9 @@ let define_value com k v =
 let raw_defined_value com k =
 	Define.raw_defined_value com.defines k
 
+let get_es_version com =
+	try int_of_string (defined_value com Define.JsEs) with _ -> 0
+
 let short_platform_name = function
 	| Cross -> "x"
 	| Js -> "js"
@@ -290,7 +293,7 @@ let get_config com =
 			pf_sys = false;
 			pf_capture_policy = CPLoopVars;
 			pf_reserved_type_paths = [([],"Object");([],"Error")];
-			pf_this_before_super = false; (* check ES6 flag? meh... *)
+			pf_this_before_super = (get_es_version com) < 6; (* cannot access `this` before `super()` when generating ES6 classes *)
 		}
 	| Lua ->
 		{

+ 0 - 3
src/generators/genjs.ml

@@ -1533,9 +1533,6 @@ let gen_single_expr ctx e expr =
 	ctx.id_counter <- 0;
 	str
 
-let get_es_version com =
-	try int_of_string (Common.defined_value com Define.JsEs) with _ -> 0
-
 let generate com =
 	(match com.js_gen with
 	| Some g -> g()

+ 1 - 1
src/typing/macroContext.ml

@@ -239,7 +239,7 @@ let make_macro_api ctx p =
 		);
 		MacroApi.set_js_generator = (fun gen ->
 			Path.mkdir_from_path ctx.com.file;
-			let js_ctx = Genjs.alloc_ctx ctx.com (Genjs.get_es_version ctx.com) in
+			let js_ctx = Genjs.alloc_ctx ctx.com (get_es_version ctx.com) in
 			ctx.com.js_gen <- Some (fun() ->
 				let t = macro_timer ctx ["jsGenerator"] in
 				gen js_ctx;

+ 23 - 0
tests/unit/src/unit/issues/Issue7869.hx

@@ -0,0 +1,23 @@
+package unit.issues;
+
+private class A {
+	function new() {}
+}
+
+private class B extends A {
+	public var f:Int;
+	public var x:()->Void;
+
+	public function new() {
+		super();
+		x = () -> f = 2;
+	}
+}
+
+class Issue7869 extends unit.Test {
+	function test() {
+		var b = new B();
+		b.x();
+		eq(b.f, 2);
+	}
+}