( programPath: babel.NodePath<t.Program>, baseName: string, )
| 41 | } |
| 42 | |
| 43 | export function getUniqueProgramIdentifier( |
| 44 | programPath: babel.NodePath<t.Program>, |
| 45 | baseName: string, |
| 46 | ): t.Identifier { |
| 47 | let name = baseName |
| 48 | let suffix = 2 |
| 49 | |
| 50 | const programScope = programPath.scope.getProgramParent() |
| 51 | |
| 52 | while ( |
| 53 | programScope.hasBinding(name) || |
| 54 | programScope.hasGlobal(name) || |
| 55 | programScope.hasReference(name) |
| 56 | ) { |
| 57 | name = `${baseName}${suffix}` |
| 58 | suffix++ |
| 59 | } |
| 60 | |
| 61 | // Register the name so subsequent calls within the same traversal |
| 62 | // see it and avoid collisions |
| 63 | programScope.references[name] = true |
| 64 | |
| 65 | return t.identifier(name) |
| 66 | } |
no outgoing calls
no test coverage detected