Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions test/trace-position.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, expect, it } from 'vitest'
import { hasTracePosition } from '../ui/src/tracePosition'

describe('hasTracePosition', () => {
it('accepts zero as a valid trace position', () => {
expect(hasTracePosition('src/index.ts', 0)).toBe(true)
})

it('rejects missing paths and positions', () => {
expect(hasTracePosition(undefined, 0)).toBe(false)
expect(hasTracePosition('src/index.ts', undefined)).toBe(false)
})
})
3 changes: 2 additions & 1 deletion ui/components/TreeNode.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import type { Tree } from '../../src/traceTree'
import { childrenById, typesById } from '~/src/appState'
import { hasTracePosition } from '~/src/tracePosition'

const props = defineProps<{ tree: Tree, depth: number }>()

Expand All @@ -22,7 +23,7 @@ function fetchTypes() {
function gotoPosition() {
if ('name' in props.tree.line) {
const { path, pos } = props.tree.line.args ?? { path: undefined, pos: undefined }
if (!path || !pos)
if (!hasTracePosition(path, pos))
return

sendMessage('gotoPosition', { fileName: path, pos })
Expand Down
3 changes: 3 additions & 0 deletions ui/src/tracePosition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function hasTracePosition(path: string | undefined, pos: number | undefined): path is string {
return Boolean(path) && pos !== undefined
}