Skip to content

Commit 7f032d6

Browse files
committed
Improve internal documentation
1 parent e25919b commit 7f032d6

File tree

5 files changed

+63
-16
lines changed

5 files changed

+63
-16
lines changed

lib/hierarchy.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22

33
var hasOwnProperty = Object.prototype.hasOwnProperty;
44

5-
function pick(n) {
5+
/**
6+
* Pick only relevant properties from a comment to store them in
7+
* an inheritance chain
8+
* @param {Object} comment
9+
* @returns {Object} reduced comment
10+
* @private
11+
*/
12+
function pick(comment) {
613
var item = {
7-
name: n.name,
8-
kind: n.kind
14+
name: comment.name,
15+
kind: comment.kind
916
};
10-
if (n.scope) {
11-
item.scope = n.scope;
17+
if (comment.scope) {
18+
item.scope = comment.scope;
1219
}
1320
return item;
1421
}

lib/parse.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
'use strict';
22

33
var doctrine = require('doctrine');
4-
var remark = require('remark');
5-
var inlineTokenizer = require('./inline_tokenizer');
64

7-
function parseMarkdown(string) {
8-
return remark.use(inlineTokenizer).parse(string);
9-
}
5+
var parseMarkdown = require('./parse_markdown');
106

117
var flatteners = {
128
'abstract': flattenBoolean,
@@ -317,6 +313,15 @@ function flattenMarkdownDescription(result, tag, key) {
317313
result[key] = parseMarkdown(tag.description);
318314
}
319315

316+
/**
317+
* Parse [kind shorthand](http://usejsdoc.org/tags-kind.html) into
318+
* both name and type tags, like `@class [<type> <name>]`
319+
*
320+
* @param {Object} result comment
321+
* @param {Object} tag parsed tag
322+
* @param {string} key tag
323+
* @private
324+
*/
320325
function flattenKindShorthand(result, tag, key) {
321326
result.kind = key;
322327

lib/parse_markdown.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var remark = require('remark');
2+
var inlineTokenizer = require('./inline_tokenizer');
3+
4+
/**
5+
* Parse a string of Markdown into a Remark
6+
* abstract syntax tree.
7+
*
8+
* @param {string} string markdown text
9+
* @returns {Object} abstract syntax tree
10+
* @private
11+
*/
12+
function parseMarkdown(string) {
13+
return remark.use(inlineTokenizer).parse(string);
14+
}
15+
16+
module.exports = parseMarkdown;

lib/parsers/javascript.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ var babylon = require('babylon'),
66
isJSDocComment = require('../../lib/is_jsdoc_comment'),
77
parse = require('../../lib/parse');
88

9+
/**
10+
* Left-pad a string so that it can be sorted lexicographically. We sort
11+
* comments to keep them in order.
12+
* @param {string} str the string
13+
* @param {number} width the width to pad to
14+
* @returns {string} a padded string with the correct width
15+
* @private
16+
*/
917
function leftPad(str, width) {
1018
str = str.toString();
1119
while (str.length < width) {
@@ -46,8 +54,24 @@ function parseJavaScript(data) {
4654

4755
var visited = {};
4856

57+
/**
58+
* Iterate through the abstract syntax tree, finding a different kind of comment
59+
* each time, and optionally including context. This is how we find
60+
* JSDoc annotations that will become part of documentation
61+
* @param {Object} ast the babel-parsed syntax tree
62+
* @param {string} type comment type to find
63+
* @param {boolean} includeContext to include context in the nodes
64+
* @returns {Array<Object>} comments
65+
* @private
66+
*/
4967
function walkComments(ast, type, includeContext) {
5068
traverse(ast, {
69+
/**
70+
* Process a parse in an abstract syntax tree
71+
* @param {Object} path ast path
72+
* @returns {undefined} causes side effects
73+
* @private
74+
*/
5175
enter: function (path) {
5276
/**
5377
* Parse a comment with doctrine and decorate the result with file position and code context.

lib/sort.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
'use strict';
22

3-
var remark = require('remark');
4-
var inlineTokenizer = require('./inline_tokenizer');
5-
6-
function parseMarkdown(string) {
7-
return remark.use(inlineTokenizer).parse(string);
8-
}
3+
var parseMarkdown = require('./parse_markdown');
94

105
/**
116
* Sort two documentation objects, given an optional order object. Returns

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy