MCPcopy Create free account
hub / github.com/AnkRoot/Augment-BYOK / findFirstInstantiationOfExportedClass

Function findFirstInstantiationOfExportedClass

tools/lib/patch.js:306–318  ·  view source on GitHub ↗
(src, exportName)

Source from the content-addressed store, hash-verified

304}
305
306function findFirstInstantiationOfExportedClass(src, exportName) {
307 const classIdent = findExportedFactoryVar(src, exportName);
308 const re = new RegExp(`([A-Za-z0-9_$]+)\\s*=\\s*new\\s+${classIdent}\\s*\\(`, "g");
309 const match = re.exec(String(src || ""));
310 if (!match || typeof match.index !== "number") throw new Error(`failed to locate instantiation: VAR=new ${classIdent}(`);
311 const openParenIdx = match.index + match[0].lastIndexOf("(");
312 const closeParenIdx = findMatchingParen(src, openParenIdx);
313 const terminatorIdx = findStatementTerminatorIndex(src, closeParenIdx + 1, {
314 allowComma: false,
315 label: `statement terminator after ${exportName} instantiation`
316 });
317 return { classIdent, varName: match[1], openParenIdx, closeParenIdx, terminatorIdx };
318}
319
320module.exports = {
321 ensureMarker,

Callers 1

patchExposeUpstreamFunction · 0.85

Calls 3

findExportedFactoryVarFunction · 0.85
findMatchingParenFunction · 0.70

Tested by

no test coverage detected