123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- let functionDoclets;
- function hasUniqueValues(obj) {
- let isUnique = true;
- const seen = [];
- Object.keys(obj).forEach(key => {
- if (seen.includes(obj[key])) {
- isUnique = false;
- }
- seen.push(obj[key]);
- });
- return isUnique;
- }
- function getParamNames(params) {
- const names = [];
- params.forEach(param => {
- let name = param.name || '';
- if (param.variable) {
- name = `...${name}`;
- }
- if (name !== '') {
- names.push(name);
- }
- });
- return names.length ? names.join(', ') : '';
- }
- function getParamVariation({params}) {
- return getParamNames(params || []);
- }
- function getUniqueVariations(doclets) {
- let counter = 0;
- const variations = {};
- const docletKeys = Object.keys(doclets);
- function getUniqueNumbers() {
- docletKeys.forEach(doclet => {
- let newLongname;
- while (true) {
- counter++;
- variations[doclet] = String(counter);
-
- newLongname = `${doclets[doclet].longname}(${variations[doclet]})`;
- if ( !functionDoclets[newLongname] ) {
- break;
- }
- }
- });
- }
- function getUniqueNames() {
-
- docletKeys.forEach(doclet => {
- variations[doclet] = doclets[doclet].variation || getParamVariation(doclets[doclet]);
- });
-
- if ( !hasUniqueValues(variations) ) {
- docletKeys.forEach(doclet => {
- variations[doclet] = getParamVariation(doclets[doclet]);
- });
-
- if ( !hasUniqueValues(variations) ) {
- getUniqueNumbers();
- }
- }
- }
-
- if (functionDoclets[`${doclets.newDoclet.longname}(1)`]) {
- getUniqueNumbers();
- }
- else {
- getUniqueNames();
- }
- return variations;
- }
- function ensureUniqueLongname(newDoclet) {
- const doclets = {
- oldDoclet: functionDoclets[newDoclet.longname],
- newDoclet: newDoclet
- };
- const docletKeys = Object.keys(doclets);
- let oldDocletLongname;
- let variations = {};
- if (doclets.oldDoclet) {
- oldDocletLongname = doclets.oldDoclet.longname;
-
-
- if (doclets.oldDoclet.variation || doclets.oldDoclet.variation === '') {
- docletKeys.forEach(doclet => {
- doclets[doclet].longname = doclets[doclet].longname.replace(/\([\s\S]*\)$/, '');
- doclets[doclet].variation = null;
- });
- }
- variations = getUniqueVariations(doclets);
-
- docletKeys.forEach(doclet => {
- doclets[doclet].longname += `(${variations[doclet]})`;
- doclets[doclet].variation = variations[doclet];
- });
-
- functionDoclets[oldDocletLongname] = null;
- functionDoclets[doclets.oldDoclet.longname] = doclets.oldDoclet;
- }
-
- functionDoclets[doclets.newDoclet.longname] = doclets.newDoclet;
- return doclets.newDoclet;
- }
- exports.handlers = {
- parseBegin() {
- functionDoclets = {};
- },
- newDoclet(e) {
- if (e.doclet.kind === 'function') {
- e.doclet = ensureUniqueLongname(e.doclet);
- }
- },
- parseComplete() {
- functionDoclets = null;
- }
- };
|