@@ -66,6 +66,7 @@ export default function inlineSveltePlugin({
6666 `^const\\s+([a-zA-Z0-9_$]+)\\s*=\\s*(?:${ tagGroup } )\\s*(\`[\\s\\S]*?\`)` ,
6767 "gm"
6868 ) ;
69+ const moduleScriptExportRE = / < s c r i p t \s + m o d u l e \s * > [ ^ < ] * \b e x p o r t \b / ;
6970
7071 const VIRT = "virtual:inline-svelte/" ;
7172 const RSLV = "\0" + VIRT ;
@@ -197,8 +198,14 @@ export default function inlineSveltePlugin({
197198 local = `Inline_${ hash } ` ;
198199 hashToLocal . set ( hash , local ) ;
199200 if ( ! cache . has ( virt ) ) cache . set ( virt , markupWithDeps ) ;
200- const ns = `__InlineNS_${ hash } ` ;
201- importsToAdd += `import * as ${ ns } from '${ virt } ';\nconst ${ local } =Object.assign(${ ns } .default, ${ ns } );\n` ;
201+
202+ const hasModuleExports = moduleScriptExportRE . test ( rawMarkup ) ;
203+ if ( hasModuleExports ) {
204+ const ns = `__InlineNS_${ hash } ` ;
205+ importsToAdd += `import * as ${ ns } from '${ virt } ';\nconst ${ local } =Object.assign(${ ns } .default, ${ ns } );\n` ;
206+ } else {
207+ importsToAdd += `import ${ local } from '${ virt } ';\n` ;
208+ }
202209 }
203210
204211 componentInfo . set ( compName , { local, virt } ) ;
@@ -262,8 +269,14 @@ export default function inlineSveltePlugin({
262269 hashToLocal . set ( hash , local ) ;
263270 const virt = `${ VIRT } ${ hash } .js` ;
264271 if ( ! cache . has ( virt ) ) cache . set ( virt , markupWithGlobals ) ;
265- const ns = `__InlineNS_${ hash } ` ;
266- importsToAdd += `import * as ${ ns } from '${ virt } ';\nconst ${ local } =Object.assign(${ ns } .default, ${ ns } );\n` ;
272+
273+ const hasModuleExports = moduleScriptExportRE . test ( rawMarkup ) ;
274+ if ( hasModuleExports ) {
275+ const ns = `__InlineNS_${ hash } ` ;
276+ importsToAdd += `import * as ${ ns } from '${ virt } ';\nconst ${ local } =Object.assign(${ ns } .default, ${ ns } );\n` ;
277+ } else {
278+ importsToAdd += `import ${ local } from '${ virt } ';\n` ;
279+ }
267280 }
268281
269282 ms . overwrite ( m . index , tplRE . lastIndex , local ) ;
0 commit comments