refactor: simplify pass (trekexecute)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-11-02 10:58:35 +01:00
commit cc277c476c
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
2 changed files with 15 additions and 12 deletions

View file

@ -365,13 +365,13 @@ function blockArgs(unquoted, unreadable) {
process.exit(2);
}
// The quote state at `to` of `text` read from `from` for quotes only: 'none'
// The quote state at `to` of `text` read from its start for quotes only: 'none'
// (outside every quote), 'open' (inside '...' or "...", or inside an earlier
// heredoc's body) or 'unknown' (the scan cannot follow the shell here).
// `state`, when given, lets the calls on one text resume where the last stopped.
function argsQuoteScan(text, from, to, openers, state) {
const fresh = (pos) => ({ pos, mode: 'none', pending: null, bodyEnd: -1 });
const st = state ? (state.pos <= to ? state : fresh(0)) : fresh(from);
// `state` lets the calls on one text resume where the last stopped; a call
// before that point starts over from the start of the text.
function argsQuoteScan(text, to, openers, state) {
const st = state.pos <= to ? state : { pos: 0, mode: 'none', pending: null, bodyEnd: -1 };
let p = st.pos;
let mode = st.mode;
let pending = st.pending;
@ -418,7 +418,6 @@ function argsQuoteScan(text, from, to, openers, state) {
if (c === '\\') {
// The scan never decides a backslash without the character it escapes.
if (p + 1 >= to) return unknown();
if (mode === 'double' && d === '\n') return unknown();
if (d === '\n') return unknown(); // scan: a continuation cannot be followed
p += 2;
continue;
@ -495,7 +494,7 @@ function argsEscapedLt(text, i, lim, openers) {
let b = 0;
while (i - 1 - b >= 0 && text[i - 1 - b] === '\\') b += 1;
const s = i - b;
return b % 2 === 1 && argsQuoteScan(text, 0, s, openers, lim.state) === 'none';
return b % 2 === 1 && argsQuoteScan(text, s, openers, lim.state) === 'none';
}
// An opener whose raw span holds a backslash-newline. The regex reading cannot