( file: FileInfo, _api: API, options: Options )
| 14 | } |
| 15 | |
| 16 | export default function transformer( |
| 17 | file: FileInfo, |
| 18 | _api: API, |
| 19 | options: Options |
| 20 | ) { |
| 21 | const j = createParserFromPath(file.path) |
| 22 | const root = j(file.source) |
| 23 | let hasChanges = false |
| 24 | |
| 25 | try { |
| 26 | // Track identifier renames that need to be applied |
| 27 | const identifierRenames: Array<{ oldName: string; newName: string }> = [] |
| 28 | // Track variables assigned from next/cache imports/requires |
| 29 | const cacheVariables = new Set<string>() |
| 30 | |
| 31 | // Handle ES6 imports: import { unstable_cacheTag } from 'next/cache' |
| 32 | root |
| 33 | .find(j.ImportDeclaration, { source: { value: 'next/cache' } }) |
| 34 | .forEach((path) => { |
| 35 | path.node.specifiers?.forEach((specifier) => { |
| 36 | if ( |
| 37 | specifier.type === 'ImportSpecifier' && |
| 38 | specifier.imported?.type === 'Identifier' && |
| 39 | shouldRenameProperty(specifier.imported.name) |
| 40 | ) { |
| 41 | const oldName = specifier.imported.name |
| 42 | const newName = UNSTABLE_TO_STABLE_MAPPING[oldName] |
| 43 | |
| 44 | // Handle alias scenarios |
| 45 | if (specifier.local && specifier.local.name === newName) { |
| 46 | // Same alias name: { unstable_cacheTag as cacheTag } -> { cacheTag } |
| 47 | const newSpecifier = j.importSpecifier(j.identifier(newName)) |
| 48 | const specifierIndex = path.node.specifiers.indexOf(specifier) |
| 49 | path.node.specifiers[specifierIndex] = newSpecifier |
| 50 | identifierRenames.push({ oldName, newName }) |
| 51 | } else { |
| 52 | // Normal case: just update the imported name |
| 53 | specifier.imported = j.identifier(newName) |
| 54 | if (!specifier.local || specifier.local.name === oldName) { |
| 55 | // Not aliased or aliased with old name: add to identifier renames |
| 56 | identifierRenames.push({ oldName, newName }) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | hasChanges = true |
| 61 | } else if (specifier.type === 'ImportNamespaceSpecifier') { |
| 62 | // Handle namespace imports: import * as cache from 'next/cache' |
| 63 | cacheVariables.add(specifier.local.name) |
| 64 | } |
| 65 | }) |
| 66 | }) |
| 67 | |
| 68 | // Handle export statements: export { unstable_cacheTag } from 'next/cache' |
| 69 | root |
| 70 | .find(j.ExportNamedDeclaration, { source: { value: 'next/cache' } }) |
| 71 | .forEach((path) => { |
| 72 | path.node.specifiers?.forEach((specifier) => { |
| 73 | if ( |
nothing calls this directly
no test coverage detected