Skip to content

Commit

Permalink
chore: speed up regex
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm committed Jun 6, 2024
1 parent cc25dbd commit c186152
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/svelte2tsx/src/utils/htmlxparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ function parseAttributes(str: string, start: number) {

// Regex ensures that attributes with > characters in them still result in the content being matched correctly
const scriptRegex =
/(<!--[^]*?-->)|(<script((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/]+)*\s*)>)([\S\s]*?)<\/script>/g;
/(<!--[^]*?-->)|(<script((?:\s+[^=>'"\/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/\s]+)*\s*)>)([\S\s]*?)<\/script>/g;
const styleRegex =
/(<!--[^]*?-->)|(<style((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/]+)*\s*)>)([\S\s]*?)<\/style>/g;
/(<!--[^]*?-->)|(<style((?:\s+[^=>'"\/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/\s]+)*\s*)>)([\S\s]*?)<\/style>/g;

function extractTag(htmlx: string, tag: 'script' | 'style') {
const exp = tag === 'script' ? scriptRegex : styleRegex;
Expand Down

0 comments on commit c186152

Please sign in to comment.