ast-parser: simplify _parseRest regex to 2 capture groups

This commit is contained in:
c0dev0id
2026-07-08 20:29:35 +02:00
parent a0104214b7
commit e908bd4768

View File

@@ -45,17 +45,17 @@ export function parseAstLog(text) {
return root; return root;
} }
const _REST_TOKEN = /(\w+)='([^']*)'|(\w+)=(\S+)|'([^']*)'|(\S+)/g; const _REST_TOKEN = /(\w+=)?('[^']*'|\S+)/g;
function _parseRest(rest) { function _parseRest(rest) {
const positionals = []; const positionals = [];
const props = {}; const props = {};
let inProps = false; let inProps = false;
for (const [, kq, vq, kb, vb, qpos, bpos] of rest.matchAll(_REST_TOKEN)) { for (const [, keyEq, raw] of rest.matchAll(_REST_TOKEN)) {
if (kq !== undefined) { inProps = true; props[kq] = coerce(vq); } const val = coerce(raw.startsWith("'") ? raw.slice(1, -1) : raw);
else if (kb !== undefined) { inProps = true; props[kb] = coerce(vb); } if (keyEq !== undefined) { inProps = true; props[keyEq.slice(0, -1)] = val; }
else if (!inProps) { positionals.push(coerce(qpos ?? bpos)); } else if (!inProps) { positionals.push(val); }
} }
return { positionals, props }; return { positionals, props };