@@ -307,7 +307,11 @@ export function convertAwaitBlock(
307
307
} ;
308
308
}
309
309
const idAwaitThenValue = typeCtx . generateUniqueId ( "AwaitThenValue" ) ;
310
- if ( node . expression . type === "Identifier" ) {
310
+ if (
311
+ node . expression . type === "Identifier" &&
312
+ // We cannot use type annotations like `(x: Foo<x>)` if they have the same identifier name.
313
+ ! hasIdentifierFor ( node . expression . name , baseParam . node )
314
+ ) {
311
315
return {
312
316
preparationScript : [ generateAwaitThenValueType ( idAwaitThenValue ) ] ,
313
317
param : {
@@ -484,3 +488,30 @@ function generateAwaitThenValueType(id: string) {
484
488
: never
485
489
: T;` ;
486
490
}
491
+
492
+ /** Checks whether the given name identifier is exists or not. */
493
+ function hasIdentifierFor ( name : string , node : ESTree . Pattern ) : boolean {
494
+ if ( node . type === "Identifier" ) {
495
+ return node . name === name ;
496
+ }
497
+ if ( node . type === "ObjectPattern" ) {
498
+ return node . properties . some ( ( property ) =>
499
+ property . type === "Property"
500
+ ? hasIdentifierFor ( name , property . value )
501
+ : hasIdentifierFor ( name , property )
502
+ ) ;
503
+ }
504
+ if ( node . type === "ArrayPattern" ) {
505
+ return node . elements . some (
506
+ ( element ) => element && hasIdentifierFor ( name , element )
507
+ ) ;
508
+ }
509
+ if ( node . type === "RestElement" ) {
510
+ return hasIdentifierFor ( name , node . argument ) ;
511
+ }
512
+ if ( node . type === "AssignmentPattern" ) {
513
+ return hasIdentifierFor ( name , node . left ) ;
514
+ }
515
+
516
+ return false ;
517
+ }
0 commit comments