refactor: move doclet module to @jsdoc/doclet

This commit is contained in:
Jeff Williams 2023-01-16 12:09:50 -08:00
parent 59ecaa1afe
commit 0ca411969e
No known key found for this signature in database
15 changed files with 107 additions and 96 deletions

View File

@ -410,7 +410,7 @@ function splitLongname(longname, options) {
* ``` * ```
* *
* @param {Array<string>} longnames - The longnames to convert into a tree. * @param {Array<string>} longnames - The longnames to convert into a tree.
* @param {Object<string, module:jsdoc/doclet.Doclet>} doclets - The doclets to attach to a tree. * @param {Object<string, module:@jsdoc/doclet.Doclet>} doclets - The doclets to attach to a tree.
* Each property should be the longname of a doclet, and each value should be the doclet for that * Each property should be the longname of a doclet, and each value should be the doclet for that
* longname. * longname.
* @return {Object} A tree with information about each longname in the format shown above. * @return {Object} A tree with information about each longname in the format shown above.

View File

@ -13,10 +13,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const { combine: combineDoclets, Doclet } = require('./lib/doclet');
const { Package } = require('./lib/package'); const { Package } = require('./lib/package');
const schema = require('./lib/schema'); const schema = require('./lib/schema');
module.exports = { module.exports = {
combineDoclets,
Doclet,
Package, Package,
schema, schema,
}; };

View File

@ -13,9 +13,6 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
/**
* @module jsdoc/doclet
*/
const _ = require('lodash'); const _ = require('lodash');
const { isFunction } = require('@jsdoc/ast').astNode; const { isFunction } = require('@jsdoc/ast').astNode;
const { const {
@ -288,7 +285,7 @@ function removeGlobal(longname) {
* Get the full path to the source file that is associated with a doclet. * Get the full path to the source file that is associated with a doclet.
* *
* @private * @private
* @param {module:jsdoc/doclet.Doclet} The doclet to check for a filepath. * @param {module:@jsdoc/doclet.Doclet} The doclet to check for a filepath.
* @return {string} The path to the doclet's source file, or an empty string if the path is not * @return {string} The path to the doclet's source file, or an empty string if the path is not
* available. * available.
*/ */
@ -323,9 +320,9 @@ function clone(source, target, properties) {
* the primary doclet over the secondary doclet. * the primary doclet over the secondary doclet.
* *
* @private * @private
* @param {module:jsdoc/doclet.Doclet} primary - The primary doclet. * @param {module:@jsdoc/doclet.Doclet} primary - The primary doclet.
* @param {module:jsdoc/doclet.Doclet} secondary - The secondary doclet. * @param {module:@jsdoc/doclet.Doclet} secondary - The secondary doclet.
* @param {module:jsdoc/doclet.Doclet} target - The doclet to which properties will be copied. * @param {module:@jsdoc/doclet.Doclet} target - The doclet to which properties will be copied.
* @param {Array.<string>} exclude - The names of properties to exclude from copying. * @param {Array.<string>} exclude - The names of properties to exclude from copying.
*/ */
function copyMostProperties(primary, secondary, target, exclude) { function copyMostProperties(primary, secondary, target, exclude) {
@ -345,9 +342,9 @@ function copyMostProperties(primary, secondary, target, exclude) {
* doclet. * doclet.
* *
* @private * @private
* @param {module:jsdoc/doclet.Doclet} primary - The primary doclet. * @param {module:@jsdoc/doclet.Doclet} primary - The primary doclet.
* @param {module:jsdoc/doclet.Doclet} secondary - The secondary doclet. * @param {module:@jsdoc/doclet.Doclet} secondary - The secondary doclet.
* @param {module:jsdoc/doclet.Doclet} target - The doclet to which properties will be copied. * @param {module:@jsdoc/doclet.Doclet} target - The doclet to which properties will be copied.
* @param {Array.<string>} include - The names of properties to copy. * @param {Array.<string>} include - The names of properties to copy.
*/ */
function copySpecificProperties(primary, secondary, target, include) { function copySpecificProperties(primary, secondary, target, include) {
@ -367,7 +364,7 @@ function copySpecificProperties(primary, secondary, target, include) {
/** /**
* Represents a single JSDoc comment. * Represents a single JSDoc comment.
* *
* @alias module:jsdoc/doclet.Doclet * @alias module:@jsdoc/doclet.Doclet
*/ */
class Doclet { class Doclet {
/** /**
@ -657,10 +654,10 @@ exports.Doclet = Doclet;
/** /**
* Combine two doclets into a new doclet. * Combine two doclets into a new doclet.
* *
* @param {module:jsdoc/doclet.Doclet} primary - The doclet whose properties will be used. * @param {module:@jsdoc/doclet.Doclet} primary - The doclet whose properties will be used.
* @param {module:jsdoc/doclet.Doclet} secondary - The doclet to use as a fallback for properties * @param {module:@jsdoc/doclet.Doclet} secondary - The doclet to use as a fallback for properties
* that the primary doclet does not have. * that the primary doclet does not have.
* @returns {module:jsdoc/doclet.Doclet} A new doclet that combines the primary and secondary * @returns {module:@jsdoc/doclet.Doclet} A new doclet that combines the primary and secondary
* doclets. * doclets.
*/ */
exports.combine = (primary, secondary) => { exports.combine = (primary, secondary) => {

View File

@ -13,10 +13,11 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
describe('jsdoc/doclet', () => { /* global jsdoc */
describe('@jsdoc/doclet/lib/doclet', () => {
// TODO: more tests // TODO: more tests
const _ = require('lodash'); const _ = require('lodash');
const doclet = require('jsdoc/doclet'); const doclet = require('../../lib/doclet');
const Doclet = doclet.Doclet; const Doclet = doclet.Doclet;
const { SCOPE } = require('@jsdoc/core').name; const { SCOPE } = require('@jsdoc/core').name;
@ -47,9 +48,9 @@ describe('jsdoc/doclet', () => {
expect(descriptor.enumerable).toBeFalse(); expect(descriptor.enumerable).toBeFalse();
}); });
// TODO(hegemonic): more tests (namespaces, modules, etc.) // TODO: more tests (namespaces, modules, etc.)
describe('name resolution', () => { describe('name resolution', () => {
// TODO(hegemonic): Load fixtures instead of creating doclets manually // TODO: Load fixtures instead of creating doclets manually
function makeDoclet(tagStrings) { function makeDoclet(tagStrings) {
const comment = `/**\n${tagStrings.join('\n')}\n*/`; const comment = `/**\n${tagStrings.join('\n')}\n*/`;
@ -57,7 +58,7 @@ describe('jsdoc/doclet', () => {
} }
describe('aliases', () => { describe('aliases', () => {
// TODO(hegemonic): This comment implies that we _don't_ need to set doclet.name... // TODO: This comment implies that we _don't_ need to set doclet.name...
// If `doclet.alias` is defined, `doclet.name` will be set to the same value by the // If `doclet.alias` is defined, `doclet.name` will be set to the same value by the
// time the test runs. Therefore, we set both `@alias` and `@name` in these tests. // time the test runs. Therefore, we set both `@alias` and `@name` in these tests.
it('can resolve aliases that identify instance members', () => { it('can resolve aliases that identify instance members', () => {
@ -185,7 +186,7 @@ describe('jsdoc/doclet', () => {
expect(newDoclet.longname).toBe('MyClass.event:A'); expect(newDoclet.longname).toBe('MyClass.event:A');
}); });
// TODO(hegemonic): This only works if you resolve the names twice. As it happens, // TODO: This only works if you resolve the names twice. As it happens,
// JSDoc does that, because it calls `Doclet#postProcess` twice, so this works in // JSDoc does that, because it calls `Doclet#postProcess` twice, so this works in
// practice. But you shouldn't have to resolve the names twice... // practice. But you shouldn't have to resolve the names twice...
xit('@event @name MyClass.EventName @memberof somethingelse works', () => { xit('@event @name MyClass.EventName @memberof somethingelse works', () => {
@ -198,7 +199,7 @@ describe('jsdoc/doclet', () => {
}); });
describe('module members', () => { describe('module members', () => {
// TODO(hegemonic): This only works if you resolve the names twice. As it happens, // TODO: This only works if you resolve the names twice. As it happens,
// JSDoc does that, because it calls `Doclet#postProcess` twice, so this works in // JSDoc does that, because it calls `Doclet#postProcess` twice, so this works in
// practice. But you shouldn't have to resolve the names twice... // practice. But you shouldn't have to resolve the names twice...
xit('@name @function @memberof works', () => { xit('@name @function @memberof works', () => {
@ -218,7 +219,7 @@ describe('jsdoc/doclet', () => {
}); });
describe('setScope', () => { describe('setScope', () => {
it('should accept the correct scope names', () => { it('accepts the correct scope names', () => {
function setScope(scopeName) { function setScope(scopeName) {
const newDoclet = new Doclet('/** Huzzah, a doclet! */', null, jsdoc.deps); const newDoclet = new Doclet('/** Huzzah, a doclet! */', null, jsdoc.deps);
@ -230,7 +231,7 @@ describe('jsdoc/doclet', () => {
}); });
}); });
it('should throw an error for invalid scope names', () => { it('throws an error for invalid scope names', () => {
function setScope() { function setScope() {
const newDoclet = new Doclet('/** Woe betide this doclet. */', null, jsdoc.deps); const newDoclet = new Doclet('/** Woe betide this doclet. */', null, jsdoc.deps);
@ -242,7 +243,7 @@ describe('jsdoc/doclet', () => {
}); });
describe('combine', () => { describe('combine', () => {
it('should override most properties of the secondary doclet', () => { it('overrides most properties of the secondary doclet', () => {
const primaryDoclet = new Doclet( const primaryDoclet = new Doclet(
'/** New and improved!\n@version 2.0.0 */', '/** New and improved!\n@version 2.0.0 */',
null, null,
@ -256,7 +257,7 @@ describe('jsdoc/doclet', () => {
}); });
}); });
it('should add properties that are missing from the secondary doclet', () => { it('adds properties from the secondary doclet that are missing', () => {
const primaryDoclet = new Doclet('/** Hello!\n@version 2.0.0 */', null, jsdoc.deps); const primaryDoclet = new Doclet('/** Hello!\n@version 2.0.0 */', null, jsdoc.deps);
const secondaryDoclet = new Doclet('/** Hello! */', null, jsdoc.deps); const secondaryDoclet = new Doclet('/** Hello! */', null, jsdoc.deps);
const newDoclet = doclet.combine(primaryDoclet, secondaryDoclet); const newDoclet = doclet.combine(primaryDoclet, secondaryDoclet);
@ -267,27 +268,23 @@ describe('jsdoc/doclet', () => {
describe('params and properties', () => { describe('params and properties', () => {
const properties = ['params', 'properties']; const properties = ['params', 'properties'];
it( it('uses params and properties from the secondary doclet if the primary lacks them', () => {
"should use the secondary doclet's params and properties if the primary doclet " + const primaryDoclet = new Doclet('/** Hello! */', null, jsdoc.deps);
'had none', const secondaryComment = [
() => { '/**',
const primaryDoclet = new Doclet('/** Hello! */', null, jsdoc.deps); ' * @param {string} foo - The foo.',
const secondaryComment = [ ' * @property {number} bar - The bar.',
'/**', ' */',
' * @param {string} foo - The foo.', ].join('\n');
' * @property {number} bar - The bar.', const secondaryDoclet = new Doclet(secondaryComment, null, jsdoc.deps);
' */', const newDoclet = doclet.combine(primaryDoclet, secondaryDoclet);
].join('\n');
const secondaryDoclet = new Doclet(secondaryComment, null, jsdoc.deps);
const newDoclet = doclet.combine(primaryDoclet, secondaryDoclet);
properties.forEach((property) => { properties.forEach((property) => {
expect(newDoclet[property]).toEqual(secondaryDoclet[property]); expect(newDoclet[property]).toEqual(secondaryDoclet[property]);
}); });
} });
);
it("should use the primary doclet's params and properties if the primary doclet has some", () => { it('uses params and properties from the primary doclet, if present', () => {
const primaryComment = [ const primaryComment = [
'/**', '/**',
' * @param {number} baz - The baz.', ' * @param {number} baz - The baz.',

View File

@ -20,6 +20,22 @@ describe('@jsdoc/doclet', () => {
expect(doclet).toBeObject(); expect(doclet).toBeObject();
}); });
describe('combineDoclets', () => {
it('is lib/doclet.combine', () => {
const { combine } = require('../../lib/doclet');
expect(doclet.combineDoclets).toBe(combine);
});
});
describe('Doclet', () => {
it('is lib/doclet.Doclet', () => {
const { Doclet } = require('../../lib/doclet');
expect(doclet.Doclet).toBe(Doclet);
});
});
describe('Package', () => { describe('Package', () => {
it('is lib/package.Package', () => { it('is lib/package.Package', () => {
const { Package } = require('../../lib/package'); const { Package } = require('../../lib/package');

View File

@ -20,9 +20,7 @@
const _ = require('lodash'); const _ = require('lodash');
const { fromParts, SCOPE, toParts } = require('@jsdoc/core').name; const { fromParts, SCOPE, toParts } = require('@jsdoc/core').name;
const jsdoc = { const { combineDoclets } = require('@jsdoc/doclet');
doclet: require('jsdoc/doclet'),
};
function mapDependencies(index, propertyName) { function mapDependencies(index, propertyName) {
const dependencies = {}; const dependencies = {};
@ -142,8 +140,8 @@ function staticToInstance(doclet) {
* from `Class2#myMethod`. * from `Class2#myMethod`.
* *
* @private * @private
* @param {module:jsdoc/doclet.Doclet} doclet - The doclet to be added. * @param {module:@jsdoc/doclet.Doclet} doclet - The doclet to be added.
* @param {Array.<module:jsdoc/doclet.Doclet>} additions - An array of doclets that will be added to * @param {Array.<module:@jsdoc/doclet.Doclet>} additions - An array of doclets that will be added to
* another symbol. * another symbol.
* @param {Object.<string, number>} indexes - A dictionary of indexes into the `additions` array. * @param {Object.<string, number>} indexes - A dictionary of indexes into the `additions` array.
* Each key is a longname, and each value is the index of the longname's doclet. * Each key is a longname, and each value is the index of the longname's doclet.
@ -164,8 +162,8 @@ function updateAddedDoclets(doclet, additions, indexes) {
* Update the index of doclets whose `undocumented` property is not `true`. * Update the index of doclets whose `undocumented` property is not `true`.
* *
* @private * @private
* @param {module:jsdoc/doclet.Doclet} doclet - The doclet to be added to the index. * @param {module:@jsdoc/doclet.Doclet} doclet - The doclet to be added to the index.
* @param {Object.<string, Array.<module:jsdoc/doclet.Doclet>>} documented - The index of doclets * @param {Object.<string, Array.<module:@jsdoc/doclet.Doclet>>} documented - The index of doclets
* whose `undocumented` property is not `true`. * whose `undocumented` property is not `true`.
* @return {void} * @return {void}
*/ */
@ -181,8 +179,8 @@ function updateDocumentedDoclets(doclet, documented) {
* Update the index of doclets with a `memberof` value. * Update the index of doclets with a `memberof` value.
* *
* @private * @private
* @param {module:jsdoc/doclet.Doclet} doclet - The doclet to be added to the index. * @param {module:@jsdoc/doclet.Doclet} doclet - The doclet to be added to the index.
* @param {Object.<string, Array.<module:jsdoc/doclet.Doclet>>} memberof - The index of doclets * @param {Object.<string, Array.<module:@jsdoc/doclet.Doclet>>} memberof - The index of doclets
* with a `memberof` value. * with a `memberof` value.
* @return {void} * @return {void}
*/ */
@ -263,7 +261,7 @@ function getInheritedAdditions(doclets, docs, { documented, memberof }) {
childDoclet = {}; childDoclet = {};
} }
member = jsdoc.doclet.combine(childDoclet, parentDoclet); member = combineDoclets(childDoclet, parentDoclet);
if (!member.inherited) { if (!member.inherited) {
member.inherits = member.longname; member.inherits = member.longname;
@ -467,7 +465,7 @@ function getImplementedAdditions(implDoclets, allDoclets, { documented, memberof
childDoclet = {}; childDoclet = {};
} }
implementationDoclet = jsdoc.doclet.combine(childDoclet, parentDoclet); implementationDoclet = combineDoclets(childDoclet, parentDoclet);
reparentDoclet(doclet, implementationDoclet); reparentDoclet(doclet, implementationDoclet);
updateImplements(implementationDoclet, parentDoclet.longname); updateImplements(implementationDoclet, parentDoclet.longname);
@ -549,7 +547,7 @@ function augment(doclets, propertyName, docletFinder, jsdocDeps) {
* For example, if `ClassA` has the instance method `myMethod`, and `ClassB` inherits from `ClassA`, * For example, if `ClassA` has the instance method `myMethod`, and `ClassB` inherits from `ClassA`,
* calling this method creates a new doclet for `ClassB#myMethod`. * calling this method creates a new doclet for `ClassB#myMethod`.
* *
* @param {!Array.<module:jsdoc/doclet.Doclet>} doclets - The doclets generated by JSDoc. * @param {!Array.<module:@jsdoc/doclet.Doclet>} doclets - The doclets generated by JSDoc.
* @param {!Object} doclets.index - The doclet index. * @param {!Object} doclets.index - The doclet index.
* @return {void} * @return {void}
*/ */
@ -568,7 +566,7 @@ exports.addInherited = (doclets) => {
* + If `MixinA` has the static method `myMethod`, and `ClassA` mixes `MixinA`, calling this method * + If `MixinA` has the static method `myMethod`, and `ClassA` mixes `MixinA`, calling this method
* creates a new doclet for the instance method `ClassA#myMethod`. * creates a new doclet for the instance method `ClassA#myMethod`.
* *
* @param {!Array.<module:jsdoc/doclet.Doclet>} doclets - The doclets generated by JSDoc. * @param {!Array.<module:@jsdoc/doclet.Doclet>} doclets - The doclets generated by JSDoc.
* @param {!Object} doclets.index - The doclet index. * @param {!Object} doclets.index - The doclet index.
* @return {void} * @return {void}
*/ */
@ -589,7 +587,7 @@ exports.addMixedIn = (doclets) => {
* If `ClassA#myMethod` used the `@override` or `@inheritdoc` tag, calling this method would also * If `ClassA#myMethod` used the `@override` or `@inheritdoc` tag, calling this method would also
* generate a new doclet that reflects the interface's documentation for `InterfaceA#myMethod`. * generate a new doclet that reflects the interface's documentation for `InterfaceA#myMethod`.
* *
* @param {!Array.<module:jsdoc/doclet.Doclet>} docs - The doclets generated by JSDoc. * @param {!Array.<module:@jsdoc/doclet.Doclet>} docs - The doclets generated by JSDoc.
* @param {!Object} doclets.index - The doclet index. * @param {!Object} doclets.index - The doclet index.
* @return {void} * @return {void}
*/ */

View File

@ -16,7 +16,7 @@
/** /**
* @module jsdoc/src/handlers * @module jsdoc/src/handlers
*/ */
const { Doclet } = require('jsdoc/doclet'); const { Doclet } = require('@jsdoc/doclet');
const escape = require('escape-string-regexp'); const escape = require('escape-string-regexp');
const { log } = require('@jsdoc/util'); const { log } = require('@jsdoc/util');
const { SCOPE } = require('@jsdoc/core').name; const { SCOPE } = require('@jsdoc/core').name;

View File

@ -210,7 +210,7 @@ class Parser extends EventEmitter {
// TODO: update docs // TODO: update docs
/** /**
* @param {module:jsdoc/doclet.Doclet} doclet The parse result to add to the result buffer. * @param {module:@jsdoc/doclet.Doclet} doclet The parse result to add to the result buffer.
*/ */
addResult(doclet) { addResult(doclet) {
const index = this._resultBuffer.index; const index = this._resultBuffer.index;
@ -332,7 +332,7 @@ class Parser extends EventEmitter {
* Retrieve the most recently seen doclet that has the given longname. * Retrieve the most recently seen doclet that has the given longname.
* *
* @param {string} longname - The longname to search for. * @param {string} longname - The longname to search for.
* @return {module:jsdoc/doclet.Doclet?} The most recent doclet for the longname. * @return {module:@jsdoc/doclet.Doclet?} The most recent doclet for the longname.
*/ */
_getDocletByLongname(longname) { _getDocletByLongname(longname) {
return this._byLongname.get(longname); return this._byLongname.get(longname);
@ -437,7 +437,7 @@ class Parser extends EventEmitter {
* Get the doclet for the lowest-level class, if any, that is in the scope chain for a given node. * Get the doclet for the lowest-level class, if any, that is in the scope chain for a given node.
* *
* @param {Object} node - The node whose scope chain will be searched. * @param {Object} node - The node whose scope chain will be searched.
* @return {module:jsdoc/doclet.Doclet?} The doclet for the lowest-level class in the node's scope * @return {module:@jsdoc/doclet.Doclet?} The doclet for the lowest-level class in the node's scope
* chain. * chain.
*/ */
_getParentClass({ enclosingScope }) { _getParentClass({ enclosingScope }) {
@ -559,7 +559,7 @@ class Parser extends EventEmitter {
* this method returns multiple doclets (in this case, the doclets for `foo` and `exports.FOO`). * this method returns multiple doclets (in this case, the doclets for `foo` and `exports.FOO`).
* *
* @param {Object} node - An AST node representing an object property. * @param {Object} node - An AST node representing an object property.
* @return {Array.<module:jsdoc/doclet.Doclet>} An array of doclets for the parent object or objects, or * @return {Array.<module:@jsdoc/doclet.Doclet>} An array of doclets for the parent object or objects, or
* an empty array if no doclets are found. * an empty array if no doclets are found.
*/ */
resolvePropertyParents({ parent }) { resolvePropertyParents({ parent }) {

View File

@ -18,7 +18,7 @@
*/ */
// TODO: consider exporting more stuff so users can override it // TODO: consider exporting more stuff so users can override it
const { astNode, Syntax } = require('@jsdoc/ast'); const { astNode, Syntax } = require('@jsdoc/ast');
const combineDoclets = require('jsdoc/doclet').combine; const { combineDoclets } = require('@jsdoc/doclet');
const { getBasename, LONGNAMES } = require('@jsdoc/core').name; const { getBasename, LONGNAMES } = require('@jsdoc/core').name;
/** /**

View File

@ -165,7 +165,7 @@ function getFilename(longname, dependencies) {
* `module.exports = function() {};`). * `module.exports = function() {};`).
* *
* @private * @private
* @param {module:jsdoc/doclet.Doclet} doclet - The doclet for the symbol. * @param {module:@jsdoc/doclet.Doclet} doclet - The doclet for the symbol.
* @return {boolean} `true` if the symbol is the only symbol exported by a module; otherwise, * @return {boolean} `true` if the symbol is the only symbol exported by a module; otherwise,
* `false`. * `false`.
*/ */
@ -720,7 +720,7 @@ exports.getSignatureReturns = ({ yields, returns }, cssClass) => {
* *
* @param {TAFFY} data - The TaffyDB database to search. * @param {TAFFY} data - The TaffyDB database to search.
* @param {Object} doclet - The doclet whose ancestors will be retrieved. * @param {Object} doclet - The doclet whose ancestors will be retrieved.
* @return {Array.<module:jsdoc/doclet.Doclet>} A array of ancestor doclets, sorted from most to * @return {Array.<module:@jsdoc/doclet.Doclet>} A array of ancestor doclets, sorted from most to
* least distant. * least distant.
*/ */
exports.getAncestors = (data, doclet) => { exports.getAncestors = (data, doclet) => {
@ -867,7 +867,7 @@ exports.prune = (data, dependencies) => {
* If a doclet corresponds to a smaller portion of an output file (for example, if the doclet * If a doclet corresponds to a smaller portion of an output file (for example, if the doclet
* represents a method), the URL will consist of a filename and a fragment ID. * represents a method), the URL will consist of a filename and a fragment ID.
* *
* @param {module:jsdoc/doclet.Doclet} doclet - The doclet that will be used to create the URL. * @param {module:@jsdoc/doclet.Doclet} doclet - The doclet that will be used to create the URL.
* @param {Object} dependencies - The JSDoc dependency container. * @param {Object} dependencies - The JSDoc dependency container.
* @return {string} The URL to the generated documentation for the doclet. * @return {string} The URL to the generated documentation for the doclet.
*/ */
@ -923,7 +923,7 @@ exports.createLink = (doclet, dependencies) => {
* @function * @function
* @see module:@jsdoc/core.name.longnamesToTree * @see module:@jsdoc/core.name.longnamesToTree
* @param {Array<string>} longnames - The longnames to convert into a tree. * @param {Array<string>} longnames - The longnames to convert into a tree.
* @param {Object<string, module:jsdoc/doclet.Doclet>} doclets - The doclets to attach to a tree. * @param {Object<string, module:@jsdoc/doclet.Doclet>} doclets - The doclets to attach to a tree.
* Each property should be the longname of a doclet, and each value should be the doclet for that * Each property should be the longname of a doclet, and each value should be the doclet for that
* longname. * longname.
* @return {Object} A tree with information about each longname. * @return {Object} A tree with information about each longname.

View File

@ -299,9 +299,9 @@ function generateSourceFiles(sourceFiles, encoding, outdir, dependencies) {
* for display purposes. This function mutates the original arrays. * for display purposes. This function mutates the original arrays.
* *
* @private * @private
* @param {Array.<module:jsdoc/doclet.Doclet>} doclets - The array of classes and functions to * @param {Array.<module:@jsdoc/doclet.Doclet>} doclets - The array of classes and functions to
* check. * check.
* @param {Array.<module:jsdoc/doclet.Doclet>} modules - The array of module doclets to search. * @param {Array.<module:@jsdoc/doclet.Doclet>} modules - The array of module doclets to search.
*/ */
function attachModuleSymbols(doclets, modules) { function attachModuleSymbols(doclets, modules) {
const symbols = {}; const symbols = {};

View File

@ -40,7 +40,7 @@ describe('module names', () => {
// Windows-specific test // Windows-specific test
if (/^win/.test(require('os').platform())) { if (/^win/.test(require('os').platform())) {
it('should always use forward slashes when creating a name from the file path', () => { it('should always use forward slashes when creating a name from the file path', () => {
const { Doclet } = require('jsdoc/doclet'); const { Doclet } = require('@jsdoc/doclet');
let doclet; let doclet;
env.sourceFiles = [ env.sourceFiles = [

View File

@ -18,7 +18,7 @@ describe('jsdoc/util/templateHelper', () => {
const _ = require('lodash'); const _ = require('lodash');
const { Dependencies } = require('@jsdoc/core'); const { Dependencies } = require('@jsdoc/core');
const { Dictionary } = require('jsdoc/tag/dictionary'); const { Dictionary } = require('jsdoc/tag/dictionary');
const doclet = require('jsdoc/doclet'); const { Doclet } = require('@jsdoc/doclet');
const helper = require('jsdoc/util/templateHelper'); const helper = require('jsdoc/util/templateHelper');
const { taffy } = require('@jsdoc/salty'); const { taffy } = require('@jsdoc/salty');
@ -686,7 +686,7 @@ describe('jsdoc/util/templateHelper', () => {
let attribs; let attribs;
it('should return an array', () => { it('should return an array', () => {
doc = new doclet.Doclet('/** ljklajsdf */', {}, jsdoc.deps); doc = new Doclet('/** ljklajsdf */', {}, jsdoc.deps);
attribs = helper.getAttribs(doc); attribs = helper.getAttribs(doc);
expect(attribs).toBeEmptyArray(); expect(attribs).toBeEmptyArray();
@ -698,7 +698,7 @@ describe('jsdoc/util/templateHelper', () => {
function doTests(tests, whatNotToContain) { function doTests(tests, whatNotToContain) {
for (const src in tests) { for (const src in tests) {
if (Object.hasOwn(tests, src)) { if (Object.hasOwn(tests, src)) {
doc = new doclet.Doclet(`/** ${src} */`, {}, jsdoc.deps); doc = new Doclet(`/** ${src} */`, {}, jsdoc.deps);
attribs = helper.getAttribs(doc); attribs = helper.getAttribs(doc);
if (tests[src]) { if (tests[src]) {
@ -799,7 +799,7 @@ describe('jsdoc/util/templateHelper', () => {
}); });
it('should detect multiple attributes', () => { it('should detect multiple attributes', () => {
const fdsaFoo = new doclet.Doclet( const fdsaFoo = new Doclet(
'/** @const module:fdsa~FOO\n@readonly\n@private */', '/** @const module:fdsa~FOO\n@readonly\n@private */',
{}, {},
jsdoc.deps jsdoc.deps
@ -835,14 +835,14 @@ describe('jsdoc/util/templateHelper', () => {
// returns links to allowed types for a doclet. // returns links to allowed types for a doclet.
it('returns an empty array if the doclet has no specified type', () => { it('returns an empty array if the doclet has no specified type', () => {
const doc = new doclet.Doclet('/** @const ASDF */', {}, jsdoc.deps); const doc = new Doclet('/** @const ASDF */', {}, jsdoc.deps);
const types = helper.getSignatureTypes(doc); const types = helper.getSignatureTypes(doc);
expect(types).toBeEmptyArray(); expect(types).toBeEmptyArray();
}); });
it("returns a string array of the doclet's types", () => { it("returns a string array of the doclet's types", () => {
const doc = new doclet.Doclet('/** @const {number|Array.<boolean>} ASDF */', {}, jsdoc.deps); const doc = new Doclet('/** @const {number|Array.<boolean>} ASDF */', {}, jsdoc.deps);
const types = helper.getSignatureTypes(doc); const types = helper.getSignatureTypes(doc);
expect(types).toBeArrayOfSize(2); expect(types).toBeArrayOfSize(2);
@ -857,7 +857,7 @@ describe('jsdoc/util/templateHelper', () => {
// make some links. // make some links.
helper.longnameToUrl.MyClass = 'MyClass.html'; helper.longnameToUrl.MyClass = 'MyClass.html';
doc = new doclet.Doclet('/** @const {MyClass} ASDF */', {}, jsdoc.deps); doc = new Doclet('/** @const {MyClass} ASDF */', {}, jsdoc.deps);
types = helper.getSignatureTypes(doc); types = helper.getSignatureTypes(doc);
expect(types).toBeArrayOfSize(1); expect(types).toBeArrayOfSize(1);
@ -871,7 +871,7 @@ describe('jsdoc/util/templateHelper', () => {
// make some links. // make some links.
helper.longnameToUrl.MyClass = 'MyClass.html'; helper.longnameToUrl.MyClass = 'MyClass.html';
doc = new doclet.Doclet('/** @const {MyClass} ASDF */', {}, jsdoc.deps); doc = new Doclet('/** @const {MyClass} ASDF */', {}, jsdoc.deps);
types = helper.getSignatureTypes(doc, 'myCSSClass'); types = helper.getSignatureTypes(doc, 'myCSSClass');
expect(types).toBeArrayOfSize(1); expect(types).toBeArrayOfSize(1);
@ -883,14 +883,14 @@ describe('jsdoc/util/templateHelper', () => {
// retrieves parameter names. // retrieves parameter names.
// if css class is provided, optional parameters are wrapped in a <span> with that class. // if css class is provided, optional parameters are wrapped in a <span> with that class.
it('returns an empty array if the doclet has no specified type', () => { it('returns an empty array if the doclet has no specified type', () => {
const doc = new doclet.Doclet('/** @function myFunction */', {}, jsdoc.deps); const doc = new Doclet('/** @function myFunction */', {}, jsdoc.deps);
const params = helper.getSignatureParams(doc); const params = helper.getSignatureParams(doc);
expect(params).toBeEmptyArray(); expect(params).toBeEmptyArray();
}); });
it("returns a string array of the doclet's parameter names", () => { it("returns a string array of the doclet's parameter names", () => {
const doc = new doclet.Doclet( const doc = new Doclet(
'/** @function myFunction\n @param {string} foo - asdf. */', '/** @function myFunction\n @param {string} foo - asdf. */',
{}, {},
jsdoc.deps jsdoc.deps
@ -902,7 +902,7 @@ describe('jsdoc/util/templateHelper', () => {
}); });
it('wraps optional parameters in <span class=..> if optClass is provided', () => { it('wraps optional parameters in <span class=..> if optClass is provided', () => {
const doc = new doclet.Doclet( const doc = new Doclet(
'/** @function myFunction\n' + '/** @function myFunction\n' +
' * @param {boolean} foo - explanation.\n' + ' * @param {boolean} foo - explanation.\n' +
' * @param {number} [bar=1] - another explanation.\n' + ' * @param {number} [bar=1] - another explanation.\n' +
@ -920,7 +920,7 @@ describe('jsdoc/util/templateHelper', () => {
}); });
it("doesn't wrap optional parameters in <span class=..> if optClass is not provided", () => { it("doesn't wrap optional parameters in <span class=..> if optClass is not provided", () => {
const doc = new doclet.Doclet( const doc = new Doclet(
'/** @function myFunction\n' + '/** @function myFunction\n' +
' * @param {boolean} foo - explanation.\n' + ' * @param {boolean} foo - explanation.\n' +
' * @param {number} [bar=1] - another explanation.\n' + ' * @param {number} [bar=1] - another explanation.\n' +
@ -960,14 +960,14 @@ describe('jsdoc/util/templateHelper', () => {
}); });
it('returns an empty array if the doclet has no returns', () => { it('returns an empty array if the doclet has no returns', () => {
const doc = new doclet.Doclet('/** @function myFunction */', {}, jsdoc.deps); const doc = new Doclet('/** @function myFunction */', {}, jsdoc.deps);
const returns = helper.getSignatureReturns(doc); const returns = helper.getSignatureReturns(doc);
expect(returns).toBeEmptyArray(); expect(returns).toBeEmptyArray();
}); });
it('returns an empty array if the doclet has @returns but with no type', () => { it('returns an empty array if the doclet has @returns but with no type', () => {
const doc = new doclet.Doclet( const doc = new Doclet(
'/** @function myFunction\n@returns an interesting result.*/', '/** @function myFunction\n@returns an interesting result.*/',
{}, {},
jsdoc.deps jsdoc.deps
@ -978,14 +978,14 @@ describe('jsdoc/util/templateHelper', () => {
}); });
it('uses the value of the `yields` property', () => { it('uses the value of the `yields` property', () => {
const doc = new doclet.Doclet('/** @yields {string} A string. */', {}, jsdoc.deps); const doc = new Doclet('/** @yields {string} A string. */', {}, jsdoc.deps);
const html = helper.getSignatureReturns(doc); const html = helper.getSignatureReturns(doc);
expect(html).toContain('string'); expect(html).toContain('string');
}); });
it('prefers `yields` over `returns`', () => { it('prefers `yields` over `returns`', () => {
const doc = new doclet.Doclet('/** @yields {string}\n@returns {number} */', {}, jsdoc.deps); const doc = new Doclet('/** @yields {string}\n@returns {number} */', {}, jsdoc.deps);
const html = helper.getSignatureReturns(doc); const html = helper.getSignatureReturns(doc);
expect(html).toContain('string'); expect(html).toContain('string');
@ -999,7 +999,7 @@ describe('jsdoc/util/templateHelper', () => {
// make some links. // make some links.
helper.longnameToUrl.MyClass = 'MyClass.html'; helper.longnameToUrl.MyClass = 'MyClass.html';
doc = new doclet.Doclet( doc = new Doclet(
'/** @function myFunction\n@returns {number|MyClass} an interesting result.*/', '/** @function myFunction\n@returns {number|MyClass} an interesting result.*/',
{}, {},
jsdoc.deps jsdoc.deps
@ -1018,7 +1018,7 @@ describe('jsdoc/util/templateHelper', () => {
// make some links. // make some links.
helper.longnameToUrl.MyClass = 'MyClass.html'; helper.longnameToUrl.MyClass = 'MyClass.html';
doc = new doclet.Doclet( doc = new Doclet(
'/** @function myFunction\n@returns {number|MyClass} an interesting result.*/', '/** @function myFunction\n@returns {number|MyClass} an interesting result.*/',
{}, {},
jsdoc.deps jsdoc.deps
@ -1037,18 +1037,18 @@ describe('jsdoc/util/templateHelper', () => {
describe('getAncestorLinks', () => { describe('getAncestorLinks', () => {
// make a hierarchy. // make a hierarchy.
const lackeys = new doclet.Doclet( const lackeys = new Doclet(
'/** @member lackeys\n@memberof module:mafia/gangs.Sharks~Henchman\n@instance*/', '/** @member lackeys\n@memberof module:mafia/gangs.Sharks~Henchman\n@instance*/',
{}, {},
jsdoc.deps jsdoc.deps
); );
const henchman = new doclet.Doclet( const henchman = new Doclet(
'/** @class Henchman\n@memberof module:mafia/gangs.Sharks\n@inner */', '/** @class Henchman\n@memberof module:mafia/gangs.Sharks\n@inner */',
{}, {},
jsdoc.deps jsdoc.deps
); );
const gang = new doclet.Doclet('/** @namespace module:mafia/gangs.Sharks */', {}, jsdoc.deps); const gang = new Doclet('/** @namespace module:mafia/gangs.Sharks */', {}, jsdoc.deps);
const mafia = new doclet.Doclet('/** @module mafia/gangs */', {}, jsdoc.deps); const mafia = new Doclet('/** @module mafia/gangs */', {}, jsdoc.deps);
const data = taffy([lackeys, henchman, gang, mafia]); const data = taffy([lackeys, henchman, gang, mafia]);
afterEach(() => { afterEach(() => {

View File

@ -15,7 +15,7 @@
*/ */
describe('@lends tag', () => { describe('@lends tag', () => {
// see also specs/documentation/lends.js for tests on @lends behaviour. // see also specs/documentation/lends.js for tests on @lends behaviour.
const { Doclet } = require('jsdoc/doclet'); const { Doclet } = require('@jsdoc/doclet');
const doc = new Doclet('/** @lends */', {}, jsdoc.deps); const doc = new Doclet('/** @lends */', {}, jsdoc.deps);
const doc2 = new Doclet('/** @lends MyClass# */', {}, jsdoc.deps); const doc2 = new Doclet('/** @lends MyClass# */', {}, jsdoc.deps);

View File

@ -57,7 +57,7 @@ describe('@overview tag', () => {
'The name should not include the entire filepath when the source file is outside the ' + 'The name should not include the entire filepath when the source file is outside the ' +
'JSDoc directory', 'JSDoc directory',
() => { () => {
const Doclet = require('jsdoc/doclet').Doclet; const { Doclet } = require('@jsdoc/doclet');
let doclet; let doclet;
let docletMeta; let docletMeta;