Skip to content

Commit 4da0d2a

Browse files
authored
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 sveltejs/language-tools#2363
1 parent 6efd9d6 commit 4da0d2a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

.changeset/itchy-peaches-compare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
chore: speed up regex

packages/svelte/src/compiler/preprocess/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ function stringify_tag_attributes(attributes) {
248248
}
249249

250250
const regex_style_tags =
251-
/<!--[^]*?-->|<style((?:\s+[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/]+)*\s*)(?:\/>|>([\S\s]*?)<\/style>)/g;
251+
/<!--[^]*?-->|<style((?:\s+[^=>'"/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/\s]+)*\s*)(?:\/>|>([\S\s]*?)<\/style>)/g;
252252
const regex_script_tags =
253-
/<!--[^]*?-->|<script((?:\s+[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/]+)*\s*)(?:\/>|>([\S\s]*?)<\/script>)/g;
253+
/<!--[^]*?-->|<script((?:\s+[^=>'"/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/\s]+)*\s*)(?:\/>|>([\S\s]*?)<\/script>)/g;
254254

255255
/**
256256
* Calculate the updates required to process all instances of the specified tag.

0 commit comments

Comments
 (0)