11import { b } from 'yuku'
22import { is } from 'yuku/utils'
33import { isRuntimeBindingVariableDeclaration } from './runtime-binding.ts'
4- import { getIdFromTSEntityName , nameOf } from './utils.ts'
4+ import {
5+ collectPatternIdentifiers ,
6+ getIdFromTSEntityName ,
7+ nameOf ,
8+ } from './utils.ts'
59import type {
610 ChunkExportPlan ,
711 DeclarationInfo ,
@@ -65,7 +69,9 @@ function collectTypeOnlyLocals(
6569
6670function collectDeclarationNames ( node : t . Node ) : string [ ] {
6771 if ( node . type === 'VariableDeclaration' ) {
68- return node . declarations . flatMap ( ( decl ) => collectPatternNames ( decl . id ) )
72+ return node . declarations . flatMap ( ( decl ) =>
73+ collectPatternIdentifiers ( decl . id ) . map ( ( { name } ) => name ) ,
74+ )
6975 }
7076
7177 if ( 'id' in node && node . id ) {
@@ -80,37 +86,6 @@ function collectDeclarationNames(node: t.Node): string[] {
8086 return [ ]
8187}
8288
83- function collectPatternNames ( node : t . Node | null | undefined ) : string [ ] {
84- if ( ! node ) return [ ]
85-
86- if ( node . type === 'Identifier' ) {
87- return [ node . name ]
88- }
89-
90- if ( node . type === 'RestElement' ) {
91- return collectPatternNames ( node . argument )
92- }
93-
94- if ( node . type === 'AssignmentPattern' ) {
95- return collectPatternNames ( node . left )
96- }
97-
98- if ( node . type === 'ArrayPattern' ) {
99- return node . elements . flatMap ( ( element ) => collectPatternNames ( element ) )
100- }
101-
102- if ( node . type === 'ObjectPattern' ) {
103- return node . properties . flatMap ( ( property ) => {
104- if ( property . type === 'RestElement' ) {
105- return collectPatternNames ( property . argument )
106- }
107- return collectPatternNames ( property . value )
108- } )
109- }
110-
111- return [ ]
112- }
113-
11489function isTypeOnlyExport (
11590 node : t . ExportNamedDeclaration ,
11691 specifier : t . ExportSpecifier ,
0 commit comments