@forge-kit/plugin-source-map-prase 0.0.2 → 0.0.4

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.
Files changed (37) hide show
  1. package/dist/app.js +17 -19
  2. package/dist/node.js +2552 -0
  3. package/package.json +5 -3
  4. package/src/App.less +35 -26
  5. package/src/App.tsx +70 -23
  6. package/src/components/map-input-panel/index.less +71 -78
  7. package/src/components/map-input-panel/index.tsx +19 -20
  8. package/src/components/panel-card/index.less +16 -13
  9. package/src/components/panel-card/index.tsx +2 -2
  10. package/src/components/trace-chain/index.less +119 -120
  11. package/src/components/trace-chain/index.tsx +9 -7
  12. package/src/main.tsx +1 -1
  13. package/src/node/index.ts +6 -0
  14. package/src/{utils/source-map → node/trace/core}/base/registry.ts +14 -11
  15. package/src/{utils/source-map → node/trace/core}/base/types.ts +1 -0
  16. package/src/node/trace/core/domain/chain-slots.ts +33 -0
  17. package/src/{utils/source-map → node/trace/core}/domain/source-content.ts +15 -2
  18. package/src/node/trace/core/domain/trace-resolver.ts +179 -0
  19. package/src/node/trace/core/domain/view-model.ts +57 -0
  20. package/src/node/trace/resolve/context.ts +59 -0
  21. package/src/node/trace/resolve/index.ts +97 -0
  22. package/src/node/trace/resolve/input.ts +35 -0
  23. package/src/node/trace/resolve/snippet-limit.ts +35 -0
  24. package/src/node/trace/resolve/types.ts +37 -0
  25. package/src/node/trace/runner.ts +149 -0
  26. package/src/shared/trace-common.ts +104 -0
  27. package/src/shared/trace-contract.ts +29 -0
  28. package/src/types.ts +11 -0
  29. package/src/utils/trace-ui/index.ts +12 -0
  30. package/src/utils/trace-ui/state.ts +81 -0
  31. package/src/utils/source-map/domain/chain-slots.ts +0 -59
  32. package/src/utils/source-map/domain/trace-resolver.ts +0 -165
  33. package/src/utils/source-map/domain/view-model.ts +0 -20
  34. package/src/utils/source-map/facade/source-map-utils.ts +0 -212
  35. package/src/utils/source-map/index.ts +0 -18
  36. /package/src/{utils/source-map → node/trace/core}/base/constants.ts +0 -0
  37. /package/src/{utils/source-map → node/trace/core}/base/path.ts +0 -0
package/dist/node.js ADDED
@@ -0,0 +1,2552 @@
1
+ "use strict";
2
+ const node_perf_hooks = require("node:perf_hooks");
3
+ const promises = require("node:fs/promises");
4
+ const node_path = require("node:path");
5
+ const node_os = require("node:os");
6
+ var PluginOriginType;
7
+ (function(PluginOriginType2) {
8
+ PluginOriginType2["Local"] = "local";
9
+ PluginOriginType2["Remote"] = "remote";
10
+ })(PluginOriginType || (PluginOriginType = {}));
11
+ var InvokeType;
12
+ (function(InvokeType2) {
13
+ InvokeType2["invoke"] = "invoke";
14
+ })(InvokeType || (InvokeType = {}));
15
+ var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
16
+ var freeSelf = typeof self == "object" && self && self.Object === Object && self;
17
+ var root = freeGlobal || freeSelf || Function("return this")();
18
+ var Symbol$1 = root.Symbol;
19
+ var objectProto$1 = Object.prototype;
20
+ var hasOwnProperty = objectProto$1.hasOwnProperty;
21
+ var nativeObjectToString$1 = objectProto$1.toString;
22
+ var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : void 0;
23
+ function getRawTag(value) {
24
+ var isOwn = hasOwnProperty.call(value, symToStringTag$1), tag = value[symToStringTag$1];
25
+ try {
26
+ value[symToStringTag$1] = void 0;
27
+ var unmasked = true;
28
+ } catch (e) {
29
+ }
30
+ var result = nativeObjectToString$1.call(value);
31
+ if (unmasked) {
32
+ if (isOwn) {
33
+ value[symToStringTag$1] = tag;
34
+ } else {
35
+ delete value[symToStringTag$1];
36
+ }
37
+ }
38
+ return result;
39
+ }
40
+ var objectProto = Object.prototype;
41
+ var nativeObjectToString = objectProto.toString;
42
+ function objectToString(value) {
43
+ return nativeObjectToString.call(value);
44
+ }
45
+ var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
46
+ var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : void 0;
47
+ function baseGetTag(value) {
48
+ if (value == null) {
49
+ return value === void 0 ? undefinedTag : nullTag;
50
+ }
51
+ return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
52
+ }
53
+ function isObject(value) {
54
+ var type = typeof value;
55
+ return value != null && (type == "object" || type == "function");
56
+ }
57
+ var asyncTag = "[object AsyncFunction]", funcTag = "[object Function]", genTag = "[object GeneratorFunction]", proxyTag = "[object Proxy]";
58
+ function isFunction(value) {
59
+ if (!isObject(value)) {
60
+ return false;
61
+ }
62
+ var tag = baseGetTag(value);
63
+ return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
64
+ }
65
+ const defineInvokeMethod = (methods) => methods;
66
+ const registerInvokeMethod = (methods) => {
67
+ if (!process?.send || !process.on)
68
+ return;
69
+ const reply = (response) => process.send?.(response);
70
+ process.on("message", async (message) => {
71
+ try {
72
+ if (message.type !== InvokeType.invoke || !message.method)
73
+ return;
74
+ const { [message.method]: handler } = methods;
75
+ if (!handler || !isFunction(handler))
76
+ throw new Error(`handler is not found: method=${message.method}`);
77
+ const result = await handler(...message.args || []);
78
+ reply({ success: true, result });
79
+ } catch (error) {
80
+ const errorText = error instanceof Error ? error.stack || error.message : String(error);
81
+ reply({ success: false, error: errorText });
82
+ }
83
+ });
84
+ };
85
+ const MAX_TRACE_DEPTH = 20;
86
+ const DEFAULT_CONTEXT_LINE_RADIUS$1 = 3;
87
+ const normalizePath = (input) => input.replace(/\\/g, "/").trim();
88
+ const getBaseName = (input) => {
89
+ const normalized = normalizePath(input);
90
+ const tokens = normalized.split("/");
91
+ return tokens[tokens.length - 1] || normalized;
92
+ };
93
+ const stripMapExt = (input) => input.endsWith(".map") ? input.slice(0, -4) : input;
94
+ const joinPath = (...parts) => {
95
+ return parts.map((part) => normalizePath(part)).filter(Boolean).join("/").replace(/\/{2,}/g, "/");
96
+ };
97
+ const registerSourceMap = (input) => {
98
+ const { registry, key, sourceMapRecord } = input;
99
+ const normalized = normalizePath(key);
100
+ if (!normalized) return registry;
101
+ const nextRegistry = { ...registry, [normalized]: sourceMapRecord };
102
+ const baseName = getBaseName(normalized);
103
+ if (!nextRegistry[baseName]) nextRegistry[baseName] = sourceMapRecord;
104
+ return nextRegistry;
105
+ };
106
+ const listSourceMapRecords = (sourceMaps) => {
107
+ const map = /* @__PURE__ */ new Map();
108
+ Object.values(sourceMaps).forEach((record) => {
109
+ if (map.has(record.mapFileName)) return;
110
+ map.set(record.mapFileName, record);
111
+ });
112
+ return Array.from(map.values());
113
+ };
114
+ const getSourceMapByFileName = (sourceMaps, fileName) => {
115
+ const normalized = normalizePath(fileName);
116
+ return sourceMaps[normalized] ?? sourceMaps[getBaseName(normalized)];
117
+ };
118
+ const getSourceMapByMapFileName = (sourceMaps, mapFileName) => {
119
+ return listSourceMapRecords(sourceMaps).find((item) => item.mapFileName === mapFileName);
120
+ };
121
+ const buildRegistryFromChainSlots = (slots) => {
122
+ let registry = {};
123
+ const orderedMapFileNames = [];
124
+ slots.forEach((slot) => {
125
+ const { sourceMapRecord: record } = slot;
126
+ if (!record) return;
127
+ orderedMapFileNames.push(record.mapFileName);
128
+ registry = registerSourceMap({ registry, key: record.mapFileName, sourceMapRecord: record });
129
+ registry = registerSourceMap({ registry, key: stripMapExt(record.mapFileName), sourceMapRecord: record });
130
+ if (record.rawSourceMap.file) {
131
+ registry = registerSourceMap({ registry, key: record.rawSourceMap.file, sourceMapRecord: record });
132
+ }
133
+ });
134
+ return { registry, orderedMapFileNames };
135
+ };
136
+ const getAutoEntryFileNameFromSlots = (slots) => {
137
+ const firstValidSlot = slots.find((slot) => slot.sourceMapRecord);
138
+ if (!firstValidSlot?.sourceMapRecord) return "";
139
+ const mappedFile = firstValidSlot.sourceMapRecord.rawSourceMap.file;
140
+ if (mappedFile) return normalizePath(mappedFile);
141
+ return stripMapExt(firstValidSlot.sourceMapRecord.mapFileName);
142
+ };
143
+ const toDisplayLocation = (location) => ({ ...location });
144
+ const MAX_EXCERPT_CHARS = 12e3;
145
+ const COLUMN_WINDOW_CHARS = 4e3;
146
+ const truncateLineByColumn = (line, targetColumn = 0) => {
147
+ if (line.length <= MAX_EXCERPT_CHARS) return line;
148
+ const halfWindow = Math.floor(COLUMN_WINDOW_CHARS / 2);
149
+ const start = Math.max(0, targetColumn - halfWindow);
150
+ const end = Math.min(line.length, start + COLUMN_WINDOW_CHARS);
151
+ const head = start > 0 ? "…[truncated]…" : "";
152
+ const tail = end < line.length ? "…[truncated]…" : "";
153
+ return `${head}${line.slice(start, end)}${tail}`;
154
+ };
155
+ const truncateExcerpt = (code) => {
156
+ if (code.length <= MAX_EXCERPT_CHARS) return code;
157
+ return `${code.slice(0, MAX_EXCERPT_CHARS)}
158
+ ...[truncated ${code.length - MAX_EXCERPT_CHARS} chars]...`;
159
+ };
160
+ const createCodeExcerpt = (input) => {
161
+ const {
162
+ fullCode,
163
+ targetLine,
164
+ radius = DEFAULT_CONTEXT_LINE_RADIUS$1,
165
+ targetColumn = 0
166
+ } = input;
167
+ const lines = fullCode.split(/\r?\n/);
168
+ if (lines.length === 0) {
169
+ return { code: truncateExcerpt(fullCode), highlightLine: targetLine };
170
+ }
171
+ const safeTarget = Math.min(Math.max(targetLine, 1), lines.length);
172
+ if (lines.length === 1) {
173
+ return { code: truncateLineByColumn(lines[0], targetColumn), highlightLine: 1 };
174
+ }
175
+ const start = Math.max(1, safeTarget - radius);
176
+ const end = Math.min(lines.length, safeTarget + radius);
177
+ return {
178
+ code: truncateExcerpt(lines.slice(start - 1, end).join("\n")),
179
+ highlightLine: safeTarget - start + 1
180
+ };
181
+ };
182
+ const findSourceCodeMatch = (hop, sourceMapRecord) => {
183
+ if (!hop.output) return null;
184
+ const { sources = [], sourcesContent = [], sourceRoot = "" } = sourceMapRecord.rawSourceMap;
185
+ const outputFile = normalizePath(hop.output.fileName);
186
+ const outputBaseName = getBaseName(outputFile);
187
+ const sourceIndex = sources.findIndex((source) => {
188
+ const normalizedSource = normalizePath(source);
189
+ const sourceWithRoot = joinPath(sourceRoot, normalizedSource);
190
+ return normalizedSource === outputFile || sourceWithRoot === outputFile || outputFile.endsWith(`/${normalizedSource}`) || outputFile.endsWith(`/${sourceWithRoot}`) || getBaseName(normalizedSource) === outputBaseName || getBaseName(sourceWithRoot) === outputBaseName;
191
+ });
192
+ if (sourceIndex < 0) return null;
193
+ const code = sourcesContent[sourceIndex];
194
+ if (!code) return null;
195
+ return {
196
+ code,
197
+ sourceFile: sources[sourceIndex],
198
+ location: toDisplayLocation(hop.output)
199
+ };
200
+ };
201
+ const resolveSourceCodeFromTrace = (traceHops, sourceMaps, options = {}) => {
202
+ const sourceMapRecords = listSourceMapRecords(sourceMaps);
203
+ const sourceMapRecordByName = new Map(sourceMapRecords.map((record) => [record.mapFileName, record]));
204
+ const { onlyLastMap = false, lastMapFileName } = options;
205
+ for (let index = traceHops.length - 1; index >= 0; index--) {
206
+ const hop = traceHops[index];
207
+ if (!hop.output || !hop.mapFileName) continue;
208
+ if (onlyLastMap && lastMapFileName && hop.mapFileName !== lastMapFileName) continue;
209
+ const sourceMapRecord = sourceMapRecordByName.get(hop.mapFileName);
210
+ if (!sourceMapRecord) continue;
211
+ const match = findSourceCodeMatch(hop, sourceMapRecord);
212
+ if (!match) continue;
213
+ return {
214
+ code: match.code,
215
+ sourceFile: match.sourceFile,
216
+ lineNumber: match.location.lineNumber,
217
+ columnNumber: match.location.columnNumber
218
+ };
219
+ }
220
+ return null;
221
+ };
222
+ const getLastResolvedOutput = (traceHops) => {
223
+ for (let index = traceHops.length - 1; index >= 0; index--) {
224
+ const output = traceHops[index].output;
225
+ if (output) return output;
226
+ }
227
+ return null;
228
+ };
229
+ var sourceMap = {};
230
+ var sourceMapGenerator = {};
231
+ var base64Vlq = {};
232
+ var base64 = {};
233
+ var hasRequiredBase64;
234
+ function requireBase64() {
235
+ if (hasRequiredBase64) return base64;
236
+ hasRequiredBase64 = 1;
237
+ var intToCharMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
238
+ base64.encode = function(number) {
239
+ if (0 <= number && number < intToCharMap.length) {
240
+ return intToCharMap[number];
241
+ }
242
+ throw new TypeError("Must be between 0 and 63: " + number);
243
+ };
244
+ base64.decode = function(charCode) {
245
+ var bigA = 65;
246
+ var bigZ = 90;
247
+ var littleA = 97;
248
+ var littleZ = 122;
249
+ var zero = 48;
250
+ var nine = 57;
251
+ var plus = 43;
252
+ var slash = 47;
253
+ var littleOffset = 26;
254
+ var numberOffset = 52;
255
+ if (bigA <= charCode && charCode <= bigZ) {
256
+ return charCode - bigA;
257
+ }
258
+ if (littleA <= charCode && charCode <= littleZ) {
259
+ return charCode - littleA + littleOffset;
260
+ }
261
+ if (zero <= charCode && charCode <= nine) {
262
+ return charCode - zero + numberOffset;
263
+ }
264
+ if (charCode == plus) {
265
+ return 62;
266
+ }
267
+ if (charCode == slash) {
268
+ return 63;
269
+ }
270
+ return -1;
271
+ };
272
+ return base64;
273
+ }
274
+ var hasRequiredBase64Vlq;
275
+ function requireBase64Vlq() {
276
+ if (hasRequiredBase64Vlq) return base64Vlq;
277
+ hasRequiredBase64Vlq = 1;
278
+ var base642 = requireBase64();
279
+ var VLQ_BASE_SHIFT = 5;
280
+ var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
281
+ var VLQ_BASE_MASK = VLQ_BASE - 1;
282
+ var VLQ_CONTINUATION_BIT = VLQ_BASE;
283
+ function toVLQSigned(aValue) {
284
+ return aValue < 0 ? (-aValue << 1) + 1 : (aValue << 1) + 0;
285
+ }
286
+ function fromVLQSigned(aValue) {
287
+ var isNegative = (aValue & 1) === 1;
288
+ var shifted = aValue >> 1;
289
+ return isNegative ? -shifted : shifted;
290
+ }
291
+ base64Vlq.encode = function base64VLQ_encode(aValue) {
292
+ var encoded = "";
293
+ var digit;
294
+ var vlq = toVLQSigned(aValue);
295
+ do {
296
+ digit = vlq & VLQ_BASE_MASK;
297
+ vlq >>>= VLQ_BASE_SHIFT;
298
+ if (vlq > 0) {
299
+ digit |= VLQ_CONTINUATION_BIT;
300
+ }
301
+ encoded += base642.encode(digit);
302
+ } while (vlq > 0);
303
+ return encoded;
304
+ };
305
+ base64Vlq.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
306
+ var strLen = aStr.length;
307
+ var result = 0;
308
+ var shift = 0;
309
+ var continuation, digit;
310
+ do {
311
+ if (aIndex >= strLen) {
312
+ throw new Error("Expected more digits in base 64 VLQ value.");
313
+ }
314
+ digit = base642.decode(aStr.charCodeAt(aIndex++));
315
+ if (digit === -1) {
316
+ throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
317
+ }
318
+ continuation = !!(digit & VLQ_CONTINUATION_BIT);
319
+ digit &= VLQ_BASE_MASK;
320
+ result = result + (digit << shift);
321
+ shift += VLQ_BASE_SHIFT;
322
+ } while (continuation);
323
+ aOutParam.value = fromVLQSigned(result);
324
+ aOutParam.rest = aIndex;
325
+ };
326
+ return base64Vlq;
327
+ }
328
+ var util = {};
329
+ var hasRequiredUtil;
330
+ function requireUtil() {
331
+ if (hasRequiredUtil) return util;
332
+ hasRequiredUtil = 1;
333
+ (function(exports) {
334
+ function getArg(aArgs, aName, aDefaultValue) {
335
+ if (aName in aArgs) {
336
+ return aArgs[aName];
337
+ } else if (arguments.length === 3) {
338
+ return aDefaultValue;
339
+ } else {
340
+ throw new Error('"' + aName + '" is a required argument.');
341
+ }
342
+ }
343
+ exports.getArg = getArg;
344
+ var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
345
+ var dataUrlRegexp = /^data:.+\,.+$/;
346
+ function urlParse(aUrl) {
347
+ var match = aUrl.match(urlRegexp);
348
+ if (!match) {
349
+ return null;
350
+ }
351
+ return {
352
+ scheme: match[1],
353
+ auth: match[2],
354
+ host: match[3],
355
+ port: match[4],
356
+ path: match[5]
357
+ };
358
+ }
359
+ exports.urlParse = urlParse;
360
+ function urlGenerate(aParsedUrl) {
361
+ var url = "";
362
+ if (aParsedUrl.scheme) {
363
+ url += aParsedUrl.scheme + ":";
364
+ }
365
+ url += "//";
366
+ if (aParsedUrl.auth) {
367
+ url += aParsedUrl.auth + "@";
368
+ }
369
+ if (aParsedUrl.host) {
370
+ url += aParsedUrl.host;
371
+ }
372
+ if (aParsedUrl.port) {
373
+ url += ":" + aParsedUrl.port;
374
+ }
375
+ if (aParsedUrl.path) {
376
+ url += aParsedUrl.path;
377
+ }
378
+ return url;
379
+ }
380
+ exports.urlGenerate = urlGenerate;
381
+ var MAX_CACHED_INPUTS = 32;
382
+ function lruMemoize(f) {
383
+ var cache = [];
384
+ return function(input) {
385
+ for (var i = 0; i < cache.length; i++) {
386
+ if (cache[i].input === input) {
387
+ var temp = cache[0];
388
+ cache[0] = cache[i];
389
+ cache[i] = temp;
390
+ return cache[0].result;
391
+ }
392
+ }
393
+ var result = f(input);
394
+ cache.unshift({
395
+ input,
396
+ result
397
+ });
398
+ if (cache.length > MAX_CACHED_INPUTS) {
399
+ cache.pop();
400
+ }
401
+ return result;
402
+ };
403
+ }
404
+ var normalize = lruMemoize(function normalize2(aPath) {
405
+ var path = aPath;
406
+ var url = urlParse(aPath);
407
+ if (url) {
408
+ if (!url.path) {
409
+ return aPath;
410
+ }
411
+ path = url.path;
412
+ }
413
+ var isAbsolute = exports.isAbsolute(path);
414
+ var parts = [];
415
+ var start = 0;
416
+ var i = 0;
417
+ while (true) {
418
+ start = i;
419
+ i = path.indexOf("/", start);
420
+ if (i === -1) {
421
+ parts.push(path.slice(start));
422
+ break;
423
+ } else {
424
+ parts.push(path.slice(start, i));
425
+ while (i < path.length && path[i] === "/") {
426
+ i++;
427
+ }
428
+ }
429
+ }
430
+ for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
431
+ part = parts[i];
432
+ if (part === ".") {
433
+ parts.splice(i, 1);
434
+ } else if (part === "..") {
435
+ up++;
436
+ } else if (up > 0) {
437
+ if (part === "") {
438
+ parts.splice(i + 1, up);
439
+ up = 0;
440
+ } else {
441
+ parts.splice(i, 2);
442
+ up--;
443
+ }
444
+ }
445
+ }
446
+ path = parts.join("/");
447
+ if (path === "") {
448
+ path = isAbsolute ? "/" : ".";
449
+ }
450
+ if (url) {
451
+ url.path = path;
452
+ return urlGenerate(url);
453
+ }
454
+ return path;
455
+ });
456
+ exports.normalize = normalize;
457
+ function join(aRoot, aPath) {
458
+ if (aRoot === "") {
459
+ aRoot = ".";
460
+ }
461
+ if (aPath === "") {
462
+ aPath = ".";
463
+ }
464
+ var aPathUrl = urlParse(aPath);
465
+ var aRootUrl = urlParse(aRoot);
466
+ if (aRootUrl) {
467
+ aRoot = aRootUrl.path || "/";
468
+ }
469
+ if (aPathUrl && !aPathUrl.scheme) {
470
+ if (aRootUrl) {
471
+ aPathUrl.scheme = aRootUrl.scheme;
472
+ }
473
+ return urlGenerate(aPathUrl);
474
+ }
475
+ if (aPathUrl || aPath.match(dataUrlRegexp)) {
476
+ return aPath;
477
+ }
478
+ if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
479
+ aRootUrl.host = aPath;
480
+ return urlGenerate(aRootUrl);
481
+ }
482
+ var joined = aPath.charAt(0) === "/" ? aPath : normalize(aRoot.replace(/\/+$/, "") + "/" + aPath);
483
+ if (aRootUrl) {
484
+ aRootUrl.path = joined;
485
+ return urlGenerate(aRootUrl);
486
+ }
487
+ return joined;
488
+ }
489
+ exports.join = join;
490
+ exports.isAbsolute = function(aPath) {
491
+ return aPath.charAt(0) === "/" || urlRegexp.test(aPath);
492
+ };
493
+ function relative(aRoot, aPath) {
494
+ if (aRoot === "") {
495
+ aRoot = ".";
496
+ }
497
+ aRoot = aRoot.replace(/\/$/, "");
498
+ var level = 0;
499
+ while (aPath.indexOf(aRoot + "/") !== 0) {
500
+ var index = aRoot.lastIndexOf("/");
501
+ if (index < 0) {
502
+ return aPath;
503
+ }
504
+ aRoot = aRoot.slice(0, index);
505
+ if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
506
+ return aPath;
507
+ }
508
+ ++level;
509
+ }
510
+ return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
511
+ }
512
+ exports.relative = relative;
513
+ var supportsNullProto = (function() {
514
+ var obj = /* @__PURE__ */ Object.create(null);
515
+ return !("__proto__" in obj);
516
+ })();
517
+ function identity(s) {
518
+ return s;
519
+ }
520
+ function toSetString(aStr) {
521
+ if (isProtoString(aStr)) {
522
+ return "$" + aStr;
523
+ }
524
+ return aStr;
525
+ }
526
+ exports.toSetString = supportsNullProto ? identity : toSetString;
527
+ function fromSetString(aStr) {
528
+ if (isProtoString(aStr)) {
529
+ return aStr.slice(1);
530
+ }
531
+ return aStr;
532
+ }
533
+ exports.fromSetString = supportsNullProto ? identity : fromSetString;
534
+ function isProtoString(s) {
535
+ if (!s) {
536
+ return false;
537
+ }
538
+ var length = s.length;
539
+ if (length < 9) {
540
+ return false;
541
+ }
542
+ if (s.charCodeAt(length - 1) !== 95 || s.charCodeAt(length - 2) !== 95 || s.charCodeAt(length - 3) !== 111 || s.charCodeAt(length - 4) !== 116 || s.charCodeAt(length - 5) !== 111 || s.charCodeAt(length - 6) !== 114 || s.charCodeAt(length - 7) !== 112 || s.charCodeAt(length - 8) !== 95 || s.charCodeAt(length - 9) !== 95) {
543
+ return false;
544
+ }
545
+ for (var i = length - 10; i >= 0; i--) {
546
+ if (s.charCodeAt(i) !== 36) {
547
+ return false;
548
+ }
549
+ }
550
+ return true;
551
+ }
552
+ function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
553
+ var cmp = strcmp(mappingA.source, mappingB.source);
554
+ if (cmp !== 0) {
555
+ return cmp;
556
+ }
557
+ cmp = mappingA.originalLine - mappingB.originalLine;
558
+ if (cmp !== 0) {
559
+ return cmp;
560
+ }
561
+ cmp = mappingA.originalColumn - mappingB.originalColumn;
562
+ if (cmp !== 0 || onlyCompareOriginal) {
563
+ return cmp;
564
+ }
565
+ cmp = mappingA.generatedColumn - mappingB.generatedColumn;
566
+ if (cmp !== 0) {
567
+ return cmp;
568
+ }
569
+ cmp = mappingA.generatedLine - mappingB.generatedLine;
570
+ if (cmp !== 0) {
571
+ return cmp;
572
+ }
573
+ return strcmp(mappingA.name, mappingB.name);
574
+ }
575
+ exports.compareByOriginalPositions = compareByOriginalPositions;
576
+ function compareByOriginalPositionsNoSource(mappingA, mappingB, onlyCompareOriginal) {
577
+ var cmp;
578
+ cmp = mappingA.originalLine - mappingB.originalLine;
579
+ if (cmp !== 0) {
580
+ return cmp;
581
+ }
582
+ cmp = mappingA.originalColumn - mappingB.originalColumn;
583
+ if (cmp !== 0 || onlyCompareOriginal) {
584
+ return cmp;
585
+ }
586
+ cmp = mappingA.generatedColumn - mappingB.generatedColumn;
587
+ if (cmp !== 0) {
588
+ return cmp;
589
+ }
590
+ cmp = mappingA.generatedLine - mappingB.generatedLine;
591
+ if (cmp !== 0) {
592
+ return cmp;
593
+ }
594
+ return strcmp(mappingA.name, mappingB.name);
595
+ }
596
+ exports.compareByOriginalPositionsNoSource = compareByOriginalPositionsNoSource;
597
+ function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
598
+ var cmp = mappingA.generatedLine - mappingB.generatedLine;
599
+ if (cmp !== 0) {
600
+ return cmp;
601
+ }
602
+ cmp = mappingA.generatedColumn - mappingB.generatedColumn;
603
+ if (cmp !== 0 || onlyCompareGenerated) {
604
+ return cmp;
605
+ }
606
+ cmp = strcmp(mappingA.source, mappingB.source);
607
+ if (cmp !== 0) {
608
+ return cmp;
609
+ }
610
+ cmp = mappingA.originalLine - mappingB.originalLine;
611
+ if (cmp !== 0) {
612
+ return cmp;
613
+ }
614
+ cmp = mappingA.originalColumn - mappingB.originalColumn;
615
+ if (cmp !== 0) {
616
+ return cmp;
617
+ }
618
+ return strcmp(mappingA.name, mappingB.name);
619
+ }
620
+ exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
621
+ function compareByGeneratedPositionsDeflatedNoLine(mappingA, mappingB, onlyCompareGenerated) {
622
+ var cmp = mappingA.generatedColumn - mappingB.generatedColumn;
623
+ if (cmp !== 0 || onlyCompareGenerated) {
624
+ return cmp;
625
+ }
626
+ cmp = strcmp(mappingA.source, mappingB.source);
627
+ if (cmp !== 0) {
628
+ return cmp;
629
+ }
630
+ cmp = mappingA.originalLine - mappingB.originalLine;
631
+ if (cmp !== 0) {
632
+ return cmp;
633
+ }
634
+ cmp = mappingA.originalColumn - mappingB.originalColumn;
635
+ if (cmp !== 0) {
636
+ return cmp;
637
+ }
638
+ return strcmp(mappingA.name, mappingB.name);
639
+ }
640
+ exports.compareByGeneratedPositionsDeflatedNoLine = compareByGeneratedPositionsDeflatedNoLine;
641
+ function strcmp(aStr1, aStr2) {
642
+ if (aStr1 === aStr2) {
643
+ return 0;
644
+ }
645
+ if (aStr1 === null) {
646
+ return 1;
647
+ }
648
+ if (aStr2 === null) {
649
+ return -1;
650
+ }
651
+ if (aStr1 > aStr2) {
652
+ return 1;
653
+ }
654
+ return -1;
655
+ }
656
+ function compareByGeneratedPositionsInflated(mappingA, mappingB) {
657
+ var cmp = mappingA.generatedLine - mappingB.generatedLine;
658
+ if (cmp !== 0) {
659
+ return cmp;
660
+ }
661
+ cmp = mappingA.generatedColumn - mappingB.generatedColumn;
662
+ if (cmp !== 0) {
663
+ return cmp;
664
+ }
665
+ cmp = strcmp(mappingA.source, mappingB.source);
666
+ if (cmp !== 0) {
667
+ return cmp;
668
+ }
669
+ cmp = mappingA.originalLine - mappingB.originalLine;
670
+ if (cmp !== 0) {
671
+ return cmp;
672
+ }
673
+ cmp = mappingA.originalColumn - mappingB.originalColumn;
674
+ if (cmp !== 0) {
675
+ return cmp;
676
+ }
677
+ return strcmp(mappingA.name, mappingB.name);
678
+ }
679
+ exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
680
+ function parseSourceMapInput(str) {
681
+ return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ""));
682
+ }
683
+ exports.parseSourceMapInput = parseSourceMapInput;
684
+ function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
685
+ sourceURL = sourceURL || "";
686
+ if (sourceRoot) {
687
+ if (sourceRoot[sourceRoot.length - 1] !== "/" && sourceURL[0] !== "/") {
688
+ sourceRoot += "/";
689
+ }
690
+ sourceURL = sourceRoot + sourceURL;
691
+ }
692
+ if (sourceMapURL) {
693
+ var parsed = urlParse(sourceMapURL);
694
+ if (!parsed) {
695
+ throw new Error("sourceMapURL could not be parsed");
696
+ }
697
+ if (parsed.path) {
698
+ var index = parsed.path.lastIndexOf("/");
699
+ if (index >= 0) {
700
+ parsed.path = parsed.path.substring(0, index + 1);
701
+ }
702
+ }
703
+ sourceURL = join(urlGenerate(parsed), sourceURL);
704
+ }
705
+ return normalize(sourceURL);
706
+ }
707
+ exports.computeSourceURL = computeSourceURL;
708
+ })(util);
709
+ return util;
710
+ }
711
+ var arraySet = {};
712
+ var hasRequiredArraySet;
713
+ function requireArraySet() {
714
+ if (hasRequiredArraySet) return arraySet;
715
+ hasRequiredArraySet = 1;
716
+ var util2 = requireUtil();
717
+ var has = Object.prototype.hasOwnProperty;
718
+ var hasNativeMap = typeof Map !== "undefined";
719
+ function ArraySet() {
720
+ this._array = [];
721
+ this._set = hasNativeMap ? /* @__PURE__ */ new Map() : /* @__PURE__ */ Object.create(null);
722
+ }
723
+ ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
724
+ var set = new ArraySet();
725
+ for (var i = 0, len = aArray.length; i < len; i++) {
726
+ set.add(aArray[i], aAllowDuplicates);
727
+ }
728
+ return set;
729
+ };
730
+ ArraySet.prototype.size = function ArraySet_size() {
731
+ return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
732
+ };
733
+ ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
734
+ var sStr = hasNativeMap ? aStr : util2.toSetString(aStr);
735
+ var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
736
+ var idx = this._array.length;
737
+ if (!isDuplicate || aAllowDuplicates) {
738
+ this._array.push(aStr);
739
+ }
740
+ if (!isDuplicate) {
741
+ if (hasNativeMap) {
742
+ this._set.set(aStr, idx);
743
+ } else {
744
+ this._set[sStr] = idx;
745
+ }
746
+ }
747
+ };
748
+ ArraySet.prototype.has = function ArraySet_has(aStr) {
749
+ if (hasNativeMap) {
750
+ return this._set.has(aStr);
751
+ } else {
752
+ var sStr = util2.toSetString(aStr);
753
+ return has.call(this._set, sStr);
754
+ }
755
+ };
756
+ ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
757
+ if (hasNativeMap) {
758
+ var idx = this._set.get(aStr);
759
+ if (idx >= 0) {
760
+ return idx;
761
+ }
762
+ } else {
763
+ var sStr = util2.toSetString(aStr);
764
+ if (has.call(this._set, sStr)) {
765
+ return this._set[sStr];
766
+ }
767
+ }
768
+ throw new Error('"' + aStr + '" is not in the set.');
769
+ };
770
+ ArraySet.prototype.at = function ArraySet_at(aIdx) {
771
+ if (aIdx >= 0 && aIdx < this._array.length) {
772
+ return this._array[aIdx];
773
+ }
774
+ throw new Error("No element indexed by " + aIdx);
775
+ };
776
+ ArraySet.prototype.toArray = function ArraySet_toArray() {
777
+ return this._array.slice();
778
+ };
779
+ arraySet.ArraySet = ArraySet;
780
+ return arraySet;
781
+ }
782
+ var mappingList = {};
783
+ var hasRequiredMappingList;
784
+ function requireMappingList() {
785
+ if (hasRequiredMappingList) return mappingList;
786
+ hasRequiredMappingList = 1;
787
+ var util2 = requireUtil();
788
+ function generatedPositionAfter(mappingA, mappingB) {
789
+ var lineA = mappingA.generatedLine;
790
+ var lineB = mappingB.generatedLine;
791
+ var columnA = mappingA.generatedColumn;
792
+ var columnB = mappingB.generatedColumn;
793
+ return lineB > lineA || lineB == lineA && columnB >= columnA || util2.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
794
+ }
795
+ function MappingList() {
796
+ this._array = [];
797
+ this._sorted = true;
798
+ this._last = { generatedLine: -1, generatedColumn: 0 };
799
+ }
800
+ MappingList.prototype.unsortedForEach = function MappingList_forEach(aCallback, aThisArg) {
801
+ this._array.forEach(aCallback, aThisArg);
802
+ };
803
+ MappingList.prototype.add = function MappingList_add(aMapping) {
804
+ if (generatedPositionAfter(this._last, aMapping)) {
805
+ this._last = aMapping;
806
+ this._array.push(aMapping);
807
+ } else {
808
+ this._sorted = false;
809
+ this._array.push(aMapping);
810
+ }
811
+ };
812
+ MappingList.prototype.toArray = function MappingList_toArray() {
813
+ if (!this._sorted) {
814
+ this._array.sort(util2.compareByGeneratedPositionsInflated);
815
+ this._sorted = true;
816
+ }
817
+ return this._array;
818
+ };
819
+ mappingList.MappingList = MappingList;
820
+ return mappingList;
821
+ }
822
+ var hasRequiredSourceMapGenerator;
823
+ function requireSourceMapGenerator() {
824
+ if (hasRequiredSourceMapGenerator) return sourceMapGenerator;
825
+ hasRequiredSourceMapGenerator = 1;
826
+ var base64VLQ = requireBase64Vlq();
827
+ var util2 = requireUtil();
828
+ var ArraySet = requireArraySet().ArraySet;
829
+ var MappingList = requireMappingList().MappingList;
830
+ function SourceMapGenerator(aArgs) {
831
+ if (!aArgs) {
832
+ aArgs = {};
833
+ }
834
+ this._file = util2.getArg(aArgs, "file", null);
835
+ this._sourceRoot = util2.getArg(aArgs, "sourceRoot", null);
836
+ this._skipValidation = util2.getArg(aArgs, "skipValidation", false);
837
+ this._ignoreInvalidMapping = util2.getArg(aArgs, "ignoreInvalidMapping", false);
838
+ this._sources = new ArraySet();
839
+ this._names = new ArraySet();
840
+ this._mappings = new MappingList();
841
+ this._sourcesContents = null;
842
+ }
843
+ SourceMapGenerator.prototype._version = 3;
844
+ SourceMapGenerator.fromSourceMap = function SourceMapGenerator_fromSourceMap(aSourceMapConsumer, generatorOps) {
845
+ var sourceRoot = aSourceMapConsumer.sourceRoot;
846
+ var generator = new SourceMapGenerator(Object.assign(generatorOps || {}, {
847
+ file: aSourceMapConsumer.file,
848
+ sourceRoot
849
+ }));
850
+ aSourceMapConsumer.eachMapping(function(mapping) {
851
+ var newMapping = {
852
+ generated: {
853
+ line: mapping.generatedLine,
854
+ column: mapping.generatedColumn
855
+ }
856
+ };
857
+ if (mapping.source != null) {
858
+ newMapping.source = mapping.source;
859
+ if (sourceRoot != null) {
860
+ newMapping.source = util2.relative(sourceRoot, newMapping.source);
861
+ }
862
+ newMapping.original = {
863
+ line: mapping.originalLine,
864
+ column: mapping.originalColumn
865
+ };
866
+ if (mapping.name != null) {
867
+ newMapping.name = mapping.name;
868
+ }
869
+ }
870
+ generator.addMapping(newMapping);
871
+ });
872
+ aSourceMapConsumer.sources.forEach(function(sourceFile) {
873
+ var sourceRelative = sourceFile;
874
+ if (sourceRoot !== null) {
875
+ sourceRelative = util2.relative(sourceRoot, sourceFile);
876
+ }
877
+ if (!generator._sources.has(sourceRelative)) {
878
+ generator._sources.add(sourceRelative);
879
+ }
880
+ var content = aSourceMapConsumer.sourceContentFor(sourceFile);
881
+ if (content != null) {
882
+ generator.setSourceContent(sourceFile, content);
883
+ }
884
+ });
885
+ return generator;
886
+ };
887
+ SourceMapGenerator.prototype.addMapping = function SourceMapGenerator_addMapping(aArgs) {
888
+ var generated = util2.getArg(aArgs, "generated");
889
+ var original = util2.getArg(aArgs, "original", null);
890
+ var source = util2.getArg(aArgs, "source", null);
891
+ var name = util2.getArg(aArgs, "name", null);
892
+ if (!this._skipValidation) {
893
+ if (this._validateMapping(generated, original, source, name) === false) {
894
+ return;
895
+ }
896
+ }
897
+ if (source != null) {
898
+ source = String(source);
899
+ if (!this._sources.has(source)) {
900
+ this._sources.add(source);
901
+ }
902
+ }
903
+ if (name != null) {
904
+ name = String(name);
905
+ if (!this._names.has(name)) {
906
+ this._names.add(name);
907
+ }
908
+ }
909
+ this._mappings.add({
910
+ generatedLine: generated.line,
911
+ generatedColumn: generated.column,
912
+ originalLine: original != null && original.line,
913
+ originalColumn: original != null && original.column,
914
+ source,
915
+ name
916
+ });
917
+ };
918
+ SourceMapGenerator.prototype.setSourceContent = function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
919
+ var source = aSourceFile;
920
+ if (this._sourceRoot != null) {
921
+ source = util2.relative(this._sourceRoot, source);
922
+ }
923
+ if (aSourceContent != null) {
924
+ if (!this._sourcesContents) {
925
+ this._sourcesContents = /* @__PURE__ */ Object.create(null);
926
+ }
927
+ this._sourcesContents[util2.toSetString(source)] = aSourceContent;
928
+ } else if (this._sourcesContents) {
929
+ delete this._sourcesContents[util2.toSetString(source)];
930
+ if (Object.keys(this._sourcesContents).length === 0) {
931
+ this._sourcesContents = null;
932
+ }
933
+ }
934
+ };
935
+ SourceMapGenerator.prototype.applySourceMap = function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
936
+ var sourceFile = aSourceFile;
937
+ if (aSourceFile == null) {
938
+ if (aSourceMapConsumer.file == null) {
939
+ throw new Error(
940
+ `SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, or the source map's "file" property. Both were omitted.`
941
+ );
942
+ }
943
+ sourceFile = aSourceMapConsumer.file;
944
+ }
945
+ var sourceRoot = this._sourceRoot;
946
+ if (sourceRoot != null) {
947
+ sourceFile = util2.relative(sourceRoot, sourceFile);
948
+ }
949
+ var newSources = new ArraySet();
950
+ var newNames = new ArraySet();
951
+ this._mappings.unsortedForEach(function(mapping) {
952
+ if (mapping.source === sourceFile && mapping.originalLine != null) {
953
+ var original = aSourceMapConsumer.originalPositionFor({
954
+ line: mapping.originalLine,
955
+ column: mapping.originalColumn
956
+ });
957
+ if (original.source != null) {
958
+ mapping.source = original.source;
959
+ if (aSourceMapPath != null) {
960
+ mapping.source = util2.join(aSourceMapPath, mapping.source);
961
+ }
962
+ if (sourceRoot != null) {
963
+ mapping.source = util2.relative(sourceRoot, mapping.source);
964
+ }
965
+ mapping.originalLine = original.line;
966
+ mapping.originalColumn = original.column;
967
+ if (original.name != null) {
968
+ mapping.name = original.name;
969
+ }
970
+ }
971
+ }
972
+ var source = mapping.source;
973
+ if (source != null && !newSources.has(source)) {
974
+ newSources.add(source);
975
+ }
976
+ var name = mapping.name;
977
+ if (name != null && !newNames.has(name)) {
978
+ newNames.add(name);
979
+ }
980
+ }, this);
981
+ this._sources = newSources;
982
+ this._names = newNames;
983
+ aSourceMapConsumer.sources.forEach(function(sourceFile2) {
984
+ var content = aSourceMapConsumer.sourceContentFor(sourceFile2);
985
+ if (content != null) {
986
+ if (aSourceMapPath != null) {
987
+ sourceFile2 = util2.join(aSourceMapPath, sourceFile2);
988
+ }
989
+ if (sourceRoot != null) {
990
+ sourceFile2 = util2.relative(sourceRoot, sourceFile2);
991
+ }
992
+ this.setSourceContent(sourceFile2, content);
993
+ }
994
+ }, this);
995
+ };
996
+ SourceMapGenerator.prototype._validateMapping = function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource, aName) {
997
+ if (aOriginal && typeof aOriginal.line !== "number" && typeof aOriginal.column !== "number") {
998
+ var message = "original.line and original.column are not numbers -- you probably meant to omit the original mapping entirely and only map the generated position. If so, pass null for the original mapping instead of an object with empty or null values.";
999
+ if (this._ignoreInvalidMapping) {
1000
+ if (typeof console !== "undefined" && console.warn) {
1001
+ console.warn(message);
1002
+ }
1003
+ return false;
1004
+ } else {
1005
+ throw new Error(message);
1006
+ }
1007
+ }
1008
+ if (aGenerated && "line" in aGenerated && "column" in aGenerated && aGenerated.line > 0 && aGenerated.column >= 0 && !aOriginal && !aSource && !aName) {
1009
+ return;
1010
+ } else if (aGenerated && "line" in aGenerated && "column" in aGenerated && aOriginal && "line" in aOriginal && "column" in aOriginal && aGenerated.line > 0 && aGenerated.column >= 0 && aOriginal.line > 0 && aOriginal.column >= 0 && aSource) {
1011
+ return;
1012
+ } else {
1013
+ var message = "Invalid mapping: " + JSON.stringify({
1014
+ generated: aGenerated,
1015
+ source: aSource,
1016
+ original: aOriginal,
1017
+ name: aName
1018
+ });
1019
+ if (this._ignoreInvalidMapping) {
1020
+ if (typeof console !== "undefined" && console.warn) {
1021
+ console.warn(message);
1022
+ }
1023
+ return false;
1024
+ } else {
1025
+ throw new Error(message);
1026
+ }
1027
+ }
1028
+ };
1029
+ SourceMapGenerator.prototype._serializeMappings = function SourceMapGenerator_serializeMappings() {
1030
+ var previousGeneratedColumn = 0;
1031
+ var previousGeneratedLine = 1;
1032
+ var previousOriginalColumn = 0;
1033
+ var previousOriginalLine = 0;
1034
+ var previousName = 0;
1035
+ var previousSource = 0;
1036
+ var result = "";
1037
+ var next;
1038
+ var mapping;
1039
+ var nameIdx;
1040
+ var sourceIdx;
1041
+ var mappings = this._mappings.toArray();
1042
+ for (var i = 0, len = mappings.length; i < len; i++) {
1043
+ mapping = mappings[i];
1044
+ next = "";
1045
+ if (mapping.generatedLine !== previousGeneratedLine) {
1046
+ previousGeneratedColumn = 0;
1047
+ while (mapping.generatedLine !== previousGeneratedLine) {
1048
+ next += ";";
1049
+ previousGeneratedLine++;
1050
+ }
1051
+ } else {
1052
+ if (i > 0) {
1053
+ if (!util2.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
1054
+ continue;
1055
+ }
1056
+ next += ",";
1057
+ }
1058
+ }
1059
+ next += base64VLQ.encode(mapping.generatedColumn - previousGeneratedColumn);
1060
+ previousGeneratedColumn = mapping.generatedColumn;
1061
+ if (mapping.source != null) {
1062
+ sourceIdx = this._sources.indexOf(mapping.source);
1063
+ next += base64VLQ.encode(sourceIdx - previousSource);
1064
+ previousSource = sourceIdx;
1065
+ next += base64VLQ.encode(mapping.originalLine - 1 - previousOriginalLine);
1066
+ previousOriginalLine = mapping.originalLine - 1;
1067
+ next += base64VLQ.encode(mapping.originalColumn - previousOriginalColumn);
1068
+ previousOriginalColumn = mapping.originalColumn;
1069
+ if (mapping.name != null) {
1070
+ nameIdx = this._names.indexOf(mapping.name);
1071
+ next += base64VLQ.encode(nameIdx - previousName);
1072
+ previousName = nameIdx;
1073
+ }
1074
+ }
1075
+ result += next;
1076
+ }
1077
+ return result;
1078
+ };
1079
+ SourceMapGenerator.prototype._generateSourcesContent = function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
1080
+ return aSources.map(function(source) {
1081
+ if (!this._sourcesContents) {
1082
+ return null;
1083
+ }
1084
+ if (aSourceRoot != null) {
1085
+ source = util2.relative(aSourceRoot, source);
1086
+ }
1087
+ var key = util2.toSetString(source);
1088
+ return Object.prototype.hasOwnProperty.call(this._sourcesContents, key) ? this._sourcesContents[key] : null;
1089
+ }, this);
1090
+ };
1091
+ SourceMapGenerator.prototype.toJSON = function SourceMapGenerator_toJSON() {
1092
+ var map = {
1093
+ version: this._version,
1094
+ sources: this._sources.toArray(),
1095
+ names: this._names.toArray(),
1096
+ mappings: this._serializeMappings()
1097
+ };
1098
+ if (this._file != null) {
1099
+ map.file = this._file;
1100
+ }
1101
+ if (this._sourceRoot != null) {
1102
+ map.sourceRoot = this._sourceRoot;
1103
+ }
1104
+ if (this._sourcesContents) {
1105
+ map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
1106
+ }
1107
+ return map;
1108
+ };
1109
+ SourceMapGenerator.prototype.toString = function SourceMapGenerator_toString() {
1110
+ return JSON.stringify(this.toJSON());
1111
+ };
1112
+ sourceMapGenerator.SourceMapGenerator = SourceMapGenerator;
1113
+ return sourceMapGenerator;
1114
+ }
1115
+ var sourceMapConsumer = {};
1116
+ var binarySearch = {};
1117
+ var hasRequiredBinarySearch;
1118
+ function requireBinarySearch() {
1119
+ if (hasRequiredBinarySearch) return binarySearch;
1120
+ hasRequiredBinarySearch = 1;
1121
+ (function(exports) {
1122
+ exports.GREATEST_LOWER_BOUND = 1;
1123
+ exports.LEAST_UPPER_BOUND = 2;
1124
+ function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
1125
+ var mid = Math.floor((aHigh - aLow) / 2) + aLow;
1126
+ var cmp = aCompare(aNeedle, aHaystack[mid], true);
1127
+ if (cmp === 0) {
1128
+ return mid;
1129
+ } else if (cmp > 0) {
1130
+ if (aHigh - mid > 1) {
1131
+ return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
1132
+ }
1133
+ if (aBias == exports.LEAST_UPPER_BOUND) {
1134
+ return aHigh < aHaystack.length ? aHigh : -1;
1135
+ } else {
1136
+ return mid;
1137
+ }
1138
+ } else {
1139
+ if (mid - aLow > 1) {
1140
+ return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
1141
+ }
1142
+ if (aBias == exports.LEAST_UPPER_BOUND) {
1143
+ return mid;
1144
+ } else {
1145
+ return aLow < 0 ? -1 : aLow;
1146
+ }
1147
+ }
1148
+ }
1149
+ exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
1150
+ if (aHaystack.length === 0) {
1151
+ return -1;
1152
+ }
1153
+ var index = recursiveSearch(
1154
+ -1,
1155
+ aHaystack.length,
1156
+ aNeedle,
1157
+ aHaystack,
1158
+ aCompare,
1159
+ aBias || exports.GREATEST_LOWER_BOUND
1160
+ );
1161
+ if (index < 0) {
1162
+ return -1;
1163
+ }
1164
+ while (index - 1 >= 0) {
1165
+ if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
1166
+ break;
1167
+ }
1168
+ --index;
1169
+ }
1170
+ return index;
1171
+ };
1172
+ })(binarySearch);
1173
+ return binarySearch;
1174
+ }
1175
+ var quickSort = {};
1176
+ var hasRequiredQuickSort;
1177
+ function requireQuickSort() {
1178
+ if (hasRequiredQuickSort) return quickSort;
1179
+ hasRequiredQuickSort = 1;
1180
+ function SortTemplate(comparator) {
1181
+ function swap(ary, x, y) {
1182
+ var temp = ary[x];
1183
+ ary[x] = ary[y];
1184
+ ary[y] = temp;
1185
+ }
1186
+ function randomIntInRange(low, high) {
1187
+ return Math.round(low + Math.random() * (high - low));
1188
+ }
1189
+ function doQuickSort(ary, comparator2, p, r) {
1190
+ if (p < r) {
1191
+ var pivotIndex = randomIntInRange(p, r);
1192
+ var i = p - 1;
1193
+ swap(ary, pivotIndex, r);
1194
+ var pivot = ary[r];
1195
+ for (var j = p; j < r; j++) {
1196
+ if (comparator2(ary[j], pivot, false) <= 0) {
1197
+ i += 1;
1198
+ swap(ary, i, j);
1199
+ }
1200
+ }
1201
+ swap(ary, i + 1, j);
1202
+ var q = i + 1;
1203
+ doQuickSort(ary, comparator2, p, q - 1);
1204
+ doQuickSort(ary, comparator2, q + 1, r);
1205
+ }
1206
+ }
1207
+ return doQuickSort;
1208
+ }
1209
+ function cloneSort(comparator) {
1210
+ let template = SortTemplate.toString();
1211
+ let templateFn = new Function(`return ${template}`)();
1212
+ return templateFn(comparator);
1213
+ }
1214
+ let sortCache = /* @__PURE__ */ new WeakMap();
1215
+ quickSort.quickSort = function(ary, comparator, start = 0) {
1216
+ let doQuickSort = sortCache.get(comparator);
1217
+ if (doQuickSort === void 0) {
1218
+ doQuickSort = cloneSort(comparator);
1219
+ sortCache.set(comparator, doQuickSort);
1220
+ }
1221
+ doQuickSort(ary, comparator, start, ary.length - 1);
1222
+ };
1223
+ return quickSort;
1224
+ }
1225
+ var hasRequiredSourceMapConsumer;
1226
+ function requireSourceMapConsumer() {
1227
+ if (hasRequiredSourceMapConsumer) return sourceMapConsumer;
1228
+ hasRequiredSourceMapConsumer = 1;
1229
+ var util2 = requireUtil();
1230
+ var binarySearch2 = requireBinarySearch();
1231
+ var ArraySet = requireArraySet().ArraySet;
1232
+ var base64VLQ = requireBase64Vlq();
1233
+ var quickSort2 = requireQuickSort().quickSort;
1234
+ function SourceMapConsumer(aSourceMap, aSourceMapURL) {
1235
+ var sourceMap2 = aSourceMap;
1236
+ if (typeof aSourceMap === "string") {
1237
+ sourceMap2 = util2.parseSourceMapInput(aSourceMap);
1238
+ }
1239
+ return sourceMap2.sections != null ? new IndexedSourceMapConsumer(sourceMap2, aSourceMapURL) : new BasicSourceMapConsumer(sourceMap2, aSourceMapURL);
1240
+ }
1241
+ SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) {
1242
+ return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
1243
+ };
1244
+ SourceMapConsumer.prototype._version = 3;
1245
+ SourceMapConsumer.prototype.__generatedMappings = null;
1246
+ Object.defineProperty(SourceMapConsumer.prototype, "_generatedMappings", {
1247
+ configurable: true,
1248
+ enumerable: true,
1249
+ get: function() {
1250
+ if (!this.__generatedMappings) {
1251
+ this._parseMappings(this._mappings, this.sourceRoot);
1252
+ }
1253
+ return this.__generatedMappings;
1254
+ }
1255
+ });
1256
+ SourceMapConsumer.prototype.__originalMappings = null;
1257
+ Object.defineProperty(SourceMapConsumer.prototype, "_originalMappings", {
1258
+ configurable: true,
1259
+ enumerable: true,
1260
+ get: function() {
1261
+ if (!this.__originalMappings) {
1262
+ this._parseMappings(this._mappings, this.sourceRoot);
1263
+ }
1264
+ return this.__originalMappings;
1265
+ }
1266
+ });
1267
+ SourceMapConsumer.prototype._charIsMappingSeparator = function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
1268
+ var c = aStr.charAt(index);
1269
+ return c === ";" || c === ",";
1270
+ };
1271
+ SourceMapConsumer.prototype._parseMappings = function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
1272
+ throw new Error("Subclasses must implement _parseMappings");
1273
+ };
1274
+ SourceMapConsumer.GENERATED_ORDER = 1;
1275
+ SourceMapConsumer.ORIGINAL_ORDER = 2;
1276
+ SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
1277
+ SourceMapConsumer.LEAST_UPPER_BOUND = 2;
1278
+ SourceMapConsumer.prototype.eachMapping = function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
1279
+ var context = aContext || null;
1280
+ var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
1281
+ var mappings;
1282
+ switch (order) {
1283
+ case SourceMapConsumer.GENERATED_ORDER:
1284
+ mappings = this._generatedMappings;
1285
+ break;
1286
+ case SourceMapConsumer.ORIGINAL_ORDER:
1287
+ mappings = this._originalMappings;
1288
+ break;
1289
+ default:
1290
+ throw new Error("Unknown order of iteration.");
1291
+ }
1292
+ var sourceRoot = this.sourceRoot;
1293
+ var boundCallback = aCallback.bind(context);
1294
+ var names = this._names;
1295
+ var sources = this._sources;
1296
+ var sourceMapURL = this._sourceMapURL;
1297
+ for (var i = 0, n = mappings.length; i < n; i++) {
1298
+ var mapping = mappings[i];
1299
+ var source = mapping.source === null ? null : sources.at(mapping.source);
1300
+ if (source !== null) {
1301
+ source = util2.computeSourceURL(sourceRoot, source, sourceMapURL);
1302
+ }
1303
+ boundCallback({
1304
+ source,
1305
+ generatedLine: mapping.generatedLine,
1306
+ generatedColumn: mapping.generatedColumn,
1307
+ originalLine: mapping.originalLine,
1308
+ originalColumn: mapping.originalColumn,
1309
+ name: mapping.name === null ? null : names.at(mapping.name)
1310
+ });
1311
+ }
1312
+ };
1313
+ SourceMapConsumer.prototype.allGeneratedPositionsFor = function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
1314
+ var line = util2.getArg(aArgs, "line");
1315
+ var needle = {
1316
+ source: util2.getArg(aArgs, "source"),
1317
+ originalLine: line,
1318
+ originalColumn: util2.getArg(aArgs, "column", 0)
1319
+ };
1320
+ needle.source = this._findSourceIndex(needle.source);
1321
+ if (needle.source < 0) {
1322
+ return [];
1323
+ }
1324
+ var mappings = [];
1325
+ var index = this._findMapping(
1326
+ needle,
1327
+ this._originalMappings,
1328
+ "originalLine",
1329
+ "originalColumn",
1330
+ util2.compareByOriginalPositions,
1331
+ binarySearch2.LEAST_UPPER_BOUND
1332
+ );
1333
+ if (index >= 0) {
1334
+ var mapping = this._originalMappings[index];
1335
+ if (aArgs.column === void 0) {
1336
+ var originalLine = mapping.originalLine;
1337
+ while (mapping && mapping.originalLine === originalLine) {
1338
+ mappings.push({
1339
+ line: util2.getArg(mapping, "generatedLine", null),
1340
+ column: util2.getArg(mapping, "generatedColumn", null),
1341
+ lastColumn: util2.getArg(mapping, "lastGeneratedColumn", null)
1342
+ });
1343
+ mapping = this._originalMappings[++index];
1344
+ }
1345
+ } else {
1346
+ var originalColumn = mapping.originalColumn;
1347
+ while (mapping && mapping.originalLine === line && mapping.originalColumn == originalColumn) {
1348
+ mappings.push({
1349
+ line: util2.getArg(mapping, "generatedLine", null),
1350
+ column: util2.getArg(mapping, "generatedColumn", null),
1351
+ lastColumn: util2.getArg(mapping, "lastGeneratedColumn", null)
1352
+ });
1353
+ mapping = this._originalMappings[++index];
1354
+ }
1355
+ }
1356
+ }
1357
+ return mappings;
1358
+ };
1359
+ sourceMapConsumer.SourceMapConsumer = SourceMapConsumer;
1360
+ function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
1361
+ var sourceMap2 = aSourceMap;
1362
+ if (typeof aSourceMap === "string") {
1363
+ sourceMap2 = util2.parseSourceMapInput(aSourceMap);
1364
+ }
1365
+ var version = util2.getArg(sourceMap2, "version");
1366
+ var sources = util2.getArg(sourceMap2, "sources");
1367
+ var names = util2.getArg(sourceMap2, "names", []);
1368
+ var sourceRoot = util2.getArg(sourceMap2, "sourceRoot", null);
1369
+ var sourcesContent = util2.getArg(sourceMap2, "sourcesContent", null);
1370
+ var mappings = util2.getArg(sourceMap2, "mappings");
1371
+ var file = util2.getArg(sourceMap2, "file", null);
1372
+ if (version != this._version) {
1373
+ throw new Error("Unsupported version: " + version);
1374
+ }
1375
+ if (sourceRoot) {
1376
+ sourceRoot = util2.normalize(sourceRoot);
1377
+ }
1378
+ sources = sources.map(String).map(util2.normalize).map(function(source) {
1379
+ return sourceRoot && util2.isAbsolute(sourceRoot) && util2.isAbsolute(source) ? util2.relative(sourceRoot, source) : source;
1380
+ });
1381
+ this._names = ArraySet.fromArray(names.map(String), true);
1382
+ this._sources = ArraySet.fromArray(sources, true);
1383
+ this._absoluteSources = this._sources.toArray().map(function(s) {
1384
+ return util2.computeSourceURL(sourceRoot, s, aSourceMapURL);
1385
+ });
1386
+ this.sourceRoot = sourceRoot;
1387
+ this.sourcesContent = sourcesContent;
1388
+ this._mappings = mappings;
1389
+ this._sourceMapURL = aSourceMapURL;
1390
+ this.file = file;
1391
+ }
1392
+ BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
1393
+ BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
1394
+ BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
1395
+ var relativeSource = aSource;
1396
+ if (this.sourceRoot != null) {
1397
+ relativeSource = util2.relative(this.sourceRoot, relativeSource);
1398
+ }
1399
+ if (this._sources.has(relativeSource)) {
1400
+ return this._sources.indexOf(relativeSource);
1401
+ }
1402
+ var i;
1403
+ for (i = 0; i < this._absoluteSources.length; ++i) {
1404
+ if (this._absoluteSources[i] == aSource) {
1405
+ return i;
1406
+ }
1407
+ }
1408
+ return -1;
1409
+ };
1410
+ BasicSourceMapConsumer.fromSourceMap = function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
1411
+ var smc = Object.create(BasicSourceMapConsumer.prototype);
1412
+ var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
1413
+ var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
1414
+ smc.sourceRoot = aSourceMap._sourceRoot;
1415
+ smc.sourcesContent = aSourceMap._generateSourcesContent(
1416
+ smc._sources.toArray(),
1417
+ smc.sourceRoot
1418
+ );
1419
+ smc.file = aSourceMap._file;
1420
+ smc._sourceMapURL = aSourceMapURL;
1421
+ smc._absoluteSources = smc._sources.toArray().map(function(s) {
1422
+ return util2.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
1423
+ });
1424
+ var generatedMappings = aSourceMap._mappings.toArray().slice();
1425
+ var destGeneratedMappings = smc.__generatedMappings = [];
1426
+ var destOriginalMappings = smc.__originalMappings = [];
1427
+ for (var i = 0, length = generatedMappings.length; i < length; i++) {
1428
+ var srcMapping = generatedMappings[i];
1429
+ var destMapping = new Mapping();
1430
+ destMapping.generatedLine = srcMapping.generatedLine;
1431
+ destMapping.generatedColumn = srcMapping.generatedColumn;
1432
+ if (srcMapping.source) {
1433
+ destMapping.source = sources.indexOf(srcMapping.source);
1434
+ destMapping.originalLine = srcMapping.originalLine;
1435
+ destMapping.originalColumn = srcMapping.originalColumn;
1436
+ if (srcMapping.name) {
1437
+ destMapping.name = names.indexOf(srcMapping.name);
1438
+ }
1439
+ destOriginalMappings.push(destMapping);
1440
+ }
1441
+ destGeneratedMappings.push(destMapping);
1442
+ }
1443
+ quickSort2(smc.__originalMappings, util2.compareByOriginalPositions);
1444
+ return smc;
1445
+ };
1446
+ BasicSourceMapConsumer.prototype._version = 3;
1447
+ Object.defineProperty(BasicSourceMapConsumer.prototype, "sources", {
1448
+ get: function() {
1449
+ return this._absoluteSources.slice();
1450
+ }
1451
+ });
1452
+ function Mapping() {
1453
+ this.generatedLine = 0;
1454
+ this.generatedColumn = 0;
1455
+ this.source = null;
1456
+ this.originalLine = null;
1457
+ this.originalColumn = null;
1458
+ this.name = null;
1459
+ }
1460
+ const compareGenerated = util2.compareByGeneratedPositionsDeflatedNoLine;
1461
+ function sortGenerated(array, start) {
1462
+ let l = array.length;
1463
+ let n = array.length - start;
1464
+ if (n <= 1) {
1465
+ return;
1466
+ } else if (n == 2) {
1467
+ let a = array[start];
1468
+ let b = array[start + 1];
1469
+ if (compareGenerated(a, b) > 0) {
1470
+ array[start] = b;
1471
+ array[start + 1] = a;
1472
+ }
1473
+ } else if (n < 20) {
1474
+ for (let i = start; i < l; i++) {
1475
+ for (let j = i; j > start; j--) {
1476
+ let a = array[j - 1];
1477
+ let b = array[j];
1478
+ if (compareGenerated(a, b) <= 0) {
1479
+ break;
1480
+ }
1481
+ array[j - 1] = b;
1482
+ array[j] = a;
1483
+ }
1484
+ }
1485
+ } else {
1486
+ quickSort2(array, compareGenerated, start);
1487
+ }
1488
+ }
1489
+ BasicSourceMapConsumer.prototype._parseMappings = function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
1490
+ var generatedLine = 1;
1491
+ var previousGeneratedColumn = 0;
1492
+ var previousOriginalLine = 0;
1493
+ var previousOriginalColumn = 0;
1494
+ var previousSource = 0;
1495
+ var previousName = 0;
1496
+ var length = aStr.length;
1497
+ var index = 0;
1498
+ var temp = {};
1499
+ var originalMappings = [];
1500
+ var generatedMappings = [];
1501
+ var mapping, segment, end, value;
1502
+ let subarrayStart = 0;
1503
+ while (index < length) {
1504
+ if (aStr.charAt(index) === ";") {
1505
+ generatedLine++;
1506
+ index++;
1507
+ previousGeneratedColumn = 0;
1508
+ sortGenerated(generatedMappings, subarrayStart);
1509
+ subarrayStart = generatedMappings.length;
1510
+ } else if (aStr.charAt(index) === ",") {
1511
+ index++;
1512
+ } else {
1513
+ mapping = new Mapping();
1514
+ mapping.generatedLine = generatedLine;
1515
+ for (end = index; end < length; end++) {
1516
+ if (this._charIsMappingSeparator(aStr, end)) {
1517
+ break;
1518
+ }
1519
+ }
1520
+ aStr.slice(index, end);
1521
+ segment = [];
1522
+ while (index < end) {
1523
+ base64VLQ.decode(aStr, index, temp);
1524
+ value = temp.value;
1525
+ index = temp.rest;
1526
+ segment.push(value);
1527
+ }
1528
+ if (segment.length === 2) {
1529
+ throw new Error("Found a source, but no line and column");
1530
+ }
1531
+ if (segment.length === 3) {
1532
+ throw new Error("Found a source and line, but no column");
1533
+ }
1534
+ mapping.generatedColumn = previousGeneratedColumn + segment[0];
1535
+ previousGeneratedColumn = mapping.generatedColumn;
1536
+ if (segment.length > 1) {
1537
+ mapping.source = previousSource + segment[1];
1538
+ previousSource += segment[1];
1539
+ mapping.originalLine = previousOriginalLine + segment[2];
1540
+ previousOriginalLine = mapping.originalLine;
1541
+ mapping.originalLine += 1;
1542
+ mapping.originalColumn = previousOriginalColumn + segment[3];
1543
+ previousOriginalColumn = mapping.originalColumn;
1544
+ if (segment.length > 4) {
1545
+ mapping.name = previousName + segment[4];
1546
+ previousName += segment[4];
1547
+ }
1548
+ }
1549
+ generatedMappings.push(mapping);
1550
+ if (typeof mapping.originalLine === "number") {
1551
+ let currentSource = mapping.source;
1552
+ while (originalMappings.length <= currentSource) {
1553
+ originalMappings.push(null);
1554
+ }
1555
+ if (originalMappings[currentSource] === null) {
1556
+ originalMappings[currentSource] = [];
1557
+ }
1558
+ originalMappings[currentSource].push(mapping);
1559
+ }
1560
+ }
1561
+ }
1562
+ sortGenerated(generatedMappings, subarrayStart);
1563
+ this.__generatedMappings = generatedMappings;
1564
+ for (var i = 0; i < originalMappings.length; i++) {
1565
+ if (originalMappings[i] != null) {
1566
+ quickSort2(originalMappings[i], util2.compareByOriginalPositionsNoSource);
1567
+ }
1568
+ }
1569
+ this.__originalMappings = [].concat(...originalMappings);
1570
+ };
1571
+ BasicSourceMapConsumer.prototype._findMapping = function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName, aColumnName, aComparator, aBias) {
1572
+ if (aNeedle[aLineName] <= 0) {
1573
+ throw new TypeError("Line must be greater than or equal to 1, got " + aNeedle[aLineName]);
1574
+ }
1575
+ if (aNeedle[aColumnName] < 0) {
1576
+ throw new TypeError("Column must be greater than or equal to 0, got " + aNeedle[aColumnName]);
1577
+ }
1578
+ return binarySearch2.search(aNeedle, aMappings, aComparator, aBias);
1579
+ };
1580
+ BasicSourceMapConsumer.prototype.computeColumnSpans = function SourceMapConsumer_computeColumnSpans() {
1581
+ for (var index = 0; index < this._generatedMappings.length; ++index) {
1582
+ var mapping = this._generatedMappings[index];
1583
+ if (index + 1 < this._generatedMappings.length) {
1584
+ var nextMapping = this._generatedMappings[index + 1];
1585
+ if (mapping.generatedLine === nextMapping.generatedLine) {
1586
+ mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
1587
+ continue;
1588
+ }
1589
+ }
1590
+ mapping.lastGeneratedColumn = Infinity;
1591
+ }
1592
+ };
1593
+ BasicSourceMapConsumer.prototype.originalPositionFor = function SourceMapConsumer_originalPositionFor(aArgs) {
1594
+ var needle = {
1595
+ generatedLine: util2.getArg(aArgs, "line"),
1596
+ generatedColumn: util2.getArg(aArgs, "column")
1597
+ };
1598
+ var index = this._findMapping(
1599
+ needle,
1600
+ this._generatedMappings,
1601
+ "generatedLine",
1602
+ "generatedColumn",
1603
+ util2.compareByGeneratedPositionsDeflated,
1604
+ util2.getArg(aArgs, "bias", SourceMapConsumer.GREATEST_LOWER_BOUND)
1605
+ );
1606
+ if (index >= 0) {
1607
+ var mapping = this._generatedMappings[index];
1608
+ if (mapping.generatedLine === needle.generatedLine) {
1609
+ var source = util2.getArg(mapping, "source", null);
1610
+ if (source !== null) {
1611
+ source = this._sources.at(source);
1612
+ source = util2.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
1613
+ }
1614
+ var name = util2.getArg(mapping, "name", null);
1615
+ if (name !== null) {
1616
+ name = this._names.at(name);
1617
+ }
1618
+ return {
1619
+ source,
1620
+ line: util2.getArg(mapping, "originalLine", null),
1621
+ column: util2.getArg(mapping, "originalColumn", null),
1622
+ name
1623
+ };
1624
+ }
1625
+ }
1626
+ return {
1627
+ source: null,
1628
+ line: null,
1629
+ column: null,
1630
+ name: null
1631
+ };
1632
+ };
1633
+ BasicSourceMapConsumer.prototype.hasContentsOfAllSources = function BasicSourceMapConsumer_hasContentsOfAllSources() {
1634
+ if (!this.sourcesContent) {
1635
+ return false;
1636
+ }
1637
+ return this.sourcesContent.length >= this._sources.size() && !this.sourcesContent.some(function(sc) {
1638
+ return sc == null;
1639
+ });
1640
+ };
1641
+ BasicSourceMapConsumer.prototype.sourceContentFor = function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
1642
+ if (!this.sourcesContent) {
1643
+ return null;
1644
+ }
1645
+ var index = this._findSourceIndex(aSource);
1646
+ if (index >= 0) {
1647
+ return this.sourcesContent[index];
1648
+ }
1649
+ var relativeSource = aSource;
1650
+ if (this.sourceRoot != null) {
1651
+ relativeSource = util2.relative(this.sourceRoot, relativeSource);
1652
+ }
1653
+ var url;
1654
+ if (this.sourceRoot != null && (url = util2.urlParse(this.sourceRoot))) {
1655
+ var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
1656
+ if (url.scheme == "file" && this._sources.has(fileUriAbsPath)) {
1657
+ return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)];
1658
+ }
1659
+ if ((!url.path || url.path == "/") && this._sources.has("/" + relativeSource)) {
1660
+ return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
1661
+ }
1662
+ }
1663
+ if (nullOnMissing) {
1664
+ return null;
1665
+ } else {
1666
+ throw new Error('"' + relativeSource + '" is not in the SourceMap.');
1667
+ }
1668
+ };
1669
+ BasicSourceMapConsumer.prototype.generatedPositionFor = function SourceMapConsumer_generatedPositionFor(aArgs) {
1670
+ var source = util2.getArg(aArgs, "source");
1671
+ source = this._findSourceIndex(source);
1672
+ if (source < 0) {
1673
+ return {
1674
+ line: null,
1675
+ column: null,
1676
+ lastColumn: null
1677
+ };
1678
+ }
1679
+ var needle = {
1680
+ source,
1681
+ originalLine: util2.getArg(aArgs, "line"),
1682
+ originalColumn: util2.getArg(aArgs, "column")
1683
+ };
1684
+ var index = this._findMapping(
1685
+ needle,
1686
+ this._originalMappings,
1687
+ "originalLine",
1688
+ "originalColumn",
1689
+ util2.compareByOriginalPositions,
1690
+ util2.getArg(aArgs, "bias", SourceMapConsumer.GREATEST_LOWER_BOUND)
1691
+ );
1692
+ if (index >= 0) {
1693
+ var mapping = this._originalMappings[index];
1694
+ if (mapping.source === needle.source) {
1695
+ return {
1696
+ line: util2.getArg(mapping, "generatedLine", null),
1697
+ column: util2.getArg(mapping, "generatedColumn", null),
1698
+ lastColumn: util2.getArg(mapping, "lastGeneratedColumn", null)
1699
+ };
1700
+ }
1701
+ }
1702
+ return {
1703
+ line: null,
1704
+ column: null,
1705
+ lastColumn: null
1706
+ };
1707
+ };
1708
+ sourceMapConsumer.BasicSourceMapConsumer = BasicSourceMapConsumer;
1709
+ function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
1710
+ var sourceMap2 = aSourceMap;
1711
+ if (typeof aSourceMap === "string") {
1712
+ sourceMap2 = util2.parseSourceMapInput(aSourceMap);
1713
+ }
1714
+ var version = util2.getArg(sourceMap2, "version");
1715
+ var sections = util2.getArg(sourceMap2, "sections");
1716
+ if (version != this._version) {
1717
+ throw new Error("Unsupported version: " + version);
1718
+ }
1719
+ this._sources = new ArraySet();
1720
+ this._names = new ArraySet();
1721
+ var lastOffset = {
1722
+ line: -1,
1723
+ column: 0
1724
+ };
1725
+ this._sections = sections.map(function(s) {
1726
+ if (s.url) {
1727
+ throw new Error("Support for url field in sections not implemented.");
1728
+ }
1729
+ var offset = util2.getArg(s, "offset");
1730
+ var offsetLine = util2.getArg(offset, "line");
1731
+ var offsetColumn = util2.getArg(offset, "column");
1732
+ if (offsetLine < lastOffset.line || offsetLine === lastOffset.line && offsetColumn < lastOffset.column) {
1733
+ throw new Error("Section offsets must be ordered and non-overlapping.");
1734
+ }
1735
+ lastOffset = offset;
1736
+ return {
1737
+ generatedOffset: {
1738
+ // The offset fields are 0-based, but we use 1-based indices when
1739
+ // encoding/decoding from VLQ.
1740
+ generatedLine: offsetLine + 1,
1741
+ generatedColumn: offsetColumn + 1
1742
+ },
1743
+ consumer: new SourceMapConsumer(util2.getArg(s, "map"), aSourceMapURL)
1744
+ };
1745
+ });
1746
+ }
1747
+ IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
1748
+ IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer;
1749
+ IndexedSourceMapConsumer.prototype._version = 3;
1750
+ Object.defineProperty(IndexedSourceMapConsumer.prototype, "sources", {
1751
+ get: function() {
1752
+ var sources = [];
1753
+ for (var i = 0; i < this._sections.length; i++) {
1754
+ for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
1755
+ sources.push(this._sections[i].consumer.sources[j]);
1756
+ }
1757
+ }
1758
+ return sources;
1759
+ }
1760
+ });
1761
+ IndexedSourceMapConsumer.prototype.originalPositionFor = function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
1762
+ var needle = {
1763
+ generatedLine: util2.getArg(aArgs, "line"),
1764
+ generatedColumn: util2.getArg(aArgs, "column")
1765
+ };
1766
+ var sectionIndex = binarySearch2.search(
1767
+ needle,
1768
+ this._sections,
1769
+ function(needle2, section2) {
1770
+ var cmp = needle2.generatedLine - section2.generatedOffset.generatedLine;
1771
+ if (cmp) {
1772
+ return cmp;
1773
+ }
1774
+ return needle2.generatedColumn - section2.generatedOffset.generatedColumn;
1775
+ }
1776
+ );
1777
+ var section = this._sections[sectionIndex];
1778
+ if (!section) {
1779
+ return {
1780
+ source: null,
1781
+ line: null,
1782
+ column: null,
1783
+ name: null
1784
+ };
1785
+ }
1786
+ return section.consumer.originalPositionFor({
1787
+ line: needle.generatedLine - (section.generatedOffset.generatedLine - 1),
1788
+ column: needle.generatedColumn - (section.generatedOffset.generatedLine === needle.generatedLine ? section.generatedOffset.generatedColumn - 1 : 0),
1789
+ bias: aArgs.bias
1790
+ });
1791
+ };
1792
+ IndexedSourceMapConsumer.prototype.hasContentsOfAllSources = function IndexedSourceMapConsumer_hasContentsOfAllSources() {
1793
+ return this._sections.every(function(s) {
1794
+ return s.consumer.hasContentsOfAllSources();
1795
+ });
1796
+ };
1797
+ IndexedSourceMapConsumer.prototype.sourceContentFor = function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
1798
+ for (var i = 0; i < this._sections.length; i++) {
1799
+ var section = this._sections[i];
1800
+ var content = section.consumer.sourceContentFor(aSource, true);
1801
+ if (content || content === "") {
1802
+ return content;
1803
+ }
1804
+ }
1805
+ if (nullOnMissing) {
1806
+ return null;
1807
+ } else {
1808
+ throw new Error('"' + aSource + '" is not in the SourceMap.');
1809
+ }
1810
+ };
1811
+ IndexedSourceMapConsumer.prototype.generatedPositionFor = function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
1812
+ for (var i = 0; i < this._sections.length; i++) {
1813
+ var section = this._sections[i];
1814
+ if (section.consumer._findSourceIndex(util2.getArg(aArgs, "source")) === -1) {
1815
+ continue;
1816
+ }
1817
+ var generatedPosition = section.consumer.generatedPositionFor(aArgs);
1818
+ if (generatedPosition) {
1819
+ var ret = {
1820
+ line: generatedPosition.line + (section.generatedOffset.generatedLine - 1),
1821
+ column: generatedPosition.column + (section.generatedOffset.generatedLine === generatedPosition.line ? section.generatedOffset.generatedColumn - 1 : 0)
1822
+ };
1823
+ return ret;
1824
+ }
1825
+ }
1826
+ return {
1827
+ line: null,
1828
+ column: null
1829
+ };
1830
+ };
1831
+ IndexedSourceMapConsumer.prototype._parseMappings = function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
1832
+ this.__generatedMappings = [];
1833
+ this.__originalMappings = [];
1834
+ for (var i = 0; i < this._sections.length; i++) {
1835
+ var section = this._sections[i];
1836
+ var sectionMappings = section.consumer._generatedMappings;
1837
+ for (var j = 0; j < sectionMappings.length; j++) {
1838
+ var mapping = sectionMappings[j];
1839
+ var source = section.consumer._sources.at(mapping.source);
1840
+ if (source !== null) {
1841
+ source = util2.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
1842
+ }
1843
+ this._sources.add(source);
1844
+ source = this._sources.indexOf(source);
1845
+ var name = null;
1846
+ if (mapping.name) {
1847
+ name = section.consumer._names.at(mapping.name);
1848
+ this._names.add(name);
1849
+ name = this._names.indexOf(name);
1850
+ }
1851
+ var adjustedMapping = {
1852
+ source,
1853
+ generatedLine: mapping.generatedLine + (section.generatedOffset.generatedLine - 1),
1854
+ generatedColumn: mapping.generatedColumn + (section.generatedOffset.generatedLine === mapping.generatedLine ? section.generatedOffset.generatedColumn - 1 : 0),
1855
+ originalLine: mapping.originalLine,
1856
+ originalColumn: mapping.originalColumn,
1857
+ name
1858
+ };
1859
+ this.__generatedMappings.push(adjustedMapping);
1860
+ if (typeof adjustedMapping.originalLine === "number") {
1861
+ this.__originalMappings.push(adjustedMapping);
1862
+ }
1863
+ }
1864
+ }
1865
+ quickSort2(this.__generatedMappings, util2.compareByGeneratedPositionsDeflated);
1866
+ quickSort2(this.__originalMappings, util2.compareByOriginalPositions);
1867
+ };
1868
+ sourceMapConsumer.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
1869
+ return sourceMapConsumer;
1870
+ }
1871
+ var sourceNode = {};
1872
+ var hasRequiredSourceNode;
1873
+ function requireSourceNode() {
1874
+ if (hasRequiredSourceNode) return sourceNode;
1875
+ hasRequiredSourceNode = 1;
1876
+ var SourceMapGenerator = requireSourceMapGenerator().SourceMapGenerator;
1877
+ var util2 = requireUtil();
1878
+ var REGEX_NEWLINE = /(\r?\n)/;
1879
+ var NEWLINE_CODE = 10;
1880
+ var isSourceNode = "$$$isSourceNode$$$";
1881
+ function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
1882
+ this.children = [];
1883
+ this.sourceContents = {};
1884
+ this.line = aLine == null ? null : aLine;
1885
+ this.column = aColumn == null ? null : aColumn;
1886
+ this.source = aSource == null ? null : aSource;
1887
+ this.name = aName == null ? null : aName;
1888
+ this[isSourceNode] = true;
1889
+ if (aChunks != null) this.add(aChunks);
1890
+ }
1891
+ SourceNode.fromStringWithSourceMap = function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
1892
+ var node = new SourceNode();
1893
+ var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
1894
+ var remainingLinesIndex = 0;
1895
+ var shiftNextLine = function() {
1896
+ var lineContents = getNextLine();
1897
+ var newLine = getNextLine() || "";
1898
+ return lineContents + newLine;
1899
+ function getNextLine() {
1900
+ return remainingLinesIndex < remainingLines.length ? remainingLines[remainingLinesIndex++] : void 0;
1901
+ }
1902
+ };
1903
+ var lastGeneratedLine = 1, lastGeneratedColumn = 0;
1904
+ var lastMapping = null;
1905
+ aSourceMapConsumer.eachMapping(function(mapping) {
1906
+ if (lastMapping !== null) {
1907
+ if (lastGeneratedLine < mapping.generatedLine) {
1908
+ addMappingWithCode(lastMapping, shiftNextLine());
1909
+ lastGeneratedLine++;
1910
+ lastGeneratedColumn = 0;
1911
+ } else {
1912
+ var nextLine = remainingLines[remainingLinesIndex] || "";
1913
+ var code = nextLine.substr(0, mapping.generatedColumn - lastGeneratedColumn);
1914
+ remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn - lastGeneratedColumn);
1915
+ lastGeneratedColumn = mapping.generatedColumn;
1916
+ addMappingWithCode(lastMapping, code);
1917
+ lastMapping = mapping;
1918
+ return;
1919
+ }
1920
+ }
1921
+ while (lastGeneratedLine < mapping.generatedLine) {
1922
+ node.add(shiftNextLine());
1923
+ lastGeneratedLine++;
1924
+ }
1925
+ if (lastGeneratedColumn < mapping.generatedColumn) {
1926
+ var nextLine = remainingLines[remainingLinesIndex] || "";
1927
+ node.add(nextLine.substr(0, mapping.generatedColumn));
1928
+ remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
1929
+ lastGeneratedColumn = mapping.generatedColumn;
1930
+ }
1931
+ lastMapping = mapping;
1932
+ }, this);
1933
+ if (remainingLinesIndex < remainingLines.length) {
1934
+ if (lastMapping) {
1935
+ addMappingWithCode(lastMapping, shiftNextLine());
1936
+ }
1937
+ node.add(remainingLines.splice(remainingLinesIndex).join(""));
1938
+ }
1939
+ aSourceMapConsumer.sources.forEach(function(sourceFile) {
1940
+ var content = aSourceMapConsumer.sourceContentFor(sourceFile);
1941
+ if (content != null) {
1942
+ if (aRelativePath != null) {
1943
+ sourceFile = util2.join(aRelativePath, sourceFile);
1944
+ }
1945
+ node.setSourceContent(sourceFile, content);
1946
+ }
1947
+ });
1948
+ return node;
1949
+ function addMappingWithCode(mapping, code) {
1950
+ if (mapping === null || mapping.source === void 0) {
1951
+ node.add(code);
1952
+ } else {
1953
+ var source = aRelativePath ? util2.join(aRelativePath, mapping.source) : mapping.source;
1954
+ node.add(new SourceNode(
1955
+ mapping.originalLine,
1956
+ mapping.originalColumn,
1957
+ source,
1958
+ code,
1959
+ mapping.name
1960
+ ));
1961
+ }
1962
+ }
1963
+ };
1964
+ SourceNode.prototype.add = function SourceNode_add(aChunk) {
1965
+ if (Array.isArray(aChunk)) {
1966
+ aChunk.forEach(function(chunk) {
1967
+ this.add(chunk);
1968
+ }, this);
1969
+ } else if (aChunk[isSourceNode] || typeof aChunk === "string") {
1970
+ if (aChunk) {
1971
+ this.children.push(aChunk);
1972
+ }
1973
+ } else {
1974
+ throw new TypeError(
1975
+ "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
1976
+ );
1977
+ }
1978
+ return this;
1979
+ };
1980
+ SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
1981
+ if (Array.isArray(aChunk)) {
1982
+ for (var i = aChunk.length - 1; i >= 0; i--) {
1983
+ this.prepend(aChunk[i]);
1984
+ }
1985
+ } else if (aChunk[isSourceNode] || typeof aChunk === "string") {
1986
+ this.children.unshift(aChunk);
1987
+ } else {
1988
+ throw new TypeError(
1989
+ "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
1990
+ );
1991
+ }
1992
+ return this;
1993
+ };
1994
+ SourceNode.prototype.walk = function SourceNode_walk(aFn) {
1995
+ var chunk;
1996
+ for (var i = 0, len = this.children.length; i < len; i++) {
1997
+ chunk = this.children[i];
1998
+ if (chunk[isSourceNode]) {
1999
+ chunk.walk(aFn);
2000
+ } else {
2001
+ if (chunk !== "") {
2002
+ aFn(chunk, {
2003
+ source: this.source,
2004
+ line: this.line,
2005
+ column: this.column,
2006
+ name: this.name
2007
+ });
2008
+ }
2009
+ }
2010
+ }
2011
+ };
2012
+ SourceNode.prototype.join = function SourceNode_join(aSep) {
2013
+ var newChildren;
2014
+ var i;
2015
+ var len = this.children.length;
2016
+ if (len > 0) {
2017
+ newChildren = [];
2018
+ for (i = 0; i < len - 1; i++) {
2019
+ newChildren.push(this.children[i]);
2020
+ newChildren.push(aSep);
2021
+ }
2022
+ newChildren.push(this.children[i]);
2023
+ this.children = newChildren;
2024
+ }
2025
+ return this;
2026
+ };
2027
+ SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
2028
+ var lastChild = this.children[this.children.length - 1];
2029
+ if (lastChild[isSourceNode]) {
2030
+ lastChild.replaceRight(aPattern, aReplacement);
2031
+ } else if (typeof lastChild === "string") {
2032
+ this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
2033
+ } else {
2034
+ this.children.push("".replace(aPattern, aReplacement));
2035
+ }
2036
+ return this;
2037
+ };
2038
+ SourceNode.prototype.setSourceContent = function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
2039
+ this.sourceContents[util2.toSetString(aSourceFile)] = aSourceContent;
2040
+ };
2041
+ SourceNode.prototype.walkSourceContents = function SourceNode_walkSourceContents(aFn) {
2042
+ for (var i = 0, len = this.children.length; i < len; i++) {
2043
+ if (this.children[i][isSourceNode]) {
2044
+ this.children[i].walkSourceContents(aFn);
2045
+ }
2046
+ }
2047
+ var sources = Object.keys(this.sourceContents);
2048
+ for (var i = 0, len = sources.length; i < len; i++) {
2049
+ aFn(util2.fromSetString(sources[i]), this.sourceContents[sources[i]]);
2050
+ }
2051
+ };
2052
+ SourceNode.prototype.toString = function SourceNode_toString() {
2053
+ var str = "";
2054
+ this.walk(function(chunk) {
2055
+ str += chunk;
2056
+ });
2057
+ return str;
2058
+ };
2059
+ SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
2060
+ var generated = {
2061
+ code: "",
2062
+ line: 1,
2063
+ column: 0
2064
+ };
2065
+ var map = new SourceMapGenerator(aArgs);
2066
+ var sourceMappingActive = false;
2067
+ var lastOriginalSource = null;
2068
+ var lastOriginalLine = null;
2069
+ var lastOriginalColumn = null;
2070
+ var lastOriginalName = null;
2071
+ this.walk(function(chunk, original) {
2072
+ generated.code += chunk;
2073
+ if (original.source !== null && original.line !== null && original.column !== null) {
2074
+ if (lastOriginalSource !== original.source || lastOriginalLine !== original.line || lastOriginalColumn !== original.column || lastOriginalName !== original.name) {
2075
+ map.addMapping({
2076
+ source: original.source,
2077
+ original: {
2078
+ line: original.line,
2079
+ column: original.column
2080
+ },
2081
+ generated: {
2082
+ line: generated.line,
2083
+ column: generated.column
2084
+ },
2085
+ name: original.name
2086
+ });
2087
+ }
2088
+ lastOriginalSource = original.source;
2089
+ lastOriginalLine = original.line;
2090
+ lastOriginalColumn = original.column;
2091
+ lastOriginalName = original.name;
2092
+ sourceMappingActive = true;
2093
+ } else if (sourceMappingActive) {
2094
+ map.addMapping({
2095
+ generated: {
2096
+ line: generated.line,
2097
+ column: generated.column
2098
+ }
2099
+ });
2100
+ lastOriginalSource = null;
2101
+ sourceMappingActive = false;
2102
+ }
2103
+ for (var idx = 0, length = chunk.length; idx < length; idx++) {
2104
+ if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
2105
+ generated.line++;
2106
+ generated.column = 0;
2107
+ if (idx + 1 === length) {
2108
+ lastOriginalSource = null;
2109
+ sourceMappingActive = false;
2110
+ } else if (sourceMappingActive) {
2111
+ map.addMapping({
2112
+ source: original.source,
2113
+ original: {
2114
+ line: original.line,
2115
+ column: original.column
2116
+ },
2117
+ generated: {
2118
+ line: generated.line,
2119
+ column: generated.column
2120
+ },
2121
+ name: original.name
2122
+ });
2123
+ }
2124
+ } else {
2125
+ generated.column++;
2126
+ }
2127
+ }
2128
+ });
2129
+ this.walkSourceContents(function(sourceFile, sourceContent) {
2130
+ map.setSourceContent(sourceFile, sourceContent);
2131
+ });
2132
+ return { code: generated.code, map };
2133
+ };
2134
+ sourceNode.SourceNode = SourceNode;
2135
+ return sourceNode;
2136
+ }
2137
+ var hasRequiredSourceMap;
2138
+ function requireSourceMap() {
2139
+ if (hasRequiredSourceMap) return sourceMap;
2140
+ hasRequiredSourceMap = 1;
2141
+ sourceMap.SourceMapGenerator = requireSourceMapGenerator().SourceMapGenerator;
2142
+ sourceMap.SourceMapConsumer = requireSourceMapConsumer().SourceMapConsumer;
2143
+ sourceMap.SourceNode = requireSourceNode().SourceNode;
2144
+ return sourceMap;
2145
+ }
2146
+ var sourceMapExports = requireSourceMap();
2147
+ const toLocationCursor = (location) => {
2148
+ return `${location.fileName}:${location.lineNumber}:${location.columnNumber}`;
2149
+ };
2150
+ const isSameLocation = (left, right) => {
2151
+ return left.fileName === right.fileName && left.lineNumber === right.lineNumber && left.columnNumber === right.columnNumber;
2152
+ };
2153
+ const resolveOriginalLocation = (rawSourceMap, position) => {
2154
+ const consumer = new sourceMapExports.SourceMapConsumer(rawSourceMap);
2155
+ try {
2156
+ const attempts = [
2157
+ { line: position.line, column: position.column, bias: sourceMapExports.SourceMapConsumer.GREATEST_LOWER_BOUND },
2158
+ { line: position.line, column: 0, bias: sourceMapExports.SourceMapConsumer.GREATEST_LOWER_BOUND },
2159
+ { line: position.line, column: position.column, bias: sourceMapExports.SourceMapConsumer.LEAST_UPPER_BOUND },
2160
+ { line: position.line, column: 0, bias: sourceMapExports.SourceMapConsumer.LEAST_UPPER_BOUND }
2161
+ ];
2162
+ for (const attempt of attempts) {
2163
+ const found = consumer.originalPositionFor(attempt);
2164
+ if (found.source && found.line != null && found.column != null) {
2165
+ return {
2166
+ fileName: found.source,
2167
+ lineNumber: found.line,
2168
+ columnNumber: found.column
2169
+ };
2170
+ }
2171
+ }
2172
+ } finally {
2173
+ const maybeDestroy = consumer.destroy;
2174
+ maybeDestroy?.();
2175
+ }
2176
+ return null;
2177
+ };
2178
+ const resolveHopFromRecord = (sourceMapRecord, input) => {
2179
+ try {
2180
+ const { lineNumber: line, columnNumber: column } = input;
2181
+ const output = resolveOriginalLocation(sourceMapRecord.rawSourceMap, { line, column });
2182
+ if (!output) return null;
2183
+ return { input, output, mapFileName: sourceMapRecord.mapFileName };
2184
+ } catch {
2185
+ return null;
2186
+ }
2187
+ };
2188
+ const appendUnresolvedHop = (input) => {
2189
+ const { traceHops, input: location, mapFileName } = input;
2190
+ traceHops.push({ input: location, mapFileName });
2191
+ };
2192
+ const resolveTraceWithOrderedMaps = (input) => {
2193
+ const { entry, sourceMaps, orderedMapFileNames, maxDepth } = input;
2194
+ const traceHops = [];
2195
+ const visited = /* @__PURE__ */ new Set();
2196
+ let current = entry;
2197
+ for (let depth = 0; depth < orderedMapFileNames.length && depth < maxDepth; depth++) {
2198
+ const mapFileName = orderedMapFileNames[depth];
2199
+ const cursor = toLocationCursor(current);
2200
+ if (visited.has(cursor)) {
2201
+ appendUnresolvedHop({ traceHops, input: current, mapFileName });
2202
+ continue;
2203
+ }
2204
+ visited.add(cursor);
2205
+ const sourceMapRecord = getSourceMapByMapFileName(sourceMaps, mapFileName);
2206
+ if (!sourceMapRecord) {
2207
+ appendUnresolvedHop({ traceHops, input: current, mapFileName });
2208
+ continue;
2209
+ }
2210
+ const hop = resolveHopFromRecord(sourceMapRecord, current);
2211
+ if (!hop) {
2212
+ appendUnresolvedHop({ traceHops, input: current, mapFileName: sourceMapRecord.mapFileName });
2213
+ continue;
2214
+ }
2215
+ traceHops.push(hop);
2216
+ current = hop.output;
2217
+ }
2218
+ return traceHops;
2219
+ };
2220
+ const resolveTraceByFileLookup = (input) => {
2221
+ const { entry, sourceMaps, maxDepth } = input;
2222
+ const traceHops = [];
2223
+ const visited = /* @__PURE__ */ new Set();
2224
+ let current = entry;
2225
+ for (let depth = 0; depth < maxDepth; depth++) {
2226
+ const cursor = toLocationCursor(current);
2227
+ if (visited.has(cursor)) {
2228
+ appendUnresolvedHop({ traceHops, input: current });
2229
+ break;
2230
+ }
2231
+ visited.add(cursor);
2232
+ const sourceMapRecord = getSourceMapByFileName(sourceMaps, current.fileName);
2233
+ if (!sourceMapRecord) {
2234
+ if (traceHops.length === 0) appendUnresolvedHop({ traceHops, input: current });
2235
+ break;
2236
+ }
2237
+ const hop = resolveHopFromRecord(sourceMapRecord, current);
2238
+ if (!hop) {
2239
+ appendUnresolvedHop({ traceHops, input: current, mapFileName: sourceMapRecord.mapFileName });
2240
+ break;
2241
+ }
2242
+ traceHops.push(hop);
2243
+ if (isSameLocation(hop.output, current)) break;
2244
+ current = hop.output;
2245
+ }
2246
+ return traceHops;
2247
+ };
2248
+ const resolveTraceBySourceMaps = async (input) => {
2249
+ const { entry, sourceMaps, orderedMapFileNames = [], options = {} } = input;
2250
+ const maxDepth = options.maxDepth ?? MAX_TRACE_DEPTH;
2251
+ if (orderedMapFileNames.length > 0) return resolveTraceWithOrderedMaps({ entry, sourceMaps, orderedMapFileNames, maxDepth });
2252
+ return resolveTraceByFileLookup({ entry, sourceMaps, maxDepth });
2253
+ };
2254
+ const DEFAULT_CONTEXT_LINE_RADIUS = 3;
2255
+ const validateResolveInput = (config) => {
2256
+ const parsedLine = Number(config.entryLine);
2257
+ const parsedColumn = Number(config.entryColumn);
2258
+ const parsedContextLineRadius = Number(config.contextLineRadius);
2259
+ const normalizedFileName = config.entryFileName.replace(/\\/g, "/").trim();
2260
+ if (!normalizedFileName) {
2261
+ return { ok: false, message: "请输入入口文件名,例如 index.js" };
2262
+ }
2263
+ if (!config.entryLine.trim()) {
2264
+ return { ok: false, message: "请输入入口行号(1-based)。" };
2265
+ }
2266
+ if (!config.entryColumn.trim()) {
2267
+ return { ok: false, message: "请输入入口列号(0-based)。" };
2268
+ }
2269
+ if (!Number.isInteger(parsedLine) || parsedLine < 1) {
2270
+ return { ok: false, message: "行号必须是大于等于 1 的整数。" };
2271
+ }
2272
+ if (!Number.isInteger(parsedColumn) || parsedColumn < 0) {
2273
+ return { ok: false, message: "列号必须是大于等于 0 的整数。" };
2274
+ }
2275
+ if (!Number.isInteger(parsedContextLineRadius) || parsedContextLineRadius < 0) {
2276
+ return { ok: false, message: "上下文行数必须是大于等于 0 的整数。" };
2277
+ }
2278
+ if (config.mapCount === 0) {
2279
+ return { ok: false, message: "未加载可用 map 文件,请先上传。" };
2280
+ }
2281
+ return {
2282
+ ok: true,
2283
+ entry: {
2284
+ fileName: normalizedFileName,
2285
+ lineNumber: parsedLine,
2286
+ columnNumber: parsedColumn
2287
+ },
2288
+ contextLineRadius: parsedContextLineRadius
2289
+ };
2290
+ };
2291
+ const buildChainStateFromSlots = (slots) => {
2292
+ const { registry, orderedMapFileNames } = buildRegistryFromChainSlots(slots);
2293
+ return {
2294
+ sourceMaps: registry,
2295
+ sourceMapFileNames: orderedMapFileNames,
2296
+ chainMapSlots: slots,
2297
+ entryFileName: getAutoEntryFileNameFromSlots(slots)
2298
+ };
2299
+ };
2300
+ const resolveTraceContextTask = async (context) => {
2301
+ const traceChain = await resolveTraceBySourceMaps({
2302
+ entry: context.entry,
2303
+ sourceMaps: context.sourceMaps,
2304
+ orderedMapFileNames: context.sourceMapFileNames,
2305
+ options: { maxDepth: MAX_TRACE_DEPTH }
2306
+ });
2307
+ const sourceCode = resolveSourceCodeFromTrace(traceChain, context.sourceMaps, {
2308
+ onlyLastMap: true,
2309
+ lastMapFileName: context.sourceMapFileNames[context.sourceMapFileNames.length - 1]
2310
+ });
2311
+ return {
2312
+ traceChain,
2313
+ sourceCode,
2314
+ lastResolved: getLastResolvedOutput(traceChain)
2315
+ };
2316
+ };
2317
+ const buildTraceMetaOutput = (resolved) => {
2318
+ if (resolved.sourceCode) {
2319
+ return {
2320
+ traceData: resolved.traceChain,
2321
+ resolvedSourceMeta: {
2322
+ sourceFile: resolved.sourceCode.sourceFile,
2323
+ lineNumber: resolved.sourceCode.lineNumber,
2324
+ columnNumber: resolved.sourceCode.columnNumber
2325
+ },
2326
+ canFetchSourceSnippet: true,
2327
+ message: "已定位到源码位置,开始加载源码片段。"
2328
+ };
2329
+ }
2330
+ if (resolved.lastResolved) {
2331
+ const display = toDisplayLocation(resolved.lastResolved);
2332
+ return {
2333
+ traceData: resolved.traceChain,
2334
+ resolvedSourceMeta: {
2335
+ sourceFile: display.fileName,
2336
+ lineNumber: display.lineNumber,
2337
+ columnNumber: display.columnNumber
2338
+ },
2339
+ canFetchSourceSnippet: false,
2340
+ message: "当前 map 不包含 sourcesContent,无法直接渲染源码内容。"
2341
+ };
2342
+ }
2343
+ return {
2344
+ traceData: resolved.traceChain,
2345
+ resolvedSourceMeta: null,
2346
+ canFetchSourceSnippet: false,
2347
+ message: "未命中映射,未定位到源码位置。"
2348
+ };
2349
+ };
2350
+ const buildTraceSnippetOutput = (input) => {
2351
+ const { contextLineRadius, resolved } = input;
2352
+ if (resolved.sourceCode) {
2353
+ const excerpt = createCodeExcerpt({
2354
+ fullCode: resolved.sourceCode.code,
2355
+ targetLine: resolved.sourceCode.lineNumber,
2356
+ radius: contextLineRadius,
2357
+ targetColumn: resolved.sourceCode.columnNumber
2358
+ });
2359
+ return {
2360
+ traceCode: excerpt.code,
2361
+ resolvedSourceMeta: {
2362
+ sourceFile: resolved.sourceCode.sourceFile,
2363
+ lineNumber: resolved.sourceCode.lineNumber,
2364
+ columnNumber: resolved.sourceCode.columnNumber
2365
+ },
2366
+ traceHighlightLines: [excerpt.highlightLine]
2367
+ };
2368
+ }
2369
+ if (resolved.lastResolved) {
2370
+ const display = toDisplayLocation(resolved.lastResolved);
2371
+ return {
2372
+ traceCode: [
2373
+ `已定位到源码位置:${display.fileName}:${display.lineNumber}:${display.columnNumber}`,
2374
+ "当前 map 不包含 sourcesContent,无法直接渲染源码内容。"
2375
+ ].join("\n"),
2376
+ resolvedSourceMeta: {
2377
+ sourceFile: display.fileName,
2378
+ lineNumber: display.lineNumber,
2379
+ columnNumber: display.columnNumber
2380
+ },
2381
+ traceHighlightLines: []
2382
+ };
2383
+ }
2384
+ return {
2385
+ traceCode: "未命中映射,未定位到源码位置。",
2386
+ resolvedSourceMeta: null,
2387
+ traceHighlightLines: []
2388
+ };
2389
+ };
2390
+ const createChainSlotFromPath = async (filePath) => {
2391
+ const resolvedPath = filePath.startsWith("~/") ? `${node_os.homedir()}/${filePath.slice(2)}` : filePath;
2392
+ const mapFileName = node_path.basename(resolvedPath);
2393
+ const slotId = `${mapFileName}-${Math.random().toString(36).slice(2, 8)}`;
2394
+ try {
2395
+ const fileText = await promises.readFile(resolvedPath, "utf8");
2396
+ const rawSourceMap = JSON.parse(fileText);
2397
+ if (!rawSourceMap || typeof rawSourceMap !== "object" || typeof rawSourceMap.mappings !== "string") {
2398
+ throw new Error("invalid source-map json");
2399
+ }
2400
+ return {
2401
+ id: slotId,
2402
+ mapFileName,
2403
+ mapFilePath: resolvedPath,
2404
+ sourceMapRecord: { rawSourceMap, mapFileName }
2405
+ };
2406
+ } catch (error) {
2407
+ const message = error instanceof Error ? error.message : "unknown error";
2408
+ return {
2409
+ id: slotId,
2410
+ mapFileName,
2411
+ mapFilePath: resolvedPath,
2412
+ error: `${mapFileName}: ${message}`
2413
+ };
2414
+ }
2415
+ };
2416
+ const createResolveContext = async (parsed) => {
2417
+ const chainSlots = await Promise.all(parsed.mapFilePaths.map(createChainSlotFromPath));
2418
+ const chainState = buildChainStateFromSlots(chainSlots);
2419
+ const validated = validateResolveInput({
2420
+ entryFileName: parsed.entryFileName,
2421
+ entryLine: parsed.entryLine,
2422
+ entryColumn: parsed.entryColumn,
2423
+ contextLineRadius: parsed.contextLineRadius || String(DEFAULT_CONTEXT_LINE_RADIUS),
2424
+ mapCount: chainState.sourceMapFileNames.length
2425
+ });
2426
+ if (!validated.ok) throw new Error(validated.message);
2427
+ return {
2428
+ entry: validated.entry,
2429
+ contextLineRadius: validated.contextLineRadius,
2430
+ sourceMaps: chainState.sourceMaps,
2431
+ sourceMapFileNames: chainState.sourceMapFileNames
2432
+ };
2433
+ };
2434
+ const INPUT_VALIDATION_PATTERNS = ["请输入", "必须是", "未加载"];
2435
+ const parseResolveInput = (payloadText) => {
2436
+ const parsed = JSON.parse(payloadText);
2437
+ if (!parsed || typeof parsed !== "object") throw new Error("invalid resolveTrace payload");
2438
+ if (!parsed.entryFileName) throw new Error("missing argument: entryFileName");
2439
+ if (!parsed.entryLine) throw new Error("missing argument: entryLine");
2440
+ if (!parsed.entryColumn) throw new Error("missing argument: entryColumn");
2441
+ if (!Array.isArray(parsed.mapFilePaths) || parsed.mapFilePaths.length === 0) {
2442
+ throw new Error("missing argument: mapFilePaths");
2443
+ }
2444
+ return {
2445
+ ...parsed,
2446
+ contextLineRadius: parsed.contextLineRadius || String(DEFAULT_CONTEXT_LINE_RADIUS)
2447
+ };
2448
+ };
2449
+ const isInputValidationMessage = (message) => INPUT_VALIDATION_PATTERNS.some((pattern) => message.includes(pattern));
2450
+ const toFallbackEntry = (parsed) => ({
2451
+ fileName: parsed.entryFileName,
2452
+ lineNumber: Number(parsed.entryLine) || 1,
2453
+ columnNumber: Number(parsed.entryColumn) || 0
2454
+ });
2455
+ const createValidationMetaOutput = (message) => ({
2456
+ traceData: [],
2457
+ resolvedSourceMeta: null,
2458
+ canFetchSourceSnippet: false,
2459
+ message
2460
+ });
2461
+ const DEFAULT_MAX_SNIPPET_PAYLOAD_BYTES = 32 * 1024;
2462
+ const SNIPPET_PAYLOAD_EXCEEDED_ERROR = "SOURCE_SNIPPET_PAYLOAD_EXCEEDED: 返回体超出限制";
2463
+ const SNIPPET_PAYLOAD_OVERHEAD_BYTES = 512;
2464
+ const parseMaxSnippetPayloadBytes = (input) => {
2465
+ if (!input.maxSnippetPayloadBytes?.trim()) return DEFAULT_MAX_SNIPPET_PAYLOAD_BYTES;
2466
+ const parsed = Number(input.maxSnippetPayloadBytes);
2467
+ if (!Number.isInteger(parsed) || parsed <= 0) throw new Error("maxSnippetPayloadBytes 必须是大于 0 的整数。");
2468
+ return parsed;
2469
+ };
2470
+ const estimateSnippetPayloadBytes = (snippet) => {
2471
+ const codeBytes = Buffer.byteLength(snippet.traceCode, "utf8");
2472
+ const sourceFileBytes = snippet.resolvedSourceMeta?.sourceFile ? Buffer.byteLength(snippet.resolvedSourceMeta.sourceFile, "utf8") : 0;
2473
+ const highlightBytes = snippet.traceHighlightLines.reduce((total, line) => {
2474
+ return total + Buffer.byteLength(String(line), "utf8") + 1;
2475
+ }, 0);
2476
+ return codeBytes + sourceFileBytes + highlightBytes + SNIPPET_PAYLOAD_OVERHEAD_BYTES;
2477
+ };
2478
+ const assertSnippetPayloadWithinLimit = (snippet, input) => {
2479
+ const maxSnippetPayloadBytes = parseMaxSnippetPayloadBytes(input);
2480
+ const payloadBytes = estimateSnippetPayloadBytes(snippet);
2481
+ if (payloadBytes > maxSnippetPayloadBytes) throw new Error(
2482
+ `${SNIPPET_PAYLOAD_EXCEEDED_ERROR} (${payloadBytes} bytes > ${maxSnippetPayloadBytes} bytes)`
2483
+ );
2484
+ };
2485
+ const pushProfilePhase = (phases, name, startedAt) => {
2486
+ phases.push({ name, durationMs: Number((node_perf_hooks.performance.now() - startedAt).toFixed(2)) });
2487
+ };
2488
+ const resolveTrace = async (payloadText) => {
2489
+ const parsed = parseResolveInput(payloadText);
2490
+ try {
2491
+ const resolveContext = await createResolveContext(parsed);
2492
+ const resolved = await resolveTraceContextTask(resolveContext);
2493
+ return buildTraceMetaOutput(resolved);
2494
+ } catch (error) {
2495
+ const message = error instanceof Error ? error.message : "unknown error";
2496
+ if (isInputValidationMessage(message)) return createValidationMetaOutput(message);
2497
+ return {
2498
+ traceData: [{ input: toFallbackEntry(parsed) }],
2499
+ resolvedSourceMeta: null,
2500
+ canFetchSourceSnippet: false,
2501
+ message: `source-map trace failed: ${message}`
2502
+ };
2503
+ }
2504
+ };
2505
+ const getSourceSnippet = async (payloadText) => {
2506
+ const parsed = parseResolveInput(payloadText);
2507
+ const resolveContext = await createResolveContext(parsed);
2508
+ const resolved = await resolveTraceContextTask(resolveContext);
2509
+ const snippetOutput = buildTraceSnippetOutput({
2510
+ contextLineRadius: resolveContext.contextLineRadius,
2511
+ resolved
2512
+ });
2513
+ assertSnippetPayloadWithinLimit(snippetOutput, parsed);
2514
+ return snippetOutput;
2515
+ };
2516
+ const profileResolveTracePhases = async (payloadText) => {
2517
+ const phases = [];
2518
+ const totalStart = node_perf_hooks.performance.now();
2519
+ const parseStart = node_perf_hooks.performance.now();
2520
+ const parsed = parseResolveInput(payloadText);
2521
+ pushProfilePhase(phases, "parseResolveInput", parseStart);
2522
+ const createContextStart = node_perf_hooks.performance.now();
2523
+ const resolveContext = await createResolveContext(parsed);
2524
+ pushProfilePhase(phases, "createResolveContext", createContextStart);
2525
+ const resolveTraceStart = node_perf_hooks.performance.now();
2526
+ const resolved = await resolveTraceContextTask(resolveContext);
2527
+ pushProfilePhase(phases, "resolveTraceContextTask", resolveTraceStart);
2528
+ const buildMetaStart = node_perf_hooks.performance.now();
2529
+ const metaOutput = buildTraceMetaOutput(resolved);
2530
+ pushProfilePhase(phases, "buildTraceMetaOutput", buildMetaStart);
2531
+ const buildSnippetStart = node_perf_hooks.performance.now();
2532
+ const snippetOutput = buildTraceSnippetOutput({
2533
+ contextLineRadius: resolveContext.contextLineRadius,
2534
+ resolved
2535
+ });
2536
+ pushProfilePhase(phases, "buildTraceSnippetOutput", buildSnippetStart);
2537
+ const estimateStart = node_perf_hooks.performance.now();
2538
+ const maxSnippetPayloadBytes = parseMaxSnippetPayloadBytes(parsed);
2539
+ const snippetPayloadBytes = estimateSnippetPayloadBytes(snippetOutput);
2540
+ pushProfilePhase(phases, "estimateSnippetPayloadBytes", estimateStart);
2541
+ return {
2542
+ phases,
2543
+ totalMs: Number((node_perf_hooks.performance.now() - totalStart).toFixed(2)),
2544
+ traceHopCount: metaOutput.traceData.length,
2545
+ resolvedSourceMetaExists: Boolean(metaOutput.resolvedSourceMeta),
2546
+ snippetPayloadBytes,
2547
+ maxSnippetPayloadBytes,
2548
+ snippetPayloadWouldExceedLimit: snippetPayloadBytes > maxSnippetPayloadBytes
2549
+ };
2550
+ };
2551
+ const invokeMethod = defineInvokeMethod({ resolveTrace, getSourceSnippet, profileResolveTracePhases });
2552
+ registerInvokeMethod(invokeMethod);