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

Function splitExportBlocks

scripts/codegen/typescript.ts:179–222  ·  view source on GitHub ↗
(compiled: string)

Source from the content-addressed store, hash-verified

177}
178
179function splitExportBlocks(compiled: string): string[] {
180 const normalizedCompiled = compiled
181 .trim()
182 .replace(/;(export\s+(?:interface|type)\s+)/g, ";\n$1")
183 .replace(/}(export\s+(?:interface|type)\s+)/g, "}\n$1");
184 const lines = normalizedCompiled.split(/\r?\n/);
185 const blocks: string[] = [];
186 let pending: string[] = [];
187
188 for (let index = 0; index < lines.length;) {
189 const line = lines[index];
190 if (!/^export\s+(?:interface|type)\s+\w+/.test(line)) {
191 pending.push(line);
192 index++;
193 continue;
194 }
195
196 const blockLines = [...pending, line];
197 pending = [];
198 let braceDepth = countBraces(line);
199 index++;
200
201 if (braceDepth === 0 && line.trim().endsWith(";")) {
202 blocks.push(blockLines.join("\n").trim());
203 continue;
204 }
205
206 while (index < lines.length) {
207 const nextLine = lines[index];
208 blockLines.push(nextLine);
209 braceDepth += countBraces(nextLine);
210 index++;
211
212 const trimmed = nextLine.trim();
213 if (braceDepth === 0 && (trimmed === "}" || trimmed.endsWith(";"))) {
214 break;
215 }
216 }
217
218 blocks.push(blockLines.join("\n").trim());
219 }
220
221 return blocks;
222}
223
224function countBraces(line: string): number {
225 let depth = 0;

Callers 1

appendUniqueExportBlocksFunction · 0.85

Calls 3

countBracesFunction · 0.85
joinMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…