{"version":3,"sources":["../../src/eslint/getJSDocComment.js"],"names":["isCommentToken","token","type","getDecorator","sourceCode","tokenBefore","getTokenBefore","includeComments","value","looksLikeExport","astNode","getReducedASTNode","node","parent","includes","getCommentsBefore","length","test","getJSDocComment","settings","findJSDocComment","minLines","maxLines","currentNode","decorator","charAt","loc","start","line","end","reducedNode"],"mappings":";;;;;;;AAAA;;;;;;AAMA;;;;;;AAMA,MAAMA,cAAc,GAAIC,KAAD,IAAW;AAChC,SAAOA,KAAK,CAACC,IAAN,KAAe,MAAf,IAAyBD,KAAK,CAACC,IAAN,KAAe,OAAxC,IAAmDD,KAAK,CAACC,IAAN,KAAe,SAAzE;AACD,CAFD;;AAIA,MAAMC,YAAY,GAAG,CAACF,KAAD,EAAQG,UAAR,KAAuB;AAC1C,MAAIH,KAAK,IAAIA,KAAK,CAACC,IAAN,KAAe,YAA5B,EAA0C;AACxC,UAAMG,WAAW,GAAGD,UAAU,CAACE,cAAX,CAA0BL,KAA1B,EAAiC;AAACM,MAAAA,eAAe,EAAE;AAAlB,KAAjC,CAApB;;AACA,QAAIF,WAAW,IAAIA,WAAW,CAACH,IAAZ,KAAqB,YAApC,IAAoDG,WAAW,CAACG,KAAZ,KAAsB,GAA9E,EAAmF;AACjF,aAAOH,WAAP;AACD;AACF;;AAED,SAAO,KAAP;AACD,CATD;AAWA;;;;;;;;;AAOA,MAAMI,eAAe,GAAG,SAAlBA,eAAkB,CAAUC,OAAV,EAAmB;AACzC,SAAOA,OAAO,CAACR,IAAR,KAAiB,0BAAjB,IAA+CQ,OAAO,CAACR,IAAR,KAAiB,wBAAhE,IACLQ,OAAO,CAACR,IAAR,KAAiB,sBADZ,IACsCQ,OAAO,CAACR,IAAR,KAAiB,iBAD9D;AAED,CAHD;AAKA;;;;;;;;;;AAQA,MAAMS,iBAAiB,GAAG,SAApBA,iBAAoB,CAAUC,IAAV,EAAgBR,UAAhB,EAA4B;AAAA,MAC/CS,MAD+C,GACrCD,IADqC,CAC/CC,MAD+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B,WAAP,EAAoB;AAClBlB,MAAAA,WAAW,GAAGD,UAAU,CAACE,cAAX,CAA0BiB,WAA1B,EAAuC;AAAChB,QAAAA,eAAe,EAAE;AAAlB,OAAvC,CAAd;AACA,YAAMiB,SAAS,GAAGrB,YAAY,CAACE,WAAD,EAAcD,UAAd,CAA9B;;AACA,UAAIoB,SAAJ,EAAe;AACbD,QAAAA,WAAW,GAAGC,SAAd;AACA;AACD;;AACD,UAAI,CAACnB,WAAD,IAAgB,CAACL,cAAc,CAACK,WAAD,CAAnC,EAAkD;AAChD,eAAO,IAAP;AACD;;AACD,UAAIA,WAAW,CAACH,IAAZ,KAAqB,MAAzB,EAAiC;AAC/BqB,QAAAA,WAAW,GAAGlB,WAAd;AACA;AACD;;AACD;AACD;;AAED,QACEA,WAAW,CAACH,IAAZ,KAAqB,OAArB,IACAG,WAAW,CAACG,KAAZ,CAAkBiB,MAAlB,CAAyB,CAAzB,MAAgC,GADhC,IAEAF,WAAW,CAACG,GAAZ,CAAgBC,KAAhB,CAAsBC,IAAtB,GAA6BvB,WAAW,CAACqB,GAAZ,CAAgBG,GAAhB,CAAoBD,IAAjD,IAAyDP,QAFzD,IAGAE,WAAW,CAACG,GAAZ,CAAgBC,KAAhB,CAAsBC,IAAtB,GAA6BvB,WAAW,CAACqB,GAAZ,CAAgBG,GAAhB,CAAoBD,IAAjD,IAAyDN,QAJ3D,EAKE;AACA,aAAOjB,WAAP;AACD;;AAED,WAAO,IAAP;AACD,GAhCD;;AAkCA,QAAMyB,WAAW,GAAGnB,iBAAiB,CAACC,IAAD,EAAOR,UAAP,CAArC;AACA;;AACA,MAAI,CAAC0B,WAAL,EAAkB;AAChB,WAAO,IAAP;AACD;;AAED,SAAOV,gBAAgB,CAACU,WAAD,CAAvB;AACD,CAlDD;;eAqDeZ,e","sourcesContent":["/**\n * Obtained originally from {@link https://github.com/eslint/eslint/blob/master/lib/util/source-code.js#L313}\n *\n * @license MIT\n */\n\n/**\n * Checks if the given token is a comment token or not.\n *\n * @param {Token} token - The token to check.\n * @returns {boolean} `true` if the token is a comment token.\n */\nconst isCommentToken = (token) => {\n return token.type === 'Line' || token.type === 'Block' || token.type === 'Shebang';\n};\n\nconst getDecorator = (token, sourceCode) => {\n if (token && token.type === 'Identifier') {\n const tokenBefore = sourceCode.getTokenBefore(token, {includeComments: true});\n if (tokenBefore && tokenBefore.type === 'Punctuator' && tokenBefore.value === '@') {\n return tokenBefore;\n }\n }\n\n return false;\n};\n\n/**\n * Check to see if its a ES6 export declaration.\n *\n * @param {ASTNode} astNode An AST node.\n * @returns {boolean} whether the given node represents an export declaration.\n * @private\n */\nconst looksLikeExport = function (astNode) {\n return astNode.type === 'ExportDefaultDeclaration' || astNode.type === 'ExportNamedDeclaration' ||\n astNode.type === 'ExportAllDeclaration' || astNode.type === 'ExportSpecifier';\n};\n\n/**\n * Reduces the provided node to the appropriate node for evaluating JSDoc comment status.\n *\n * @param {ASTNode} node An AST node.\n * @param {SourceCode} sourceCode The ESLint SourceCode.\n * @returns {ASTNode} The AST node that can be evaluated for appropriate JSDoc comments.\n * @private\n */\nconst getReducedASTNode = function (node, sourceCode) {\n let {parent} = node;\n\n switch (node.type) {\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n case 'TSEnumDeclaration':\n case 'ClassDeclaration':\n case 'FunctionDeclaration':\n return looksLikeExport(parent) ? parent : node;\n\n case 'ClassExpression':\n case 'ObjectExpression':\n case 'ArrowFunctionExpression':\n case 'FunctionExpression':\n if (\n !['CallExpression', 'OptionalCallExpression', 'NewExpression'].includes(parent.type)\n ) {\n while (\n !sourceCode.getCommentsBefore(parent).length &&\n !/Function/u.test(parent.type) &&\n parent.type !== 'MethodDefinition' &&\n parent.type !== 'Property'\n ) {\n parent = parent.parent;\n\n if (!parent) {\n break;\n }\n }\n\n if (parent && parent.type !== 'FunctionDeclaration' && parent.type !== 'Program') {\n return parent;\n }\n }\n\n return node;\n\n default:\n return node;\n }\n};\n\n/**\n * Retrieves the JSDoc comment for a given node.\n *\n * @param {SourceCode} sourceCode The ESLint SourceCode\n * @param {ASTNode} node The AST node to get the comment for.\n * @param {object} settings The settings in context\n * @returns {Token|null} The Block comment token containing the JSDoc comment\n * for the given node or null if not found.\n * @public\n * @deprecated\n */\nconst getJSDocComment = function (sourceCode, node, settings) {\n /**\n * Checks for the presence of a JSDoc comment for the given node and returns it.\n *\n * @param {ASTNode} astNode The AST node to get the comment for.\n * @returns {Token|null} The Block comment token containing the JSDoc comment\n * for the given node or null if not found.\n * @private\n */\n const findJSDocComment = (astNode) => {\n const {minLines, maxLines} = settings;\n let currentNode = astNode;\n let tokenBefore = null;\n\n while (currentNode) {\n tokenBefore = sourceCode.getTokenBefore(currentNode, {includeComments: true});\n const decorator = getDecorator(tokenBefore, sourceCode);\n if (decorator) {\n currentNode = decorator;\n continue;\n }\n if (!tokenBefore || !isCommentToken(tokenBefore)) {\n return null;\n }\n if (tokenBefore.type === 'Line') {\n currentNode = tokenBefore;\n continue;\n }\n break;\n }\n\n if (\n tokenBefore.type === 'Block' &&\n tokenBefore.value.charAt(0) === '*' &&\n currentNode.loc.start.line - tokenBefore.loc.end.line >= minLines &&\n currentNode.loc.start.line - tokenBefore.loc.end.line <= maxLines\n ) {\n return tokenBefore;\n }\n\n return null;\n };\n\n const reducedNode = getReducedASTNode(node, sourceCode);\n /* istanbul ignore next */\n if (!reducedNode) {\n return null;\n }\n\n return findJSDocComment(reducedNode);\n};\n\nexport {getReducedASTNode};\nexport default getJSDocComment;\n"],"file":"getJSDocComment.js"}