Skip to content

Commit ce406b1

Browse files
authored
(fix) don't blank non-top-level scripts (#1662)
..in the new transformation #1644
1 parent 5ebd899 commit ce406b1

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

packages/svelte2tsx/src/svelte2tsx/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ function processSvelteTemplate(
282282

283283
// resolve scripts
284284
const { scriptTag, moduleScriptTag } = scripts.getTopLevelScriptTags();
285-
scripts.blankOtherScriptTags(str);
285+
if (options.mode !== 'ts') {
286+
scripts.blankOtherScriptTags(str);
287+
}
286288

287289
//resolve stores
288290
const resolvedStores = stores.getStoreNames();

packages/svelte2tsx/src/utils/htmlxparser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function extractTag(htmlx: string, tag: 'script' | 'style', useNewTransformation
4646
let content = match[4];
4747
if (!content) {
4848
if (useNewTransformation) {
49-
// Keep tag and transform it properly by removing it
49+
// Keep tag and transform it like a regular element
5050
content = '';
5151
} else {
5252
// Self-closing/empty tags don't need replacement

packages/svelte2tsx/test/svelte2tsx/samples/script-in-rawhtml/expectedv2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
;
88
async () => {
99

10-
``;};
10+
`<script type="application/ld+json">${JSON.stringify(schema)}</script>`;};
1111
return { props: {}, slots: {}, getters: {}, events: {} }}
1212

1313
export default class Input__SvelteComponent_ extends __sveltets_1_createSvelte2TsxComponent(__sveltets_1_partial(__sveltets_1_with_any_event(render()))) {

packages/svelte2tsx/test/svelte2tsx/samples/script-inside-head-after-toplevel-script/expectedv2.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
let b = 'top level';
55
;
66
async () => { { svelteHTML.createElement("div", {});
7-
7+
{ svelteHTML.createElement("script", {}); }
88
}
99

1010

1111

1212
{ svelteHTML.createElement("svelte:head", {});
1313
{ svelteHTML.createElement("link", { "rel":`stylesheet`,"href":`/lib/jodit.es2018.min.css`,});}
14-
14+
{ svelteHTML.createElement("script", { "src":`/lib/jodit.es2018.min.js`,});
15+
16+
}
1517
}};
1618
return { props: {}, slots: {}, getters: {}, events: {} }}
1719

0 commit comments

Comments
 (0)