Is there a way to get a line number of a node in typescript file using typescript compiler API?

105 views Asked by At

From this docs: https://github.com/Microsoft/TypeScript-wiki/blob/main/Using-the-Compiler-API.md#traversing-the-ast-with-a-little-linter, I can get the line number of the node in the given Abstract Syntax Tree.

function report(node: ts.Node, message: string) {
    const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
    console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`);
  }

Is there a way to get the line number of this node in the original typescript file?

0

There are 0 answers