MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / withLiteralsBlanked

Function withLiteralsBlanked

packages/hosts/mcp/src/create-artifact.ts:113–120  ·  view source on GitHub ↗
(code: string)

Source from the content-addressed store, hash-verified

111/** Replaces comments and quoted/template literals with same-length blanks, so
112 * offsets stay valid and their contents can't be mistaken for code. */
113const withLiteralsBlanked = (code: string): string => {
114 const blank = (text: string): string => text.replace(/[^\n]/g, " ");
115 return code.replace(
116 // Order matters: line comment, block comment, then each quote flavour.
117 /\/\/[^\n]*|\/\*[\s\S]*?\*\/|'(?:\\.|[^'\\\n])*'|"(?:\\.|[^"\\\n])*"|`(?:\\.|[^`\\])*`/g,
118 blank,
119 );
120};
121
122/** A React hook call: `useFoo(`, not `x.useFoo(` and not `abusefoo(`. */
123const HOOK_CALL = /(?<![.\w$])(use[A-Z][\w$]*)\s*\(/;

Callers 2

hookCalledInLoopFunction · 0.85
providerPairingRejectionFunction · 0.85

Calls 1

replaceMethod · 0.65

Tested by

no test coverage detected