Skip to content

Commit

Permalink
Merge branch 'noprint' into lint
Browse files Browse the repository at this point in the history
  • Loading branch information
bhsd-harry committed Nov 20, 2024
2 parents ace63b4 + dc31e8a commit 6dcfe1a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ export abstract class AstNode implements AstNodeBase {
return parentNode ?? this;
}

/**
* 将行列号转换为字符位置
* @param top 行号
* @param left 列号
*/
indexFromPos(top: number, left: number): number | undefined {
const lines = String(this).split('\n');
return top >= 0 && left >= 0 && top <= lines.length - 1 && left <= lines[top]!.length
? lines.slice(0, top).reduce((acc, cur) => acc + cur.length + 1, 0) + left
: undefined;
}

/**
* 将字符位置转换为行列号
* @param index 字符位置
Expand Down

0 comments on commit 6dcfe1a

Please sign in to comment.