Skip to content

Commit

Permalink
Fix jsdocs for multi-line ES6-style methods
Browse files Browse the repository at this point in the history
Summary:
The function definition and body can be in different places for multi-line declarations, so the docblock might not get pulled in. None of the existing docs seem to be affected, but putting up the fix for posterity.

Test Plan:
I modified `AlertIOS.alert` (in Libraries/Utilties/AlertIOS.js) to actually have a docblock, and ran `website/publish.sh` (with the push bit commented out). The added doc doesn't get picked up with the current code, but it does with the fix.
  • Loading branch information
hansonw committed May 14, 2015
1 parent 1f8b97a commit 97aad16
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions website/jsdocs/jsdocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,21 @@ function sanitizeTypehint(string) {

/**
* @param {object} node
* @param {object} docNode Node used for location/docblock purposes
* @param {object} state
* @param {string} source
* @param {array<object>} commentsForFile
* @param {array<string>} linesForFile
* @return {object}
*/
function getFunctionData(node, state, source, commentsForFile, linesForFile) {
function getFunctionData(
node,
docNode,
state,
source,
commentsForFile,
linesForFile
) {
var params = [];
var typechecks = commentsForFile.typechecks;
var typehintsFromBlock = null;
Expand Down Expand Up @@ -287,9 +295,9 @@ function getFunctionData(node, state, source, commentsForFile, linesForFile) {
});
}
return {
line: node.loc.start.line,
line: docNode.loc.start.line,
source: source.substring.apply(source, node.range),
docblock: getDocBlock(node, commentsForFile, linesForFile),
docblock: getDocBlock(docNode, commentsForFile, linesForFile),
modifiers: [],
params: params,
tparams: tparams,
Expand Down Expand Up @@ -320,7 +328,7 @@ function getObjectData(node, state, source, scopeChain,

switch (property.value.type) {
case Syntax.FunctionExpression:
var methodData = getFunctionData(property.value, state, source,
var methodData = getFunctionData(property.value, property, state, source,
commentsForFile, linesForFile);
methodData.name = property.key.name || property.key.value;
methodData.source = source.substring.apply(source, property.range);
Expand All @@ -335,7 +343,8 @@ function getObjectData(node, state, source, scopeChain,
if (expr) {
if (expr.type === Syntax.FunctionDeclaration) {
var functionData =
getFunctionData(expr, state, source, commentsForFile, linesForFile);
getFunctionData(expr, property, state, source, commentsForFile,
linesForFile);
functionData.name = property.key.name || property.key.value;
functionData.modifiers.push('static');
methods.push(functionData);
Expand Down Expand Up @@ -389,7 +398,7 @@ function getClassData(node, state, source, commentsForFile, linesForFile) {
if (bodyItem.type === Syntax.MethodDefinition) {
if (bodyItem.value.type === Syntax.FunctionExpression) {
var methodData =
getFunctionData(bodyItem.value, state, source,
getFunctionData(bodyItem.value, bodyItem, state, source,
commentsForFile, linesForFile);
methodData.name = bodyItem.key.name;
methodData.source = source.substring.apply(source, bodyItem.range);
Expand Down Expand Up @@ -529,7 +538,8 @@ function parseSource(source) {
break;
case Syntax.FunctionDeclaration:
case Syntax.FunctionExpression:
data = getFunctionData(definition, _state, source, ast.comments, lines);
data = getFunctionData(definition, definition, _state, source,
ast.comments, lines);
data.type = 'function';
break;
default:
Expand Down

0 comments on commit 97aad16

Please sign in to comment.