| 68 | }, {}); |
| 69 | |
| 70 | export const renameFunction = ( |
| 71 | overloadIndex: FunctionOverloadIndex, |
| 72 | newName: string |
| 73 | ) => { |
| 74 | Object.entries(overloadIndex).forEach(([signature, overload]) => { |
| 75 | overload.references.forEach((node) => { |
| 76 | if (node.type === 'function') { |
| 77 | node['prototype'].header.name.identifier = newName; |
| 78 | } else if ( |
| 79 | node.type === 'function_call' && |
| 80 | node.identifier.type === 'postfix' |
| 81 | ) { |
| 82 | // @ts-ignore |
| 83 | const specifier = node.identifier.expression.identifier.specifier; |
| 84 | if (specifier) { |
| 85 | specifier.identifier = newName; |
| 86 | } else { |
| 87 | console.warn('Unknown function node to rename', node); |
| 88 | throw new Error( |
| 89 | `Function specifier type ${node.type} not recognized` |
| 90 | ); |
| 91 | } |
| 92 | } else if ( |
| 93 | node.type === 'function_call' && |
| 94 | 'specifier' in node.identifier && |
| 95 | 'identifier' in node.identifier.specifier |
| 96 | ) { |
| 97 | node.identifier.specifier.identifier = newName; |
| 98 | } else if ( |
| 99 | node.type === 'function_call' && |
| 100 | node.identifier.type === 'identifier' |
| 101 | ) { |
| 102 | node.identifier.identifier = newName; |
| 103 | } else { |
| 104 | console.warn('Unknown function node to rename', node); |
| 105 | throw new Error(`Function for type ${node.type} not recognized`); |
| 106 | } |
| 107 | }); |
| 108 | }); |
| 109 | return overloadIndex; |
| 110 | }; |
| 111 | |
| 112 | export const renameFunctions = ( |
| 113 | functions: FunctionScopeIndex, |