@@ -34,6 +34,7 @@ import {
3434 getExpressionTypeArgs ,
3535 getNodeLocation ,
3636 groupMembers ,
37+ isValidPythonIdentifier ,
3738} from "./astUtils" ;
3839import { sanitizeReservedWords , uniqBy } from "./irToString" ;
3940import { Needed } from "./types" ;
@@ -792,15 +793,15 @@ export class Converter {
792793 const spread = ! ! param . getDotDotDotToken ( ) ;
793794 const optional = ! ! param . hasQuestionToken ( ) ;
794795 const name = param . getName ( ) ;
795- const isValidPythonIdentifier = / ^ [ a - z A - Z _ $ ] [ a - z A - Z 0 - 9 _ ] * $ / . test ( name ) ;
796+ const isIdentifier = isValidPythonIdentifier ( name ) ;
796797 const oldNameContext = this . nameContext ?. slice ( ) ;
797798 const paramType = param . getTypeNode ( ) ! ;
798799 const isLast = idx === params . length - 1 ;
799800 if ( isLast && Node . isTypeLiteral ( paramType ) ) {
800801 // If it's the last argument and the type is a type literal, we'll
801802 // destructure it so don't make a type.
802803 this . nameContext = undefined ;
803- } else if ( isValidPythonIdentifier ) {
804+ } else if ( isIdentifier ) {
804805 this . pushNameContext ( name ) ;
805806 } else {
806807 this . nameContext = undefined ;
@@ -1119,10 +1120,12 @@ export class Converter {
11191120 isStatic : false ,
11201121 } ) ;
11211122 const irProps = ( [ ] as PropertyIR [ ] ) . concat (
1122- astProperties . map ( ( prop ) => this . propertySignatureToIR ( prop , false ) ) ,
1123- staticAstProperties . map ( ( prop ) =>
1124- this . propertySignatureToIR ( prop , true ) ,
1125- ) ,
1123+ astProperties
1124+ . filter ( ( x ) => isValidPythonIdentifier ( x . getName ( ) ) )
1125+ . map ( ( prop ) => this . propertySignatureToIR ( prop , false ) ) ,
1126+ staticAstProperties
1127+ . filter ( ( x ) => isValidPythonIdentifier ( x . getName ( ) ) )
1128+ . map ( ( prop ) => this . propertySignatureToIR ( prop , true ) ) ,
11261129 ) ;
11271130 const props = uniqBy ( irProps , ( { name } ) => name ) ;
11281131 return {
0 commit comments