1 line
17 KiB
Plaintext
Raw Normal View History

{"version":3,"file":"alignTransform.cjs","names":["_commentParser","require","rewireSource","util","zeroWidth","name","start","tag","type","shouldAlign","tags","index","source","tokens","replace","includesTag","includes","iterator","previousTag","getWidth","width","Math","max","length","delimiter","getTypelessInfo","fields","hasNoTypes","every","maxNamedTagLength","map","filter","maxUnnamedTagLength","space","len","padStart","alignTransform","customSpacings","indent","preserveMainDescriptionPostDelimiter","wrapIndent","disableWrapIndent","intoTags","alignTokens","typelessInfo","nothingAfter","delim","description","postName","postType","postTag","untypedNameAdjustment","untypedTypeAdjustment","spacings","postDelimiter","update","line","indentTag","isEmpty","end","postHyphenSpacing","postHyphen","hyphenSpacing","reduce","tagIndentMode","ret","_default","exports","default","module"],"sources":["../src/alignTransform.js"],"sourcesContent":["/**\n * Transform based on https://github.com/syavorsky/comment-parser/blob/master/src/transforms/align.ts\n *\n * It contains some customizations to align based on the tags, and some custom options.\n */\n\nimport {\n // `comment-parser/primitives` export\n util,\n} from 'comment-parser';\n\n/**\n * @typedef {{\n * hasNoTypes: boolean,\n * maxNamedTagLength: import('./iterateJsdoc.js').Integer,\n * maxUnnamedTagLength: import('./iterateJsdoc.js').Integer\n * }} TypelessInfo\n */\n\nconst {\n rewireSource,\n} = util;\n\n/**\n * @typedef {{\n * name: import('./iterateJsdoc.js').Integer,\n * start: import('./iterateJsdoc.js').Integer,\n * tag: import('./iterateJsdoc.js').Integer,\n * type: import('./iterateJsdoc.js').Integer\n * }} Width\n */\n\n/** @type {Width} */\nconst zeroWidth = {\n name: 0,\n start: 0,\n tag: 0,\n type: 0,\n};\n\n/**\n * @param {string[]} tags\n * @param {import('./iterateJsdoc.js').Integer} index\n * @param {import('comment-parser').Line[]} source\n * @returns {boolean}\n */\nconst shouldAlign = (tags, index, source) => {\n const tag = source[index].tokens.tag.replace('@', '');\n const includesTag = tags.includes(tag);\n\n if (includesTag) {\n return true;\n }\n\n if (tag !== '') {\n return false;\n }\n\n for (let iterator = index; iterator >= 0; iterator--) {\n const previousTag = source[iterator].tokens.tag.replace('@', '');\n\n if (previousTag !== '') {\n if (tags.includes(previousTag)) {\n return true;\n }\n\n return false;\n }\n }\n\n return true;\n};\n\n/**\n * @param {string[]} tags\n * @returns {(\n * width: Width,\n * line: {\n * tokens: import('comment-parser').Tokens\n * },\n * index: import('./iterateJsdoc.js').Integer,\n * source: import('comment-parser').Line[]\n * ) => Width}\n */\nconst getWidth = (tags) => {\n return (width, {\n tokens,\n }, index, source) => {\n if (!shouldAlign(tags, index, source)) {\n return width;\n }\n\n return {\n name: Math.max(width.name, tokens.name.length),\n start: tokens.delimiter === '/**' ? tokens.start.length : width.start,\n tag: Math.max(width.tag, tokens.tag.length),\n type: Math.max(width.type, tokens.type.length),\n };\n };\n};\n\n/**\n * @param {{\n * description: string;\n * tags: import('comment-parser').Spec[];\n * problems: import('comment-parser').Problem[];\n * }} fields\n * @returns {TypelessInfo}\n */\nconst getTypelessInfo = (fields) => {\n const hasNoTypes = fields.tags.every(({\n type,\n }) => {\n return !type;\n });\n const maxNamedTagLength = Math.max(...fields.tags.map(({\n tag,\n name,\n }) => {\n return name.length === 0 ? -1 : tag.length;\n }).filter((length) => {\n return length !== -1;\n })) + 1;\n const maxUnnamedTagLength = Math.max(...fields.tags.map(({\n tag,\n name,\n }) => {\n return name.length === 0 ? tag.length : -1;\n }).filter((length) => {\n return length !== -1;\n })) + 1;\n return {\n hasNoTypes,\n maxNamedTagLength,\n maxUnnamedTagLength,\n };\n};\n\n/**\n * @param {import('./iterateJsdoc.js').Inte