(file: FileInfo, api: API)
| 90 | } |
| 91 | |
| 92 | export default function transformer(file: FileInfo, api: API): string { |
| 93 | let specifiersByPackage = getSpecifiersByPackage(file.path); |
| 94 | let j = api.jscodeshift.withParser({ |
| 95 | parse(source: string) { |
| 96 | return recastParse(source, { |
| 97 | parser: { |
| 98 | parse(innerSource: string) { |
| 99 | return parse(innerSource, { |
| 100 | sourceType: 'module', |
| 101 | plugins: [ |
| 102 | 'jsx', |
| 103 | 'typescript', |
| 104 | 'importAssertions', |
| 105 | 'dynamicImport', |
| 106 | 'decorators-legacy', |
| 107 | 'classProperties', |
| 108 | 'classPrivateProperties', |
| 109 | 'classPrivateMethods', |
| 110 | 'exportDefaultFrom', |
| 111 | 'exportNamespaceFrom', |
| 112 | 'objectRestSpread', |
| 113 | 'optionalChaining', |
| 114 | 'nullishCoalescingOperator', |
| 115 | 'topLevelAwait' |
| 116 | ], |
| 117 | tokens: true, |
| 118 | errorRecovery: true |
| 119 | }); |
| 120 | } |
| 121 | } |
| 122 | }); |
| 123 | } |
| 124 | }); |
| 125 | |
| 126 | let root = j(file.source); |
| 127 | let program = root.get().node.program as t.Program; |
| 128 | let uniqueSources = new Set<string>(); |
| 129 | let existingImports = new Map<string, t.ImportDeclaration>(); |
| 130 | let didChange = false; |
| 131 | |
| 132 | for (let node of program.body) { |
| 133 | if (node.type === 'ImportDeclaration') { |
| 134 | let source = node.source.value; |
| 135 | if (typeof source !== 'string') { |
| 136 | continue; |
| 137 | } |
| 138 | |
| 139 | existingImports.set(getImportDeclarationKey(node), node); |
| 140 | |
| 141 | if (source in specifiersByPackage) { |
| 142 | let sourceMap = specifiersByPackage[source]; |
| 143 | for (let specifier of node.specifiers ?? []) { |
| 144 | if (specifier.type !== 'ImportSpecifier') { |
| 145 | continue; |
| 146 | } |
| 147 | |
| 148 | let importedName = getImportedName(specifier); |
| 149 | let candidates = sourceMap[importedName]; |
nothing calls this directly
no test coverage detected