From 2e9ef25d0f3c86f9c56c68de75a93c4049a75aba Mon Sep 17 00:00:00 2001 From: Aleksandr Kuzmenko Date: Fri, 15 May 2020 20:45:59 +0300 Subject: [PATCH] [es6]fix same name locals in different __init__ methods (#9426) --- src/generators/genjs.ml | 20 ++++++++++---------- tests/misc/es6/Test.hx | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/generators/genjs.ml b/src/generators/genjs.ml index dc7b3dde415..7fb89c5be72 100644 --- a/src/generators/genjs.ml +++ b/src/generators/genjs.ml @@ -818,25 +818,25 @@ and gen_function ?(keyword="function") ctx f pos = ctx.in_loop <- snd old; ctx.separator <- true -and gen_block_element ?(after=false) ctx e = +and gen_block_element ?(newline_after=false) ?(keep_blocks=false) ctx e = match e.eexpr with - | TBlock el -> - List.iter (gen_block_element ~after ctx) el + | TBlock el when not keep_blocks -> + List.iter (gen_block_element ~newline_after ctx) el | TCall ({ eexpr = TIdent "__feature__" }, { eexpr = TConst (TString f) } :: eif :: eelse) -> if has_feature ctx f then - gen_block_element ~after ctx eif + gen_block_element ~newline_after ctx eif else (match eelse with | [] -> () - | [e] -> gen_block_element ~after ctx e + | [e] -> gen_block_element ~newline_after ctx e | _ -> die "" __LOC__) | TFunction _ -> - gen_block_element ~after ctx (mk (TParenthesis e) e.etype e.epos) + gen_block_element ~newline_after ctx (mk (TParenthesis e) e.etype e.epos) | TObjectDecl fl -> - List.iter (fun (_,e) -> gen_block_element ~after ctx e) fl + List.iter (fun (_,e) -> gen_block_element ~newline_after ctx e) fl | _ -> - if not after then newline ctx; + if not newline_after then newline ctx; gen_expr ctx e; - if after then newline ctx + if newline_after then newline ctx and gen_value ctx e = let clear_mapping = add_mapping ctx e in @@ -1895,7 +1895,7 @@ let generate com = add_feature ctx "js.Lib.global"; print ctx "$global.$haxeUID |= 0;\n"; end; - List.iter (gen_block_element ~after:true ctx) (List.rev ctx.inits); + List.iter (gen_block_element ~newline_after:true ~keep_blocks:(ctx.es_version >= 6) ctx) (List.rev ctx.inits); List.iter (generate_static ctx) (List.rev ctx.statics); (match com.main with | None -> () diff --git a/tests/misc/es6/Test.hx b/tests/misc/es6/Test.hx index 3443596941c..4fec1638c16 100644 --- a/tests/misc/es6/Test.hx +++ b/tests/misc/es6/Test.hx @@ -68,6 +68,22 @@ class GrandChildNoArgs extends ChildOneArg { } } +class Issue9426_1 { + static function __init__() { + var sameName = Std.random(10); + Test.use(sameName); + Test.use(sameName); + } +} + +class Issue9426_2 { + static function __init__() { + var sameName = Std.random(10); + Test.use(sameName); + Test.use(sameName); + } +} + class Test { public static var calls:Array; @:pure(false) public static function use(v:Any) {}