|
1 | 1 | import type { NodePath } from '@babel/traverse' |
2 | 2 | import type { ImportDeclaration, StringLiteral } from '@babel/types' |
| 3 | +import type { SourceAnalysis } from '@/js/babel' |
3 | 4 | import type { IJsHandlerOptions } from '@/types' |
4 | 5 | import MagicString from 'magic-string' |
5 | 6 | import { describe, expect, it } from 'vitest' |
@@ -95,4 +96,28 @@ describe('sourceAnalysis helpers', () => { |
95 | 96 | expect(analysis.walker.imports).toBe(originalImports) |
96 | 97 | expect(analysis.walker.imports.size).toBe(originalImportCount) |
97 | 98 | }) |
| 99 | + |
| 100 | + it('returns early when there are no module specifiers to rewrite', () => { |
| 101 | + const imports = { |
| 102 | + size: 0, |
| 103 | + [Symbol.iterator]() { |
| 104 | + throw new Error('should not iterate imports') |
| 105 | + }, |
| 106 | + } |
| 107 | + |
| 108 | + const analysis = { |
| 109 | + ast: {} as SourceAnalysis['ast'], |
| 110 | + walker: { |
| 111 | + imports, |
| 112 | + } as unknown as SourceAnalysis['walker'], |
| 113 | + jsTokenUpdater: new JsTokenUpdater(), |
| 114 | + targetPaths: [], |
| 115 | + importDeclarations: new Set(), |
| 116 | + exportDeclarations: new Set(), |
| 117 | + requireCallPaths: [], |
| 118 | + ignoredPaths: new WeakSet(), |
| 119 | + } satisfies SourceAnalysis |
| 120 | + |
| 121 | + expect(collectModuleSpecifierReplacementTokens(analysis, { './foo': './bar' })).toEqual([]) |
| 122 | + }) |
98 | 123 | }) |
0 commit comments