projecte_ionic/node_modules/eslint-plugin-jsdoc/dist/eslint/getJSDocComment.js.map
2022-02-09 18:30:03 +01:00

1 line
13 KiB
Plaintext
Executable file

{"version":3,"sources":["../../src/eslint/getJSDocComment.js"],"names":["isCommentToken","token","type","getDecorator","sourceCode","value","nested","tokenBefore","getTokenBefore","includeComments","looksLikeExport","astNode","getTSFunctionComment","parent","grandparent","greatGrandparent","greatGreatGrandparent","invokedExpression","Set","allowableCommentNode","getReducedASTNode","node","has","getCommentsBefore","length","test","getJSDocComment","settings","findJSDocComment","minLines","maxLines","currentNode","decorator","charAt","loc","start","line","end","reducedNode"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,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,MAAI,CAACH,KAAL,EAAY;AACV,WAAO,KAAP;AACD;;AACD,MAAIA,KAAK,CAACC,IAAN,KAAe,YAAf,IAA+BD,KAAK,CAACI,KAAN,KAAgB,GAAnD,EAAwD;AACtD,QAAIC,MAAM,GAAG,CAAb;AACA,QAAIC,WAAW,GAAGN,KAAlB;;AACA,OAAG;AACDM,MAAAA,WAAW,GAAGH,UAAU,CAACI,cAAX,CAA0BD,WAA1B,EAAuC;AAACE,QAAAA,eAAe,EAAE;AAAlB,OAAvC,CAAd,CADC,CAED;;AACA,UAAIF,WAAW,IAAIA,WAAW,CAACL,IAAZ,KAAqB,YAAxC,EAAsD;AACpD,YAAIK,WAAW,CAACF,KAAZ,KAAsB,GAA1B,EAA+B;AAC7BC,UAAAA,MAAM;AACP;;AACD,YAAIC,WAAW,CAACF,KAAZ,KAAsB,GAA1B,EAA+B;AAC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cesContent":["/**\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) {\n return false;\n }\n if (token.type === 'Punctuator' && token.value === ')') {\n let nested = 0;\n let tokenBefore = token;\n do {\n tokenBefore = sourceCode.getTokenBefore(tokenBefore, {includeComments: true});\n // istanbul ignore if\n if (tokenBefore && tokenBefore.type === 'Punctuator') {\n if (tokenBefore.value === ')') {\n nested++;\n }\n if (tokenBefore.value === '(') {\n if (nested) {\n nested--;\n } else {\n break;\n }\n }\n }\n } while (tokenBefore);\n\n return tokenBefore;\n }\n if (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\nconst getTSFunctionComment = function (astNode) {\n const {parent} = astNode;\n const grandparent = parent.parent;\n const greatGrandparent = grandparent.parent;\n const greatGreatGrandparent = greatGrandparent && greatGrandparent.parent;\n\n // istanbul ignore if\n if (parent.type !== 'TSTypeAnnotation') {\n return astNode;\n }\n\n switch (grandparent.type) {\n case 'ClassProperty':\n case 'TSDeclareFunction':\n case 'TSMethodSignature':\n case 'TSPropertySignature':\n return grandparent;\n case 'ArrowFunctionExpression':\n // istanbul ignore else\n if (\n greatGrandparent.type === 'VariableDeclarator'\n\n // && greatGreatGrandparent.parent.type === 'VariableDeclaration'\n ) {\n return greatGreatGrandparent.parent;\n }\n\n // istanbul ignore next\n return astNode;\n case 'FunctionExpression':\n // istanbul ignore else\n if (greatGrandparent.type === 'MethodDefinition') {\n return greatGrandparent;\n }\n\n // Fallthrough\n default:\n // istanbul ignore if\n if (grandparent.type !== 'Identifier') {\n // istanbul ignore next\n return astNode;\n }\n }\n\n // istanbul ignore next\n switch (greatGrandparent.type) {\n case 'ArrowFunctionExpression':\n // istanbul ignore else\n if (\n greatGreatGrandparent.type === 'VariableDeclarator' &&\n greatGreatGrandparent.parent.type === 'VariableDeclaration'\n ) {\n return greatGreatGrandparent.parent;\n }\n\n // istanbul ignore next\n return astNode;\n case 'FunctionDeclaration':\n return greatGrandparent;\n case 'VariableDeclarator':\n // istanbul ignore else\n if (greatGreatGrandparent.type === 'VariableDeclaration') {\n return greatGreatGrandparent;\n }\n\n // Fallthrough\n default:\n // istanbul ignore next\n return astNode;\n }\n};\n\nconst invokedExpression = new Set(['CallExpression', 'OptionalCallExpression', 'NewExpression']);\nconst allowableCommentNode = new Set([\n 'VariableDeclaration',\n 'ExpressionStatement',\n 'MethodDefinition',\n 'Property',\n 'ObjectProperty',\n 'ClassProperty',\n]);\n\n/* eslint-disable complexity */\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 'TSFunctionType':\n return getTSFunctionComment(node);\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n case 'TSEnumDeclaration':\n case 'ClassDeclaration':\n case 'FunctionDeclaration':\n return looksLikeExport(parent) ? parent : node;\n\n case 'TSDeclareFunction':\n case 'ClassExpression':\n case 'ObjectExpression':\n case 'ArrowFunctionExpression':\n case 'TSEmptyBodyFunctionExpression':\n case 'FunctionExpression':\n if (\n !invokedExpression.has(parent.type)\n ) {\n while (\n !sourceCode.getCommentsBefore(parent).length &&\n !/Function/u.test(parent.type) &&\n !allowableCommentNode.has(parent.type)\n ) {\n parent = parent.parent;\n\n if (!parent) {\n break;\n }\n }\n if (parent && parent.type !== 'FunctionDeclaration' && parent.type !== 'Program') {\n if (parent.parent && parent.parent.type === 'ExportNamedDeclaration') {\n return parent.parent;\n }\n\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 */\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\n return findJSDocComment(reducedNode);\n};\n\nexport {\n getReducedASTNode, getJSDocComment, getDecorator,\n};\nexport default getJSDocComment;\n"],"file":"getJSDocComment.js"}