Skip to content

Commit

Permalink
fix: adjust regex
Browse files Browse the repository at this point in the history
add "space character" to the negated set to speed it up
closes #440
  • Loading branch information
dummdidumm committed Jun 5, 2024
1 parent 5516102 commit 268c26d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# prettier-plugin-svelte changelog

## 3.2.4

- (fix) speed up regex

## 3.2.3

- (fix) don't force-self-close `<slot>` tags
Expand Down
4 changes: 2 additions & 2 deletions src/lib/snipTagContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { base64ToString, stringToBase64 } from '../base64-string';
export const snippedTagContentAttribute = '✂prettier:content✂';

const scriptRegex =
/<!--[^]*?-->|<script((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/]+)*\s*)>([^]*?)<\/script>/g;
/<!--[^]*?-->|<script((?:\s+[^=>'"\/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/\s]+)*\s*)>([^]*?)<\/script>/g;
const styleRegex =
/<!--[^]*?-->|<style((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/]+)*\s*)>([^]*?)<\/style>/g;
/<!--[^]*?-->|<style((?:\s+[^=>'"\/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"\/\s]+)*\s*)>([^]*?)<\/style>/g;

export function snipScriptAndStyleTagContent(source: string): string {
let scriptMatchSpans = getMatchIndexes('script');
Expand Down
14 changes: 14 additions & 0 deletions test/printer/samples/script-attributes-multiline.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script
deferlooooooooooooooooooongnaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaame
async
src="fds"
></script>

<svelte:head>
<script
deferlooooooooooooooooooongnaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaame
async
src="fds"
on:load={() => {}}
></script>
</svelte:head>

0 comments on commit 268c26d

Please sign in to comment.