@jsenv/sourcemap 1.4.5 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/magic_source.js +5 -0
- package/src/sourcemap_edits.js +46 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/sourcemap",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@jridgewell/gen-mapping": "0.3.13",
|
|
17
17
|
"@jridgewell/sourcemap-codec": "1.6.0",
|
|
18
18
|
"@jridgewell/trace-mapping": "0.3.31",
|
|
19
|
-
"@jsenv/urls": "2.9.
|
|
19
|
+
"@jsenv/urls": "2.9.11",
|
|
20
20
|
"magic-string": "1.2.3",
|
|
21
21
|
"source-map-js": "1.2.1"
|
|
22
22
|
},
|
package/src/magic_source.js
CHANGED
|
@@ -28,6 +28,11 @@ export const createMagicSource = (content) => {
|
|
|
28
28
|
edits.push({ type: "replace", start, end, replacement });
|
|
29
29
|
magicString.overwrite(start, end, replacement);
|
|
30
30
|
},
|
|
31
|
+
insert: ({ position, text }) => {
|
|
32
|
+
touched = true;
|
|
33
|
+
edits.push({ type: "insert", position, text });
|
|
34
|
+
magicString.appendLeft(position, text);
|
|
35
|
+
},
|
|
31
36
|
remove: ({ start, end }) => {
|
|
32
37
|
touched = true;
|
|
33
38
|
edits.push({ type: "remove", start, end });
|
package/src/sourcemap_edits.js
CHANGED
|
@@ -37,6 +37,14 @@ export const applyContentEditsOnSourcemap = (sourcemap, { content, edits }) => {
|
|
|
37
37
|
prependText = edit.text + prependText;
|
|
38
38
|
continue;
|
|
39
39
|
}
|
|
40
|
+
if (edit.type === "insert") {
|
|
41
|
+
spans.push({
|
|
42
|
+
start: edit.position,
|
|
43
|
+
end: edit.position,
|
|
44
|
+
replacement: edit.text,
|
|
45
|
+
});
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
40
48
|
spans.push({
|
|
41
49
|
start: edit.start,
|
|
42
50
|
end: edit.end,
|
|
@@ -175,6 +183,8 @@ export const applyContentEditsOnSourcemap = (sourcemap, { content, edits }) => {
|
|
|
175
183
|
);
|
|
176
184
|
};
|
|
177
185
|
|
|
186
|
+
// decode() output is owned here: segments are moved (and their column
|
|
187
|
+
// mutated) into the shifted structure without copies
|
|
178
188
|
const decoded = decode(sourcemap.mappings);
|
|
179
189
|
const decodedShifted = [];
|
|
180
190
|
const pushSegment = (newLine, segment) => {
|
|
@@ -184,7 +194,30 @@ export const applyContentEditsOnSourcemap = (sourcemap, { content, edits }) => {
|
|
|
184
194
|
decodedShifted[newLine].push(segment);
|
|
185
195
|
};
|
|
186
196
|
for (let lineIndex = 0; lineIndex < decoded.length; lineIndex++) {
|
|
187
|
-
|
|
197
|
+
const segments = decoded[lineIndex];
|
|
198
|
+
// whole-line fast path: no edit starts at or before this line anymore,
|
|
199
|
+
// and the tail rebase does not apply to it — the line moves as one block
|
|
200
|
+
if (
|
|
201
|
+
lineIndex !== tailOldLine &&
|
|
202
|
+
(recordIndex === records.length ||
|
|
203
|
+
records[recordIndex].startLine > lineIndex)
|
|
204
|
+
) {
|
|
205
|
+
if (segments.length > 0) {
|
|
206
|
+
const newLine = lineIndex + lineDelta;
|
|
207
|
+
while (decodedShifted.length <= newLine) {
|
|
208
|
+
decodedShifted.push([]);
|
|
209
|
+
}
|
|
210
|
+
if (decodedShifted[newLine].length === 0) {
|
|
211
|
+
decodedShifted[newLine] = segments;
|
|
212
|
+
} else {
|
|
213
|
+
for (const segment of segments) {
|
|
214
|
+
decodedShifted[newLine].push(segment);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
for (const segment of segments) {
|
|
188
221
|
const column = segment[0];
|
|
189
222
|
while (
|
|
190
223
|
recordIndex < records.length &&
|
|
@@ -199,14 +232,19 @@ export const applyContentEditsOnSourcemap = (sourcemap, { content, edits }) => {
|
|
|
199
232
|
) {
|
|
200
233
|
continue;
|
|
201
234
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
235
|
+
let newLine;
|
|
236
|
+
let newColumn;
|
|
237
|
+
if (lineIndex === tailOldLine && column >= tailOldColumn) {
|
|
238
|
+
newLine = tailNewLine;
|
|
239
|
+
newColumn = tailNewColumn + (column - tailOldColumn);
|
|
240
|
+
} else {
|
|
241
|
+
newLine = lineIndex + lineDelta;
|
|
242
|
+
newColumn = column;
|
|
243
|
+
}
|
|
244
|
+
if (newColumn !== column) {
|
|
245
|
+
segment[0] = newColumn;
|
|
206
246
|
}
|
|
207
|
-
|
|
208
|
-
segmentShifted[0] = newColumn;
|
|
209
|
-
pushSegment(newLine, segmentShifted);
|
|
247
|
+
pushSegment(newLine, segment);
|
|
210
248
|
}
|
|
211
249
|
}
|
|
212
250
|
|