@@ -122,13 +122,13 @@ export function parseStaticImport(
122122) : ParsedStaticImport {
123123 const cleanedImports = clearImports ( matched . imports ) ;
124124
125- const namedImports = { } ;
126- for ( const namedImport of cleanedImports
127- . match ( / { ( [ ^ } ] * ) } / ) ?. [ 1 ]
128- ?. split ( "," ) || [ ] ) {
129- const [ , source = namedImport . trim ( ) , importName = source ] =
130- namedImport . match ( / ^ \s * ( \S * ) a s ( \S * ) \s * $ / ) || [ ] ;
131- if ( source && ! TYPE_RE . test ( source ) ) {
125+ const namedImports : Record < string , string > = { } ;
126+ const _matches = cleanedImports . match ( / { ( [ ^ } ] * ) } / ) ?. [ 1 ] ?. split ( "," ) || [ ] ;
127+ for ( const namedImport of _matches ) {
128+ const _match = namedImport . match ( / ^ \s * ( \S * ) a s ( \S * ) \s * $ / ) ;
129+ const source = _match ?. [ 1 ] || namedImport . trim ( ) ;
130+ const importName = _match ?. [ 2 ] || source ;
131+ if ( ! TYPE_RE . test ( source ) ) {
132132 namedImports [ source ] = importName ;
133133 }
134134 }
@@ -151,16 +151,14 @@ export function parseTypeImport(
151151
152152 const cleanedImports = clearImports ( matched . imports ) ;
153153
154- const namedImports = { } ;
155- for ( const namedImport of cleanedImports
156- . match ( / { ( [ ^ } ] * ) } / ) ?. [ 1 ]
157- ?. split ( "," ) || [ ] ) {
158- const [ , source = namedImport . trim ( ) , importName = source ] = ( ( ) => {
159- return / \s + a s \s + / . test ( namedImport )
160- ? namedImport . match ( / ^ \s * t y p e \s + ( \S * ) a s ( \S * ) \s * $ / ) || [ ]
161- : namedImport . match ( / ^ \s * t y p e \s + ( \S * ) \s * $ / ) || [ ] ;
162- } ) ( ) ;
163-
154+ const namedImports : Record < string , string > = { } ;
155+ const _matches = cleanedImports . match ( / { ( [ ^ } ] * ) } / ) ?. [ 1 ] ?. split ( "," ) || [ ] ;
156+ for ( const namedImport of _matches ) {
157+ const _match = / \s + a s \s + / . test ( namedImport )
158+ ? namedImport . match ( / ^ \s * t y p e \s + ( \S * ) a s ( \S * ) \s * $ / )
159+ : namedImport . match ( / ^ \s * t y p e \s + ( \S * ) \s * $ / ) ;
160+ const source = _match ?. [ 1 ] || namedImport . trim ( ) ;
161+ const importName = _match ?. [ 2 ] || source ;
164162 if ( source && TYPE_RE . test ( namedImport ) ) {
165163 namedImports [ source ] = importName ;
166164 }
@@ -326,7 +324,7 @@ function normalizeExports(exports: (ESMExport & { declaration?: string })[]) {
326324 if ( ! exp . names && exp . name ) {
327325 exp . names = [ exp . name ] ;
328326 }
329- if ( exp . type === "declaration" ) {
327+ if ( exp . type === "declaration" && exp . declaration ) {
330328 exp . declarationType = exp . declaration . replace (
331329 / ^ d e c l a r e \s * / ,
332330 "" ,
@@ -368,14 +366,15 @@ export async function resolveModuleExportNames(
368366
369367 // Recursive * exports
370368 for ( const exp of exports ) {
371- if ( exp . type === "star" ) {
372- const subExports = await resolveModuleExportNames ( exp . specifier , {
373- ...options ,
374- url,
375- } ) ;
376- for ( const subExport of subExports ) {
377- exportNames . add ( subExport ) ;
378- }
369+ if ( exp . type !== "star" || ! exp . specifier ) {
370+ continue ;
371+ }
372+ const subExports = await resolveModuleExportNames ( exp . specifier , {
373+ ...options ,
374+ url,
375+ } ) ;
376+ for ( const subExport of subExports ) {
377+ exportNames . add ( subExport ) ;
379378 }
380379 }
381380
0 commit comments