Skip to content
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

feat: add JSDoc example #8533

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions core/modules/parsers/wikiparser/try.js

This file was deleted.

31 changes: 19 additions & 12 deletions core/modules/parsers/wikiparser/wikiparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@ Attributes are stored as hashmaps of the following objects:
/*global $tw: false */
"use strict";

/*
type: content type of text
text: text to be parsed
options: see below:
parseAsInline: true to parse text as inline instead of block
wiki: reference to wiki to use
_canonical_uri: optional URI of content if text is missing or empty
configTrimWhiteSpace: true to trim whitespace
*/
var WikiParser = function(type,text,options) {
/**
* WikiParser class for parsing text of a specified MIME type.
*
* @class
* @constructor
* @param {string} type - The content type of the text to be parsed.
* @param {string} text - The text to be parsed.
* @param {Object} options - Options for parsing.
* @param {boolean} [options.parseAsInline=false] - If true, the text will be parsed as an inline run.
* @param {Object} options.wiki - Reference to the wiki to use.
* @param {string} [options._canonical_uri] - Optional URI of the content if the text is missing or empty.
* @param {boolean} [options.configTrimWhiteSpace=false] - If true, trims white space according to configuration.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the full-stop at the end of the comment text can be removed.
IMO "The" and "the" can be removed -- most of the time. So it does not obscure the important content. eg:

 * @param {string} type - Content type of the text to be parsed
 * @param {string} text - Text to be parsed
 * @param {Object} options - Parser options
 * @param {boolean} [options.parseAsInline=false] - If true, the text will be parsed as an inline run
 * @param {Object} options.wiki - Reference to the wiki store in use
 * @param {string} [options._canonical_uri] - Optional URI of the content if text is missing or empty
 * @param {boolean} [options.configTrimWhiteSpace=false] - If true, the parser trims white space

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this will be the updated prompt:

add jsdoc, only output jsdoc for this class and its method, no impl. full-stop at the end of the comment text can be removed. "The" and "the" can be removed -- most of the time. So it does not obscure the important content.

*/
function WikiParser(type,text,options) {
this.wiki = options.wiki;
var self = this;
// Check for an externally linked tiddler
Expand Down Expand Up @@ -99,8 +103,11 @@ var WikiParser = function(type,text,options) {
// Return the parse tree
};

/*
*/
/**
* Load a remote tiddler from a given URL.
*
* @param {string} url - The URL of the remote tiddler to load.
*/
WikiParser.prototype.loadRemoteTiddler = function(url) {
var self = this;
$tw.utils.httpRequest({
Expand Down
43 changes: 27 additions & 16 deletions core/modules/widgets/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,30 @@ Widget base class
/*global $tw: false */
"use strict";

/*
Create a widget object for a parse tree node
parseTreeNode: reference to the parse tree node to be rendered
options: see below
Options include:
wiki: mandatory reference to wiki associated with this render tree
parentWidget: optional reference to a parent renderer node for the context chain
document: optional document object to use instead of global document
*/
var Widget = function(parseTreeNode,options) {
/**
* Widget class for creating a widget object for a parse tree node.
*
* @class
* @constructor
* @param {Object} parseTreeNode - Reference to the parse tree node to be rendered.
* @param {Object} options - Options for the widget.
* @param {Object} options.wiki - Mandatory reference to the wiki associated with this render tree.
* @param {Widget} [options.parentWidget] - Optional reference to a parent renderer node for the context chain.
* @param {Document} [options.document] - Optional document object to use instead of the global document.
*/
function Widget(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
};

/*
Initialise widget properties. These steps are pulled out of the constructor so that we can reuse them in subclasses
*/
/**
* Initialise widget properties. These steps are pulled out of the constructor so that we can reuse them in subclasses.
*
* @param {Object} parseTreeNode - Reference to the parse tree node to be rendered.
* @param {Object} options - Options for the widget.
* @param {Object} options.wiki - Mandatory reference to the wiki associated with this render tree.
* @param {Widget} [options.parentWidget] - Optional reference to a parent renderer node for the context chain.
* @param {Document} [options.document] - Optional document object to use instead of the global document.
*/
Widget.prototype.initialise = function(parseTreeNode,options) {
// Bail if parseTreeNode is undefined, meaning that the widget constructor was called without any arguments so that it can be subclassed
if(parseTreeNode === undefined) {
Expand Down Expand Up @@ -64,9 +72,12 @@ Widget.prototype.initialise = function(parseTreeNode,options) {
}
};

/*
Render this widget into the DOM
*/
/**
* Render this widget into the DOM.
*
* @param {Element} parent - The parent DOM node to render into.
* @param {Element} nextSibling - The next sibling DOM node to render before.
*/
Widget.prototype.render = function(parent,nextSibling) {
this.parentDomNode = parent;
this.execute();
Expand Down
54 changes: 32 additions & 22 deletions core/modules/wiki.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @typedef {import('$:/core/modules/parsers/wikiparser/wikiparser.js')["text/vnd.tiddlywiki"]} WikiParser
* @typedef {import('$:/core/modules/widgets/widget.js').widget} Widget
*/

/*\
title: $:/core/modules/wiki.js
type: application/javascript
Expand All @@ -22,10 +27,6 @@ Adds the following properties to the wiki object:
/*global $tw: false */
"use strict";

/**
* @typedef {import('$:/core/modules/widgets/widget.js').widget} Widget
*/

/**
* @type {Widget}
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the 2 comment blocks be merged to 1 block, or do we need 2 of them?

Expand Down Expand Up @@ -1048,19 +1049,26 @@ exports.initParsers = function(moduleType) {
}
};

/*
Parse a block of text of a specified MIME type
type: content type of text to be parsed
text: text
options: see below
Options include:
parseAsInline: if true, the text of the tiddler will be parsed as an inline run
_canonical_uri: optional string of the canonical URI of this content
*/
/**
* Parse a block of text of a specified MIME type.
*
* @param {string} type - The content type of the text to be parsed.
* @param {string} text - The text to be parsed.
* @param {Object} [options] - Options for parsing.
* @param {boolean} [options.parseAsInline=false] - If true, the text will be parsed as an inline run.
* @param {string} [options._canonical_uri] - Optional string of the canonical URI of this content.
* @param {string} [options.defaultType="text/vnd.tiddlywiki"] - The default type to use if no parser is found for the specified type.
* @param {boolean} [options.configTrimWhiteSpace=false] - If true, trims white space according to configuration.
*
* @returns {WikiParser|null} The parser instance or null if no parser is found.
*/
exports.parseText = function(type,text,options) {
text = text || "";
options = options || {};
// Select a parser
/**
* @type WikiParser
* Select a parser
*/
var Parser = $tw.Wiki.parsers[type];
if(!Parser && $tw.utils.getFileExtensionInfo(type)) {
Parser = $tw.Wiki.parsers[$tw.utils.getFileExtensionInfo(type).type];
Expand Down Expand Up @@ -1150,14 +1158,16 @@ exports.getTextReferenceParserInfo = function(title,field,index,options) {
return parserInfo;
}

/*
Parse a block of text of a specified MIME type
text: text on which to perform substitutions
widget
options: see below
Options include:
substitutions: an optional array of substitutions
*/
/**
* Parse a block of text of a specified MIME type and perform substitutions.
*
* @param {string} text - The text on which to perform substitutions.
* @param {Widget} widget - The widget context used for variable substitution.
* @param {Object} [options] - Options for substitutions.
* @param {Array<{name: string, value: string}>} [options.substitutions] - An optional array of substitutions.
*
* @returns {string} The text with substitutions applied.
*/
exports.getSubstitutedText = function(text,widget,options) {
options = options || {};
text = text || "";
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"bin": {
"tiddlywiki": "./tiddlywiki.js"
},
"types": "./types",
"types": "./types/tw.d.ts",
"main": "./boot/boot.js",
"repository": {
"type": "git",
Expand Down