From e908bd4768ee9e349459d801c3acfc3c4592027f Mon Sep 17 00:00:00 2001 From: c0dev0id Date: Wed, 8 Jul 2026 20:29:35 +0200 Subject: [PATCH] ast-parser: simplify _parseRest regex to 2 capture groups --- static/ast-parser.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/static/ast-parser.js b/static/ast-parser.js index f9988a5..57528df 100644 --- a/static/ast-parser.js +++ b/static/ast-parser.js @@ -45,17 +45,17 @@ export function parseAstLog(text) { return root; } -const _REST_TOKEN = /(\w+)='([^']*)'|(\w+)=(\S+)|'([^']*)'|(\S+)/g; +const _REST_TOKEN = /(\w+=)?('[^']*'|\S+)/g; function _parseRest(rest) { const positionals = []; const props = {}; let inProps = false; - for (const [, kq, vq, kb, vb, qpos, bpos] of rest.matchAll(_REST_TOKEN)) { - if (kq !== undefined) { inProps = true; props[kq] = coerce(vq); } - else if (kb !== undefined) { inProps = true; props[kb] = coerce(vb); } - else if (!inProps) { positionals.push(coerce(qpos ?? bpos)); } + for (const [, keyEq, raw] of rest.matchAll(_REST_TOKEN)) { + const val = coerce(raw.startsWith("'") ? raw.slice(1, -1) : raw); + if (keyEq !== undefined) { inProps = true; props[keyEq.slice(0, -1)] = val; } + else if (!inProps) { positionals.push(val); } } return { positionals, props };