From 4da0d2a1d4d511129c2eb90a34ed3ce90a0896ac Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Wed, 5 Jun 2024 22:16:58 +0200 Subject: [PATCH] chore: speed up regex (#11918) This regex can take longer than expected in certain situations, making it more explicit and adding "not a whitespace" to the set speeds it up Related https://github.com/sveltejs/language-tools/issues/2363 --- .changeset/itchy-peaches-compare.md | 5 +++++ packages/svelte/src/compiler/preprocess/index.js | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/itchy-peaches-compare.md diff --git a/.changeset/itchy-peaches-compare.md b/.changeset/itchy-peaches-compare.md new file mode 100644 index 0000000000..9f7ae884af --- /dev/null +++ b/.changeset/itchy-peaches-compare.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +chore: speed up regex diff --git a/packages/svelte/src/compiler/preprocess/index.js b/packages/svelte/src/compiler/preprocess/index.js index 9b101249a5..11cf9fdf7a 100644 --- a/packages/svelte/src/compiler/preprocess/index.js +++ b/packages/svelte/src/compiler/preprocess/index.js @@ -248,9 +248,9 @@ function stringify_tag_attributes(attributes) { } const regex_style_tags = - /|'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/]+)*\s*)(?:\/>|>([\S\s]*?)<\/style>)/g; + /|'"/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/\s]+)*\s*)(?:\/>|>([\S\s]*?)<\/style>)/g; const regex_script_tags = - /|'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/]+)*\s*)(?:\/>|>([\S\s]*?)<\/script>)/g; + /|'"/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/\s]+)*\s*)(?:\/>|>([\S\s]*?)<\/script>)/g; /** * Calculate the updates required to process all instances of the specified tag.