ast-parser: simplify _parseRest regex to 2 capture groups
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user