1 line
17 KiB
Text
1 line
17 KiB
Text
|
|
{"version":3,"file":"tsMethodSignatureStyle.cjs","names":["_iterateJsdoc","_interopRequireDefault","require","_jsdocUtils","_jsdoccomment","e","__esModule","default","_default","exports","iterateJsdoc","context","indent","jsdoc","utils","functionType","options","enableFixer","checkType","tag","potentialType","type","parsedType","parseType","traverse","nde","parentNode","property","idx","key","reportJSDoc","objectField","obj","index","elements","indexOf","meta","quote","name","parameters","returnType","typeParameters","rewireByParsedType","intersection","object","convertToMethod","func","methods","methodIndexes","element","entries","push","methodIndex","toReversed","splice","convertToFunction","node","arrow","constructor","parenthesis","Error","funcs","removals","length","optional","readonly","right","removal","map","tags","filterTags","Boolean","tagMightHaveTypePosition","iterateAllJsdocs","docs","description","url","fixable","schema","enum","additionalProperties","properties","module"],"sources":["../../src/rules/tsMethodSignatureStyle.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\nimport {\n rewireByParsedType,\n} from '../jsdocUtils.js';\nimport {\n parse as parseType,\n traverse,\n} from '@es-joy/jsdoccomment';\n\nexport default iterateJsdoc(({\n context,\n indent,\n jsdoc,\n utils,\n}) => {\n const functionType = context.options[0] ?? 'property';\n const {\n enableFixer = true,\n } = context.options[1] ?? {};\n\n /**\n * @param {import('@es-joy/jsdoccomment').JsdocTagWithInline} tag\n */\n const checkType = (tag) => {\n const potentialType = tag.type;\n let parsedType;\n try {\n parsedType = parseType(\n /** @type {string} */ (potentialType), 'typescript',\n );\n } catch {\n return;\n }\n\n traverse(parsedType, (nde, parentNode) => {\n // @ts-expect-error Adding our own property for use below\n nde.parentNode = parentNode;\n });\n\n traverse(parsedType, (nde, parentNode, property, idx) => {\n switch (nde.type) {\n case 'JsdocTypeFunction': {\n if (functionType !== 'method') {\n break;\n }\n\n if (parentNode?.type === 'JsdocTypeObjectField' &&\n typeof parentNode.key === 'string'\n ) {\n utils.reportJSDoc(\n 'Found function property; prefer method signature.',\n tag,\n enableFixer ? () => {\n const objectField = parentNode;\n const obj =\n /**\n * @type {import('jsdoc-type-pratt-parser').ObjectFieldResult & {\n * parentNode: import('jsdoc-type-pratt-parser').ObjectResult\n * }}\n */\n (objectField).parentNode;\n\n const index = obj.elements.indexOf(parentNode);\n\n obj.elements[index] = {\n /* c8 ignore next 5 -- Guard */\n meta: nde.meta ?\n {\n quote: objectField.meta.quote,\n ...nde.meta,\n } :\n {\n quote: objectField.meta.quote,\n },\n name: /** @type {string} */ (objectField.key),\n parameters: nde.parameters,\n returnType: /** @type {import('jsdoc-type-pratt-parser').RootResult} */ (\n nde.returnType\n ),\n type: 'JsdocTypeMethodSignature',\n typeParameters: nde.typeParameters,\n };\n\n rewireByParsedType(jsdoc, tag, parsedType, indent);\n } : null,\n );\n break;\n }\n\n if (parentNode?.type === 'JsdocTypeParenthesis' &&\n // @ts-expect-error Our own added API\n parentNode.parentNode?.type === 'JsdocTypeIntersection' &&\n // @ts-expect-error Our own added API\n parentNode.parentNode.parentNode.type === 'JsdocTypeObj
|