Skip to content

Commit

Permalink
Add @param annotation for synthesized "var_args" params.
Browse files Browse the repository at this point in the history
Fixes #1929

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=130671361
  • Loading branch information
tbreisacher authored and dimvar committed Aug 19, 2016
1 parent f04d4f7 commit c4c0447
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 13 deletions.
9 changes: 9 additions & 0 deletions src/com/google/javascript/jscomp/Es6ConvertSuper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.javascript.rhino.IR;
import com.google.javascript.rhino.JSDocInfoBuilder;
import com.google.javascript.rhino.JSTypeExpression;
import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.Token;

/**
* Converts {@code super} nodes. This has to run before the main
Expand Down Expand Up @@ -83,6 +86,12 @@ private void addSyntheticConstructor(Node classNode) {
IR.paramList(IR.name("var_args")),
body);
memberDef = IR.memberFunctionDef("constructor", constructor);
JSDocInfoBuilder info = new JSDocInfoBuilder(false);
info.recordParameter(
"var_args",
new JSTypeExpression(
new Node(Token.ELLIPSIS, new Node(Token.QMARK)), "<Es6ConvertSuper>"));
memberDef.setJSDocInfo(info.build());
}
memberDef.useSourceInfoIfMissingFromForTree(classNode);
classMembers.addChildToFront(memberDef);
Expand Down
66 changes: 53 additions & 13 deletions test/com/google/javascript/jscomp/Es6ToEs3ConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ public void testAnonymousSuper() {
test(
"f(class extends D { f() { super.g() } })",
LINE_JOINER.join(
"/** @constructor @struct @const @extends {D} */",
"/** @constructor @struct @const",
" * @extends {D}",
" * @param {...?} var_args",
" */",
"var testcode$classdecl$var0 = function(var_args) { D.apply(this,arguments); };",
"$jscomp.inherits(testcode$classdecl$var0, D);",
"testcode$classdecl$var0.prototype.f = function() {super.g(); };",
Expand Down Expand Up @@ -542,7 +545,10 @@ public void testExtends() {
LINE_JOINER.join(
"/** @constructor @struct */",
"var D = function() {};",
"/** @constructor @struct @extends {D} */",
"/** @constructor @struct",
" * @extends {D}",
" * @param {...?} var_args",
" */",
"var C = function(var_args) { D.apply(this, arguments); };",
"$jscomp.inherits(C, D);"));
assertThat(getLastCompiler().injected).containsExactly("es6/util/inherits");
Expand Down Expand Up @@ -572,7 +578,10 @@ public void testExtends() {
test(
"class C extends ns.D { }",
LINE_JOINER.join(
"/** @constructor @struct @extends {ns.D} */",
"/** @constructor @struct",
" * @extends {ns.D}",
" * @param {...?} var_args",
" */",
"var C = function(var_args) { ns.D.apply(this, arguments); };",
"$jscomp.inherits(C, ns.D);"));

Expand All @@ -582,7 +591,10 @@ public void testExtends() {
LINE_JOINER.join(
"/** @constructor @struct */",
"var D = function() {};",
"/** @constructor @struct @extends {D} */",
"/** @constructor @struct",
" * @extends {D}",
" * @param {...?} var_args",
" */",
"var C = function(var_args) {};"));
}

Expand All @@ -608,7 +620,10 @@ public void testExtendsInterface() {
"/** @struct @interface */",
"var D = function() {};",
"D.prototype.f = function() {};",
"/** @struct @interface @extends{D} */",
"/**",
" * @struct @interface",
" * @param {...?} var_args",
" * @extends{D} */",
"var C = function(var_args) { D.apply(this, arguments); };",
"C.prototype.g = function() {};"));
}
Expand Down Expand Up @@ -765,7 +780,10 @@ public void testClassNested() {
"/** @constructor @struct */",
"var C = function() {};",
"C.prototype.f = function() {",
" /** @constructor @struct @extends{C} */",
" /**",
" * @constructor @struct",
" * @param {...?} var_args",
" * @extends{C} */",
" var D = function(var_args) { C.apply(this, arguments); };",
" $jscomp.inherits(D, C);",
"};"));
Expand Down Expand Up @@ -830,7 +848,10 @@ public void testSuperCallNonConstructor() {
test(
"class S extends B { static f() { super(); } }",
LINE_JOINER.join(
"/** @constructor @struct @extends {B} */",
"/** @constructor @struct",
" * @extends {B}",
" * @param {...?} var_args",
" */",
"var S = function(var_args) { B.apply(this, arguments); };",
"$jscomp.inherits(S, B);",
"/** @this {?} */",
Expand All @@ -839,7 +860,10 @@ public void testSuperCallNonConstructor() {
test(
"class S extends B { f() { super(); } }",
LINE_JOINER.join(
"/** @constructor @struct @extends {B} */",
"/** @constructor @struct",
" * @extends {B}",
" * @param {...?} var_args",
" */",
"var S = function(var_args) { B.apply(this, arguments); };",
"$jscomp.inherits(S, B);",
"S.prototype.f=function() {",
Expand Down Expand Up @@ -944,7 +968,10 @@ public void testInheritFromExterns() {
"ExternsClass.m = function() {};"),
"class CodeClass extends ExternsClass {}",
LINE_JOINER.join(
"/** @constructor @struct @extends {ExternsClass} */",
"/** @constructor @struct",
" * @extends {ExternsClass}",
" * @param {...?} var_args",
" */",
"var CodeClass = function(var_args) {",
" ExternsClass.apply(this,arguments)",
"};",
Expand Down Expand Up @@ -995,7 +1022,11 @@ public void testInvalidClassUse() {
"/** @constructor @struct */",
"function Foo() {}",
"Foo.prototype.f = function() {};",
"/** @constructor @struct @extends {Foo} */",
"/**",
" * @constructor @struct",
" * @extends {Foo}",
" * @param {...?} var_args",
" */",
"var Sub=function(var_args) { Foo.apply(this, arguments); }",
"$jscomp.inherits(Sub, Foo);",
"(new Sub).f();"));
Expand All @@ -1019,7 +1050,10 @@ public void testInvalidClassUse() {
"/** @constructor */",
"function Foo() {}",
"Foo.f = function() {};",
"/** @constructor @struct @extends {Foo} */",
"/** @constructor @struct",
" * @extends {Foo}",
" * @param {...?} var_args",
" */",
"var Sub = function(var_args) { Foo.apply(this, arguments); };",
"$jscomp.inherits(Sub, Foo);"));
}
Expand Down Expand Up @@ -1155,7 +1189,10 @@ public void testEs5GettersAndSettersOnClassesWithClassSideInheritance() {
" get: function() {}",
" }",
"});",
"/** @constructor @struct @extends {C} */",
"/** @constructor @struct",
" * @extends {C}",
" * @param {...?} var_args",
" */",
"var D = function(var_args) { C.apply(this,arguments); };",
"/** @nocollapse @type {?} */",
"D.value;",
Expand Down Expand Up @@ -1311,7 +1348,10 @@ public void testStaticGetterSetter() {
" }",
"})",
"",
"/** @constructor @struct @extends {C} */",
"/** @constructor @struct",
" * @extends {C}",
" * @param {...?} var_args",
" */",
"var Sub = function(var_args) {",
" C.apply(this, arguments);",
"};",
Expand Down

0 comments on commit c4c0447

Please sign in to comment.