Skip to content

Commit

Permalink
fix RegExp leading to slow parsing w/out tags
Browse files Browse the repository at this point in the history
  • Loading branch information
nebrelbug committed May 13, 2023
1 parent 4be3cbe commit f7ed8f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions deno_dist/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ export default function parse(
}, "");

const parseOpenReg = new RegExp(
"([^]*?)" + escapeRegExp(config.tags[0]) + "(-|_)?\\s*(" + prefixes +
")?\\s*",
escapeRegExp(config.tags[0]) + "(-|_)?\\s*(" + prefixes + ")?\\s*",
"g",
);

Expand All @@ -119,11 +118,12 @@ export default function parse(
let m;

while ((m = parseOpenReg.exec(str))) {
const precedingString = str.slice(lastIndex, m.index);

lastIndex = m[0].length + m.index;

const precedingString = m[1];
const wsLeft = m[2];
const prefix = m[3] || ""; // by default either ~, =, or empty
const wsLeft = m[1];
const prefix = m[2] || ""; // by default either ~, =, or empty

pushString(precedingString, wsLeft);

Expand Down
9 changes: 5 additions & 4 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default function parse(str: string, config: EtaConfig): Array<AstObject>
"");

const parseOpenReg = new RegExp(
"([^]*?)" + escapeRegExp(config.tags[0]) + "(-|_)?\\s*(" + prefixes + ")?\\s*",
escapeRegExp(config.tags[0]) + "(-|_)?\\s*(" + prefixes + ")?\\s*",
"g"
);

Expand All @@ -111,11 +111,12 @@ export default function parse(str: string, config: EtaConfig): Array<AstObject>
let m;

while ((m = parseOpenReg.exec(str))) {
const precedingString = str.slice(lastIndex, m.index);

lastIndex = m[0].length + m.index;

const precedingString = m[1];
const wsLeft = m[2];
const prefix = m[3] || ""; // by default either ~, =, or empty
const wsLeft = m[1];
const prefix = m[2] || ""; // by default either ~, =, or empty

pushString(precedingString, wsLeft);

Expand Down

0 comments on commit f7ed8f6

Please sign in to comment.