Skip to content

Commit

Permalink
fix: Improves types for registerPlugin and getPlugin (#8058)
Browse files Browse the repository at this point in the history
* fix: improves types for registerPlugin and getPlugin

* fix: corrects parameter type for registerPlugin

* docs(fix): add support for {typeof class} expression

* chore: move js-doc-typeof-plugin to build dir
  • Loading branch information
gjanblaszczyk authored Jan 24, 2023
1 parent 509b3d0 commit 2e96253
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .jsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css"
]
},
"plugins": ["plugins/markdown"],
"plugins": ["plugins/markdown", "build/jsdoc-typeof-plugin"],
"markdown": {
"tags": ["example"],
"idInHeadings": true
Expand Down
12 changes: 12 additions & 0 deletions build/jsdoc-typeof-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* The jsdoc plugin that will convert types like {typeof ClassName} into {Class<ClassName>}
*/
exports.handlers = {
jsdocCommentFound: event => {
event.comment = (event.comment || '').replace(/\{.*typeof\s+([^\s\|]+).*\}/g, typeExpression => {
return typeExpression.replace(/typeof\s+([^\s\|\}]+)/g, (expression, className) => {
return 'Class<' + className + '>';
});
});
}
};
8 changes: 4 additions & 4 deletions src/js/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const pluginExists = (name) => pluginStorage.hasOwnProperty(name);
* @param {string} name
* The name of a plugin.
*
* @return {Function|undefined}
* @return {typeof Plugin|Function|undefined}
* The plugin (or undefined).
*/
const getPlugin = (name) => pluginExists(name) ? pluginStorage[name] : undefined;
Expand Down Expand Up @@ -336,10 +336,10 @@ class Plugin {
* must not match an existing plugin or a method on the `Player`
* prototype.
*
* @param {Function} plugin
* @param {typeof Plugin|Function} plugin
* A sub-class of `Plugin` or a function for basic plugins.
*
* @return {Function}
* @return {typeof Plugin|Function}
* For advanced plugins, a factory function for that plugin. For
* basic plugins, a wrapper function that initializes the plugin.
*/
Expand Down Expand Up @@ -444,7 +444,7 @@ class Plugin {
* @param {string} name
* The name of a plugin.
*
* @returns {Function|undefined}
* @returns {typeof Plugin|Function|undefined}
* The plugin (or `undefined`).
*/
Plugin.getPlugin = getPlugin;
Expand Down

0 comments on commit 2e96253

Please sign in to comment.