refactor: simplify pass (trekexecute)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
63fd33daaf
commit
cc277c476c
2 changed files with 15 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue