{"version":3,"file":"parseCommentStrategy.cjs","names":["_jsdoccomment","require","batchCacheBySourceCode","WeakMap","getOxParseStrategy","settings","oxParseStrategy","exports","isJsdocComment","comment","test","value","getBatchCache","sourceCode","indent","cacheByIndent","get","Map","set","existing","comments","getAllComments","filter","blocks","parseCommentBatch","cache","index","entries","block","parseCommentForSource","commentNode","parseComment"],"sources":["../src/parseCommentStrategy.js"],"sourcesContent":["import {\n  parseComment,\n  parseCommentBatch,\n} from '@ox-jsdoc/jsdoccomment';\n\n/**\n * @typedef {'single' | 'batch'} OxParseStrategy\n */\n\n/**\n * @typedef {import('estree').Comment | import('eslint').AST.Token | {\n *   value: string,\n *   range?: [number, number]\n * }} CommentNode\n */\n\n/**\n * @typedef {{\n *   oxParseStrategy?: OxParseStrategy\n * }} ParseSettings\n */\n\n/**\n * @type {WeakMap<\n *   import('eslint').SourceCode,\n *   Map<string, WeakMap<CommentNode, import('@ox-jsdoc/jsdoccomment').JsdocBlockWithInline>>\n * >}\n */\nconst batchCacheBySourceCode = new WeakMap();\n\n/**\n * @param {ParseSettings} settings\n * @returns {OxParseStrategy}\n */\nconst getOxParseStrategy = (settings) => {\n  return settings.oxParseStrategy === 'batch' ? 'batch' : 'single';\n};\n\n/**\n * @param {CommentNode} comment\n * @returns {boolean}\n */\nconst isJsdocComment = (comment) => {\n  return (/^\\*(?!\\*)/v).test(comment.value);\n};\n\n/**\n * @param {import('eslint').SourceCode} sourceCode\n * @param {string} indent\n * @returns {WeakMap<CommentNode, import('@ox-jsdoc/jsdoccomment').JsdocBlockWithInline>}\n */\nconst getBatchCache = (sourceCode, indent) => {\n  let cacheByIndent = batchCacheBySourceCode.get(sourceCode);\n  if (!cacheByIndent) {\n    cacheByIndent = new Map();\n    batchCacheBySourceCode.set(sourceCode, cacheByIndent);\n  }\n\n  const existing = cacheByIndent.get(indent);\n  if (existing) {\n    return existing;\n  }\n\n  const comments = /** @type {CommentNode[]} */ (\n    sourceCode.getAllComments()\n  ).filter(isJsdocComment);\n  const {\n    blocks,\n  } = parseCommentBatch(comments, {\n    indent,\n  });\n  const cache = new WeakMap();\n\n  for (const [\n    index,\n    comment,\n  ] of comments.entries()) {\n    const block = blocks[index];\n    if (block) {\n      cache.set(comment, block);\n    }\n  }\n\n  cacheByIndent.set(indent, cache);\n  return cache;\n};\n\n/**\n * @param {import('eslint').SourceCode} sourceCode\n * @param {CommentNode} commentNode\n * @param {ParseSettings} settings\n * @param {string} [indent]\n * @returns {import('@ox-jsdoc/jsdoccomment').JsdocBlockWithInline}\n */\nconst parseCommentForSource = (sourceCode, commentNode, settings, indent = '') => {\n  if (getOxParseStrategy(settings) !== 'batch') {\n    return parseComment(commentNode, indent);\n  }\n\n  const cache = getBatchCache(sourceCode, indent);\n  return cache.get(commentNode) ?? parseComment(commentNode, indent);\n};\n\nexport {\n  getOxParseStrategy,\n  parseCommentForSource,\n};\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAKA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,sBAAsB,GAAG,IAAIC,OAAO,CAAC,CAAC;;AAE5C;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAIC,QAAQ,IAAK;EACvC,OAAOA,QAAQ,CAACC,eAAe,KAAK,OAAO,GAAG,OAAO,GAAG,QAAQ;AAClE,CAAC;;AAED;AACA;AACA;AACA;AAHAC,OAAA,CAAAH,kBAAA,GAAAA,kBAAA;AAIA,MAAMI,cAAc,GAAIC,OAAO,IAAK;EAClC,OAAQ,YAAY,CAAEC,IAAI,CAACD,OAAO,CAACE,KAAK,CAAC;AAC3C,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,MAAMC,aAAa,GAAGA,CAACC,UAAU,EAAEC,MAAM,KAAK;EAC5C,IAAIC,aAAa,GAAGb,sBAAsB,CAACc,GAAG,CAACH,UAAU,CAAC;EAC1D,IAAI,C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