@@ -177,38 +177,41 @@ export function ImportDeclaration(this: Printer, node: t.ImportDeclaration) {
177177 this . word ( "import" ) ;
178178 this . space ( ) ;
179179
180- if ( node . importKind === "type" || node . importKind === "typeof" ) {
180+ const isTypeKind = node . importKind === "type" || node . importKind === "typeof" ;
181+ if ( isTypeKind ) {
181182 this . word ( node . importKind ) ;
182183 this . space ( ) ;
183184 }
184185
185186 const specifiers = node . specifiers . slice ( 0 ) ;
186- if ( specifiers ?. length ) {
187- // print "special" specifiers first
188- for ( ; ; ) {
189- const first = specifiers [ 0 ] ;
190- if (
191- isImportDefaultSpecifier ( first ) ||
192- isImportNamespaceSpecifier ( first )
193- ) {
194- this . print ( specifiers . shift ( ) , node ) ;
195- if ( specifiers . length ) {
196- this . token ( "," ) ;
197- this . space ( ) ;
198- }
199- } else {
200- break ;
187+ const hasSpecifiers = ! ! specifiers . length ;
188+ // print "special" specifiers first. The loop condition is constant,
189+ // but there is a "break" in the body.
190+ while ( hasSpecifiers ) {
191+ const first = specifiers [ 0 ] ;
192+ if ( isImportDefaultSpecifier ( first ) || isImportNamespaceSpecifier ( first ) ) {
193+ this . print ( specifiers . shift ( ) , node ) ;
194+ if ( specifiers . length ) {
195+ this . token ( "," ) ;
196+ this . space ( ) ;
201197 }
198+ } else {
199+ break ;
202200 }
201+ }
203202
204- if ( specifiers . length ) {
205- this . token ( "{" ) ;
206- this . space ( ) ;
207- this . printList ( specifiers , node ) ;
208- this . space ( ) ;
209- this . token ( "}" ) ;
210- }
203+ if ( specifiers . length ) {
204+ this . token ( "{" ) ;
205+ this . space ( ) ;
206+ this . printList ( specifiers , node ) ;
207+ this . space ( ) ;
208+ this . token ( "}" ) ;
209+ } else if ( isTypeKind && ! hasSpecifiers ) {
210+ this . token ( "{" ) ;
211+ this . token ( "}" ) ;
212+ }
211213
214+ if ( hasSpecifiers || isTypeKind ) {
212215 this . space ( ) ;
213216 this . word ( "from" ) ;
214217 this . space ( ) ;
0 commit comments