Skip to content

Commit 8f086bb

Browse files
authored
(fix) svelte2tsx runtime error diagnostics line number (#1183)
- null check in checkIfImportIsEventDispatcher - fix svelte2tsx runtime error diagnostics #1182
1 parent 52904b6 commit 8f086bb

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

packages/language-server/src/plugins/typescript/DocumentSnapshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function preprocessSvelteFile(document: Document, options: SvelteSnapshotOptions
187187
} catch (e: any) {
188188
// Error start/end logic is different and has different offsets for line, so we need to convert that
189189
const start: Position = {
190-
line: e.start?.line - 1 ?? 0,
190+
line: (e.start?.line ?? 1) - 1,
191191
character: e.start?.column ?? 0
192192
};
193193
const end: Position = e.end ? { line: e.end.line - 1, character: e.end.column } : start;

packages/svelte2tsx/src/svelte2tsx/nodes/ComponentEvents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ function checkIfImportIsEventDispatcher(node: ts.ImportDeclaration): string | un
382382
}
383383

384384
const namedImports = node.importClause?.namedBindings;
385-
if (ts.isNamedImports(namedImports)) {
385+
if (namedImports && ts.isNamedImports(namedImports)) {
386386
const eventDispatcherImport = namedImports.elements.find(
387387
// If it's an aliased import, propertyName is set
388388
(el) => (el.propertyName || el.name).text === 'createEventDispatcher'

0 commit comments

Comments
 (0)