-
Notifications
You must be signed in to change notification settings - Fork 60
Add support for collapsing parameter properties with default values. #738
Conversation
#731 is closely related to this issue (rest parameters instead of parameters with default values). |
@@ -162,6 +162,19 @@ public void visit(NodeTraversal t, Node n, Node parent) { | |||
maybeSetInlineTypeExpression(parent, n, bestJSDocInfo, true); | |||
} | |||
break; | |||
// If a DEVAULE_VALUE is in a PARAM_LIST we type annotate its first child which is the | |||
// actual parameter. | |||
case DEFAULT_VALUE: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default values can occur in ES6 destructuring too:
let {x = 0} = {};
Are sure this makes sense for those cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know this syntax before.
Added a test case. It seems fine because the parent node here is not a parameter list.
@@ -308,12 +308,6 @@ public void visit(NodeTraversal t, Node n, Node parent) { | |||
if (!nodeAfterDefault.isName()) { | |||
continue; | |||
} | |||
// It appears that adding ACCESS_MODIFIERs to Default params do not come out though | |||
// the CodeGenerator, thus not safe to remove the declaration. | |||
// TODO(rado): fix in emitting code and remove this line. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, for cleaning up my TODOs!
@@ -5,7 +5,7 @@ class Klass { | |||
|
|||
/** | |||
* @param {number} n | |||
* @param {Array<?>=} list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why delete the '='? I looked around and it appears closure allows one to write this with or without the '=', but the one with '=' is more common.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted.
Also added a test case for default values in ES6 destructuring.
String paramName = nodeAfterDefault.getString(); | ||
@Nullable | ||
JSTypeExpression paramType = | ||
constructorJsDoc == null ? null : constructorJsDoc.getParameterType(paramName); | ||
// The class member declaration on "this" will not have "=" in the JSDoc most of the time. Therefore we need to remove the "=" from the JSDoc of the parameter declaration so we can compare the types and collapse the parameter property. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment goes over 100+ chars
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
gradle googleJavaFormat
stopped working for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I look at that, the code passed on travis so maybe our formatter setup is not working.
Fixes #650
One side-effect of this change is that it adds type annotations to function parameters with default values which fixes the implicity any errors.