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