mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
fix: use a special longname for a non-default export in an ES2015 module
Previously, we used `exports.NAME`, which was both incorrect and confusing.
This commit is contained in:
parent
575f0dccc8
commit
f7d5fa77b0
@ -171,20 +171,19 @@ export function nodeToValue(node) {
|
||||
|
||||
case Syntax.ExportNamedDeclaration:
|
||||
if (node.declaration) {
|
||||
// like `var` in: export var foo = 'bar';
|
||||
// we need a single value, so we use the first variable name
|
||||
// Like the declaration in: `export const foo = 'bar';`
|
||||
// We need a single value, so we use the first variable name.
|
||||
if (node.declaration.declarations) {
|
||||
str = `exports.${nodeToValue(node.declaration.declarations[0])}`;
|
||||
str = `${LONGNAMES.MODULE_EXPORT}.${nodeToValue(node.declaration.declarations[0])}`;
|
||||
} else {
|
||||
str = `exports.${nodeToValue(node.declaration)}`;
|
||||
str = `${LONGNAMES.MODULE_EXPORT}.${nodeToValue(node.declaration)}`;
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise we'll use the ExportSpecifier nodes
|
||||
break;
|
||||
|
||||
case Syntax.ExportSpecifier:
|
||||
str = `exports.${nodeToValue(node.exported)}`;
|
||||
str = `${LONGNAMES.MODULE_EXPORT}.${nodeToValue(node.exported)}`;
|
||||
break;
|
||||
|
||||
case Syntax.ArrowFunctionExpression:
|
||||
|
||||
@ -36,6 +36,8 @@ export const LONGNAMES = {
|
||||
GLOBAL: '<global>',
|
||||
/** Longname for the default export in an ES2015 module. */
|
||||
MODULE_DEFAULT_EXPORT: '<moduleDefaultExport>',
|
||||
/** Longname prefix for an export in an ES2015 module. */
|
||||
MODULE_EXPORT: '<moduleExport>',
|
||||
};
|
||||
|
||||
// Module namespace prefix.
|
||||
|
||||
@ -196,6 +196,10 @@ describe('@jsdoc/core.name', () => {
|
||||
it('has a MODULE_DEFAULT_EXPORT property', () => {
|
||||
expect(name.LONGNAMES.MODULE_DEFAULT_EXPORT).toBeString();
|
||||
});
|
||||
|
||||
it('has a MODULE_EXPORT property', () => {
|
||||
expect(name.LONGNAMES.MODULE_EXPORT).toBeString();
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: longnamesToTree tests
|
||||
|
||||
@ -20,8 +20,11 @@ import escape from 'escape-string-regexp';
|
||||
|
||||
const PROTOTYPE_OWNER_REGEXP = /^(.+?)(\.prototype|#)$/;
|
||||
const { LONGNAMES, SCOPE } = name;
|
||||
const ESCAPED_MODULE_LONGNAMES =
|
||||
escape(LONGNAMES.MODULE_DEFAULT_EXPORT) + '|' + escape('module.exports');
|
||||
const ESCAPED_MODULE_LONGNAMES = [
|
||||
escape(LONGNAMES.MODULE_DEFAULT_EXPORT),
|
||||
escape(LONGNAMES.MODULE_EXPORT),
|
||||
escape('module.exports'),
|
||||
].join('|');
|
||||
|
||||
let currentModule = null;
|
||||
// Modules inferred from the value of an `@alias` tag, like `@alias module:foo.bar`.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user