Skip to content

Commit 85961bb

Browse files
committed
Revert "TypeScript Sourcemap"
This reverts commit dab8785.
1 parent 2bf2342 commit 85961bb

File tree

1 file changed

+18
-31
lines changed

1 file changed

+18
-31
lines changed
Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
1-
const lineBreakG = /\r\n?|\n|\u2028|\u2029/g;
2-
3-
interface Edit {
4-
start: number;
5-
end: number;
6-
value: string;
7-
}
8-
9-
export interface Position {
10-
line: number;
11-
column: number;
12-
}
1+
import {lineBreakG} from "acorn";
132

143
export class Sourcemap {
15-
private readonly _input: string;
16-
private readonly _edits: Edit[];
174
constructor(input = "") {
185
this._input = input;
196
this._edits = [];
207
}
21-
private _bisectLeft(index: number): number {
8+
_bisectLeft(index) {
229
let lo = 0;
2310
let hi = this._edits.length;
2411
while (lo < hi) {
@@ -28,7 +15,7 @@ export class Sourcemap {
2815
}
2916
return lo;
3017
}
31-
private _bisectRight(index: number): number {
18+
_bisectRight(index) {
3219
let lo = 0;
3320
let hi = this._edits.length;
3421
while (lo < hi) {
@@ -38,25 +25,25 @@ export class Sourcemap {
3825
}
3926
return lo;
4027
}
41-
insertLeft(index: number, value: string): void {
28+
insertLeft(index, value) {
4229
this.replaceLeft(index, index, value);
4330
}
44-
insertRight(index: number, value: string): void {
31+
insertRight(index, value) {
4532
this.replaceRight(index, index, value);
4633
}
47-
delete(start: number, end: number): void {
34+
delete(start, end) {
4835
this.replaceRight(start, end, "");
4936
}
50-
replaceLeft(start: number, end: number, value: string): void {
37+
replaceLeft(start, end, value) {
5138
this._edits.splice(this._bisectLeft(start), 0, {start, end, value});
5239
}
53-
replaceRight(start: number, end: number, value: string): void {
40+
replaceRight(start, end, value) {
5441
this._edits.splice(this._bisectRight(start), 0, {start, end, value});
5542
}
56-
translate(position: Position): Position {
43+
translate(position) {
5744
let index = 0;
58-
let ci: Position = {line: 1, column: 0};
59-
let co: Position = {line: 1, column: 0};
45+
let ci = {line: 1, column: 0};
46+
let co = {line: 1, column: 0};
6047
for (const {start, end, value} of this._edits) {
6148
if (start > index) {
6249
const l = positionLength(this._input, index, start);
@@ -78,7 +65,7 @@ export class Sourcemap {
7865
const l = positionSubtract(position, co);
7966
return positionAdd(ci, l);
8067
}
81-
toString(): string {
68+
toString() {
8269
let output = "";
8370
let index = 0;
8471
for (const {start, end, value} of this._edits) {
@@ -91,13 +78,13 @@ export class Sourcemap {
9178
}
9279
}
9380

94-
function positionCompare(a: Position, b: Position): number {
81+
function positionCompare(a, b) {
9582
return a.line - b.line || a.column - b.column;
9683
}
9784

98-
function positionLength(input: string, start = 0, end = input.length): Position {
99-
let match: RegExpExecArray | null;
100-
let line = 0;
85+
function positionLength(input, start = 0, end = input.length) {
86+
let match,
87+
line = 0;
10188
lineBreakG.lastIndex = start;
10289
while ((match = lineBreakG.exec(input)) && match.index < end) {
10390
++line;
@@ -106,10 +93,10 @@ function positionLength(input: string, start = 0, end = input.length): Position
10693
return {line, column: end - start};
10794
}
10895

109-
function positionSubtract(b: Position, a: Position): Position {
96+
function positionSubtract(b, a) {
11097
return b.line === a.line ? {line: 0, column: b.column - a.column} : {line: b.line - a.line, column: b.column};
11198
}
11299

113-
function positionAdd(p: Position, l: Position): Position {
100+
function positionAdd(p, l) {
114101
return l.line === 0 ? {line: p.line, column: p.column + l.column} : {line: p.line + l.line, column: l.column};
115102
}

0 commit comments

Comments
 (0)