|
1 | 1 | import * as ts from 'typescript';
|
2 |
| -import {updateModuleSpecifier} from './import-operations'; |
| 2 | +import {updateModuleSpecifier, updateNamedImport} from './import-operations'; |
3 | 3 |
|
4 | 4 | describe('import operations', () => {
|
5 | 5 | describe('updateModuleSpecifier', () => {
|
@@ -39,6 +39,51 @@ describe('import operations', () => {
|
39 | 39 | });
|
40 | 40 | });
|
41 | 41 | });
|
| 42 | + |
| 43 | + describe('updateNamedExport', () => { |
| 44 | + function runUpdateNamedExportTest( |
| 45 | + description: string, |
| 46 | + opts: { |
| 47 | + oldFile: string; |
| 48 | + newFile: string; |
| 49 | + oldExport: string; |
| 50 | + newExport: string; |
| 51 | + }, |
| 52 | + ): void { |
| 53 | + const node = createNode(opts.oldFile, ts.SyntaxKind.NamedImports) as ts.NamedImports; |
| 54 | + const newImport = updateNamedImport(node, { |
| 55 | + oldExport: opts.oldExport, |
| 56 | + newExport: opts.newExport, |
| 57 | + })?.updateFn(opts.oldFile); |
| 58 | + expect(newImport).withContext(description).toBe(opts.newFile); |
| 59 | + } |
| 60 | + it('updates the named exports of import declarations', () => { |
| 61 | + runUpdateNamedExportTest('named binding', { |
| 62 | + oldExport: 'oldExport', |
| 63 | + newExport: 'newExport', |
| 64 | + oldFile: `import { oldExport } from 'module-name';`, |
| 65 | + newFile: `import { newExport } from 'module-name';`, |
| 66 | + }); |
| 67 | + runUpdateNamedExportTest('aliased named binding', { |
| 68 | + oldExport: 'oldExport', |
| 69 | + newExport: 'newExport', |
| 70 | + oldFile: `import { oldExport as alias } from 'module-name';`, |
| 71 | + newFile: `import { newExport as alias } from 'module-name';`, |
| 72 | + }); |
| 73 | + runUpdateNamedExportTest('multiple named bindings', { |
| 74 | + oldExport: 'oldExport1', |
| 75 | + newExport: 'newExport1', |
| 76 | + oldFile: `import { oldExport1, export2 } from 'module-name';`, |
| 77 | + newFile: `import { newExport1, export2 } from 'module-name';`, |
| 78 | + }); |
| 79 | + runUpdateNamedExportTest('multiple named bindings w/ alias', { |
| 80 | + oldExport: 'oldExport2', |
| 81 | + newExport: 'newExport2', |
| 82 | + oldFile: `import { export1, oldExport2 as alias2 } from 'module-name';`, |
| 83 | + newFile: `import { export1, newExport2 as alias2 } from 'module-name';`, |
| 84 | + }); |
| 85 | + }); |
| 86 | + }); |
42 | 87 | });
|
43 | 88 |
|
44 | 89 | function createSourceFile(text: string): ts.SourceFile {
|
|
0 commit comments