(
ops: string[], moduleProvider: ImportProvider)
| 75 | } |
| 76 | |
| 77 | export function getCustomConverterOpsModule( |
| 78 | ops: string[], moduleProvider: ImportProvider): string { |
| 79 | const result: string[] = ['// This file is autogenerated\n']; |
| 80 | |
| 81 | // Separate namespaced apis from non namespaced ones as they require a |
| 82 | // different export pattern that treats each namespace as a whole. |
| 83 | |
| 84 | const flatOps = []; |
| 85 | const namespacedOps: {[key: string]: string[]} = {}; |
| 86 | |
| 87 | for (const opSymbol of ops) { |
| 88 | if (opSymbol.match(/\./)) { |
| 89 | const parts = opSymbol.split(/\./); |
| 90 | const namespace = parts[0]; |
| 91 | const opName = parts[1]; |
| 92 | |
| 93 | if (namespacedOps[namespace] == null) { |
| 94 | namespacedOps[namespace] = []; |
| 95 | } |
| 96 | namespacedOps[namespace].push(opName); |
| 97 | } else { |
| 98 | flatOps.push(opSymbol); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | // Group the namespaced symbols by namespace |
| 103 | for (const namespace of Object.keys(namespacedOps)) { |
| 104 | const opSymbols = namespacedOps[namespace]; |
| 105 | result.push(moduleProvider.importNamespacedOpsForConverterStr( |
| 106 | namespace, opSymbols)); |
| 107 | } |
| 108 | |
| 109 | for (const opSymbol of flatOps) { |
| 110 | result.push(moduleProvider.importOpForConverterStr(opSymbol)); |
| 111 | } |
| 112 | |
| 113 | return result.join('\n'); |
| 114 | } |
| 115 | |
| 116 | function addLine(target: string[], line: string) { |
| 117 | target.push(line); |
no test coverage detected
searching dependent graphs…