Skip to content

⬅️ Back to Table of Contents

📄 convert-comments

📊 Analysis Summary

Metric Count
🔧 Functions 1
📦 Imports 3

📚 Table of Contents

🛠️ File Location:

📂 packages/typescript-estree/src/convert-comments.ts

📦 Imports

Name Source
TSESTree ./ts-estree
getLocFor ./node-utils
AST_TOKEN_TYPES ./ts-estree

Functions

convertComments(ast: ts.SourceFile): TSESTree.Comment[]

Convert all comments for the given AST.

Parameters:

  • ast any: the AST object

Returns: undefined the converted ESTreeComment

Tags: @private

Raw JSDoc
/**
 * Convert all comments for the given AST.
 * @param ast the AST object
 * @returns the converted ESTreeComment
 * @private
 */

Calls:

  • Array.from
  • tsutils.iterateComments
  • getLocFor (from ./node-utils)
Code
export function convertComments(ast: ts.SourceFile): TSESTree.Comment[] {
  return Array.from(
    tsutils.iterateComments(ast),
    ({ end, kind, pos, value }) => {
      const type =
        kind === ts.SyntaxKind.SingleLineCommentTrivia
          ? AST_TOKEN_TYPES.Line
          : AST_TOKEN_TYPES.Block;
      const range: TSESTree.Range = [pos, end];
      const loc = getLocFor(range, ast);

      return {
        type,
        loc,
        range,
        value,
      };
    },
  );
}

Generated by Syntax Scribe