Skip to content

Commit

Permalink
refactor: move borrows resolver to @jsdoc/doclet package
Browse files Browse the repository at this point in the history
  • Loading branch information
hegemonic committed Jan 22, 2023
1 parent 9d5dcf9 commit 69d1a0a
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 51 deletions.
2 changes: 2 additions & 0 deletions packages/jsdoc-doclet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
*/
const { combine: combineDoclets, Doclet } = require('./lib/doclet');
const { Package } = require('./lib/package');
const { resolveBorrows } = require('./lib/borrow');
const schema = require('./lib/schema');

module.exports = {
combineDoclets,
Doclet,
Package,
resolveBorrows,
schema,
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
limitations under the License.
*/
/**
* A collection of functions relating to resolving @borrows tags in JSDoc symbols.
* @module jsdoc/borrow
* Functions that resolve `@borrows` tags in JSDoc comments.
*/
const _ = require('lodash');
const { SCOPE } = require('@jsdoc/core').name;
Expand Down Expand Up @@ -51,10 +50,10 @@ function cloneBorrowedDoclets({ borrowed, longname }, doclets) {
}

/**
Take a copy of the docs for borrowed symbols and attach them to the
docs for the borrowing symbol. This process changes the symbols involved,
moving docs from the "borrowed" array and into the general docs, then
deleting the "borrowed" array.
Take a copy of the docs for borrowed symbols and attach them to the
docs for the borrowing symbol. This process changes the symbols involved,
moving docs from the "borrowed" array and into the general docs, then
deleting the "borrowed" array.
*/
exports.resolveBorrows = (doclets) => {
for (let doclet of doclets.index.borrowed) {
Expand Down
2 changes: 2 additions & 0 deletions packages/jsdoc-doclet/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
xdescribe('jsdoc/borrow', () => {
xdescribe('@jsdoc/doclet/lib/borrow', () => {
// TODO
});
8 changes: 8 additions & 0 deletions packages/jsdoc-doclet/test/specs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ describe('@jsdoc/doclet', () => {
});
});

describe('resolveBorrows', () => {
it('is lib/borrow.resolveBorrows', () => {
const { resolveBorrows } = require('../../lib/borrow');

expect(doclet.resolveBorrows).toBe(resolveBorrows);
});
});

describe('schema', () => {
it('is lib/schema', () => {
const schema = require('../../lib/schema');
Expand Down
6 changes: 2 additions & 4 deletions packages/jsdoc/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ const Engine = require('@jsdoc/cli');
const { EventBus, log } = require('@jsdoc/util');
const { Filter } = require('jsdoc/src/filter');
const fs = require('fs');
const { Package } = require('@jsdoc/doclet');
const { Package, resolveBorrows } = require('@jsdoc/doclet');
const path = require('path');
const { Scanner } = require('jsdoc/src/scanner');
const stripBom = require('strip-bom');
const stripJsonComments = require('strip-json-comments');
const { taffy } = require('@jsdoc/salty');
const Promise = require('bluebird');

/**
* Helper methods for running JSDoc on the command line.
Expand Down Expand Up @@ -340,7 +339,6 @@ module.exports = (() => {
cli.parseFiles = () => {
// Must be imported after the config is loaded.
const augment = require('jsdoc/augment');
const borrow = require('jsdoc/borrow');

let docs;
const env = dependencies.get('env');
Expand All @@ -357,7 +355,7 @@ module.exports = (() => {
log.debug('Adding inherited symbols, mixins, and interface implementations...');
augment.augmentAll(docs);
log.debug('Adding borrowed doclets...');
borrow.resolveBorrows(docs);
resolveBorrows(docs);
log.debug('Post-processing complete.');

props.parser.fireProcessingComplete(docs);
Expand Down
182 changes: 145 additions & 37 deletions packages/jsdoc/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/jsdoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"@jsdoc/salty": "^0.2.3",
"@jsdoc/tag": "^0.1.5",
"@jsdoc/util": "^0.2.8",
"bluebird": "^3.7.2",
"catharsis": "^0.9.0",
"code-prettify": "^0.1.0",
"color-themes-for-google-code-prettify": "^2.0.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/jsdoc/test/specs/tags/borrowstag.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ describe('@borrows tag', () => {
});

it('When a symbol has a @borrows tag, the borrowed symbol is added to the symbol.', () => {
const borrow = require('jsdoc/borrow');
const { resolveBorrows } = require('@jsdoc/doclet');
const docSet = jsdoc.getDocSetFromFile('test/fixtures/borrowstag2.js');

borrow.resolveBorrows(docSet.doclets);
resolveBorrows(docSet.doclets);

const strRtrim = docSet
.getByLongname('str.rtrim')
Expand Down

0 comments on commit 69d1a0a

Please sign in to comment.