Skip to content

Commit

Permalink
[js] clean up after Simn and add a test (closes #7869)
Browse files Browse the repository at this point in the history
  • Loading branch information
nadako committed Feb 26, 2019
1 parent e0ddd85 commit defd505
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 ->
{
Expand Down
3 changes: 0 additions & 3 deletions src/generators/genjs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/typing/macroContext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/src/unit/issues/Issue7869.hx
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit defd505

Please sign in to comment.