Skip to content

Commit 2d89d3f

Browse files
Fix playground crash on no target (#6753)
fix #6752
1 parent 9c2b1b8 commit 2d89d3f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
3+
changeKind: fix
4+
packages:
5+
- "@typespec/playground"
6+
---
7+
8+
Guard against diagnostic reported without a target

packages/playground/src/react/diagnostic-list/diagnostic-list.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,18 @@ const DiagnosticItem: FunctionComponent<DiagnosticItemProps> = ({ diagnostic, on
6464
};
6565

6666
const DiagnosticTargetLink = memo(({ target }: { target: DiagnosticTarget | typeof NoTarget }) => {
67+
if (target === undefined) {
68+
return (
69+
<span title="Diagnostic didn't report a target. This is a bug on the emitter.">
70+
No target
71+
</span>
72+
);
73+
}
6774
if (typeof target === "symbol") {
6875
return <span></span>;
6976
}
7077
const location = getSourceLocation(target);
78+
7179
const file = location.file.path === "/test/main.tsp" ? "" : `${location.file.path}:`;
7280
const { line, character } = location.file.getLineAndCharacterOfPosition(location.pos);
7381
return (

0 commit comments

Comments
 (0)