jest-allure2-reporter
Version:
Idiomatic Jest reporter for Allure Framework
38 lines • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ASTHelper = void 0;
class ASTHelper {
#sourceFiles = new Map();
#nodes = new Map();
#ts;
constructor(ts) {
this.#ts = ts;
}
findNodeInAST(ast, lineNumber, columnNumber) {
const id = `${ast.fileName}:${lineNumber}:${columnNumber}`;
if (!this.#nodes.has(id)) {
const ts = this.#ts;
const pos = ast.getPositionOfLineAndCharacter(lineNumber - 1, columnNumber - 1);
// TODO: find a non-private API for `getTouchingToken`
const token = ts.getTouchingToken(ast, pos);
let node = token;
while (node.kind !== ts.SyntaxKind.CallExpression) {
node = node.parent;
}
this.#nodes.set(id, node);
return node;
}
return this.#nodes.get(id);
}
getAST(fileName) {
return this.#sourceFiles.get(fileName);
}
parseAST(fileName, content) {
const ts = this.#ts;
const ast = ts.createSourceFile(fileName, content, ts.ScriptTarget.Latest, true);
this.#sourceFiles.set(ast.fileName, ast);
return ast;
}
}
exports.ASTHelper = ASTHelper;
//# sourceMappingURL=ASTHelper.js.map