Skip to content

Commit

Permalink
Add pos to reference pragma import node
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Oct 6, 2024
1 parent 72b4827 commit f704a2b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/knip/src/typescript/SourceFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion packages/knip/src/typescript/visitors/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit f704a2b

Please sign in to comment.