mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
fix: prevent circular refs when params have the same type expression
Catharsis caches parse results by default; if you parse the same type expression twice, with the same options, you get the same object each time. When the user passes the `--debug` flag, we expose the parsed type for each parameter as an enumerable property of the doclet. If two parameters used the same type expression, the resulting doclet could contain a circular reference. This change disables the Catharsis cache, so that Catharsis returns a new object for each parsed type, which prevents circular references. As a result, this change fixes an issue with the `-X` flag, and with some JSDoc templates.
This commit is contained in:
parent
152773690f
commit
c9b12b09ec
@ -234,7 +234,10 @@ function parseTypeExpression(tagInfo) {
|
||||
}
|
||||
|
||||
try {
|
||||
parsedType = catharsis.parse(tagInfo.typeExpression, {jsdoc: true});
|
||||
parsedType = catharsis.parse(tagInfo.typeExpression, {
|
||||
jsdoc: true,
|
||||
useCache: false
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
// always re-throw so the caller has a chance to report which file was bad
|
||||
|
||||
16
packages/jsdoc/test/fixtures/paramtagsametype.js
vendored
Normal file
16
packages/jsdoc/test/fixtures/paramtagsametype.js
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
const foo = {
|
||||
bar: {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Baz class.
|
||||
*/
|
||||
foo.bar.Baz = class {
|
||||
/**
|
||||
* Creates a Baz.
|
||||
*
|
||||
* @param {string=} first - First parameter.
|
||||
* @param {string=} second - Second parameter.
|
||||
*/
|
||||
constructor(first, second) {}
|
||||
};
|
||||
28
packages/jsdoc/test/specs/documentation/paramtagsametype.js
Normal file
28
packages/jsdoc/test/specs/documentation/paramtagsametype.js
Normal file
@ -0,0 +1,28 @@
|
||||
const env = require('jsdoc/env');
|
||||
|
||||
describe('multiple @param tags with the same type expression', () => {
|
||||
const debug = Boolean(env.opts.debug);
|
||||
|
||||
afterEach(() => {
|
||||
env.opts.debug = debug;
|
||||
});
|
||||
|
||||
it('does not have circular references when type.parsedType is enumerable', () => {
|
||||
let docSet;
|
||||
let params;
|
||||
let stringified;
|
||||
|
||||
// Force type.parsedType to be enumerable.
|
||||
env.opts.debug = true;
|
||||
docSet = jsdoc.getDocSetFromFile('test/fixtures/paramtagsametype.js');
|
||||
params = docSet.getByLongname('foo.bar.Baz').filter(d => !d.undocumented)[0].params;
|
||||
stringified = JSON.stringify(params);
|
||||
|
||||
expect(stringified).toContain('"parsedType":');
|
||||
expect(stringified).not.toContain('<CircularRef>');
|
||||
|
||||
// Prevent the schema validator from complaining about `parsedType`. (The schema _should_
|
||||
// allow that property, but for some reason, that doesn't work correctly.)
|
||||
params.forEach(p => delete p.type.parsedType);
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user