@@ -139,18 +139,32 @@ async function ssrTransformScript(
139139 const importId = defineImport ( hoistIndex , node . source . value as string , {
140140 importedNames : node . specifiers
141141 . map ( ( s ) => {
142- if ( s . type === 'ImportSpecifier' ) return s . imported . name
142+ if ( s . type === 'ImportSpecifier' )
143+ return s . imported . type === 'Identifier'
144+ ? s . imported . name
145+ : // @ts -expect-error TODO: Estree types don't consider arbitrary module namespace specifiers yet
146+ s . imported . value
143147 else if ( s . type === 'ImportDefaultSpecifier' ) return 'default'
144148 } )
145149 . filter ( isDefined ) ,
146150 } )
147151 s . remove ( node . start , node . end )
148152 for ( const spec of node . specifiers ) {
149153 if ( spec . type === 'ImportSpecifier' ) {
150- idToImportMap . set (
151- spec . local . name ,
152- `${ importId } .${ spec . imported . name } ` ,
153- )
154+ if ( spec . imported . type === 'Identifier' ) {
155+ idToImportMap . set (
156+ spec . local . name ,
157+ `${ importId } .${ spec . imported . name } ` ,
158+ )
159+ } else {
160+ idToImportMap . set (
161+ spec . local . name ,
162+ `${ importId } [${
163+ // @ts -expect-error TODO: Estree types don't consider arbitrary module namespace specifiers yet
164+ JSON . stringify ( spec . imported . value )
165+ } ]`,
166+ )
167+ }
154168 } else if ( spec . type === 'ImportDefaultSpecifier' ) {
155169 idToImportMap . set ( spec . local . name , `${ importId } .default` )
156170 } else {
@@ -194,9 +208,15 @@ async function ssrTransformScript(
194208 } ,
195209 )
196210 for ( const spec of node . specifiers ) {
211+ const exportedAs =
212+ spec . exported . type === 'Identifier'
213+ ? spec . exported . name
214+ : // @ts -expect-error TODO: Estree types don't consider arbitrary module namespace specifiers yet
215+ spec . exported . value
216+
197217 defineExport (
198218 node . start ,
199- spec . exported . name ,
219+ exportedAs ,
200220 `${ importId } .${ spec . local . name } ` ,
201221 )
202222 }
@@ -205,7 +225,14 @@ async function ssrTransformScript(
205225 for ( const spec of node . specifiers ) {
206226 const local = spec . local . name
207227 const binding = idToImportMap . get ( local )
208- defineExport ( node . end , spec . exported . name , binding || local )
228+
229+ const exportedAs =
230+ spec . exported . type === 'Identifier'
231+ ? spec . exported . name
232+ : // @ts -expect-error TODO: Estree types don't consider arbitrary module namespace specifiers yet
233+ spec . exported . value
234+
235+ defineExport ( node . end , exportedAs , binding || local )
209236 }
210237 }
211238 }
0 commit comments