|
1 | 1 | import { join, relative } from 'pathe' |
2 | 2 | import { describe, expect, it } from 'vitest' |
3 | 3 | import { normalizeScanDirs, scanDirExports, stringifyImports } from '../src' |
| 4 | +import { scanExports } from '../src/node/scan-dirs' |
4 | 5 |
|
5 | 6 | describe('scan-dirs', () => { |
6 | 7 | it('scanDirExports', async () => { |
@@ -90,6 +91,11 @@ describe('scan-dirs', () => { |
90 | 91 | "from": "index.ts", |
91 | 92 | "name": "useDoubled", |
92 | 93 | }, |
| 94 | + { |
| 95 | + "as": "useSleep", |
| 96 | + "from": "async-value.ts", |
| 97 | + "name": "useSleep", |
| 98 | + }, |
93 | 99 | { |
94 | 100 | "as": "vanillaA", |
95 | 101 | "from": "vanilla.js", |
@@ -279,6 +285,17 @@ describe('scan-dirs', () => { |
279 | 285 | const singleAsteriskExports = await scanDirExports([dirWithSingleAsterisk]) |
280 | 286 | expect(singleAsteriskExports.some(i => i.name === 'CustomType2')).toEqual(true) |
281 | 287 | }) |
| 288 | + |
| 289 | + it('should not register JS reserved words as exports from declaration expressions', async () => { |
| 290 | + // mlly's regex parser incorrectly captures `async` from arrow function |
| 291 | + // bodies (e.g. `export const x = () => foo(async () => {})`) as an export |
| 292 | + // name. unimport should filter these out. |
| 293 | + const filepath = join(__dirname, '../playground/composables/async-value.ts') |
| 294 | + const exports = await scanExports(filepath, false) |
| 295 | + const names = exports.map(i => i.name) |
| 296 | + expect(names).toContain('useSleep') |
| 297 | + expect(names).not.toContain('async') |
| 298 | + }) |
282 | 299 | }) |
283 | 300 |
|
284 | 301 | it('normalizeScanDirs', () => { |
|
0 commit comments