Skip to content

Commit

Permalink
[js] add parens to compound exprs passed to Syntax.code() (fixes Haxe…
Browse files Browse the repository at this point in the history
  • Loading branch information
RealyUniqueName committed Dec 12, 2019
1 parent 3e260bb commit 7900dbe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/generators/genjs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,19 @@ and gen_syntax ctx meth args pos =
else
spr ctx (String.concat "\n" (ExtString.String.nsplit code "\r\n"))
| _ ->
let rec reveal_expr expr =
match expr.eexpr with
| TCast (e, _) | TMeta (_, e) -> reveal_expr e
| _ -> expr
in
let args = List.map
(fun arg ->
match (reveal_expr arg).eexpr with
| TIf _ | TBinop _ | TUnop _ -> { arg with eexpr = TParenthesis arg }
| _ -> arg
)
args
in
Codegen.interpolate_code ctx.com code args (spr ctx) (gen_value ctx) code_pos
end
| "field" , [eobj;efield] ->
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/src/unit/issues/Issue9027.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package unit.issues;

class Issue9027 extends unit.Test {
#if js
static var a:String = "a";
static var b:String = "b";

function test() {
eq(2, js.Syntax.code('{0}.length', a + b));
eq(2, js.Syntax.code('{0}.length', a < b ? "cd" : "efg"));
}
#end
}

0 comments on commit 7900dbe

Please sign in to comment.