MCPcopy Index your code
hub / github.com/github/copilot-sdk / renameInternalPythonSymbols

Function renameInternalPythonSymbols

scripts/codegen/utils.ts:687–717  ·  view source on GitHub ↗
(
    code: string,
    typeNames: Iterable<string>
)

Source from the content-addressed store, hash-verified

685 * identifiers for the types that carry `visibility: "internal"`.
686 */
687export function renameInternalPythonSymbols(
688 code: string,
689 typeNames: Iterable<string>
690): string {
691 const escapeRegex = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
692 let result = code;
693 const sortedTypes = [...typeNames].sort((a, b) => b.length - a.length);
694 // Phase 1: rename each identifier globally at word boundaries.
695 for (const t of sortedTypes) {
696 result = result.replace(
697 new RegExp(`(?<![A-Za-z0-9_])${escapeRegex(t)}(?![A-Za-z0-9_])`, "g"),
698 `_${t}`
699 );
700 }
701 // Phase 2: restore JSON-key strings that match the rename target. Those
702 // strings carry the wire-protocol definition name and must remain untouched
703 // regardless of the Python-side rename. Patterns: `obj.get("Foo")` and
704 // `result["Foo"] = ...` in quicktype's serialization helpers.
705 for (const t of sortedTypes) {
706 const escaped = escapeRegex(t);
707 result = result.replace(
708 new RegExp(`(obj\\.get\\(")_${escaped}("\\))`, "g"),
709 `$1${t}$2`
710 );
711 result = result.replace(
712 new RegExp(`(result\\[")_${escaped}("\\])`, "g"),
713 `$1${t}$2`
714 );
715 }
716 return result;
717}
718
719/**
720 * Collects the set of (publicTypeName, internalFieldName[]) pairs from a

Callers 2

generateSessionEventsFunction · 0.85
generateRpcFunction · 0.85

Calls 1

escapeRegexFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…