diff --git a/src/context/common.ml b/src/context/common.ml index e3ce0002e57..a16a62dd72d 100644 --- a/src/context/common.ml +++ b/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 -> { diff --git a/src/generators/genjs.ml b/src/generators/genjs.ml index ed93aa57e42..ba7300b1ad4 100644 --- a/src/generators/genjs.ml +++ b/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() diff --git a/src/typing/macroContext.ml b/src/typing/macroContext.ml index 144f0c6dd23..74a7f647d3d 100644 --- a/src/typing/macroContext.ml +++ b/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; diff --git a/tests/unit/src/unit/issues/Issue7869.hx b/tests/unit/src/unit/issues/Issue7869.hx new file mode 100644 index 00000000000..5280bf96813 --- /dev/null +++ b/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); + } +}