瀏覽代碼

[js] make sure js.Syntax treats its arguments as values

closes #7630
Simon Krajewski 6 年之前
父節點
當前提交
23acfe1259
共有 2 個文件被更改,包括 20 次插入1 次删除
  1. 1 1
      src/generators/genjs.ml
  2. 19 0
      tests/unit/src/unit/issues/Issue7630.hx

+ 1 - 1
src/generators/genjs.ml

@@ -949,7 +949,7 @@ and gen_syntax ctx meth args pos =
 				else
 					spr ctx (String.concat "\n" (ExtString.String.nsplit code "\r\n"))
 			| _ ->
-				Codegen.interpolate_code ctx.com code args (spr ctx) (gen_expr ctx) code_pos
+				Codegen.interpolate_code ctx.com code args (spr ctx) (gen_value ctx) code_pos
 		end
 	| "field" , [eobj;efield] ->
 		gen_value ctx eobj;

+ 19 - 0
tests/unit/src/unit/issues/Issue7630.hx

@@ -0,0 +1,19 @@
+package unit.issues;
+
+class Issue7630 extends unit.Test {
+	#if js
+	function test() {
+		var r = Math.random();
+
+    	func(inlineMe(if (r > 0.5) 42 else 21));
+	}
+
+	@:pure(false)
+	static function func(x:Float) { }
+
+	static inline function inlineMe(code: Int) {
+		var code2 = code;
+		return js.Syntax.code("{0} + 1", code2);
+	}
+	#end
+}