yaml-unist-parser
Version:
A YAML parser that produces output compatible with unist
42 lines (40 loc) • 1.08 kB
JavaScript
import { createPosition } from "../factories/position.mjs";
import { transformComment } from "./comment.mjs";
import { transformContentProperties } from "./content.mjs";
import { transformNode } from "./transform.mjs";
//#region src/transforms/context.ts
var Context = class {
text;
comments = [];
#lineCounter;
constructor(text, lineCounter) {
this.text = text;
this.#lineCounter = lineCounter;
}
transformOffset(offset) {
const { line, col } = this.#lineCounter.linePos(offset);
return {
line,
column: col,
offset
};
}
transformRange(range) {
const [start, end] = range.map((position) => this.transformOffset(position));
return createPosition(start, end);
}
transformNode(node, props) {
return transformNode(node, this, props);
}
transformComment(node) {
const comment = transformComment(node, this);
this.comments.push(comment);
return comment;
}
transformContentProperties(node, tokens) {
return transformContentProperties(node, tokens, this);
}
};
var context_default = Context;
//#endregion
export { context_default as default };