Browse Source

[js] properly escape field name when extracting enum parameters named as js keywords (closes #7220)

Dan Korostelev 7 years ago
parent
commit
83dbcc94af
2 changed files with 20 additions and 1 deletions
  1. 1 1
      src/generators/genjs.ml
  2. 19 0
      tests/unit/src/unit/issues/Issue7220.hx

+ 1 - 1
src/generators/genjs.ml

@@ -533,7 +533,7 @@ and gen_expr ctx e =
 		gen_value ctx x;
 		if not (Common.defined ctx.com Define.JsEnumsAsArrays) then
 			let fname = (match f.ef_type with TFun((args,_)) -> let fname,_,_ = List.nth args i in  fname | _ -> assert false ) in
-			print ctx ".%s" (fname)
+			print ctx ".%s" (ident fname)
 		else
 			print ctx "[%i]" (i + 2)
 	| TField (_, FStatic ({cl_path = [],""},f)) ->

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

@@ -0,0 +1,19 @@
+package unit.issues;
+
+private enum Expr {
+	Const(const:Int);
+}
+
+class Issue7220 extends unit.Test {
+	function test() {
+		eq(extract(Const(15)), 15);
+	}
+
+	static function extract(e:Expr):Int {
+		switch e {
+			case Const(const):
+				return const;
+		}
+	}
+}
+