|
12 | 12 | * insertion safely — only one survives. |
13 | 13 | */ |
14 | 14 |
|
15 | | -/** |
16 | | - * Build the fixer-side inserts for missing import + optional hoist. |
17 | | - * Returns an array of fixer operations the caller appends to its own |
18 | | - * fix() return value. |
19 | | - * |
20 | | - * summary — output of summarizeImportTarget() |
21 | | - * fixer — the fixer passed to context.report({ fix }) |
22 | | - * importLine — the literal `import { ... } from '...'` text |
23 | | - * hoistLine — optional; the literal `const x = ...()` text |
24 | | - */ |
25 | | -export function appendImportFixes(summary, fixer, importLine, hoistLine) { |
26 | | - const ops = [] |
27 | | - if (!summary.hasImport) { |
28 | | - if (summary.lastImport) { |
29 | | - ops.push(fixer.insertTextAfter(summary.lastImport, `\n${importLine}`)) |
30 | | - } else { |
31 | | - ops.push(fixer.insertTextBeforeRange([0, 0], `${importLine}\n`)) |
32 | | - } |
33 | | - } |
34 | | - if (hoistLine && !summary.hasLocal) { |
35 | | - if (summary.lastImport) { |
36 | | - ops.push(fixer.insertTextAfter(summary.lastImport, `\n\n${hoistLine}`)) |
37 | | - } else { |
38 | | - ops.push(fixer.insertTextBeforeRange([0, 0], `${hoistLine}\n\n`)) |
39 | | - } |
40 | | - } |
41 | | - return ops |
42 | | -} |
43 | | - |
44 | 15 | /** |
45 | 16 | * Walk a Program node body once and figure out: |
46 | 17 | * - the last top-level ImportDeclaration node (or undefined) |
@@ -108,3 +79,32 @@ export function summarizeImportTarget( |
108 | 79 | } |
109 | 80 | return { hasImport, hasLocal, lastImport } |
110 | 81 | } |
| 82 | + |
| 83 | +/** |
| 84 | + * Build the fixer-side inserts for missing import + optional hoist. |
| 85 | + * Returns an array of fixer operations the caller appends to its own |
| 86 | + * fix() return value. |
| 87 | + * |
| 88 | + * summary — output of summarizeImportTarget() |
| 89 | + * fixer — the fixer passed to context.report({ fix }) |
| 90 | + * importLine — the literal `import { ... } from '...'` text |
| 91 | + * hoistLine — optional; the literal `const x = ...()` text |
| 92 | + */ |
| 93 | +export function appendImportFixes(summary, fixer, importLine, hoistLine) { |
| 94 | + const ops = [] |
| 95 | + if (!summary.hasImport) { |
| 96 | + if (summary.lastImport) { |
| 97 | + ops.push(fixer.insertTextAfter(summary.lastImport, `\n${importLine}`)) |
| 98 | + } else { |
| 99 | + ops.push(fixer.insertTextBeforeRange([0, 0], `${importLine}\n`)) |
| 100 | + } |
| 101 | + } |
| 102 | + if (hoistLine && !summary.hasLocal) { |
| 103 | + if (summary.lastImport) { |
| 104 | + ops.push(fixer.insertTextAfter(summary.lastImport, `\n\n${hoistLine}`)) |
| 105 | + } else { |
| 106 | + ops.push(fixer.insertTextBeforeRange([0, 0], `${hoistLine}\n\n`)) |
| 107 | + } |
| 108 | + } |
| 109 | + return ops |
| 110 | +} |
0 commit comments