@@ -139,18 +139,32 @@ async function ssrTransformScript(
139
139
const importId = defineImport ( hoistIndex , node . source . value as string , {
140
140
importedNames : node . specifiers
141
141
. 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
143
147
else if ( s . type === 'ImportDefaultSpecifier' ) return 'default'
144
148
} )
145
149
. filter ( isDefined ) ,
146
150
} )
147
151
s . remove ( node . start , node . end )
148
152
for ( const spec of node . specifiers ) {
149
153
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
+ }
154
168
} else if ( spec . type === 'ImportDefaultSpecifier' ) {
155
169
idToImportMap . set ( spec . local . name , `${ importId } .default` )
156
170
} else {
@@ -194,9 +208,15 @@ async function ssrTransformScript(
194
208
} ,
195
209
)
196
210
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
+
197
217
defineExport (
198
218
node . start ,
199
- spec . exported . name ,
219
+ exportedAs ,
200
220
`${ importId } .${ spec . local . name } ` ,
201
221
)
202
222
}
@@ -205,7 +225,14 @@ async function ssrTransformScript(
205
225
for ( const spec of node . specifiers ) {
206
226
const local = spec . local . name
207
227
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 )
209
236
}
210
237
}
211
238
}
0 commit comments