Commit d033538c authored by David Sveningsson's avatar David Sveningsson
Browse files

fix(transform): expose `computeOffset`

parent 0e32355d
Pipeline #138009149 passed with stages
in 9 minutes and 23 seconds
......@@ -9,6 +9,11 @@ import { Source } from "../context";
const espree = require("espree");
const walk = require("acorn-walk");
export interface Position {
line: number;
column: number;
}
/* espree puts location information a bit different than estree */
declare module "estree" {
interface TemplateElement {
......@@ -29,9 +34,13 @@ function joinTemplateLiteral(nodes: ESTree.TemplateElement[]): string {
}
/**
* espree locations does not include offset, need to calculate it manually.
* Compute source offset from line and column and the given markup.
*
* @param position - Line and column.
* @param data - Source markup.
* @returns The byte offset into the markup which line and column corresponds to.
*/
function computeOffset(position: ESTree.Position, data: string): number {
export function computeOffset(position: Position, data: string): number {
let line = position.line;
let column = position.column + 1;
for (let i = 0; i < data.length; i++) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment