File tree 2 files changed +16
-2
lines changed
2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ export const optimizeImports: SveltePreprocessor<"script"> = () => {
32
32
if ( / n o d e _ m o d u l e s / . test ( filename ) ) return ;
33
33
34
34
// Wrap the content in a `<script>` tag to parse it with the Svelte parser.
35
- const content = `<script>${ raw } </script>` ;
35
+ const content = `<script lang="ts" >${ raw } </script>` ;
36
36
const s = new MagicString ( content ) ;
37
37
38
38
walk ( parse ( content ) , {
@@ -60,7 +60,7 @@ export const optimizeImports: SveltePreprocessor<"script"> = () => {
60
60
} ,
61
61
} ) ;
62
62
63
- s . replace ( / ^ < s c r i p t > / , "" ) ;
63
+ s . replace ( / ^ < s c r i p t l a n g = " t s " > / , "" ) ;
64
64
s . replace ( / < \/ s c r i p t > $ / , "" ) ;
65
65
66
66
return {
Original file line number Diff line number Diff line change @@ -138,4 +138,18 @@ import Analytics from "carbon-pictograms-svelte/lib/Analytics.svelte";`);
138
138
import Accordion from "carbon-components-svelte/src/Accordion/Accordion.svelte";
139
139
` ) ;
140
140
} ) ;
141
+
142
+ test ( "import type statements should be preserved" , ( ) => {
143
+ expect (
144
+ preprocess ( {
145
+ content : `
146
+ import { Theme } from "carbon-components-svelte";
147
+ import type { CarbonTheme } from "carbon-components-svelte/src/Theme/Theme.svelte";
148
+ ` ,
149
+ } ) ,
150
+ ) . toEqual ( `
151
+ import Theme from "carbon-components-svelte/src/Theme/Theme.svelte";
152
+ import type { CarbonTheme } from "carbon-components-svelte/src/Theme/Theme.svelte";
153
+ ` ) ;
154
+ } ) ;
141
155
} ) ;
You can’t perform that action at this time.
0 commit comments