Normalize module paths to ignore ~/. differences

This commit is contained in:
ahocevar
2018-05-12 19:19:26 +02:00
parent 554968f8f2
commit 6cd6e3cc83

View File

@@ -26,13 +26,13 @@ function addDefaultExportPath(obj) {
const match = lines[i].match(/^export default ([A-Za-z_$][A-Za-z0-9_$]+);$/); const match = lines[i].match(/^export default ([A-Za-z_$][A-Za-z0-9_$]+);$/);
if (match) { if (match) {
// Use variable name if default export is assigned to a variable. // Use variable name if default export is assigned to a variable.
obj[index] = name.replace(module, `${module}~${match[1]}`); obj[index] = name = name.replace(module, `${module}~${match[1]}`);
return; return;
} }
} }
if (hasDefaultExport) { if (hasDefaultExport) {
// Duplicate last part if default export is not assigned to a variable. // Duplicate last part if default export is not assigned to a variable.
obj[index] = name.replace(module, `${module}~${module.split('/').pop()}`); obj[index] = name = name.replace(module, `${module}~${module.split('/').pop()}`);
} }
} }
}); });
@@ -40,6 +40,24 @@ function addDefaultExportPath(obj) {
}); });
} }
function replaceLinks(comment) {
const matches = comment.match(/\{@link [^\} #]+}/g);
if (matches) {
const modules = matches.map(m => {
const mm = m.match(/(module:[^\}]+)}$/);
if (mm) {
return mm[1];
}
}).filter(m => !!m);
const newModules = modules.concat();
addDefaultExportPath(newModules);
modules.forEach((module, i) => {
comment = comment.replace(module, newModules[i]);
});
}
return comment;
}
exports.handlers = { exports.handlers = {
/** /**
@@ -56,6 +74,17 @@ exports.handlers = {
const pathArgs = [doclet.meta.path].concat(levelsUp.map(() => '../')); const pathArgs = [doclet.meta.path].concat(levelsUp.map(() => '../'));
moduleRoot = path.resolve.apply(null, pathArgs); moduleRoot = path.resolve.apply(null, pathArgs);
} else { } else {
if (doclet.description) {
doclet.description = replaceLinks(doclet.description);
}
if (doclet.classdesc) {
doclet.classdesc = replaceLinks(doclet.classdesc);
}
const module = doclet.longname.split('#').shift();
if (module.indexOf('module:') == 0 && module.indexOf('.') !== -1) {
doclet.longname = doclet.longname.replace(module, module.replace('.', '~'));
}
if (doclet.augments) { if (doclet.augments) {
addDefaultExportPath(doclet.augments); addDefaultExportPath(doclet.augments);
} }
@@ -72,14 +101,6 @@ exports.handlers = {
addDefaultExportPath(doclet.type); addDefaultExportPath(doclet.type);
} }
} }
},
/**
* Adds `options.*` params for options that match the longname of one of the
* collected typedefs.
* @param {Object} e Event object.
*/
parseComplete: function(e) {
} }
}; };