@@ -58,7 +58,6 @@ const {
58
58
ArrayPrototypeSome,
59
59
ArrayPrototypeSort,
60
60
ArrayPrototypeSplice,
61
- ArrayPrototypeToString,
62
61
ArrayPrototypeUnshift,
63
62
Boolean,
64
63
Error,
@@ -233,25 +232,28 @@ writer.options = { ...inspect.defaultOptions, showProxy: true };
233
232
const toDynamicImport = ( codeLine ) => {
234
233
let dynamicImportStatement = '' ;
235
234
let moduleName = '' ;
236
- const toCamelCase = ( str ) => str . replace ( / [ - _ ] ( \w ) / g, ( _ , c ) => c . toUpperCase ( ) ) ;
237
235
const ast = acornParse ( codeLine , { sourceType : 'module' , ecmaVersion : 'latest' } ) ;
236
+ const toCamelCase = ( str ) => str . replace ( / [ - _ ] ( \w ) / g, ( _ , c ) => c . toUpperCase ( ) ) ;
238
237
acornWalk . ancestor ( ast , {
239
- ImportDeclaration : ( node ) => {
238
+ ImportDeclaration ( node ) {
240
239
const importedModules = node . source . value ;
241
- const importedSpecifiers = node . specifiers . map ( ( specifier ) => specifier . local . name ) ;
240
+ const importedSpecifiers = node . specifiers . map ( ( specifier ) => {
241
+ if ( specifier . local . name === specifier ?. imported ?. name ) {
242
+ return specifier . local . name ;
243
+ }
244
+ return `${ specifier ?. imported ?. name ? specifier . imported . name + ':' : '' } ${ specifier . local . name } ` ;
245
+ } ) ;
242
246
if ( importedSpecifiers . length > 1 ) {
243
247
moduleName = `{${ importedSpecifiers . join ( ',' ) } }` ;
244
248
} else {
245
- const formattedSpecifiers = importedSpecifiers . length ? ArrayPrototypeToString ( importedSpecifiers ) : '' ;
246
- moduleName = toCamelCase ( formattedSpecifiers || importedModules ) ;
249
+ moduleName = toCamelCase ( importedSpecifiers . length ? importedSpecifiers . toString ( ) : importedModules ) ;
247
250
}
248
251
dynamicImportStatement += `const ${ moduleName } = await import('${ importedModules } ');` ;
249
252
} ,
250
253
} ) ;
251
254
return dynamicImportStatement ;
252
255
} ;
253
256
254
-
255
257
function REPLServer ( prompt ,
256
258
stream ,
257
259
eval_ ,
0 commit comments