UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

44 lines • 1.23 kB
import { parseProgram } from "./parse.js"; /** A line and its asynchronous jobs share ownership of incidental parses. */ export class ParseScope { references = 1; programs = []; released = false; parse(command, aliases = new Set(), extglob = true) { if (this.references === 0) throw new Error('parse scope is released'); const program = parseProgram(command, aliases, extglob); this.programs.push(program); return program.root; } fork() { return new ParseScope(); } retain() { if (this.references === 0) throw new Error('parse scope is released'); this.references += 1; let released = false; return () => { if (released) return; released = true; this.drop(); }; } release() { if (this.released) return; this.released = true; this.drop(); } drop() { this.references -= 1; if (this.references !== 0) return; for (const program of this.programs) program.release(); this.programs.length = 0; } } //# sourceMappingURL=scope.js.map