From 268c26d8703b397eb0f69aff2cdeabc0924bcf5b Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Wed, 5 Jun 2024 18:22:59 +0200 Subject: [PATCH] fix: adjust regex add "space character" to the negated set to speed it up closes #440 --- CHANGELOG.md | 4 ++++ src/lib/snipTagContent.ts | 4 ++-- .../samples/script-attributes-multiline.html | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 test/printer/samples/script-attributes-multiline.html diff --git a/CHANGELOG.md b/CHANGELOG.md index ba77dbe..ccbe078 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # prettier-plugin-svelte changelog +## 3.2.4 + +- (fix) speed up regex + ## 3.2.3 - (fix) don't force-self-close `` tags diff --git a/src/lib/snipTagContent.ts b/src/lib/snipTagContent.ts index cb02d8d..89b0dc6 100644 --- a/src/lib/snipTagContent.ts +++ b/src/lib/snipTagContent.ts @@ -3,9 +3,9 @@ import { base64ToString, stringToBase64 } from '../base64-string'; export const snippedTagContentAttribute = '✂prettier:content✂'; const scriptRegex = - /|'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/]+)*\s*)>([^]*?)<\/script>/g; + /|'"\/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/\s]+)*\s*)>([^]*?)<\/script>/g; const styleRegex = - /|'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/]+)*\s*)>([^]*?)<\/style>/g; + /|'"\/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/\s]+)*\s*)>([^]*?)<\/style>/g; export function snipScriptAndStyleTagContent(source: string): string { let scriptMatchSpans = getMatchIndexes('script'); diff --git a/test/printer/samples/script-attributes-multiline.html b/test/printer/samples/script-attributes-multiline.html new file mode 100644 index 0000000..29a69ca --- /dev/null +++ b/test/printer/samples/script-attributes-multiline.html @@ -0,0 +1,14 @@ + + + + +