prettier-plugin-jsdoc
Advanced tools
+7
-0
@@ -5,2 +5,9 @@ # Changelog | ||
| ## [1.4.0](https://github.com/hosseinmd/prettier-plugin-jsdoc/compare/v1.3.3...v1.4.0) (2025-10-29) | ||
| ### Features | ||
| * add support for import tags ([#252](https://github.com/hosseinmd/prettier-plugin-jsdoc/issues/252)) ([ab5c488](https://github.com/hosseinmd/prettier-plugin-jsdoc/commit/ab5c488b2d92d9706c01aaca08f410b16cd6a7da)) | ||
| ### [1.3.3](https://github.com/hosseinmd/prettier-plugin-jsdoc/compare/v1.3.2...v1.3.3) (2025-07-01) | ||
@@ -7,0 +14,0 @@ |
+28
-0
@@ -125,2 +125,30 @@ import prettier from "prettier"; | ||
| }; | ||
| readonly jsdocMergeImports: { | ||
| readonly name: "jsdocMergeImports"; | ||
| readonly type: "boolean"; | ||
| readonly category: "jsdoc"; | ||
| readonly default: true; | ||
| readonly description: "Merge all imports tags in the same block from the same source into one tag"; | ||
| }; | ||
| readonly jsdocNamedImportPadding: { | ||
| readonly name: "jsdocNamedImportPadding"; | ||
| readonly type: "boolean"; | ||
| readonly category: "jsdoc"; | ||
| readonly default: false; | ||
| readonly description: "Whether or not to pad brackets for single line named imports"; | ||
| }; | ||
| readonly jsdocNamedImportLineSplitting: { | ||
| readonly name: "jsdocNamedImportLineSplitting"; | ||
| readonly type: "boolean"; | ||
| readonly category: "jsdoc"; | ||
| readonly default: true; | ||
| readonly description: "Split import tags with multiple named imports into multiple lines"; | ||
| }; | ||
| readonly jsdocFormatImports: { | ||
| readonly name: "jsdocFormatImports"; | ||
| readonly type: "boolean"; | ||
| readonly category: "jsdoc"; | ||
| readonly default: true; | ||
| readonly description: "Format import tags"; | ||
| }; | ||
| }; | ||
@@ -127,0 +155,0 @@ declare const defaultOptions: JsdocOptions; |
+32
-0
@@ -140,2 +140,30 @@ import { getParser } from "./parser.js"; | ||
| }, | ||
| jsdocMergeImports: { | ||
| name: "jsdocMergeImports", | ||
| type: "boolean", | ||
| category: "jsdoc", | ||
| default: true, | ||
| description: "Merge all imports tags in the same block from the same source into one tag", | ||
| }, | ||
| jsdocNamedImportPadding: { | ||
| name: "jsdocNamedImportPadding", | ||
| type: "boolean", | ||
| category: "jsdoc", | ||
| default: false, | ||
| description: "Whether or not to pad brackets for single line named imports", | ||
| }, | ||
| jsdocNamedImportLineSplitting: { | ||
| name: "jsdocNamedImportLineSplitting", | ||
| type: "boolean", | ||
| category: "jsdoc", | ||
| default: true, | ||
| description: "Split import tags with multiple named imports into multiple lines", | ||
| }, | ||
| jsdocFormatImports: { | ||
| name: "jsdocFormatImports", | ||
| type: "boolean", | ||
| category: "jsdoc", | ||
| default: true, | ||
| description: "Format import tags", | ||
| }, | ||
| }; | ||
@@ -159,2 +187,6 @@ const defaultOptions = { | ||
| jsdocTagsOrder: options.jsdocTagsOrder.default, | ||
| jsdocFormatImports: options.jsdocFormatImports.default, | ||
| jsdocNamedImportPadding: options.jsdocNamedImportPadding.default, | ||
| jsdocMergeImports: options.jsdocMergeImports.default, | ||
| jsdocNamedImportLineSplitting: options.jsdocNamedImportLineSplitting.default, | ||
| }; | ||
@@ -161,0 +193,0 @@ const parsers = { |
+122
-5
@@ -34,2 +34,3 @@ (function (global, factory) { | ||
| const IGNORE = "ignore"; | ||
| const IMPORT = "import"; | ||
| const LICENSE = "license"; | ||
@@ -101,2 +102,3 @@ const MEMBER = "member"; | ||
| LICENSE, | ||
| IMPORT, | ||
| MODULE, | ||
@@ -123,2 +125,3 @@ NAMESPACE, | ||
| IGNORE, | ||
| IMPORT, | ||
| LICENSE, | ||
@@ -138,2 +141,3 @@ MODULE, | ||
| ...TAGS_DEFAULT, | ||
| IMPORT, | ||
| MEMBEROF, | ||
@@ -148,2 +152,3 @@ MODULE, | ||
| EXAMPLE, | ||
| IMPORT, | ||
| PRIVATE_REMARKS, | ||
@@ -176,2 +181,3 @@ REMARKS, | ||
| const TAGS_ORDER = { | ||
| [IMPORT]: 0, | ||
| [REMARKS]: 1, | ||
@@ -700,3 +706,3 @@ [PRIVATE_REMARKS]: 2, | ||
| if (TAGS_PEV_FORMATE_DESCRIPTION.includes(tag) || | ||
| !TAGS_ORDER[tag]) { | ||
| TAGS_ORDER[tag] === undefined) { | ||
| descriptionString = description; | ||
@@ -880,4 +886,5 @@ } | ||
| let shouldSortAgain = false; | ||
| tags = tags | ||
| .reduce((tagGroups, cur) => { | ||
| const importDetailsBySource = {}; | ||
| const importSourceByDescription = {}; | ||
| const tagGroups = tags.reduce((tagGroups, cur) => { | ||
| if (tagGroups.length === 0 || | ||
@@ -891,6 +898,38 @@ (TAGS_GROUP_HEAD.includes(cur.tag) && canGroupNextTags)) { | ||
| } | ||
| if (options.jsdocFormatImports && cur.tag === IMPORT) { | ||
| const importDetails = getImportDetails(cur); | ||
| if (importDetails) { | ||
| if (options.jsdocMergeImports) { | ||
| const existingImport = importDetailsBySource[importDetails.src]; | ||
| if (existingImport) { | ||
| importDetailsBySource[importDetails.src].push(importDetails); | ||
| return tagGroups; | ||
| } | ||
| importDetailsBySource[importDetails.src] = [importDetails]; | ||
| } | ||
| else { | ||
| writeImportDetailsToSpec(importDetails, options); | ||
| importSourceByDescription[importDetails.spec.description] = | ||
| importDetails.src; | ||
| } | ||
| } | ||
| } | ||
| tagGroups[tagGroups.length - 1].push(cur); | ||
| return tagGroups; | ||
| }, []) | ||
| .flatMap((tagGroup, index, array) => { | ||
| }, []); | ||
| if (options.jsdocFormatImports && options.jsdocMergeImports) { | ||
| Object.keys(importDetailsBySource).forEach((src) => { | ||
| const importDetails = importDetailsBySource[src]; | ||
| const firstImpSpec = importDetails[0].spec; | ||
| const { defaultImport, namedImports } = importDetails.reduce((prev, curr) => { | ||
| prev.namedImports.push(...curr.namedImports); | ||
| if (curr.defaultImport) | ||
| prev.defaultImport = curr.defaultImport; | ||
| return prev; | ||
| }, { namedImports: [], defaultImport: undefined }); | ||
| writeImportDetailsToSpec({ src, defaultImport, namedImports, spec: firstImpSpec }, options); | ||
| importSourceByDescription[firstImpSpec.description] = src; | ||
| }); | ||
| } | ||
| tags = tagGroups.flatMap((tagGroup, index, array) => { | ||
| tagGroup.sort((a, b) => { | ||
@@ -908,2 +947,11 @@ if (paramsOrder && | ||
| } | ||
| if (options.jsdocFormatImports && a.tag === IMPORT && b.tag === IMPORT) { | ||
| const aSrc = importSourceByDescription[a.description] ?? a.description; | ||
| const bSrc = importSourceByDescription[b.description] ?? a.description; | ||
| const aVal = aSrc.startsWith(".") ? 1 : 0; | ||
| const bVal = bSrc.startsWith(".") ? 1 : 0; | ||
| if (aVal === bVal) | ||
| return aSrc.localeCompare(bSrc); | ||
| return aVal - bVal; | ||
| } | ||
| return (getTagOrderWeight(a.tag, options) - getTagOrderWeight(b.tag, options)); | ||
@@ -1135,2 +1183,39 @@ }); | ||
| } | ||
| function writeImportDetailsToSpec(importDetails, options) { | ||
| const { defaultImport, namedImports, src, spec } = importDetails; | ||
| namedImports.sort((a, b) => (a.alias ?? a.name).localeCompare(b.alias ?? b.name)); | ||
| const importClauses = []; | ||
| if (defaultImport) | ||
| importClauses.push(defaultImport); | ||
| if (namedImports.length > 0) { | ||
| const makeMultiLine = options.jsdocNamedImportLineSplitting && namedImports.length > 1; | ||
| const typeString = namedImports | ||
| .map((t) => { | ||
| const val = t.alias ? `${t.name} as ${t.alias}` : `${t.name}`; | ||
| return makeMultiLine ? ` ${val}` : val; | ||
| }) | ||
| .join(makeMultiLine ? ",\n" : ", "); | ||
| const namedImportClause = makeMultiLine | ||
| ? `{\n${typeString}\n}` | ||
| : options.jsdocNamedImportPadding | ||
| ? `{ ${typeString} }` | ||
| : `{${typeString}}`; | ||
| importClauses.push(namedImportClause); | ||
| } | ||
| spec.description = `${importClauses.join(", ")} from "${src}"`; | ||
| } | ||
| function getImportDetails(spec) { | ||
| const match = spec.description.match(/([^\s\\,\\{\\}]+)?(?:[^\\{\\}]*)\{?([^\\{\\}]*)?\}?(?:\s+from\s+)[\\'\\"](\S+)[\\'\\"]/s); | ||
| if (!match) | ||
| return null; | ||
| const defaultImport = match[1] || ""; | ||
| const namedImportsClause = match[2] || ""; | ||
| const src = match[3] || ""; | ||
| const typeMatches = namedImportsClause.matchAll(/([^\s\\,\\{\\}]+)(?:\s+as\s+)?([^\s\\,\\{\\}]+)?/g); | ||
| const namedImports = []; | ||
| for (const typeMatch of typeMatches) { | ||
| namedImports.push({ name: typeMatch[1], alias: typeMatch[2] }); | ||
| } | ||
| return { spec, src, namedImports, defaultImport }; | ||
| } | ||
@@ -1271,2 +1356,30 @@ const options = { | ||
| }, | ||
| jsdocMergeImports: { | ||
| name: "jsdocMergeImports", | ||
| type: "boolean", | ||
| category: "jsdoc", | ||
| default: true, | ||
| description: "Merge all imports tags in the same block from the same source into one tag", | ||
| }, | ||
| jsdocNamedImportPadding: { | ||
| name: "jsdocNamedImportPadding", | ||
| type: "boolean", | ||
| category: "jsdoc", | ||
| default: false, | ||
| description: "Whether or not to pad brackets for single line named imports", | ||
| }, | ||
| jsdocNamedImportLineSplitting: { | ||
| name: "jsdocNamedImportLineSplitting", | ||
| type: "boolean", | ||
| category: "jsdoc", | ||
| default: true, | ||
| description: "Split import tags with multiple named imports into multiple lines", | ||
| }, | ||
| jsdocFormatImports: { | ||
| name: "jsdocFormatImports", | ||
| type: "boolean", | ||
| category: "jsdoc", | ||
| default: true, | ||
| description: "Format import tags", | ||
| }, | ||
| }; | ||
@@ -1290,2 +1403,6 @@ const defaultOptions = { | ||
| jsdocTagsOrder: options.jsdocTagsOrder.default, | ||
| jsdocFormatImports: options.jsdocFormatImports.default, | ||
| jsdocNamedImportPadding: options.jsdocNamedImportPadding.default, | ||
| jsdocMergeImports: options.jsdocMergeImports.default, | ||
| jsdocNamedImportLineSplitting: options.jsdocNamedImportLineSplitting.default, | ||
| }; | ||
@@ -1292,0 +1409,0 @@ const parsers = { |
@@ -1,1 +0,1 @@ | ||
| !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("comment-parser"),require("prettier"),require("binary-searching"),require("mdast-util-from-markdown"),require("prettier/plugins/babel"),require("prettier/plugins/flow"),require("prettier/plugins/typescript")):"function"==typeof define&&define.amd?define(["exports","comment-parser","prettier","binary-searching","mdast-util-from-markdown","prettier/plugins/babel","prettier/plugins/flow","prettier/plugins/typescript"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).sayHello={},e.commentParser,e.prettier,null,e.mdastUtilFromMarkdown,e.parserBabel,e.parserFlow,e.parserTypescript)}(this,(function(e,t,n,r,a,s,i,o){"use strict";function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=c(s),p=c(i),d=c(o);const u="abstract",g="borrows",m="callback",f="category",h="class",y="constant",j="default",$="defaultValue",b="deprecated",w="description",S="example",v="extends",x="external",L="file",W="fires",D="function",P="ignore",T="license",C="member",k="memberof",A="module",O="namespace",E="overload",F="override",I="param",M="privateRemarks",R="property",_="remarks",z="returns",U="since",q="throws",K="todo",V="type",G="typedef",B="satisfies",H="yields",J={tag:"this_is_for_space",name:"",optional:!1,type:"",description:"",source:[],problems:[]},N={arg:I,argument:I,const:y,constructor:h,desc:w,emits:W,examples:S,exception:q,fileoverview:L,func:D,host:x,method:D,overview:L,params:I,prop:R,return:z,var:C,virtual:u,yield:H,hidden:P},Y=[j,$],Q=[g,f,b,w,S,v,T,A,O,E,F,M,_,z,U,q,K,H,L,...Y],X=[g,g,b,w,S,P,T,A,O,E,F,M,_,U,K,L],Z=[g,...Y,k,A,"see"],ee=[g,f,w,S,M,_,U,K],te=[v,I,R,z,q,V,B,G,H],ne=[m,G],re=[...ne,V,R,I,z,H,q],ae={[_]:1,[M]:2,providesModule:3,[A]:4,[T]:5,flow:6,async:7,private:8,[P]:9,[k]:10,version:11,[L]:12,author:13,[b]:14,[U]:15,[f]:16,[w]:17,[S]:18,[u]:19,augments:20,[y]:21,[j]:22,[$]:23,[x]:24,[E]:25,[W]:26,template:27,typeParam:28,[D]:29,[O]:30,[g]:31,[h]:32,[v]:33,[C]:34,[G]:35,[V]:36,[B]:37,[R]:38,[m]:39,[I]:40,[H]:41,[z]:42,[q]:43,other:44,see:45,[K]:46};function se(e,t){return(e.match(new RegExp(t,"g"))||[]).length}function ie(e){return e?e.match(/^https?:\/\//i)?e:e.startsWith("- ")?e.slice(0,2)+ie(e.slice(2)):e[0].toUpperCase()+e.slice(1):e}async function oe(e,t,r){const{printWidth:a,jsdocKeepUnParseAbleExampleIndent:s}=r;e.split("\n").slice(1).every((e=>!e.trim()||e.startsWith(t)))&&(e=e.replace(new RegExp(`\n${t.replace(/[\t]/g,"[\\t]")}`,"g"),"\n"));try{let s="";const i=a-4;s=e.trim().startsWith("{")?await n.format(e||"",{...r,parser:"json",printWidth:i}):await n.format(e||"",{...r,printWidth:i}),e=s.replace(/(^|\n)/g,`\n${t}`)}catch(n){e=(e=`\n${e.split("\n").map((e=>`${t}${s?e:e.trim()}`)).join("\n")}\n`).replace(/^\n[\s]+\n/g,"\n")}return e}const ce=(e,t)=>{const n=t.plugins.find((t=>"object"==typeof t&&null!==t&&!(t instanceof URL)&&t.name&&t.parsers&&t.parsers.hasOwnProperty(e)));return!n||"prettier-plugin-jsdoc"===n.name||n.parsers?.hasOwnProperty("jsdoc-parser")?void 0:n.parsers?.[e]},le=e=>Y.includes(e),pe="2@^5!~#sdE!_TABLE";async function de(e,t,r,s){if(!t)return t;const{printWidth:i}=r,{tagStringLength:o=0,beginningSpace:c}=s,l=[...(t=(t=t.replace(/^(\d+)[-][\s|]+/g,"$1. ")).replace(/\n+(\s*\d+)[-][\s]+/g,"\n$1. ")).matchAll(/```\S*?\n[\s\S]+?```/gm),...t.matchAll(/^\r?\n^(?:(?:(?:[ ]{4}|\t).*(?:\r?\n|$))+)/gm)],p=[];t=t.replace(/((\n|^)\|[\s\S]*?)((\n[^|])|$)/g,((e,t,n,r,a,s)=>{for(const t of l)if(void 0!==t.index&&t.index<=s+1&&s+e.length+1<=t.index+t[0].length)return e;return e=r?e.slice(0,-1):e,p.push(e),`\n\n${pe}\n\n${r?r.slice(1):""}`})),r.jsdocCapitalizeDescription&&!Z.includes(e)&&(t=ie(t)),t=`${o?`${"!".repeat(o-1)}?`:""}${t.startsWith("```")?"\n":""}${t}`;let d=0;t=t.replace(new RegExp(`\\n[ ]{${c.length}}`,"g"),"\n");const u=a.fromMarkdown(t);let g=await async function t(a,s,o){return Array.isArray(a.children)?(await Promise.all(a.children.map((async(n,c)=>{switch(n.type){case"listItem":{let e=`\n${s}- `;if("number"==typeof a.start){const t=c+(a.start??1);e=`\n${s}${t}. `}const r=s+" ".repeat(e.length-1);return`${e}${(await t(n,r,a)).trim()}`}case"list":{let r="";return e!==w&&"root"===a.type&&c===a.children.length-1&&(r="\n"),`\n${await t(n,s,a)}${r}`}case"paragraph":{const a=await t(n,s,o);return n.costumeType===pe?a:`\n\n${a.split("\\\n").map((t=>{const n=[];t=t.replace(/{@(link|linkcode|linkplain)[\s](([^{}])*)}/g,((e,t,r)=>(n.push(r),`{@${t}${"_".repeat(r.length)}}`))),t=t.replace(/\s+/g," "),r.jsdocCapitalizeDescription&&!Z.includes(e)&&(t=ie(t)),r.jsdocDescriptionWithDot&&(t=t.replace(/([\w\p{L}])$/u,"$1."));let a=function(e,t,n){let r=e.trim();if(!r)return r;let a="";for(;r.length>t;){let e=r.lastIndexOf(" ",r.startsWith("\n")?t+1:t);e<=n.length&&(e=r.indexOf(" ",n.length+1)),-1===e&&(e=r.length),a+=r.substring(0,e),r=r.substring(e+1),r&&(r=`${n}${r}`,r=`\n${r}`)}return a+=r,`${n}${a}`}(t,i,s);return a=a.replace(/{@(link|linkcode|linkplain)([_]+)}/g,((e,t,r)=>{const a=n[0];return a.length===r.length?(n.shift(),`{@${t} ${a}}`):e})),a})).join("\\\n")}`}case"strong":return`**${await t(n,s,a)}**`;case"emphasis":return`_${await t(n,s,a)}_`;case"heading":return`\n\n${s}${"#".repeat(n.depth)} ${await t(n,s,a)}`;case"link":case"image":return`[${await t(n,s,a)}](${n.url})`;case"linkReference":return`[${await t(n,s,a)}][${n.label}]`;case"definition":return`\n\n[${n.label}]: ${n.url}`;case"blockquote":return`\n\n> ${(await t(n,"",a)).trim().replace(/(\n+)/g,`$1${s}> `)}`}return t(n,s,a)})))).join(""):async function(e,t,a){if("inlineCode"===e.type)return`\`${e.value}\``;if("code"===e.type){let n=e.value||"",a=t;if(n)if(e.lang){const a=(e=>{switch(e){case"js":case"javascript":case"jsx":return["babel","babel-flow","vue"];case"ts":case"typescript":case"tsx":return["typescript","babel-ts","angular"];case"json":case"css":return["css"];case"less":return["less"];case"scss":return["scss"];case"html":return["html"];case"yaml":return["yaml"];default:return["babel"]}})(e.lang.toLowerCase()),s=a?.includes(r.parser)?r.parser:a?.[0]||e.lang;n=await oe(n,t,{...r,parser:s,jsdocKeepUnParseAbleExampleIndent:!0})}else r.jsdocPreferCodeFences||(a=t+" ".repeat(4)),n=await oe(n,a,{...r,jsdocKeepUnParseAbleExampleIndent:!0});const s=r.jsdocPreferCodeFences||!!e.lang;return n=s?n:n.trimEnd(),n?s?`\n\n${a}\`\`\`${e.lang||""}${n}\`\`\``:`\n${n}`:""}if(e.value===pe&&(a&&(a.costumeType=pe),p.length>0)){let a=p?.[d]||"";return d++,a&&(a=(await n.format(a,{...r,parser:"markdown"})).trim()),`${a?`\n\n${t}${a.split("\n").join(`\n${t}`)}`:e.value}`}return"break"===e.type?"\\\n":e.value||e.title||e.alt||""}(a,s,o)}(u,c,null);return g=g.replace(/^[\s\n]+/g,""),g=g.replace(/^([!]+\?)/g,""),g}const ue=async({name:e,description:t,type:n,tag:r},a,s,i,o,c,l)=>{let p="\n";if(r===J.tag)return p;const{printWidth:d,jsdocSpaces:u,jsdocVerticalAlignment:g,jsdocDescriptionTag:m,tsdoc:f,useTabs:h,tabWidth:y,jsdocSeparateTagGroups:j}=i,$=" ".repeat(u);let b=0,v=0,x=0,L=0;g&&te.includes(r)&&(r?b+=o-r.length:o&&(L+=o+$.length),n?v+=c-n.length:c&&(L+=c+$.length),e?x+=l-e.length:l&&(L=l+$.length));const W=r!==w||m;if(W&&(p+=`@${r}${" ".repeat(b||0)}`),n){p+=$+(()=>{if(!le(r))return`{${n}}`;if("[]"===n)return"[ ]";if("{}"===n)return"{ }";return/^{.*[A-z0-9_]+ ?:.*}$/.test(n)?n.replace(/; ([A-z0-9_])/g,", $1"):n})()+" ".repeat(v)}if(e&&(p+=`${$}${e}${" ".repeat(x)}`),r!==S||f){if(t){let e="";if(W&&(p+=$+" ".repeat(L)),Z.includes(r)||!ae[r])e=t;else{const[,n]=/^\s*(\S+)/.exec(t)||["",""],a=r===w||[S,_,M].includes(r)&&f?"":" ";e=r!==w&&p.length+n.length>d||[_,M].includes(r)?`\n${a}`+await de(r,t,i,{beginningSpace:a}):await de(r,t,i,{tagStringLength:p.length-1,beginningSpace:a})}j&&(e=e.trimEnd()),p+=e.startsWith("\n")?e.replace(/^\n[\s]+\n/g,"\n"):e.trimStart()}}else{const e=t.match(/<caption>([\s\S]*?)<\/caption>/i);e&&(t=t.replace(e[0],""),p=`${p} ${e[0]}`);const n=h?"\t":" ".repeat(y);p+=(await oe(t,n,i)).replace(new RegExp(`^\\n${n.replace(/[\t]/g,"[\\t]").replace(/[^S\r\n]/g,"[^S\\r\\n]")}\\n`),"").trimEnd()}return p+=function({tag:e,isEndTag:t}){return[w,S,K].includes(e)&&!t?"\n":""}({tag:r,isEndTag:a===s.length-1}),p},{name:ge,tag:me,type:fe,description:he}=t.tokenizers,ye=(e,r)=>async function(a,s,i){let o=i??s;const c=(ce(r,o)?.parse||e)(a,o);o={...o,printWidth:o.jsdocPrintWidth??o.printWidth};const l="auto"===o.endOfLine?function(e){const t={"\r":0,"\r\n":0,"\n":0},n=/\r\n?|\n/g;let r;for(;r=n.exec(e);)t[r[0]]++;const a=t["\r"],s=t["\r\n"],i=t["\n"],o=Math.max(a,s,i);return i===o?"lf":s===o?"crlf":"cr"}(a):o.endOfLine;return o={...o,endOfLine:"lf"},await Promise.all(c.comments.map((async e=>{if(!be(e))return;const r=function(e,t){try{const n=e.split("\n");let r=0;for(let e=0;e<t.loc.end.line-1;e++)r+=n[e].length+1;r+=t.loc.end.column;const a=e.slice(r),s=a.match(/^\s*function\s+\w*\s*\(([^)]*)\)/);if(s){const e=s[1];return e.split(",").map((e=>{const t=e.trim(),n=t.indexOf(":");return(n>-1?t.slice(0,n):t).split(/\s+/)[0].replace(/[{}[\]]/g,"")})).filter((e=>e&&"..."!==e))}const i=a.match(/^\s*(?:const|let|var)\s+\w+\s*=\s*\(([^)]*)\)\s*=>/);if(i){const e=i[1];return e.split(",").map((e=>{const t=e.trim(),n=t.indexOf(":");return(n>-1?t.slice(0,n):t).split(/\s+/)[0].replace(/[{}[\]]/g,"")})).filter((e=>e&&"..."!==e))}const o=a.match(/^\s*(\w+)\s*\(([^)]*)\)/);if(o){const e=o[2];return e.split(",").map((e=>{const t=e.trim(),n=t.indexOf(":");return(n>-1?t.slice(0,n):t).split(/\s+/)[0].replace(/[{}[\]]/g,"")})).filter((e=>e&&"..."!==e))}return}catch(e){return}}(a,e),s=e.value;e.value=e.value.replace(/^([*]+)/g,"*");const i=`/*${e.value.replace(/\r\n?/g,"\n")}*/`;if(!/^\/\*\*[\s\S]+?\*\/$/.test(i))return;const c=t.parse(i,{spacing:"preserve",tokenizers:[me(),e=>le(e.tag)?e:fe("preserve")(e),ge(),he("preserve")]})[0];if(e.value="",!c)return;!function(e){e.tags=e.tags.map((({tag:e,type:t,name:n,description:r,default:a,...s})=>{e=e||"",t=t||"",n=n||"",r=r||"",a=a?.trim();const i=e.indexOf("{");-1!==i&&"}"===e[e.length-1]&&(t=e.slice(i+1,-1)+" "+t,e=e.slice(0,i));const o=(e=e.trim()).toLowerCase(),c=we.findIndex((([e])=>e.toLowerCase()===o));return c>=0?e=we[c][0]:o in N&&(e=N[o]),t=t.trim(),(n=n.trim())&&Q.includes(e)&&(r=`${n} ${r}`,n=""),t&&X.includes(e)&&(r=`{${t}} ${r}`,t=""),{tag:e,type:t,name:n,description:r,default:a,...s}}))}(c),function(e){let t=e.description||"";e.description="",e.tags=e.tags.filter((({description:e,tag:n})=>n.toLowerCase()!==w||(e.trim()&&(t+="\n\n"+e),!1))),t&&e.tags.unshift({tag:w,description:t,name:void 0,type:void 0,source:[],optional:!1,problems:[]})}(c);const p=function(e,t,n){const r=t.split(/\r\n?|\n/g)[e.loc.start.line-1];let a=0,s=0;for(let t=e.loc.start.column-1;t>=0;t--){const e=r[t];if(" "===e)a++;else{if("\t"!==e)break;s++}}return n.printWidth-(a+s*n.tabWidth)-" * ".length}(e,a,o);let d=0,u=0,g=0,m=c.tags.map((({type:e,optional:t,...n})=>(e&&(e=e.replace(/[=]$/,(()=>(t=!0,""))),e=function(e,t){const n=[];let r=e.replace(/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/g,(e=>(n.push(e),`String$${n.length-1}$`)));return r.includes("`")?e:(r=t(r),r.replace(/String\$(\d+)\$/g,((e,t)=>n[t])))}(e,(e=>{e=(e=(e=(e=e.trim()).replace(/\.</g,"<")).replace(/\*/g," any ")).replace(/^\?\s*(\w+)$/,"$1 | null").replace(/^(\w+)\s*\?$/,"$1 | null");let t=!0;for(;t;)t=!1,e=e.replace(/(^|[^$\w\xA0-\uFFFF])Array\s*<((?:[^<>=]|=>|=(?!>)|<(?:[^<>=]|=>|=(?!>))+>)+)>/g,((e,n,r)=>(t=!0,`${n}(${r})[]`)));return e}))),{...n,type:e,optional:t})));m=je(m,r,o),o.jsdocSeparateReturnsFromParam&&(m=m.flatMap(((e,t)=>e.tag===z&&m[t-1]?.tag===I?[J,e]:[e]))),o.jsdocAddDefaultToDescription&&(m=m.map(Se)),m=await Promise.all(m.map(ve).map((async({type:e,...t})=>(e&&(e=await async function(e,t){try{const r="type name = ";let a=e,s=!1;return a.startsWith("...")&&(s=!0,a=`(${a.slice(3)})[]`),a=await n.format(`${r}${a}`,{...t,parser:"typescript",plugins:[],filepath:"file.ts"}),a=a.slice(r.length),a=a.replace(/^\s*/g,"").replace(/[;\n]*$/g,"").replace(/^\|/g,"").trim(),s&&(a="..."+a.replace(/\[\s*\]$/,"")),a}catch(t){return e}}(e,{...o,printWidth:p})),{...t,type:e})))).then((e=>e.map((({type:e,name:t,description:n,tag:r,...a})=>(te.includes(r)&&(d=Math.max(d,r.length),u=Math.max(u,e.length),g=Math.max(g,t.length)),{type:e,name:t,description:n,tag:r,...a}))))),o.jsdocSeparateTagGroups&&(m=m.flatMap(((e,t)=>{const n=m[t-1];return n&&n.tag!==w&&n.tag!==S&&n.tag!==J.tag&&e.tag!==J.tag&&n.tag!==e.tag?[J,e]:[e]})));const f=m.filter((({description:e,tag:t})=>!(!e&&ee.includes(t))));for(const[t,n]of f.entries()){const r=await ue(n,t,f,{...o,printWidth:p},d,u,g);e.value+=r}e.value=e.value.trimEnd(),e.value&&(e.value=function(e,t,n){return"singleLine"===n.jsdocCommentLineStrategy&&0===se(t.trim(),"\n")||"keep"===n.jsdocCommentLineStrategy&&0===se(e,"\n")?`* ${t.trim()} `:`*${t.replace(/(\n(?!$))/g,"\n * ")}\n `}(s,e.value,o)),"cr"===l?e.value=e.value.replace(/\n/g,"\r"):"crlf"===l&&(e.value=e.value.replace(/\n/g,"\r\n"))}))),c.comments=c.comments.filter((e=>!(be(e)&&!e.value))),c};function je(e,t,n){let r=!1,a=!1;return e=e.reduce(((e,t)=>((0===e.length||ne.includes(t.tag)&&r)&&(r=!1,e.push([])),re.includes(t.tag)&&(r=!0),e[e.length-1].push(t),e)),[]).flatMap(((e,r,s)=>(e.sort(((e,r)=>{if(t&&t.length>1&&e.tag===I&&r.tag===I){const n=t.indexOf(e.name),a=t.indexOf(r.name);return n>-1&&a>-1?n-a:0}return $e(e.tag,n)-$e(r.tag,n)})),s.length-1!==r&&e.push(J),r>0&&e[0]?.tag&&!ne.includes(e[0].tag)&&(a=!0),e))),a?je(e,t,n):e}function $e(e,t){if(e===w&&!t.jsdocDescriptionTag)return-1;let n;return n=void 0!==t.jsdocTagsOrder?.[e]?t.jsdocTagsOrder[e]:ae[e],void 0===n?ae.other:n}function be(e){return"CommentBlock"===e.type||"Block"===e.type}const we=Object.entries(ae);function Se(e){if(e.optional&&e.default){let{description:t}=e;return t=t.replace(/(?:\s*Default\s+is\s+`.*?`\.?)+/g,""),t&&!/[.\n]$/.test(t)&&(t+="."),t+=` Default is \`${e.default}\``,{...e,description:t.trim()}}return e}function ve({name:e,optional:t,default:n,tag:r,type:a,source:s,description:i,...o}){if(le(r)){const t=(s.find((e=>e.source.includes(`@${r}`)))?.source||"").match(/@default(Value)? (\[.*]|{.*}|\(.*\)|'.*'|".*"|`.*`| \w+)( ((?!\*\/).+))?/),n=t?.[2]||"",o=t?.[4]||"";t&&(a=n,e="",i=o)}else t&&(e?e=n?`[${e}=${n}]`:`[${e}]`:a=`${a} | undefined`);return{...o,tag:r,name:e,description:i,optional:t,type:a,source:s,default:n}}const xe={jsdocSpaces:{name:"jsdocSpaces",type:"int",category:"jsdoc",default:1,description:"How many spaces will be used to separate tag elements."},jsdocDescriptionWithDot:{name:"jsdocDescriptionWithDot",type:"boolean",category:"jsdoc",default:!1,description:"Should dot be inserted at the end of description"},jsdocDescriptionTag:{name:"jsdocDescriptionTag",type:"boolean",category:"jsdoc",default:!1,description:"Should description tag be used"},jsdocVerticalAlignment:{name:"jsdocVerticalAlignment",type:"boolean",category:"jsdoc",default:!1,description:"Should tags, types, names and description be aligned"},jsdocKeepUnParseAbleExampleIndent:{name:"jsdocKeepUnParseAbleExampleIndent",type:"boolean",category:"jsdoc",default:!1,description:"Should unParseAble example (pseudo code or no js code) keep its indentation"},jsdocSingleLineComment:{name:"jsdocSingleLineComment",type:"boolean",category:"jsdoc",deprecated:"use jsdocCommentLineStrategy instead will be remove on v2",default:!0,description:"Should compact single line comment"},jsdocCommentLineStrategy:{name:"jsdocCommentLineStrategy",type:"choice",choices:[{value:"singleLine",description:"Should compact single line comment, if possible"},{value:"multiline",description:"Should compact multi line comment"},{value:"keep",description:"Should keep original line comment"}],category:"jsdoc",default:"singleLine",description:"How comments line should be"},jsdocSeparateReturnsFromParam:{name:"jsdocSeparateReturnsFromParam",type:"boolean",category:"jsdoc",default:!1,description:"Add an space between last @param and @returns"},jsdocSeparateTagGroups:{name:"jsdocSeparateTagGroups",type:"boolean",category:"jsdoc",default:!1,description:"Add an space between tag groups"},jsdocCapitalizeDescription:{name:"jsdocCapitalizeDescription",type:"boolean",category:"jsdoc",default:!0,description:"Should capitalize first letter of description"},tsdoc:{name:"tsdoc",type:"boolean",category:"jsdoc",default:!1,description:"Should format as tsdoc"},jsdocPrintWidth:{name:"jsdocPrintWidth",type:"int",category:"jsdoc",default:void 0,description:"If You don't set value to jsdocPrintWidth, the printWidth will be use as jsdocPrintWidth."},jsdocAddDefaultToDescription:{name:"jsdocAddDefaultToDescription",type:"boolean",category:"jsdoc",default:!0,description:"Add Default value of a param to end description"},jsdocPreferCodeFences:{name:"jsdocPreferCodeFences",type:"boolean",category:"jsdoc",default:!1,description:'Prefer to render code blocks using "fences" (triple backticks). If not set, blocks without a language tag will be rendered with a four space indentation.'},jsdocLineWrappingStyle:{name:"jsdocLineWrappingStyle",type:"choice",choices:[{value:"greedy",description:"Lines wrap as soon as they reach the print width"}],category:"jsdoc",default:"greedy",description:"Strategy for wrapping lines for the given print width. More options may be added in the future."},jsdocTagsOrder:{name:"jsdocTagsOrder",type:"string",category:"jsdoc",default:void 0,description:"How many spaces will be used to separate tag elements."}},Le={jsdocSpaces:xe.jsdocSpaces.default,jsdocPrintWidth:xe.jsdocPrintWidth.default,jsdocDescriptionWithDot:xe.jsdocDescriptionWithDot.default,jsdocDescriptionTag:xe.jsdocDescriptionTag.default,jsdocVerticalAlignment:xe.jsdocVerticalAlignment.default,jsdocKeepUnParseAbleExampleIndent:xe.jsdocKeepUnParseAbleExampleIndent.default,jsdocSingleLineComment:xe.jsdocSingleLineComment.default,jsdocCommentLineStrategy:xe.jsdocCommentLineStrategy.default,jsdocSeparateReturnsFromParam:xe.jsdocSeparateReturnsFromParam.default,jsdocSeparateTagGroups:xe.jsdocSeparateTagGroups.default,jsdocCapitalizeDescription:xe.jsdocCapitalizeDescription.default,jsdocAddDefaultToDescription:xe.jsdocAddDefaultToDescription.default,jsdocPreferCodeFences:xe.jsdocPreferCodeFences.default,tsdoc:xe.tsdoc.default,jsdocLineWrappingStyle:xe.jsdocLineWrappingStyle.default,jsdocTagsOrder:xe.jsdocTagsOrder.default},We={get babel(){return De(l.default.parsers.babel,"babel")},get"babel-flow"(){return De(l.default.parsers["babel-flow"],"babel-flow")},get"babel-ts"(){return De(l.default.parsers["babel-ts"],"babel-ts")},get flow(){return De(p.default.parsers.flow,"flow")},get typescript(){return De(d.default.parsers.typescript,"typescript")},get"jsdoc-parser"(){return De(l.default.parsers["babel-ts"],"babel-ts")}};function De(e,t){const n=ye(e.parse,t),r=(s,i)=>{!function(e){e.jsdocTagsOrder&&(e.jsdocTagsOrder=JSON.parse(e.jsdocTagsOrder));if(e.jsdocCommentLineStrategy)return;e.jsdocSingleLineComment?e.jsdocCommentLineStrategy="singleLine":e.jsdocCommentLineStrategy="multiline"}(i);const o=ce(t,i);if(!o)return e.preprocess?e.preprocess(s,i):s;const c=o.preprocess||e.preprocess;return Object.assign(a,{...a,...o,preprocess:r,parse:n}),c?c(s,i):s},a={...e,preprocess:r,parse:n};return a}e.defaultOptions=Le,e.options=xe,e.parsers=We,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
| !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("comment-parser"),require("prettier"),require("binary-searching"),require("mdast-util-from-markdown"),require("prettier/plugins/babel"),require("prettier/plugins/flow"),require("prettier/plugins/typescript")):"function"==typeof define&&define.amd?define(["exports","comment-parser","prettier","binary-searching","mdast-util-from-markdown","prettier/plugins/babel","prettier/plugins/flow","prettier/plugins/typescript"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).sayHello={},e.commentParser,e.prettier,null,e.mdastUtilFromMarkdown,e.parserBabel,e.parserFlow,e.parserTypescript)}(this,(function(e,t,n,r,s,a,o,i){"use strict";function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=c(a),p=c(o),d=c(i);const u="abstract",m="borrows",g="callback",f="category",h="class",j="constant",y="default",$="defaultValue",b="deprecated",w="description",S="example",v="extends",I="external",x="file",L="fires",P="function",W="ignore",C="import",D="license",T="member",k="memberof",A="module",O="namespace",F="overload",E="override",M="param",R="privateRemarks",_="property",z="remarks",N="returns",U="since",q="throws",K="todo",V="type",G="typedef",B="satisfies",H="yields",J={tag:"this_is_for_space",name:"",optional:!1,type:"",description:"",source:[],problems:[]},Y={arg:M,argument:M,const:j,constructor:h,desc:w,emits:L,examples:S,exception:q,fileoverview:x,func:P,host:I,method:P,overview:x,params:M,prop:_,return:N,var:T,virtual:u,yield:H,hidden:W},Q=[y,$],X=[m,f,b,w,S,v,D,C,A,O,F,E,R,z,N,U,q,K,H,x,...Q],Z=[m,m,b,w,S,W,C,D,A,O,F,E,R,z,U,K,x],ee=[m,...Q,C,k,A,"see"],te=[m,f,w,S,C,R,z,U,K],ne=[v,M,_,N,q,V,B,G,H],re=[g,G],se=[...re,V,_,M,N,H,q],ae={[C]:0,[z]:1,[R]:2,providesModule:3,[A]:4,[D]:5,flow:6,async:7,private:8,[W]:9,[k]:10,version:11,[x]:12,author:13,[b]:14,[U]:15,[f]:16,[w]:17,[S]:18,[u]:19,augments:20,[j]:21,[y]:22,[$]:23,[I]:24,[F]:25,[L]:26,template:27,typeParam:28,[P]:29,[O]:30,[m]:31,[h]:32,[v]:33,[T]:34,[G]:35,[V]:36,[B]:37,[_]:38,[g]:39,[M]:40,[H]:41,[N]:42,[q]:43,other:44,see:45,[K]:46};function oe(e,t){return(e.match(new RegExp(t,"g"))||[]).length}function ie(e){return e?e.match(/^https?:\/\//i)?e:e.startsWith("- ")?e.slice(0,2)+ie(e.slice(2)):e[0].toUpperCase()+e.slice(1):e}async function ce(e,t,r){const{printWidth:s,jsdocKeepUnParseAbleExampleIndent:a}=r;e.split("\n").slice(1).every((e=>!e.trim()||e.startsWith(t)))&&(e=e.replace(new RegExp(`\n${t.replace(/[\t]/g,"[\\t]")}`,"g"),"\n"));try{let a="";const o=s-4;a=e.trim().startsWith("{")?await n.format(e||"",{...r,parser:"json",printWidth:o}):await n.format(e||"",{...r,printWidth:o}),e=a.replace(/(^|\n)/g,`\n${t}`)}catch(n){e=(e=`\n${e.split("\n").map((e=>`${t}${a?e:e.trim()}`)).join("\n")}\n`).replace(/^\n[\s]+\n/g,"\n")}return e}const le=(e,t)=>{const n=t.plugins.find((t=>"object"==typeof t&&null!==t&&!(t instanceof URL)&&t.name&&t.parsers&&t.parsers.hasOwnProperty(e)));return!n||"prettier-plugin-jsdoc"===n.name||n.parsers?.hasOwnProperty("jsdoc-parser")?void 0:n.parsers?.[e]},pe=e=>Q.includes(e),de="2@^5!~#sdE!_TABLE";async function ue(e,t,r,a){if(!t)return t;const{printWidth:o}=r,{tagStringLength:i=0,beginningSpace:c}=a,l=[...(t=(t=t.replace(/^(\d+)[-][\s|]+/g,"$1. ")).replace(/\n+(\s*\d+)[-][\s]+/g,"\n$1. ")).matchAll(/```\S*?\n[\s\S]+?```/gm),...t.matchAll(/^\r?\n^(?:(?:(?:[ ]{4}|\t).*(?:\r?\n|$))+)/gm)],p=[];t=t.replace(/((\n|^)\|[\s\S]*?)((\n[^|])|$)/g,((e,t,n,r,s,a)=>{for(const t of l)if(void 0!==t.index&&t.index<=a+1&&a+e.length+1<=t.index+t[0].length)return e;return e=r?e.slice(0,-1):e,p.push(e),`\n\n${de}\n\n${r?r.slice(1):""}`})),r.jsdocCapitalizeDescription&&!ee.includes(e)&&(t=ie(t)),t=`${i?`${"!".repeat(i-1)}?`:""}${t.startsWith("```")?"\n":""}${t}`;let d=0;t=t.replace(new RegExp(`\\n[ ]{${c.length}}`,"g"),"\n");const u=s.fromMarkdown(t);let m=await async function t(s,a,i){return Array.isArray(s.children)?(await Promise.all(s.children.map((async(n,c)=>{switch(n.type){case"listItem":{let e=`\n${a}- `;if("number"==typeof s.start){const t=c+(s.start??1);e=`\n${a}${t}. `}const r=a+" ".repeat(e.length-1);return`${e}${(await t(n,r,s)).trim()}`}case"list":{let r="";return e!==w&&"root"===s.type&&c===s.children.length-1&&(r="\n"),`\n${await t(n,a,s)}${r}`}case"paragraph":{const s=await t(n,a,i);return n.costumeType===de?s:`\n\n${s.split("\\\n").map((t=>{const n=[];t=t.replace(/{@(link|linkcode|linkplain)[\s](([^{}])*)}/g,((e,t,r)=>(n.push(r),`{@${t}${"_".repeat(r.length)}}`))),t=t.replace(/\s+/g," "),r.jsdocCapitalizeDescription&&!ee.includes(e)&&(t=ie(t)),r.jsdocDescriptionWithDot&&(t=t.replace(/([\w\p{L}])$/u,"$1."));let s=function(e,t,n){let r=e.trim();if(!r)return r;let s="";for(;r.length>t;){let e=r.lastIndexOf(" ",r.startsWith("\n")?t+1:t);e<=n.length&&(e=r.indexOf(" ",n.length+1)),-1===e&&(e=r.length),s+=r.substring(0,e),r=r.substring(e+1),r&&(r=`${n}${r}`,r=`\n${r}`)}return s+=r,`${n}${s}`}(t,o,a);return s=s.replace(/{@(link|linkcode|linkplain)([_]+)}/g,((e,t,r)=>{const s=n[0];return s.length===r.length?(n.shift(),`{@${t} ${s}}`):e})),s})).join("\\\n")}`}case"strong":return`**${await t(n,a,s)}**`;case"emphasis":return`_${await t(n,a,s)}_`;case"heading":return`\n\n${a}${"#".repeat(n.depth)} ${await t(n,a,s)}`;case"link":case"image":return`[${await t(n,a,s)}](${n.url})`;case"linkReference":return`[${await t(n,a,s)}][${n.label}]`;case"definition":return`\n\n[${n.label}]: ${n.url}`;case"blockquote":return`\n\n> ${(await t(n,"",s)).trim().replace(/(\n+)/g,`$1${a}> `)}`}return t(n,a,s)})))).join(""):async function(e,t,s){if("inlineCode"===e.type)return`\`${e.value}\``;if("code"===e.type){let n=e.value||"",s=t;if(n)if(e.lang){const s=(e=>{switch(e){case"js":case"javascript":case"jsx":return["babel","babel-flow","vue"];case"ts":case"typescript":case"tsx":return["typescript","babel-ts","angular"];case"json":case"css":return["css"];case"less":return["less"];case"scss":return["scss"];case"html":return["html"];case"yaml":return["yaml"];default:return["babel"]}})(e.lang.toLowerCase()),a=s?.includes(r.parser)?r.parser:s?.[0]||e.lang;n=await ce(n,t,{...r,parser:a,jsdocKeepUnParseAbleExampleIndent:!0})}else r.jsdocPreferCodeFences||(s=t+" ".repeat(4)),n=await ce(n,s,{...r,jsdocKeepUnParseAbleExampleIndent:!0});const a=r.jsdocPreferCodeFences||!!e.lang;return n=a?n:n.trimEnd(),n?a?`\n\n${s}\`\`\`${e.lang||""}${n}\`\`\``:`\n${n}`:""}if(e.value===de&&(s&&(s.costumeType=de),p.length>0)){let s=p?.[d]||"";return d++,s&&(s=(await n.format(s,{...r,parser:"markdown"})).trim()),`${s?`\n\n${t}${s.split("\n").join(`\n${t}`)}`:e.value}`}return"break"===e.type?"\\\n":e.value||e.title||e.alt||""}(s,a,i)}(u,c,null);return m=m.replace(/^[\s\n]+/g,""),m=m.replace(/^([!]+\?)/g,""),m}const me=async({name:e,description:t,type:n,tag:r},s,a,o,i,c,l)=>{let p="\n";if(r===J.tag)return p;const{printWidth:d,jsdocSpaces:u,jsdocVerticalAlignment:m,jsdocDescriptionTag:g,tsdoc:f,useTabs:h,tabWidth:j,jsdocSeparateTagGroups:y}=o,$=" ".repeat(u);let b=0,v=0,I=0,x=0;m&&ne.includes(r)&&(r?b+=i-r.length:i&&(x+=i+$.length),n?v+=c-n.length:c&&(x+=c+$.length),e?I+=l-e.length:l&&(x=l+$.length));const L=r!==w||g;if(L&&(p+=`@${r}${" ".repeat(b||0)}`),n){p+=$+(()=>{if(!pe(r))return`{${n}}`;if("[]"===n)return"[ ]";if("{}"===n)return"{ }";return/^{.*[A-z0-9_]+ ?:.*}$/.test(n)?n.replace(/; ([A-z0-9_])/g,", $1"):n})()+" ".repeat(v)}if(e&&(p+=`${$}${e}${" ".repeat(I)}`),r!==S||f){if(t){let e="";if(L&&(p+=$+" ".repeat(x)),ee.includes(r)||void 0===ae[r])e=t;else{const[,n]=/^\s*(\S+)/.exec(t)||["",""],s=r===w||[S,z,R].includes(r)&&f?"":" ";e=r!==w&&p.length+n.length>d||[z,R].includes(r)?`\n${s}`+await ue(r,t,o,{beginningSpace:s}):await ue(r,t,o,{tagStringLength:p.length-1,beginningSpace:s})}y&&(e=e.trimEnd()),p+=e.startsWith("\n")?e.replace(/^\n[\s]+\n/g,"\n"):e.trimStart()}}else{const e=t.match(/<caption>([\s\S]*?)<\/caption>/i);e&&(t=t.replace(e[0],""),p=`${p} ${e[0]}`);const n=h?"\t":" ".repeat(j);p+=(await ce(t,n,o)).replace(new RegExp(`^\\n${n.replace(/[\t]/g,"[\\t]").replace(/[^S\r\n]/g,"[^S\\r\\n]")}\\n`),"").trimEnd()}return p+=function({tag:e,isEndTag:t}){return[w,S,K].includes(e)&&!t?"\n":""}({tag:r,isEndTag:s===a.length-1}),p},{name:ge,tag:fe,type:he,description:je}=t.tokenizers,ye=(e,r)=>async function(s,a,o){let i=o??a;const c=(le(r,i)?.parse||e)(s,i);i={...i,printWidth:i.jsdocPrintWidth??i.printWidth};const l="auto"===i.endOfLine?function(e){const t={"\r":0,"\r\n":0,"\n":0},n=/\r\n?|\n/g;let r;for(;r=n.exec(e);)t[r[0]]++;const s=t["\r"],a=t["\r\n"],o=t["\n"],i=Math.max(s,a,o);return o===i?"lf":a===i?"crlf":"cr"}(s):i.endOfLine;return i={...i,endOfLine:"lf"},await Promise.all(c.comments.map((async e=>{if(!we(e))return;const r=function(e,t){try{const n=e.split("\n");let r=0;for(let e=0;e<t.loc.end.line-1;e++)r+=n[e].length+1;r+=t.loc.end.column;const s=e.slice(r),a=s.match(/^\s*function\s+\w*\s*\(([^)]*)\)/);if(a){const e=a[1];return e.split(",").map((e=>{const t=e.trim(),n=t.indexOf(":");return(n>-1?t.slice(0,n):t).split(/\s+/)[0].replace(/[{}[\]]/g,"")})).filter((e=>e&&"..."!==e))}const o=s.match(/^\s*(?:const|let|var)\s+\w+\s*=\s*\(([^)]*)\)\s*=>/);if(o){const e=o[1];return e.split(",").map((e=>{const t=e.trim(),n=t.indexOf(":");return(n>-1?t.slice(0,n):t).split(/\s+/)[0].replace(/[{}[\]]/g,"")})).filter((e=>e&&"..."!==e))}const i=s.match(/^\s*(\w+)\s*\(([^)]*)\)/);if(i){const e=i[2];return e.split(",").map((e=>{const t=e.trim(),n=t.indexOf(":");return(n>-1?t.slice(0,n):t).split(/\s+/)[0].replace(/[{}[\]]/g,"")})).filter((e=>e&&"..."!==e))}return}catch(e){return}}(s,e),a=e.value;e.value=e.value.replace(/^([*]+)/g,"*");const o=`/*${e.value.replace(/\r\n?/g,"\n")}*/`;if(!/^\/\*\*[\s\S]+?\*\/$/.test(o))return;const c=t.parse(o,{spacing:"preserve",tokenizers:[fe(),e=>pe(e.tag)?e:he("preserve")(e),ge(),je("preserve")]})[0];if(e.value="",!c)return;!function(e){e.tags=e.tags.map((({tag:e,type:t,name:n,description:r,default:s,...a})=>{e=e||"",t=t||"",n=n||"",r=r||"",s=s?.trim();const o=e.indexOf("{");-1!==o&&"}"===e[e.length-1]&&(t=e.slice(o+1,-1)+" "+t,e=e.slice(0,o));const i=(e=e.trim()).toLowerCase(),c=Se.findIndex((([e])=>e.toLowerCase()===i));return c>=0?e=Se[c][0]:i in Y&&(e=Y[i]),t=t.trim(),(n=n.trim())&&X.includes(e)&&(r=`${n} ${r}`,n=""),t&&Z.includes(e)&&(r=`{${t}} ${r}`,t=""),{tag:e,type:t,name:n,description:r,default:s,...a}}))}(c),function(e){let t=e.description||"";e.description="",e.tags=e.tags.filter((({description:e,tag:n})=>n.toLowerCase()!==w||(e.trim()&&(t+="\n\n"+e),!1))),t&&e.tags.unshift({tag:w,description:t,name:void 0,type:void 0,source:[],optional:!1,problems:[]})}(c);const p=function(e,t,n){const r=t.split(/\r\n?|\n/g)[e.loc.start.line-1];let s=0,a=0;for(let t=e.loc.start.column-1;t>=0;t--){const e=r[t];if(" "===e)s++;else{if("\t"!==e)break;a++}}return n.printWidth-(s+a*n.tabWidth)-" * ".length}(e,s,i);let d=0,u=0,m=0,g=c.tags.map((({type:e,optional:t,...n})=>(e&&(e=e.replace(/[=]$/,(()=>(t=!0,""))),e=function(e,t){const n=[];let r=e.replace(/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/g,(e=>(n.push(e),`String$${n.length-1}$`)));return r.includes("`")?e:(r=t(r),r.replace(/String\$(\d+)\$/g,((e,t)=>n[t])))}(e,(e=>{e=(e=(e=(e=e.trim()).replace(/\.</g,"<")).replace(/\*/g," any ")).replace(/^\?\s*(\w+)$/,"$1 | null").replace(/^(\w+)\s*\?$/,"$1 | null");let t=!0;for(;t;)t=!1,e=e.replace(/(^|[^$\w\xA0-\uFFFF])Array\s*<((?:[^<>=]|=>|=(?!>)|<(?:[^<>=]|=>|=(?!>))+>)+)>/g,((e,n,r)=>(t=!0,`${n}(${r})[]`)));return e}))),{...n,type:e,optional:t})));g=$e(g,r,i),i.jsdocSeparateReturnsFromParam&&(g=g.flatMap(((e,t)=>e.tag===N&&g[t-1]?.tag===M?[J,e]:[e]))),i.jsdocAddDefaultToDescription&&(g=g.map(ve)),g=await Promise.all(g.map(Ie).map((async({type:e,...t})=>(e&&(e=await async function(e,t){try{const r="type name = ";let s=e,a=!1;return s.startsWith("...")&&(a=!0,s=`(${s.slice(3)})[]`),s=await n.format(`${r}${s}`,{...t,parser:"typescript",plugins:[],filepath:"file.ts"}),s=s.slice(r.length),s=s.replace(/^\s*/g,"").replace(/[;\n]*$/g,"").replace(/^\|/g,"").trim(),a&&(s="..."+s.replace(/\[\s*\]$/,"")),s}catch(t){return e}}(e,{...i,printWidth:p})),{...t,type:e})))).then((e=>e.map((({type:e,name:t,description:n,tag:r,...s})=>(ne.includes(r)&&(d=Math.max(d,r.length),u=Math.max(u,e.length),m=Math.max(m,t.length)),{type:e,name:t,description:n,tag:r,...s}))))),i.jsdocSeparateTagGroups&&(g=g.flatMap(((e,t)=>{const n=g[t-1];return n&&n.tag!==w&&n.tag!==S&&n.tag!==J.tag&&e.tag!==J.tag&&n.tag!==e.tag?[J,e]:[e]})));const f=g.filter((({description:e,tag:t})=>!(!e&&te.includes(t))));for(const[t,n]of f.entries()){const r=await me(n,t,f,{...i,printWidth:p},d,u,m);e.value+=r}e.value=e.value.trimEnd(),e.value&&(e.value=function(e,t,n){return"singleLine"===n.jsdocCommentLineStrategy&&0===oe(t.trim(),"\n")||"keep"===n.jsdocCommentLineStrategy&&0===oe(e,"\n")?`* ${t.trim()} `:`*${t.replace(/(\n(?!$))/g,"\n * ")}\n `}(a,e.value,i)),"cr"===l?e.value=e.value.replace(/\n/g,"\r"):"crlf"===l&&(e.value=e.value.replace(/\n/g,"\r\n"))}))),c.comments=c.comments.filter((e=>!(we(e)&&!e.value))),c};function $e(e,t,n){let r=!1,s=!1;const a={},o={},i=e.reduce(((e,t)=>{if((0===e.length||re.includes(t.tag)&&r)&&(r=!1,e.push([])),se.includes(t.tag)&&(r=!0),n.jsdocFormatImports&&t.tag===C){const r=function(e){const t=e.description.match(/([^\s\\,\\{\\}]+)?(?:[^\\{\\}]*)\{?([^\\{\\}]*)?\}?(?:\s+from\s+)[\\'\\"](\S+)[\\'\\"]/s);if(!t)return null;const n=t[1]||"",r=t[2]||"",s=t[3]||"",a=r.matchAll(/([^\s\\,\\{\\}]+)(?:\s+as\s+)?([^\s\\,\\{\\}]+)?/g),o=[];for(const e of a)o.push({name:e[1],alias:e[2]});return{spec:e,src:s,namedImports:o,defaultImport:n}}(t);if(r)if(n.jsdocMergeImports){if(a[r.src])return a[r.src].push(r),e;a[r.src]=[r]}else xe(r,n),o[r.spec.description]=r.src}return e[e.length-1].push(t),e}),[]);return n.jsdocFormatImports&&n.jsdocMergeImports&&Object.keys(a).forEach((e=>{const t=a[e],r=t[0].spec,{defaultImport:s,namedImports:i}=t.reduce(((e,t)=>(e.namedImports.push(...t.namedImports),t.defaultImport&&(e.defaultImport=t.defaultImport),e)),{namedImports:[],defaultImport:void 0});xe({src:e,defaultImport:s,namedImports:i,spec:r},n),o[r.description]=e})),e=i.flatMap(((e,r,a)=>(e.sort(((e,r)=>{if(t&&t.length>1&&e.tag===M&&r.tag===M){const n=t.indexOf(e.name),s=t.indexOf(r.name);return n>-1&&s>-1?n-s:0}if(n.jsdocFormatImports&&e.tag===C&&r.tag===C){const t=o[e.description]??e.description,n=o[r.description]??e.description,s=t.startsWith(".")?1:0,a=n.startsWith(".")?1:0;return s===a?t.localeCompare(n):s-a}return be(e.tag,n)-be(r.tag,n)})),a.length-1!==r&&e.push(J),r>0&&e[0]?.tag&&!re.includes(e[0].tag)&&(s=!0),e))),s?$e(e,t,n):e}function be(e,t){if(e===w&&!t.jsdocDescriptionTag)return-1;let n;return n=void 0!==t.jsdocTagsOrder?.[e]?t.jsdocTagsOrder[e]:ae[e],void 0===n?ae.other:n}function we(e){return"CommentBlock"===e.type||"Block"===e.type}const Se=Object.entries(ae);function ve(e){if(e.optional&&e.default){let{description:t}=e;return t=t.replace(/(?:\s*Default\s+is\s+`.*?`\.?)+/g,""),t&&!/[.\n]$/.test(t)&&(t+="."),t+=` Default is \`${e.default}\``,{...e,description:t.trim()}}return e}function Ie({name:e,optional:t,default:n,tag:r,type:s,source:a,description:o,...i}){if(pe(r)){const t=(a.find((e=>e.source.includes(`@${r}`)))?.source||"").match(/@default(Value)? (\[.*]|{.*}|\(.*\)|'.*'|".*"|`.*`| \w+)( ((?!\*\/).+))?/),n=t?.[2]||"",i=t?.[4]||"";t&&(s=n,e="",o=i)}else t&&(e?e=n?`[${e}=${n}]`:`[${e}]`:s=`${s} | undefined`);return{...i,tag:r,name:e,description:o,optional:t,type:s,source:a,default:n}}function xe(e,t){const{defaultImport:n,namedImports:r,src:s,spec:a}=e;r.sort(((e,t)=>(e.alias??e.name).localeCompare(t.alias??t.name)));const o=[];if(n&&o.push(n),r.length>0){const e=t.jsdocNamedImportLineSplitting&&r.length>1,n=r.map((t=>{const n=t.alias?`${t.name} as ${t.alias}`:`${t.name}`;return e?` ${n}`:n})).join(e?",\n":", "),s=e?`{\n${n}\n}`:t.jsdocNamedImportPadding?`{ ${n} }`:`{${n}}`;o.push(s)}a.description=`${o.join(", ")} from "${s}"`}const Le={jsdocSpaces:{name:"jsdocSpaces",type:"int",category:"jsdoc",default:1,description:"How many spaces will be used to separate tag elements."},jsdocDescriptionWithDot:{name:"jsdocDescriptionWithDot",type:"boolean",category:"jsdoc",default:!1,description:"Should dot be inserted at the end of description"},jsdocDescriptionTag:{name:"jsdocDescriptionTag",type:"boolean",category:"jsdoc",default:!1,description:"Should description tag be used"},jsdocVerticalAlignment:{name:"jsdocVerticalAlignment",type:"boolean",category:"jsdoc",default:!1,description:"Should tags, types, names and description be aligned"},jsdocKeepUnParseAbleExampleIndent:{name:"jsdocKeepUnParseAbleExampleIndent",type:"boolean",category:"jsdoc",default:!1,description:"Should unParseAble example (pseudo code or no js code) keep its indentation"},jsdocSingleLineComment:{name:"jsdocSingleLineComment",type:"boolean",category:"jsdoc",deprecated:"use jsdocCommentLineStrategy instead will be remove on v2",default:!0,description:"Should compact single line comment"},jsdocCommentLineStrategy:{name:"jsdocCommentLineStrategy",type:"choice",choices:[{value:"singleLine",description:"Should compact single line comment, if possible"},{value:"multiline",description:"Should compact multi line comment"},{value:"keep",description:"Should keep original line comment"}],category:"jsdoc",default:"singleLine",description:"How comments line should be"},jsdocSeparateReturnsFromParam:{name:"jsdocSeparateReturnsFromParam",type:"boolean",category:"jsdoc",default:!1,description:"Add an space between last @param and @returns"},jsdocSeparateTagGroups:{name:"jsdocSeparateTagGroups",type:"boolean",category:"jsdoc",default:!1,description:"Add an space between tag groups"},jsdocCapitalizeDescription:{name:"jsdocCapitalizeDescription",type:"boolean",category:"jsdoc",default:!0,description:"Should capitalize first letter of description"},tsdoc:{name:"tsdoc",type:"boolean",category:"jsdoc",default:!1,description:"Should format as tsdoc"},jsdocPrintWidth:{name:"jsdocPrintWidth",type:"int",category:"jsdoc",default:void 0,description:"If You don't set value to jsdocPrintWidth, the printWidth will be use as jsdocPrintWidth."},jsdocAddDefaultToDescription:{name:"jsdocAddDefaultToDescription",type:"boolean",category:"jsdoc",default:!0,description:"Add Default value of a param to end description"},jsdocPreferCodeFences:{name:"jsdocPreferCodeFences",type:"boolean",category:"jsdoc",default:!1,description:'Prefer to render code blocks using "fences" (triple backticks). If not set, blocks without a language tag will be rendered with a four space indentation.'},jsdocLineWrappingStyle:{name:"jsdocLineWrappingStyle",type:"choice",choices:[{value:"greedy",description:"Lines wrap as soon as they reach the print width"}],category:"jsdoc",default:"greedy",description:"Strategy for wrapping lines for the given print width. More options may be added in the future."},jsdocTagsOrder:{name:"jsdocTagsOrder",type:"string",category:"jsdoc",default:void 0,description:"How many spaces will be used to separate tag elements."},jsdocMergeImports:{name:"jsdocMergeImports",type:"boolean",category:"jsdoc",default:!0,description:"Merge all imports tags in the same block from the same source into one tag"},jsdocNamedImportPadding:{name:"jsdocNamedImportPadding",type:"boolean",category:"jsdoc",default:!1,description:"Whether or not to pad brackets for single line named imports"},jsdocNamedImportLineSplitting:{name:"jsdocNamedImportLineSplitting",type:"boolean",category:"jsdoc",default:!0,description:"Split import tags with multiple named imports into multiple lines"},jsdocFormatImports:{name:"jsdocFormatImports",type:"boolean",category:"jsdoc",default:!0,description:"Format import tags"}},Pe={jsdocSpaces:Le.jsdocSpaces.default,jsdocPrintWidth:Le.jsdocPrintWidth.default,jsdocDescriptionWithDot:Le.jsdocDescriptionWithDot.default,jsdocDescriptionTag:Le.jsdocDescriptionTag.default,jsdocVerticalAlignment:Le.jsdocVerticalAlignment.default,jsdocKeepUnParseAbleExampleIndent:Le.jsdocKeepUnParseAbleExampleIndent.default,jsdocSingleLineComment:Le.jsdocSingleLineComment.default,jsdocCommentLineStrategy:Le.jsdocCommentLineStrategy.default,jsdocSeparateReturnsFromParam:Le.jsdocSeparateReturnsFromParam.default,jsdocSeparateTagGroups:Le.jsdocSeparateTagGroups.default,jsdocCapitalizeDescription:Le.jsdocCapitalizeDescription.default,jsdocAddDefaultToDescription:Le.jsdocAddDefaultToDescription.default,jsdocPreferCodeFences:Le.jsdocPreferCodeFences.default,tsdoc:Le.tsdoc.default,jsdocLineWrappingStyle:Le.jsdocLineWrappingStyle.default,jsdocTagsOrder:Le.jsdocTagsOrder.default,jsdocFormatImports:Le.jsdocFormatImports.default,jsdocNamedImportPadding:Le.jsdocNamedImportPadding.default,jsdocMergeImports:Le.jsdocMergeImports.default,jsdocNamedImportLineSplitting:Le.jsdocNamedImportLineSplitting.default},We={get babel(){return Ce(l.default.parsers.babel,"babel")},get"babel-flow"(){return Ce(l.default.parsers["babel-flow"],"babel-flow")},get"babel-ts"(){return Ce(l.default.parsers["babel-ts"],"babel-ts")},get flow(){return Ce(p.default.parsers.flow,"flow")},get typescript(){return Ce(d.default.parsers.typescript,"typescript")},get"jsdoc-parser"(){return Ce(l.default.parsers["babel-ts"],"babel-ts")}};function Ce(e,t){const n=ye(e.parse,t),r=(a,o)=>{!function(e){e.jsdocTagsOrder&&(e.jsdocTagsOrder=JSON.parse(e.jsdocTagsOrder));if(e.jsdocCommentLineStrategy)return;e.jsdocSingleLineComment?e.jsdocCommentLineStrategy="singleLine":e.jsdocCommentLineStrategy="multiline"}(o);const i=le(t,o);if(!i)return e.preprocess?e.preprocess(a,o):a;const c=i.preprocess||e.preprocess;return Object.assign(s,{...s,...i,preprocess:r,parse:n}),c?c(a,o):a},s={...e,preprocess:r,parse:n};return s}e.defaultOptions=Pe,e.options=Le,e.parsers=We,Object.defineProperty(e,"__esModule",{value:!0})})); |
+84
-5
| import { parse, tokenizers } from "comment-parser"; | ||
| import { addStarsToTheBeginningOfTheLines, convertToModernType, formatType, detectEndOfLine, findPluginByParser, isDefaultTag, } from "./utils.js"; | ||
| import { DESCRIPTION, PARAM, RETURNS, EXAMPLE } from "./tags.js"; | ||
| import { DESCRIPTION, PARAM, RETURNS, EXAMPLE, IMPORT } from "./tags.js"; | ||
| import { TAGS_DESCRIPTION_NEEDED, TAGS_GROUP_HEAD, TAGS_GROUP_CONDITION, TAGS_NAMELESS, TAGS_ORDER, TAGS_SYNONYMS, TAGS_TYPELESS, TAGS_VERTICALLY_ALIGN_ABLE, } from "./roles.js"; | ||
@@ -147,4 +147,5 @@ import { stringify } from "./stringify.js"; | ||
| let shouldSortAgain = false; | ||
| tags = tags | ||
| .reduce((tagGroups, cur) => { | ||
| const importDetailsBySource = {}; | ||
| const importSourceByDescription = {}; | ||
| const tagGroups = tags.reduce((tagGroups, cur) => { | ||
| if (tagGroups.length === 0 || | ||
@@ -158,6 +159,38 @@ (TAGS_GROUP_HEAD.includes(cur.tag) && canGroupNextTags)) { | ||
| } | ||
| if (options.jsdocFormatImports && cur.tag === IMPORT) { | ||
| const importDetails = getImportDetails(cur); | ||
| if (importDetails) { | ||
| if (options.jsdocMergeImports) { | ||
| const existingImport = importDetailsBySource[importDetails.src]; | ||
| if (existingImport) { | ||
| importDetailsBySource[importDetails.src].push(importDetails); | ||
| return tagGroups; | ||
| } | ||
| importDetailsBySource[importDetails.src] = [importDetails]; | ||
| } | ||
| else { | ||
| writeImportDetailsToSpec(importDetails, options); | ||
| importSourceByDescription[importDetails.spec.description] = | ||
| importDetails.src; | ||
| } | ||
| } | ||
| } | ||
| tagGroups[tagGroups.length - 1].push(cur); | ||
| return tagGroups; | ||
| }, []) | ||
| .flatMap((tagGroup, index, array) => { | ||
| }, []); | ||
| if (options.jsdocFormatImports && options.jsdocMergeImports) { | ||
| Object.keys(importDetailsBySource).forEach((src) => { | ||
| const importDetails = importDetailsBySource[src]; | ||
| const firstImpSpec = importDetails[0].spec; | ||
| const { defaultImport, namedImports } = importDetails.reduce((prev, curr) => { | ||
| prev.namedImports.push(...curr.namedImports); | ||
| if (curr.defaultImport) | ||
| prev.defaultImport = curr.defaultImport; | ||
| return prev; | ||
| }, { namedImports: [], defaultImport: undefined }); | ||
| writeImportDetailsToSpec({ src, defaultImport, namedImports, spec: firstImpSpec }, options); | ||
| importSourceByDescription[firstImpSpec.description] = src; | ||
| }); | ||
| } | ||
| tags = tagGroups.flatMap((tagGroup, index, array) => { | ||
| tagGroup.sort((a, b) => { | ||
@@ -175,2 +208,11 @@ if (paramsOrder && | ||
| } | ||
| if (options.jsdocFormatImports && a.tag === IMPORT && b.tag === IMPORT) { | ||
| const aSrc = importSourceByDescription[a.description] ?? a.description; | ||
| const bSrc = importSourceByDescription[b.description] ?? a.description; | ||
| const aVal = aSrc.startsWith(".") ? 1 : 0; | ||
| const bVal = bSrc.startsWith(".") ? 1 : 0; | ||
| if (aVal === bVal) | ||
| return aSrc.localeCompare(bSrc); | ||
| return aVal - bVal; | ||
| } | ||
| return (getTagOrderWeight(a.tag, options) - getTagOrderWeight(b.tag, options)); | ||
@@ -402,2 +444,39 @@ }); | ||
| } | ||
| function writeImportDetailsToSpec(importDetails, options) { | ||
| const { defaultImport, namedImports, src, spec } = importDetails; | ||
| namedImports.sort((a, b) => (a.alias ?? a.name).localeCompare(b.alias ?? b.name)); | ||
| const importClauses = []; | ||
| if (defaultImport) | ||
| importClauses.push(defaultImport); | ||
| if (namedImports.length > 0) { | ||
| const makeMultiLine = options.jsdocNamedImportLineSplitting && namedImports.length > 1; | ||
| const typeString = namedImports | ||
| .map((t) => { | ||
| const val = t.alias ? `${t.name} as ${t.alias}` : `${t.name}`; | ||
| return makeMultiLine ? ` ${val}` : val; | ||
| }) | ||
| .join(makeMultiLine ? ",\n" : ", "); | ||
| const namedImportClause = makeMultiLine | ||
| ? `{\n${typeString}\n}` | ||
| : options.jsdocNamedImportPadding | ||
| ? `{ ${typeString} }` | ||
| : `{${typeString}}`; | ||
| importClauses.push(namedImportClause); | ||
| } | ||
| spec.description = `${importClauses.join(", ")} from "${src}"`; | ||
| } | ||
| function getImportDetails(spec) { | ||
| const match = spec.description.match(/([^\s\\,\\{\\}]+)?(?:[^\\{\\}]*)\{?([^\\{\\}]*)?\}?(?:\s+from\s+)[\\'\\"](\S+)[\\'\\"]/s); | ||
| if (!match) | ||
| return null; | ||
| const defaultImport = match[1] || ""; | ||
| const namedImportsClause = match[2] || ""; | ||
| const src = match[3] || ""; | ||
| const typeMatches = namedImportsClause.matchAll(/([^\s\\,\\{\\}]+)(?:\s+as\s+)?([^\s\\,\\{\\}]+)?/g); | ||
| const namedImports = []; | ||
| for (const typeMatch of typeMatches) { | ||
| namedImports.push({ name: typeMatch[1], alias: typeMatch[2] }); | ||
| } | ||
| return { spec, src, namedImports, defaultImport }; | ||
| } | ||
| //# sourceMappingURL=parser.js.map |
+1
-0
@@ -33,2 +33,3 @@ declare const TAGS_SYNONYMS: { | ||
| declare const TAGS_ORDER: { | ||
| import: number; | ||
| remarks: number; | ||
@@ -35,0 +36,0 @@ privateRemarks: number; |
+6
-1
@@ -1,2 +0,2 @@ | ||
| import { ABSTRACT, ASYNC, AUGMENTS, AUTHOR, BORROWS, CALLBACK, CATEGORY, CLASS, CONSTANT, DEFAULT, DEFAULT_VALUE, DEPRECATED, DESCRIPTION, EXAMPLE, EXTENDS, EXTERNAL, FILE, FIRES, FLOW, FUNCTION, IGNORE, LICENSE, MEMBER, MEMBEROF, MODULE, NAMESPACE, OVERLOAD, OVERRIDE, PARAM, PRIVATE, PRIVATE_REMARKS, PROPERTY, PROVIDES_MODULE, REMARKS, RETURNS, SEE, SINCE, TEMPLATE, THROWS, TODO, TYPE, SATISFIES, TYPE_PARAM, TYPEDEF, VERSION, YIELDS, } from "./tags.js"; | ||
| import { ABSTRACT, ASYNC, AUGMENTS, AUTHOR, BORROWS, CALLBACK, CATEGORY, CLASS, CONSTANT, DEFAULT, DEFAULT_VALUE, DEPRECATED, DESCRIPTION, EXAMPLE, EXTENDS, EXTERNAL, FILE, FIRES, FLOW, FUNCTION, IGNORE, IMPORT, LICENSE, MEMBER, MEMBEROF, MODULE, NAMESPACE, OVERLOAD, OVERRIDE, PARAM, PRIVATE, PRIVATE_REMARKS, PROPERTY, PROVIDES_MODULE, REMARKS, RETURNS, SEE, SINCE, TEMPLATE, THROWS, TODO, TYPE, SATISFIES, TYPE_PARAM, TYPEDEF, VERSION, YIELDS, } from "./tags.js"; | ||
| const TAGS_SYNONYMS = { | ||
@@ -33,2 +33,3 @@ arg: PARAM, | ||
| LICENSE, | ||
| IMPORT, | ||
| MODULE, | ||
@@ -55,2 +56,3 @@ NAMESPACE, | ||
| IGNORE, | ||
| IMPORT, | ||
| LICENSE, | ||
@@ -70,2 +72,3 @@ MODULE, | ||
| ...TAGS_DEFAULT, | ||
| IMPORT, | ||
| MEMBEROF, | ||
@@ -80,2 +83,3 @@ MODULE, | ||
| EXAMPLE, | ||
| IMPORT, | ||
| PRIVATE_REMARKS, | ||
@@ -119,2 +123,3 @@ REMARKS, | ||
| const TAGS_ORDER = { | ||
| [IMPORT]: 0, | ||
| [REMARKS]: 1, | ||
@@ -121,0 +126,0 @@ [PRIVATE_REMARKS]: 2, |
@@ -74,3 +74,3 @@ import { formatDescription, descriptionEndLine, } from "./descriptionFormatter.js"; | ||
| if (TAGS_PEV_FORMATE_DESCRIPTION.includes(tag) || | ||
| !TAGS_ORDER[tag]) { | ||
| TAGS_ORDER[tag] === undefined) { | ||
| descriptionString = description; | ||
@@ -77,0 +77,0 @@ } |
+2
-1
@@ -23,2 +23,3 @@ import { Spec } from "comment-parser"; | ||
| declare const IGNORE = "ignore"; | ||
| declare const IMPORT = "import"; | ||
| declare const LICENSE = "license"; | ||
@@ -50,2 +51,2 @@ declare const MEMBER = "member"; | ||
| declare const SPACE_TAG_DATA: Spec; | ||
| export { ABSTRACT, ASYNC, AUGMENTS, AUTHOR, BORROWS, CALLBACK, CATEGORY, CLASS, CONSTANT, DEFAULT, DEFAULT_VALUE, DEPRECATED, DESCRIPTION, EXAMPLE, EXTENDS, EXTERNAL, FILE, FIRES, FLOW, FUNCTION, IGNORE, LICENSE, MEMBER, MEMBEROF, MODULE, NAMESPACE, OVERLOAD, OVERRIDE, PARAM, PRIVATE_REMARKS, PRIVATE, PROPERTY, PROVIDES_MODULE, REMARKS, RETURNS, SEE, SINCE, TEMPLATE, THROWS, TODO, TYPE, TYPE_PARAM, TYPEDEF, SATISFIES, VERSION, YIELDS, SPACE_TAG_DATA, }; | ||
| export { ABSTRACT, ASYNC, AUGMENTS, AUTHOR, BORROWS, CALLBACK, CATEGORY, CLASS, CONSTANT, DEFAULT, DEFAULT_VALUE, DEPRECATED, DESCRIPTION, EXAMPLE, EXTENDS, EXTERNAL, FILE, FIRES, FLOW, FUNCTION, IGNORE, IMPORT, LICENSE, MEMBER, MEMBEROF, MODULE, NAMESPACE, OVERLOAD, OVERRIDE, PARAM, PRIVATE_REMARKS, PRIVATE, PROPERTY, PROVIDES_MODULE, REMARKS, RETURNS, SEE, SINCE, TEMPLATE, THROWS, TODO, TYPE, TYPE_PARAM, TYPEDEF, SATISFIES, VERSION, YIELDS, SPACE_TAG_DATA, }; |
+2
-1
@@ -22,2 +22,3 @@ const ABSTRACT = "abstract"; | ||
| const IGNORE = "ignore"; | ||
| const IMPORT = "import"; | ||
| const LICENSE = "license"; | ||
@@ -57,3 +58,3 @@ const MEMBER = "member"; | ||
| }; | ||
| export { ABSTRACT, ASYNC, AUGMENTS, AUTHOR, BORROWS, CALLBACK, CATEGORY, CLASS, CONSTANT, DEFAULT, DEFAULT_VALUE, DEPRECATED, DESCRIPTION, EXAMPLE, EXTENDS, EXTERNAL, FILE, FIRES, FLOW, FUNCTION, IGNORE, LICENSE, MEMBER, MEMBEROF, MODULE, NAMESPACE, OVERLOAD, OVERRIDE, PARAM, PRIVATE_REMARKS, PRIVATE, PROPERTY, PROVIDES_MODULE, REMARKS, RETURNS, SEE, SINCE, TEMPLATE, THROWS, TODO, TYPE, TYPE_PARAM, TYPEDEF, SATISFIES, VERSION, YIELDS, SPACE_TAG_DATA, }; | ||
| export { ABSTRACT, ASYNC, AUGMENTS, AUTHOR, BORROWS, CALLBACK, CATEGORY, CLASS, CONSTANT, DEFAULT, DEFAULT_VALUE, DEPRECATED, DESCRIPTION, EXAMPLE, EXTENDS, EXTERNAL, FILE, FIRES, FLOW, FUNCTION, IGNORE, IMPORT, LICENSE, MEMBER, MEMBEROF, MODULE, NAMESPACE, OVERLOAD, OVERRIDE, PARAM, PRIVATE_REMARKS, PRIVATE, PROPERTY, PROVIDES_MODULE, REMARKS, RETURNS, SEE, SINCE, TEMPLATE, THROWS, TODO, TYPE, TYPE_PARAM, TYPEDEF, SATISFIES, VERSION, YIELDS, SPACE_TAG_DATA, }; | ||
| //# sourceMappingURL=tags.js.map |
+4
-0
@@ -19,2 +19,6 @@ import { ParserOptions } from "prettier"; | ||
| jsdocTagsOrder?: Record<string, number>; | ||
| jsdocFormatImports: boolean; | ||
| jsdocNamedImportPadding: boolean; | ||
| jsdocMergeImports: boolean; | ||
| jsdocNamedImportLineSplitting: boolean; | ||
| } | ||
@@ -21,0 +25,0 @@ export interface AllOptions extends ParserOptions, JsdocOptions { |
+1
-1
| { | ||
| "name": "prettier-plugin-jsdoc", | ||
| "version": "1.3.3", | ||
| "version": "1.5.0", | ||
| "description": "A Prettier plugin to format JSDoc comments.", | ||
@@ -5,0 +5,0 @@ "private": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
250603
8.85%3402
8.55%18
50%