File tree Expand file tree Collapse file tree 2 files changed +10
-24
lines changed
src/compiler/pre-transform Expand file tree Collapse file tree 2 files changed +10
-24
lines changed Original file line number Diff line number Diff line change @@ -208,7 +208,6 @@ describe(codemodLegacyNodes.name, () => {
208208
209209 expect ( print ( transformed ) ) . toMatchInlineSnapshot ( `
210210 "<script context="module">
211- import Button from "./Button.svelte";
212211 import { defineMeta } from "@storybook/addon-svelte-csf";
213212 import Button from "./Button.svelte";
214213
@@ -273,6 +272,7 @@ describe(codemodLegacyNodes.name, () => {
273272
274273 expect ( print ( transformed ) ) . toMatchInlineSnapshot ( `
275274 "<script context="module" lang="ts">
275+ import { defineMeta } from "@storybook/addon-svelte-csf";
276276 import Button from "./Button.svelte";
277277
278278 const { Story } = defineMeta({ component: Button });
Original file line number Diff line number Diff line change @@ -202,33 +202,11 @@ export async function codemodLegacyNodes(params: Params): Promise<SvelteAST.Root
202202 instance = instance ? ( visit ( instance , state ) as SvelteAST . Script ) : null ;
203203
204204 if ( ! module ) {
205- const {
206- pkgImportDeclaration,
207- defineMetaFromExportConstMeta,
208- storiesComponentImportDeclaration,
209- } = state ;
210-
211- let body : ESTreeAST . Program [ 'body' ] = [ ] ;
212-
213- // WARN: This scope is bug prone
214-
215- if ( pkgImportDeclaration ) {
216- body . push ( pkgImportDeclaration ) ;
217- }
218-
219- if ( storiesComponentImportDeclaration ) {
220- body . push ( storiesComponentImportDeclaration ) ;
221- }
222-
223- if ( defineMetaFromExportConstMeta ) {
224- body . push ( defineMetaFromExportConstMeta ) ;
225- }
226-
227205 module = createASTScript ( {
228206 module : true ,
229207 content : {
230208 type : 'Program' ,
231- body,
209+ body : [ ] ,
232210 sourceType : 'module' ,
233211 } ,
234212 } ) ;
@@ -303,6 +281,14 @@ export async function codemodLegacyNodes(params: Params): Promise<SvelteAST.Root
303281 node . body . unshift ( state . storiesComponentImportDeclaration ) ;
304282 }
305283
284+ if ( state . pkgImportDeclaration ) {
285+ node . body . unshift ( state . pkgImportDeclaration ) ;
286+ }
287+
288+ if ( state . defineMetaFromExportConstMeta ) {
289+ node . body . push ( state . defineMetaFromExportConstMeta ) ;
290+ }
291+
306292 if ( state . defineMetaFromComponentMeta ) {
307293 node . body . push ( state . defineMetaFromComponentMeta ) ;
308294 }
You can’t perform that action at this time.
0 commit comments