-
Notifications
You must be signed in to change notification settings - Fork 484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(nest): Better nesting implementation #732
Conversation
44371d3
to
d5461de
Compare
dcf7201
to
ad5c22e
Compare
This nesting implementation uses a proper recursive tree algorithm Fixes #554 BREAKING CHANGE: referencing inferred destructure params without renaming them, like $0.x, from JSDoc comments will no longer work. To reference them, instead add a param tag to name the destructuring param, and then refer to members of that name. Before: ```js /** * @param {number} $0.x a member of x */ function a({ x }) {} ``` After: ```js /** * @param {Object} options * @param {number} options.x a member of x */ function a({ x }) {} ```
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.
This code is not too easy to follow so I looked closer at the tests and they look good to me.
One way to make reviewing large PRs easier might be to get the formatting changes done in its own commit.
declarations/comment.js
Outdated
@@ -58,7 +58,21 @@ declare type CommentContextGitHub = { | |||
url: string | |||
}; | |||
|
|||
declare type CommentTag = { | |||
declare type CommentTagBase = { |
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 do you need to do declare
here. Can't you just do:
type CommentTagBase = {
...
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.
Yep! I always wrote declare type
because that's what the Flow library definition documentation talks about, but apparently declare actually doesn't mean anything, which is confusing - I'd love to track down whether it has any meaning anywhere, or why it was there in the first place.
lib/infer/params.js
Outdated
function addPrefix(doc, prefix) { | ||
if (!Array.isArray(doc) && doc.name) { | ||
doc.name = prefix + doc.name; | ||
// TODO: use a constant |
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.
Looks like a constant to me
lib/infer/params.js
Outdated
return paramToDoc(property, i, prefix + '$' + String(i) + '.'); | ||
case 'Identifier': | ||
// if the destructuring type is an array, the elements | ||
// in it are identifiers |
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.
Does this handle object destructuring shorthand?
function f({x}) {
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.
Also, isfunction f({x, ...y}) {
handled?
lib/nest.js
Outdated
|
||
const PATH_SPLIT = /(?:\[])?\./g; | ||
|
||
function rejectUnnamedTags( |
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.
reject is a bit misleading... maybe remove?
], | ||
'renaming' | ||
); | ||
|
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.
Maybe add test for function f({x}) {}
and function f({x, ...xs}) {}
?
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.
👍 added a test for the latter, and it works well. We have a test for the former at L170 of params.js
✨ Thank you @arv! Much appreciated! Re: formatting - something's afoot - since #710 there shouldn't be new surprises with formatting, and I'm seeing some in this issue, specifically in |
TODO: /** hi */
function f({ x: { y: { z } } }) {} Produces ### Table of Contents
- [f](#f)
## f
hi
**Parameters**
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.x` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.$0.y` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.$0.$0.z` Which is wrong. I need to do a second pass on the prefixing system. |
inferParams, | ||
inferProperties, | ||
inferReturn, | ||
inferMembership(), | ||
inferType, | ||
nest, |
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.
Doesn't nest
need to come after inferMembership
?
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 don't believe so: nest nests tags (properties, params) - hierarchy
nests according to membership. I'm excited to refactor hierarchy too as soon as this is release-ready. But there might be something I'm missing here that isn't uncovered by test fixtures?
…d Array destructuring: documenting destructured array elements with indices instead of names, because the names are purely internal details
Okay, this passes tests and now makes sense! This is a relatively big change, encompassing:
I'd greatly appreciate a code review if anyone can spare the time!
TODO
This now relies on Permitting numeric keys in parameter names eslint/doctrine#192 to avoid a regression: without a fix or workaround in doclet parsing, it will regress the ability to explicitly document destructuring arrays.Use our temporary fork repo to avoid this being a blocker.Fixes #554 and fixes #677