jsdoczoom 0.4.13 → 0.4.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,9 +17,9 @@ import { appendText, DESCRIPTION_TAGS } from "./types.js";
17
17
  * Returns the raw JSDoc text without the leading `/**` and trailing `*​/` delimiters,
18
18
  * or null if no file-level JSDoc is found.
19
19
  */
20
- export function extractFileJsdoc(sourceText) {
20
+ export function extractFileJsdoc(sourceText, fileName = "input.tsx") {
21
21
  const sourceFile = ts.createSourceFile(
22
- "input.ts",
22
+ fileName,
23
23
  sourceText,
24
24
  ts.ScriptTarget.Latest,
25
25
  true,
@@ -33,9 +33,11 @@ export function extractFileJsdoc(sourceText) {
33
33
  );
34
34
  }
35
35
  // Find the first non-import top-level statement
36
+ let firstImport;
36
37
  let firstNonImportStatement;
37
38
  for (const statement of sourceFile.statements) {
38
39
  if (ts.isImportDeclaration(statement)) {
40
+ firstImport ??= statement;
39
41
  continue;
40
42
  }
41
43
  firstNonImportStatement = statement;
@@ -45,7 +47,24 @@ export function extractFileJsdoc(sourceText) {
45
47
  if (firstNonImportStatement === undefined) {
46
48
  return findFirstJsdocBlock(sourceText, 0, sourceText.length);
47
49
  }
48
- // The JSDoc block sits in the leading trivia of the first non-import statement.
50
+ // When imports exist, the file-level JSDoc lives in the leading trivia of
51
+ // the first import (before any imports), not the first non-import statement.
52
+ // Check there first; fall back to the first non-import statement's trivia
53
+ // for the "JSDoc after imports" pattern.
54
+ if (firstImport) {
55
+ const importFullStart = firstImport.getFullStart();
56
+ const importNodeStart = firstImport.getStart(sourceFile);
57
+ const preImportJsdoc = findFirstJsdocBlock(
58
+ sourceText,
59
+ importFullStart,
60
+ importNodeStart,
61
+ );
62
+ if (preImportJsdoc !== null) {
63
+ return preImportJsdoc;
64
+ }
65
+ }
66
+ // JSDoc in the leading trivia of the first non-import statement
67
+ // (handles "JSDoc after imports but before code" pattern).
49
68
  const fullStart = firstNonImportStatement.getFullStart();
50
69
  const nodeStart = firstNonImportStatement.getStart(sourceFile);
51
70
  return findFirstJsdocBlock(sourceText, fullStart, nodeStart);
@@ -203,7 +222,7 @@ export function parseFileSummaries(filePath) {
203
222
  } catch {
204
223
  throw new JsdocError("FILE_NOT_FOUND", `File not found: ${filePath}`);
205
224
  }
206
- const jsdocText = extractFileJsdoc(sourceText);
225
+ const jsdocText = extractFileJsdoc(sourceText, filePath);
207
226
  if (jsdocText === null) {
208
227
  return {
209
228
  path: filePath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsdoczoom",
3
- "version": "0.4.13",
3
+ "version": "0.4.16",
4
4
  "description": "CLI tool for extracting JSDoc summaries at configurable depths",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -14,7 +14,10 @@ import { type ParsedFileInfo } from "./types.js";
14
14
  * Returns the raw JSDoc text without the leading `/**` and trailing `*​/` delimiters,
15
15
  * or null if no file-level JSDoc is found.
16
16
  */
17
- export declare function extractFileJsdoc(sourceText: string): string | null;
17
+ export declare function extractFileJsdoc(
18
+ sourceText: string,
19
+ fileName?: string,
20
+ ): string | null;
18
21
  /**
19
22
  * Parse a TypeScript file and extract its summary and description from file-level JSDoc.
20
23
  *