MCPcopy Create free account
hub / github.com/observablehq/framework / translate

Method translate

src/sourcemap.ts:70–94  ·  view source on GitHub ↗
(position: Position)

Source from the content-addressed store, hash-verified

68 return this;
69 }
70 translate(position: Position): Position {
71 let index = 0;
72 let ci: Position = {line: 1, column: 0};
73 let co: Position = {line: 1, column: 0};
74 for (const {start, end, value} of this._edits) {
75 if (start > index) {
76 const l = positionLength(this.input, index, start);
77 const ci2 = positionAdd(ci, l);
78 const co2 = positionAdd(co, l);
79 if (positionCompare(co2, position) > 0) break;
80 ci = ci2;
81 co = co2;
82 }
83 const il = positionLength(this.input, start, end);
84 const ol = positionLength(value);
85 const ci2 = positionAdd(ci, il);
86 const co2 = positionAdd(co, ol);
87 if (positionCompare(co2, position) > 0) return ci;
88 ci = ci2;
89 co = co2;
90 index = end;
91 }
92 const l = positionSubtract(position, co);
93 return positionAdd(ci, l);
94 }
95 trim(): typeof this {
96 const input = this.input;
97 if (input.startsWith("\n")) this.delete(0, 1); // TODO better trim

Callers 1

sourcemap-test.tsFile · 0.80

Calls 4

positionLengthFunction · 0.85
positionAddFunction · 0.85
positionCompareFunction · 0.85
positionSubtractFunction · 0.85

Tested by

no test coverage detected