This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Add support for collapsing parameter properties with default values. #738
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5c85984
Add support for collapsing parameter properties with default values.
bowenni 887c50c
Merge branch 'master' into fb4
bowenni 60044f1
Merge branch 'master' into fb4
bowenni 339a29e
Handle the case where a parameter is optional and has a default value.
bowenni 66bbf0a
Merge branch 'master' into fb4
bowenni c09b220
Merge branch 'master' into fb4
bowenni 2fe491b
Merge branch 'master' into fb4
bowenni 0cedac1
Fix formatting.
bowenni 3048dbd
Merge branch 'fb4' of github.com:bowenni/clutz into fb4
bowenni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -309,16 +309,18 @@ 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 commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, for cleaning up my TODOs! |
||
if (param.isDefaultValue()) { | ||
continue; | ||
} | ||
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. | ||
if (param.isDefaultValue() && Token.EQUALS.equals(paramType.getRoot().getToken())) { | ||
paramType = | ||
new JSTypeExpression( | ||
paramType.getRoot().getFirstChild(), paramType.getSourceName()); | ||
} | ||
// Names must be equal. Types must be equal, or if the declaration has no type it is | ||
// assumed to be the type of the parameter. | ||
if (declaration.memberName.equals(paramName) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,6 @@ class C { | |
/** @private {number} */ | ||
this.d = d; | ||
} | ||
} | ||
} | ||
|
||
let {x = 0} = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.