MCPcopy
hub / github.com/thesysdev/openui / scanNewCompleted

Function scanNewCompleted

packages/lang-core/src/parser/parser.ts:480–538  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

478 }
479
480 function scanNewCompleted(): number {
481 let depth = 0,
482 ternaryDepth = 0,
483 inStr: false | '"' | "'" = false,
484 esc = false;
485 let stmtStart = completedEnd;
486
487 for (let i = completedEnd; i < cleaned.length; i++) {
488 const c = cleaned[i];
489 if (esc) {
490 esc = false;
491 continue;
492 }
493 if (c === "\\" && inStr) {
494 esc = true;
495 continue;
496 }
497 if (inStr) {
498 if (c === inStr) inStr = false;
499 continue;
500 }
501 if (c === '"' || c === "'") {
502 inStr = c;
503 continue;
504 }
505
506 if (c === "(" || c === "[" || c === "{") depth++;
507 else if (c === ")" || c === "]" || c === "}") depth = Math.max(0, depth - 1);
508 // Track ternary ? and : at bracket depth 0 (colons inside {} are object key separators)
509 else if (c === "?" && depth === 0) ternaryDepth++;
510 else if (c === ":" && depth === 0 && ternaryDepth > 0) ternaryDepth--;
511 else if (c === "\n" && depth <= 0 && ternaryDepth <= 0) {
512 // Before splitting, look ahead past whitespace to see if the next
513 // meaningful character is `?` or `:` — ternary continuation.
514 let peek = i + 1;
515 while (
516 peek < cleaned.length &&
517 (cleaned[peek] === " " ||
518 cleaned[peek] === "\t" ||
519 cleaned[peek] === "\r" ||
520 cleaned[peek] === "\n")
521 )
522 peek++;
523 if (
524 peek < cleaned.length &&
525 (cleaned[peek] === "?" || (cleaned[peek] === ":" && ternaryDepth > 0))
526 ) {
527 continue; // ternary continuation — don't split
528 }
529 // Depth-0 newline = end of a statement
530 const t = cleaned.slice(stmtStart, i).trim();
531 if (t) addStmt(t);
532 stmtStart = i + 1; // next statement begins after this newline
533 completedEnd = i + 1; // advance the "already processed" watermark
534 }
535 }
536
537 return stmtStart; // start of the current pending (incomplete) statement

Callers 1

currentResultFunction · 0.85

Calls 1

addStmtFunction · 0.85

Tested by

no test coverage detected