fix: do not consider `style` literals inside `<script>` blocks

pull/18595/head
Jason Rasmussen 7 days ago
parent 44a7813730
commit 82f79a6e6e
No known key found for this signature in database
GPG Key ID: 2EF24B77EAFA4A41

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: do not consider `style` literals inside `<script>` blocks

@ -251,7 +251,7 @@ function stringify_tag_attributes(attributes) {
}
const regex_style_tags =
/<!--[^]*?-->|<style((?:\s+[^=>'"/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/\s]+)*\s*)(?:\/>|>([\S\s]*?)<\/style>)/g;
/<!--[^]*?-->|<script[^]*?<\/script>|<style((?:\s+[^=>'"/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/\s]+)*\s*)(?:\/>|>([\S\s]*?)<\/style>)/g;
const regex_script_tags =
/<!--[^]*?-->|<script((?:\s+[^=>'"/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/\s]+)*\s*)(?:\/>|>([\S\s]*?)<\/script>)/g;

@ -0,0 +1,13 @@
import * as assert from 'node:assert';
import { test } from '../../test';
export default test({
preprocess: {
style: ({ content }) => {
assert.equal(content, 'BEFORE');
return {
code: 'PROCESSED'
};
}
}
});

@ -0,0 +1,5 @@
<script>
const scope = (rules) => `<style>${rules.replaceAll('::highlight(a-', '::highlight(b-')}</style>`;
</script>
<style>BEFORE</style>

@ -0,0 +1,5 @@
<script>
const scope = (rules) => `<style>${rules.replaceAll('::highlight(a-', '::highlight(b-')}</style>`;
</script>
<style>PROCESSED</style>
Loading…
Cancel
Save