( file: FileInfo, _api: API, options: Options )
| 7 | } |
| 8 | |
| 9 | export default function transformer( |
| 10 | file: FileInfo, |
| 11 | _api: API, |
| 12 | options: Options |
| 13 | ) { |
| 14 | const j = createParserFromPath(file.path) |
| 15 | const root = j(file.source) |
| 16 | let hasModifications = false |
| 17 | let foundReactRender = 0 |
| 18 | let hasRenderImport = false |
| 19 | let defaultReactDomImport: string | undefined |
| 20 | |
| 21 | root.find(j.ImportDeclaration).forEach((path) => { |
| 22 | if (path.node.source.value === 'react-dom') { |
| 23 | return path.node.specifiers.forEach((specifier) => { |
| 24 | if (specifier.local.name === 'render') { |
| 25 | hasRenderImport = true |
| 26 | } |
| 27 | if (specifier.type === 'ImportDefaultSpecifier') { |
| 28 | defaultReactDomImport = specifier.local.name |
| 29 | } |
| 30 | }) |
| 31 | } |
| 32 | return false |
| 33 | }) |
| 34 | |
| 35 | root |
| 36 | .find(j.CallExpression) |
| 37 | .filter((path) => { |
| 38 | const { node } = path |
| 39 | let found = false |
| 40 | |
| 41 | if ( |
| 42 | defaultReactDomImport && |
| 43 | node.callee.type === 'MemberExpression' && |
| 44 | (node.callee.object as any).name === defaultReactDomImport && |
| 45 | (node.callee.property as any).name === 'render' |
| 46 | ) { |
| 47 | found = true |
| 48 | } |
| 49 | |
| 50 | if (hasRenderImport && (node.callee as any).name === 'render') { |
| 51 | found = true |
| 52 | } |
| 53 | |
| 54 | if (found) { |
| 55 | foundReactRender++ |
| 56 | hasModifications = true |
| 57 | |
| 58 | if (!Array.isArray(path.parentPath?.parentPath?.value)) { |
| 59 | indexContext.nestedRender = true |
| 60 | return false |
| 61 | } |
| 62 | |
| 63 | const newNode = j.exportDefaultDeclaration( |
| 64 | j.functionDeclaration( |
| 65 | j.identifier('NextIndexWrapper'), |
| 66 | [], |
nothing calls this directly
no test coverage detected