(src, methodName, buildInjection)
| 65 | } |
| 66 | |
| 67 | function injectIntoAsyncMethods(src, methodName, buildInjection) { |
| 68 | const s = String(src || ""); |
| 69 | const re = new RegExp(`async\\s+${methodName}\\s*\\(([^)]*)\\)`, "g"); |
| 70 | const matches = Array.from(s.matchAll(re)); |
| 71 | if (matches.length === 0) throw new Error(`${methodName} needle not found (upstream may have changed)`); |
| 72 | |
| 73 | let out = s; |
| 74 | let patched = 0; |
| 75 | for (let i = matches.length - 1; i >= 0; i--) { |
| 76 | const match = matches[i]; |
| 77 | const idx = typeof match.index === "number" ? match.index : -1; |
| 78 | if (idx < 0) throw new Error(`${methodName} needle match missing index`); |
| 79 | const openBrace = out.indexOf("{", idx); |
| 80 | if (openBrace < 0) throw new Error(`${methodName} patch: failed to locate method body opening brace`); |
| 81 | |
| 82 | const injection = |
| 83 | typeof buildInjection === "function" |
| 84 | ? String(buildInjection({ params: parseParamNames(match[1] || ""), match, index: idx }) ?? "") |
| 85 | : String(buildInjection ?? ""); |
| 86 | if (!injection) continue; |
| 87 | |
| 88 | out = out.slice(0, openBrace + 1) + injection + out.slice(openBrace + 1); |
| 89 | patched += 1; |
| 90 | } |
| 91 | |
| 92 | return { out, count: patched }; |
| 93 | } |
| 94 | |
| 95 | function injectIntoArrowPropertyFunctions(src, propertyName, buildInjection) { |
| 96 | const s = String(src || ""); |
no test coverage detected