소스 검색

[js][es6] remove default arguments when rewriting constructors (closes #9321)

Dan Korostelev 5 년 전
부모
커밋
c40f569779
2개의 변경된 파일41개의 추가작업 그리고 2개의 파일을 삭제
  1. 11 2
      src/filters/ES6Ctors.ml
  2. 30 0
      tests/unit/src/unit/issues/Issue9321.hx

+ 11 - 2
src/filters/ES6Ctors.ml

@@ -36,6 +36,9 @@ let rec replace_super_call e =
 	| _ ->
 		map_expr replace_super_call e
 
+let remove_default_arg_values args =
+	List.map (fun (v,_) -> v,None) args
+
 exception Accessed_this of texpr
 
 (* return whether given expression has `this` access before calling `super` *)
@@ -202,7 +205,10 @@ let rewrite_ctors com =
 							]
 						} in
 
-						cf_ctor.cf_expr <- Some { ctor_expr with eexpr = TFunction { tf_ctor with tf_expr = e_ctor_replaced } };
+						cf_ctor.cf_expr <- Some { ctor_expr with eexpr = TFunction { tf_ctor with
+							tf_args = remove_default_arg_values tf_ctor.tf_args;
+							tf_expr = e_ctor_replaced
+						} };
 					end;
 
 					if cl == root then begin
@@ -224,7 +230,10 @@ let rewrite_ctors com =
 								make_hx_ctor_call e_skip_flag
 							]
 						} in
-						cf_ctor.cf_expr <- Some { ctor_expr with eexpr = TFunction { tf_ctor with tf_expr = e_ctor_replaced } };
+						cf_ctor.cf_expr <- Some { ctor_expr with eexpr = TFunction { tf_ctor with
+							tf_args = remove_default_arg_values tf_ctor.tf_args;
+							tf_expr = e_ctor_replaced
+						} };
 
 					| None -> ())
 				)

+ 30 - 0
tests/unit/src/unit/issues/Issue9321.hx

@@ -0,0 +1,30 @@
+package unit.issues;
+
+class Issue9321 extends unit.Test {
+	function test() {
+		eq(new Child().arg, "child");
+	}
+}
+
+@:keep
+private class Base {
+	function new(arg = "base") {}
+}
+
+@:keep
+private class Child extends Base {
+	public final arg:String;
+	public function new(arg = "child") {
+		super();
+		this.arg = arg;
+	}
+}
+
+@:keep
+private class GrandChild extends Child {
+	public function new() {
+		use(this);
+		super();
+	}
+	@:pure(false) static function use(v:Any) {}
+}