|
7 | 7 | import Viewer from './Viewer.svelte'; |
8 | 8 | import { Editor, Workspace, type File } from 'editor'; |
9 | 9 | import { untrack } from 'svelte'; |
10 | | - import { decode } from '@jridgewell/sourcemap-codec'; |
| 10 | + import { decode, type SourceMapSegment } from '@jridgewell/sourcemap-codec'; |
11 | 11 |
|
12 | 12 | interface Props { |
13 | 13 | status: string | null; |
|
88 | 88 | if (markdown) return; |
89 | 89 |
|
90 | 90 | if (view === 'js' || view === 'css') { |
91 | | - const output = view === 'js' ? js_workspace : css_workspace; |
| 91 | + const v = view; // so that TS doesn't think it could become something different |
| 92 | + const output = v === 'js' ? js_workspace : css_workspace; |
92 | 93 |
|
93 | | - const highlight = (line: number, a: number[], b: number[]) => { |
| 94 | + const highlight = (line: number, a: SourceMapSegment, b: SourceMapSegment) => { |
94 | 95 | const split = { |
95 | | - original: workspace.current.contents.split('\n'), |
96 | | - generated: current.result[view].code.split('\n') |
| 96 | + original: workspace.current!.contents.split('\n'), |
| 97 | + generated: current!.result![v]!.code.split('\n') |
97 | 98 | }; |
98 | 99 |
|
99 | 100 | const original = { |
100 | | - start: split.original.slice(0, a[2]).join('\n').length + 1 + a[3], |
101 | | - end: split.original.slice(0, b[2]).join('\n').length + 1 + b[3] |
| 101 | + start: split.original.slice(0, a[2]).join('\n').length + 1 + a[3]!, |
| 102 | + end: split.original.slice(0, b[2]).join('\n').length + 1 + b[3]! |
102 | 103 | }; |
103 | 104 |
|
104 | 105 | const generated = { |
|
116 | 117 | }; |
117 | 118 |
|
118 | 119 | workspace.onhover((pos) => { |
119 | | - if (!current?.result?.[view]?.map) return; |
| 120 | + if (!current?.result?.[v]?.map) return; |
120 | 121 |
|
121 | | - const mappings = decode(current.result[view].map.mappings); |
| 122 | + const mappings = decode(current.result[v].map.mappings); |
122 | 123 |
|
123 | 124 | const { line, column } = locate(workspace.current.contents, pos)!; |
124 | 125 |
|
|
129 | 130 | const a = segments[j]; |
130 | 131 | const b = segments[j + 1]; |
131 | 132 |
|
132 | | - if (!b) continue; |
| 133 | + if (a[2]! > line) continue; |
| 134 | + if (b[2]! < line) continue; |
133 | 135 |
|
134 | | - if (a[2] > line) continue; |
135 | | - if (b[2] < line) continue; |
136 | | -
|
137 | | - if (a[2] === line && a[3] > column) continue; |
138 | | - if (b[2] === line && b[3] < column) continue; |
| 136 | + if (a[2]! === line && a[3]! > column) continue; |
| 137 | + if (b[2]! === line && b[3]! < column) continue; |
139 | 138 |
|
140 | 139 | // if we're still here, we have a match |
141 | 140 | highlight(i, a, b); |
|
147 | 146 | }); |
148 | 147 |
|
149 | 148 | output.onhover((pos) => { |
150 | | - if (!current?.result?.[view]?.map) return; |
| 149 | + if (!current?.result?.[v]?.map) return; |
151 | 150 |
|
152 | | - const mappings = decode(current.result[view].map.mappings); |
| 151 | + const mappings = decode(current.result[v].map.mappings); |
153 | 152 |
|
154 | | - const { line, column } = locate(current.result[view].code, pos)!; |
| 153 | + const { line, column } = locate(current.result[v].code, pos)!; |
155 | 154 |
|
156 | 155 | const segments = mappings[line]; |
157 | 156 |
|
|
0 commit comments