matchAll -> exec loop

This commit is contained in:
Ske 2020-06-12 15:32:30 +02:00
parent fd9c2ee734
commit 68b1fab369

View file

@ -70,7 +70,10 @@
const parts = []; const parts = [];
let lastMatch = 0; let lastMatch = 0;
for (const match of usage.matchAll(/`([^`]+)`/g)) { // matchAll isn't common yet, using exec :(
const re = /`([^`]+)`/g;
let match;
while (match = re.exec(usage)) {
if (match.index > 0) if (match.index > 0)
parts.push({type: "str", str: usage.substring(lastMatch, match.index)}); parts.push({type: "str", str: usage.substring(lastMatch, match.index)});
parts.push({type: "arg", arg: match[1]}); parts.push({type: "arg", arg: match[1]});