bippy 0.7.3-dev.0c7e504 → 0.7.3-dev.2c148fc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -1
- package/README.md +4 -11
- package/dist/core.cjs +1 -1
- package/dist/core.js +1 -1
- package/dist/errors.d.cts +4 -1
- package/dist/errors.d.ts +4 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +27 -27
- package/dist/index.d.ts +27 -27
- package/dist/index.js +1 -1
- package/dist/rdt-hook.cjs +1 -1
- package/dist/rdt-hook.js +1 -1
- package/dist/source.cjs +11 -12
- package/dist/source.d.cts +24 -22
- package/dist/source.d.ts +24 -22
- package/dist/source.js +12 -13
- package/package.json +4 -4
- package/src/call-listener.ts +13 -0
- package/src/core.ts +188 -183
- package/src/rdt-hook.ts +43 -29
- package/src/react-internals/generated/react-work-tags.ts +3 -0
- package/src/react-internals/index.ts +36 -14
- package/src/react.ts +11 -1
- package/src/source/constants.ts +10 -6
- package/src/source/get-source.ts +1 -136
- package/src/source/inspect-hooks.ts +5 -3
- package/src/source/normalize-file-name.ts +416 -0
- package/src/source/parse-stack.ts +111 -63
- package/src/source/symbolication.ts +78 -38
|
@@ -2,6 +2,7 @@ import { decode, type SourceMapMappings, type SourceMapSegment } from "@jridgewe
|
|
|
2
2
|
|
|
3
3
|
import { BippySourceMapError } from "../errors.js";
|
|
4
4
|
import { SCHEME_REGEX } from "./constants.js";
|
|
5
|
+
import { normalizeFileName } from "./normalize-file-name.js";
|
|
5
6
|
import type { StackFrame } from "./parse-stack.js";
|
|
6
7
|
|
|
7
8
|
export interface DecodedSourceMapSection {
|
|
@@ -207,6 +208,13 @@ export const getSourceFromSourceMap = (
|
|
|
207
208
|
);
|
|
208
209
|
};
|
|
209
210
|
|
|
211
|
+
const getStringIndex = (values: string[], target: string): number => {
|
|
212
|
+
for (let valueIndex = 0; valueIndex < values.length; valueIndex++) {
|
|
213
|
+
if (values[valueIndex] === target) return valueIndex;
|
|
214
|
+
}
|
|
215
|
+
return -1;
|
|
216
|
+
};
|
|
217
|
+
|
|
210
218
|
const getSourceFromMappingsByFunctionName = (
|
|
211
219
|
mappings: SourceMapMappings,
|
|
212
220
|
sources: string[],
|
|
@@ -215,13 +223,17 @@ const getSourceFromMappingsByFunctionName = (
|
|
|
215
223
|
ignoredSourceIndices?: Set<number>,
|
|
216
224
|
): StackFrame | null => {
|
|
217
225
|
if (!names) return null;
|
|
218
|
-
const functionNameIndex = names
|
|
226
|
+
const functionNameIndex = getStringIndex(names, functionName);
|
|
219
227
|
if (functionNameIndex === -1) return null;
|
|
220
228
|
|
|
221
229
|
let ignoredSource: StackFrame | null = null;
|
|
222
|
-
for (
|
|
223
|
-
|
|
230
|
+
for (let lineIndex = 0; lineIndex < mappings.length; lineIndex++) {
|
|
231
|
+
const lineMapping = mappings[lineIndex];
|
|
232
|
+
for (let segmentIndex = 0; segmentIndex < lineMapping.length; segmentIndex++) {
|
|
233
|
+
const segment = lineMapping[segmentIndex];
|
|
224
234
|
if (segment[4] !== functionNameIndex) continue;
|
|
235
|
+
if (ignoredSource && segment[1] !== undefined && ignoredSourceIndices?.has(segment[1]))
|
|
236
|
+
continue;
|
|
225
237
|
const source = getSourceFromSegment(segment, sources, ignoredSourceIndices, names);
|
|
226
238
|
if (!source) continue;
|
|
227
239
|
if (!source.isIgnoreListed) return source;
|
|
@@ -261,37 +273,40 @@ export const getSourceFromSourceMapByFunctionName = (
|
|
|
261
273
|
);
|
|
262
274
|
};
|
|
263
275
|
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
fileName: string,
|
|
268
|
-
): string | null => {
|
|
269
|
-
if (!sourcesContent) return null;
|
|
270
|
-
const sourceIndex = sources.indexOf(fileName);
|
|
271
|
-
return sourceIndex === -1 ? null : (sourcesContent[sourceIndex] ?? null);
|
|
276
|
+
const canonicalSourcePath = (fileName: string): string => {
|
|
277
|
+
const normalizedFileName = normalizeFileName(fileName);
|
|
278
|
+
return normalizedFileName.startsWith("./") ? normalizedFileName.slice(2) : normalizedFileName;
|
|
272
279
|
};
|
|
273
280
|
|
|
274
281
|
export const getSourceContentFromSourceMap = (
|
|
275
282
|
sourceMap: SourceMap,
|
|
276
283
|
originalFileName: string,
|
|
277
284
|
): string | null => {
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
originalFileName
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
285
|
+
const maps = [sourceMap, ...(sourceMap.sections?.map((section) => section.map) ?? [])];
|
|
286
|
+
let hasExactSource = false;
|
|
287
|
+
for (const map of maps) {
|
|
288
|
+
const sourceIndex = getStringIndex(map.sources, originalFileName);
|
|
289
|
+
if (sourceIndex === -1) continue;
|
|
290
|
+
hasExactSource = true;
|
|
291
|
+
const sourceContent = map.sourcesContent?.[sourceIndex];
|
|
292
|
+
if (typeof sourceContent === "string") return sourceContent;
|
|
293
|
+
}
|
|
294
|
+
if (hasExactSource) return null;
|
|
295
|
+
|
|
296
|
+
const canonicalFileName = canonicalSourcePath(originalFileName);
|
|
297
|
+
if (!canonicalFileName) return null;
|
|
298
|
+
let matchedFileName: string | undefined;
|
|
299
|
+
let matchedContent: string | null = null;
|
|
300
|
+
for (const map of maps) {
|
|
301
|
+
for (let index = 0; index < map.sources.length; index++) {
|
|
302
|
+
const fileName = map.sources[index];
|
|
303
|
+
if (!fileName || canonicalSourcePath(fileName) !== canonicalFileName) continue;
|
|
304
|
+
if (matchedFileName !== undefined && matchedFileName !== fileName) return null;
|
|
305
|
+
matchedFileName = fileName;
|
|
306
|
+
matchedContent ??= map.sourcesContent?.[index] ?? null;
|
|
307
|
+
}
|
|
293
308
|
}
|
|
294
|
-
return
|
|
309
|
+
return matchedContent;
|
|
295
310
|
};
|
|
296
311
|
|
|
297
312
|
const resolveUrl = (reference: string, baseUrl: string): string | null => {
|
|
@@ -434,12 +449,46 @@ const getIgnoredSourceIndices = (rawSourceMap: StandardSourceMap): Set<number> |
|
|
|
434
449
|
return ignoreList?.length ? new Set(ignoreList) : undefined;
|
|
435
450
|
};
|
|
436
451
|
|
|
452
|
+
const isAbsoluteSourcePath = (source: string): boolean =>
|
|
453
|
+
source.startsWith("/") || /^[a-zA-Z]:[\\/]/.test(source) || SCHEME_REGEX.test(source);
|
|
454
|
+
|
|
455
|
+
const resolveRelativeSource = (source: string, sourceMapUrl: string): string => {
|
|
456
|
+
if (!source.startsWith("./") && !source.startsWith("../")) return source;
|
|
457
|
+
if (INLINE_SOURCEMAP_REGEX.test(sourceMapUrl)) return source;
|
|
458
|
+
return resolveUrl(source, sourceMapUrl) ?? source;
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
const normalizeJoinedSourcePath = (joinedSource: string): string => {
|
|
462
|
+
const pathSegments = joinedSource.split("/");
|
|
463
|
+
const normalizedPathSegments: string[] = [];
|
|
464
|
+
for (const pathSegment of pathSegments) {
|
|
465
|
+
if (pathSegment === "" || pathSegment === ".") {
|
|
466
|
+
if (pathSegment === "" && normalizedPathSegments.length === 0) {
|
|
467
|
+
normalizedPathSegments.push("");
|
|
468
|
+
}
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
if (pathSegment === "..") {
|
|
472
|
+
const previousSegment = normalizedPathSegments[normalizedPathSegments.length - 1];
|
|
473
|
+
if (previousSegment && previousSegment !== ".." && previousSegment !== "") {
|
|
474
|
+
normalizedPathSegments.pop();
|
|
475
|
+
} else {
|
|
476
|
+
normalizedPathSegments.push("..");
|
|
477
|
+
}
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
normalizedPathSegments.push(pathSegment);
|
|
481
|
+
}
|
|
482
|
+
return normalizedPathSegments.join("/");
|
|
483
|
+
};
|
|
484
|
+
|
|
437
485
|
const resolveSourceRoot = (
|
|
438
486
|
sourceRoot: string | undefined,
|
|
439
487
|
source: string,
|
|
440
488
|
sourceMapUrl: string,
|
|
441
489
|
): string => {
|
|
442
|
-
if (
|
|
490
|
+
if (isAbsoluteSourcePath(source)) return source;
|
|
491
|
+
if (!sourceRoot) return resolveRelativeSource(source, sourceMapUrl);
|
|
443
492
|
const normalizedSourceRoot = sourceRoot.endsWith("/") ? sourceRoot : `${sourceRoot}/`;
|
|
444
493
|
const normalizedSource = source.replace(/^\.\//, "");
|
|
445
494
|
try {
|
|
@@ -448,16 +497,7 @@ const resolveSourceRoot = (
|
|
|
448
497
|
: new URL(normalizedSourceRoot, sourceMapUrl).toString();
|
|
449
498
|
return new URL(normalizedSource, baseUrl).toString();
|
|
450
499
|
} catch {
|
|
451
|
-
|
|
452
|
-
const normalizedPathSegments: string[] = [];
|
|
453
|
-
for (const pathSegment of pathSegments) {
|
|
454
|
-
if (pathSegment === "..") {
|
|
455
|
-
normalizedPathSegments.pop();
|
|
456
|
-
} else if (pathSegment !== ".") {
|
|
457
|
-
normalizedPathSegments.push(pathSegment);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
return normalizedPathSegments.join("/");
|
|
500
|
+
return normalizeJoinedSourcePath(`${normalizedSourceRoot}${normalizedSource}`);
|
|
461
501
|
}
|
|
462
502
|
};
|
|
463
503
|
|