MCPcopy Create free account
hub / github.com/chhoumann/quickadd / findOptionsObjectSpans

Function findOptionsObjectSpans

src/utils/userScriptSecrets.ts:264–315  ·  view source on GitHub ↗
(source: string)

Source from the content-addressed store, hash-verified

262}
263
264function findOptionsObjectSpans(source: string): Array<{ start: number; end: number }> {
265 const spans: Array<{ start: number; end: number }> = [];
266 const constants = collectStringConstants(source);
267 let current = 0;
268
269 while (current < source.length) {
270 current = skipWhitespaceAndComments(source, current);
271 const char = source[current];
272 const next = source[current + 1];
273
274 if (char === "\"" || char === "'" || char === "`") {
275 const literal = readStringLiteral(source, current);
276 current = literal ? literal.end : current + 1;
277 continue;
278 }
279
280 if (char === "/" && next === "/") {
281 const newline = source.indexOf("\n", current + 2);
282 current = newline === -1 ? source.length : newline + 1;
283 continue;
284 }
285
286 if (char === "/" && next === "*") {
287 const end = source.indexOf("*/", current + 2);
288 current = end === -1 ? source.length : end + 2;
289 continue;
290 }
291
292 const key = readOptionKey(source, current, constants);
293 if (!key) {
294 current += 1;
295 continue;
296 }
297
298 current = skipWhitespaceAndComments(source, key.end);
299 if (source[current] !== ":") {
300 current = key.end;
301 continue;
302 }
303
304 current = skipWhitespaceAndComments(source, current + 1);
305 if (key.name !== "options") continue;
306 if (source[current] !== "{") continue;
307
308 const end = findMatchingDelimiter(source, current, "{", "}");
309 if (end === -1) break;
310 spans.push({ start: current + 1, end });
311 current = end + 1;
312 }
313
314 return spans;
315}
316
317function readOptionKey(
318 source: string,

Callers 1

Calls 6

collectStringConstantsFunction · 0.85
readStringLiteralFunction · 0.85
readOptionKeyFunction · 0.85
findMatchingDelimiterFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected