eslint-codemod-utils
Version:
A collection of AST helper functions for more complex ESLint rule fixes.
23 lines (22 loc) • 704 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNodeAfterComment = void 0;
/**
* @example
* ```tsx
* // this is the search comment
* const findThisNode = 10
* ^^^^^^^^^^^^^^^^^^^^^^^
* ```
*/
function getNodeAfterComment(source, comment) {
// `eslint.SourceCode.getTokenAfter` expects the vanilla-ESLint `Comment`
// shape; cast across the thin-but-real shape difference between it and
// `TSESTree.Comment` (the runtime objects are the same).
const token = source.getTokenAfter(comment);
if (token) {
return source.getNodeByRangeIndex(token.range[1]);
}
return null;
}
exports.getNodeAfterComment = getNodeAfterComment;