From f704a2bbfd614972c2a2f6c3c997eac1f895a28c Mon Sep 17 00:00:00 2001 From: Lars Kappert Date: Sun, 6 Oct 2024 14:13:24 +0200 Subject: [PATCH] Add `pos` to reference pragma import node --- packages/knip/src/typescript/SourceFile.ts | 6 ++++++ packages/knip/src/typescript/visitors/helpers.ts | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/knip/src/typescript/SourceFile.ts b/packages/knip/src/typescript/SourceFile.ts index 98d321492..6223fc5f8 100644 --- a/packages/knip/src/typescript/SourceFile.ts +++ b/packages/knip/src/typescript/SourceFile.ts @@ -19,6 +19,12 @@ type PragmaMap = { path?: { value?: string; pos?: number }; types?: { value?: string; pos?: number }; }; + range?: { + kind?: number; + pos?: number; + end?: number; + hasTrailingNewLine?: boolean; + }; }; export interface BoundSourceFile extends ts.SourceFile { diff --git a/packages/knip/src/typescript/visitors/helpers.ts b/packages/knip/src/typescript/visitors/helpers.ts index 9622e0877..b60e4efdd 100644 --- a/packages/knip/src/typescript/visitors/helpers.ts +++ b/packages/knip/src/typescript/visitors/helpers.ts @@ -17,7 +17,8 @@ export function getImportsFromPragmas(sourceFile: BoundSourceFile) { ? jsxImportSourcePragmas[jsxImportSourcePragmas.length - 1] : jsxImportSourcePragmas; const { factory: specifier } = jsxImportSourcePragma?.arguments ?? {}; - if (specifier) importNodes.push({ specifier, isTypeOnly: true, identifier: '__jsx', pos: 0 }); + const pos = jsxImportSourcePragma.range?.pos ?? 0; + if (specifier) importNodes.push({ specifier, isTypeOnly: true, identifier: '__jsx', pos }); } const referencePragma = sourceFile.pragmas.get('reference');