Skip to content

Commit

Permalink
fix: ignore style tag inside script tag
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm committed Aug 29, 2023
1 parent 5a8cfa5 commit 1018345
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/svelte2tsx/src/utils/htmlxparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,18 @@ function extractTag(htmlx: string, tag: 'script' | 'style') {
}

function findVerbatimElements(htmlx: string) {
return [...extractTag(htmlx, 'script'), ...extractTag(htmlx, 'style')];
const styleTags = extractTag(htmlx, 'style');
const tags = extractTag(htmlx, 'script');
for (const styleTag of styleTags) {
// Could happen if someone has a `<style>...</style>` string in their script tag
const insideScript = tags.some(
(tag) => tag.start < styleTag.start && tag.end > styleTag.end
);
if (!insideScript) {
tags.push(styleTag);
}
}
return tags;
}

function blankVerbatimContent(htmlx: string, verbatimElements: Node[]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
///<reference types="svelte" />
;function render() {

const config = { branding: { primaryColor: '#012345' } },
branding = config?.branding;

const cssString = `<style>:root {--primary-color: ${
branding?.primaryColor ?? '#ABCDEF'
};}</style>`;
;
async () => {};
return { props: /** @type {Record<string, never>} */ ({}), slots: {}, events: {} }}

export default class Input__SvelteComponent_ extends __sveltets_2_createSvelte2TsxComponent(__sveltets_2_partial(__sveltets_2_with_any_event(render()))) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
const config = { branding: { primaryColor: '#012345' } },
branding = config?.branding;
const cssString = `<style>:root {--primary-color: ${
branding?.primaryColor ?? '#ABCDEF'
};}</style>`;
</script>

0 comments on commit 1018345

Please sign in to comment.