-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
Fixing jsdoc parsing of functions that are defined over multiple lines (Fixes #410) #360
Conversation
Forgot to make a branch and ended up adding in some extra docs to this PR too...however their getting rendered depends on the original commit (03a562f). Just an FYI about the second and third commits. |
Also, I did complete the CLA. |
@@ -131,6 +131,16 @@ function getDocBlock(node, commentsForFile, linesForFile) { | |||
} | |||
var docblock; | |||
var prevLine = node.loc.start.line - 1; | |||
var startText = linesForFile[prevLine].trim(); | |||
|
|||
// Get to actual start of function declaration (for multi-line declarations) |
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.
@hansonw can you review this part?
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.
Good catch @pjjanak! However I don't think this will work; for example there are Flow typehints that contain left parens (namely for function types).
I did some digging, and actually this is only an issue for multi-line class method declarations. It looks like Esprima handles ES6 class methods by creating a MethodDefinition
AST node which contains another AST node with the actual FunctionDeclaration
- the MethodDefinition
has the correct line range.
A simpler fix would be to just call getDocBlock
on the MethodDefinition
AST node in getClassData
near line 395 below, and override the docblock there.
Looks good to me! Leaving the rest to you, @vjeux. |
Thanks, it is now in the repo! |
Fixes facebook#410) Summary: As it was implemented, the jsdoc parser would look only the first non-blank line immediately preceding a function declaration. However, the line that was set as the beginning of a function declaration was where the opening bracket (`{`) was. This is insufficient for functions whose definitions span multiple lines. For example, this declaration would not find the comments above it: ``` /** * Clones rows **/ cloneWithRows( dataBlob: Array<any> | {[key: string]: any}, rowIdentities: ?Array<string> ): ListViewDataSource { ... } ``` With this change, the parser will first check if we have a closing parenthesis. If we do and don't have a matching open parenthesis we continue moving up the lines until we find it. Then we set previous line to be the line before that, the true beginning of the function declaration. Closes facebook#360 Github Author: Peter Janak <pjanak@nhl.com> Test Plan: Run the website
Fixes facebook#410) Summary: As it was implemented, the jsdoc parser would look only the first non-blank line immediately preceding a function declaration. However, the line that was set as the beginning of a function declaration was where the opening bracket (`{`) was. This is insufficient for functions whose definitions span multiple lines. For example, this declaration would not find the comments above it: ``` /** * Clones rows **/ cloneWithRows( dataBlob: Array<any> | {[key: string]: any}, rowIdentities: ?Array<string> ): ListViewDataSource { ... } ``` With this change, the parser will first check if we have a closing parenthesis. If we do and don't have a matching open parenthesis we continue moving up the lines until we find it. Then we set previous line to be the line before that, the true beginning of the function declaration. Closes facebook#360 Github Author: Peter Janak <pjanak@nhl.com> Test Plan: Run the website
Fixes facebook#410) Summary: As it was implemented, the jsdoc parser would look only the first non-blank line immediately preceding a function declaration. However, the line that was set as the beginning of a function declaration was where the opening bracket (`{`) was. This is insufficient for functions whose definitions span multiple lines. For example, this declaration would not find the comments above it: ``` /** * Clones rows **/ cloneWithRows( dataBlob: Array<any> | {[key: string]: any}, rowIdentities: ?Array<string> ): ListViewDataSource { ... } ``` With this change, the parser will first check if we have a closing parenthesis. If we do and don't have a matching open parenthesis we continue moving up the lines until we find it. Then we set previous line to be the line before that, the true beginning of the function declaration. Closes facebook#360 Github Author: Peter Janak <pjanak@nhl.com> Test Plan: Run the website
* Fix CI * Update config.yml
Added shortcuts for developer menu on Windows and Linux. Typing adb commands is not necessary.
As it was implemented, the jsdoc parser would look only the first non-blank line immediately preceding a function declaration. However, the line that was set as the beginning of a function declaration was where the opening bracket (
{
) was. This is insufficient for functions whose definitions span multiple lines. For example, this declaration would not find the comments above it:With this change, the parser will first check if we have a closing parenthesis. If we do and don't have a matching open parenthesis we continue moving up the lines until we find it. Then we set previous line to be the line before that, the true beginning of the function declaration.