|
16 | 16 | * the already-highlighted span tree, not the raw text — hljs |
17 | 17 | * splits text nodes, so any <a> we wrap before it runs would be |
18 | 18 | * blown away. Uses `ns.onHljsReady` from boot.js to gate. */ |
| 19 | + |
| 20 | +import { |
| 21 | + JSONParse, |
| 22 | + MapCtor, |
| 23 | + StringPrototypeMatchAll, |
| 24 | + StringPrototypeStartsWith, |
| 25 | +} from '@socketsecurity/lib/primordials' |
19 | 26 | ;(() => { |
20 | 27 | const ns = window[Symbol.for('socket-pages')] |
21 | 28 | if (!ns) { |
|
24 | 31 |
|
25 | 32 | const installSourceLinks = () => { |
26 | 33 | const rawAnchors = document.body.getAttribute('data-file-anchors') |
27 | | - const anchorByPath = new Map() |
| 34 | + const anchorByPath = new MapCtor() |
28 | 35 | if (rawAnchors) { |
29 | 36 | try { |
30 | | - const entries = JSON.parse(rawAnchors) |
| 37 | + const entries = JSONParse(rawAnchors) |
31 | 38 | for (const [p, a] of entries) { |
32 | 39 | anchorByPath.set(p, a) |
33 | 40 | } |
|
40 | 47 | /* Build a basename-swap fallback so `./compare.js` in source |
41 | 48 | * resolves to `compare.ts` on disk. Keyed by `<dir>/<basename>` |
42 | 49 | * without extension; value is the primary anchor. */ |
43 | | - const anchorByStem = new Map() |
| 50 | + const anchorByStem = new MapCtor() |
44 | 51 | for (const [path, anchor] of anchorByPath) { |
45 | 52 | const stem = path.replace(/\.[a-z0-9]+$/i, '') |
46 | 53 | if (!anchorByStem.has(stem)) { |
|
49 | 56 | } |
50 | 57 |
|
51 | 58 | const resolveRelPath = (fromPath, ref) => { |
52 | | - if (!ref.startsWith('./') && !ref.startsWith('../')) { |
| 59 | + if ( |
| 60 | + !StringPrototypeStartsWith(ref, './') && |
| 61 | + !StringPrototypeStartsWith(ref, '../') |
| 62 | + ) { |
53 | 63 | return null |
54 | 64 | } |
55 | 65 | const fromDir = fromPath.split('/').slice(0, -1) |
|
85 | 95 | return |
86 | 96 | } |
87 | 97 | const matches = [] |
88 | | - for (const m of text.matchAll(urlRe)) { |
| 98 | + for (const m of StringPrototypeMatchAll(text, urlRe)) { |
89 | 99 | matches.push({ |
90 | 100 | start: m.index, |
91 | 101 | end: m.index + m[0].length, |
|
94 | 104 | type: 'url', |
95 | 105 | }) |
96 | 106 | } |
97 | | - for (const m of text.matchAll(quotedPathRe)) { |
| 107 | + for (const m of StringPrototypeMatchAll(text, quotedPathRe)) { |
98 | 108 | const pathRef = m[2] |
99 | 109 | const anchor = filePath ? resolveRelPath(filePath, pathRef) : null |
100 | 110 | if (!anchor) { |
|
0 commit comments