Skip to content

Commit 104f09e

Browse files
committed
fix
1 parent c22aa49 commit 104f09e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

packages/svelte/src/compiler/migrate/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,12 @@ export function migrate(source, { filename, use_ts } = {}) {
207207
analysis.uses_props ||
208208
state.has_svelte_self;
209209

210+
const need_ts_tag =
211+
state.uses_ts &&
212+
(!parsed.instance || !parsed.instance.attributes.some((attr) => attr.name === 'lang'));
213+
210214
if (!parsed.instance && need_script) {
211-
str.appendRight(0, '<script>');
215+
str.appendRight(0, need_ts_tag ? '<script lang="ts">' : '<script>');
212216
}
213217

214218
if (state.has_svelte_self && filename) {
@@ -327,11 +331,7 @@ export function migrate(source, { filename, use_ts } = {}) {
327331
str.appendRight(insertion_point, props_declaration);
328332
}
329333

330-
if (
331-
state.uses_ts &&
332-
parsed.instance &&
333-
!parsed.instance.attributes.some((attr) => attr.name === 'lang')
334-
) {
334+
if (parsed.instance && need_ts_tag) {
335335
str.appendRight(parsed.instance.start + '<script'.length, ' lang="ts"');
336336
}
337337
}

packages/svelte/tests/migrate/samples/slot-use_ts/output.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script>
1+
<script lang="ts">
22
interface Props {
33
children?: import('svelte').Snippet;
44
}

0 commit comments

Comments
 (0)