@@ -987,7 +987,7 @@ namespace ts {
987
987
return name . kind === SyntaxKind . ComputedPropertyName && ! isStringOrNumericLiteralLike ( name . expression ) ;
988
988
}
989
989
990
- export function getTextOfPropertyName ( name : PropertyName | NoSubstitutionTemplateLiteral ) : __String {
990
+ export function tryGetTextOfPropertyName ( name : PropertyName | NoSubstitutionTemplateLiteral ) : __String | undefined {
991
991
switch ( name . kind ) {
992
992
case SyntaxKind . Identifier :
993
993
case SyntaxKind . PrivateIdentifier :
@@ -998,12 +998,16 @@ namespace ts {
998
998
return escapeLeadingUnderscores ( name . text ) ;
999
999
case SyntaxKind . ComputedPropertyName :
1000
1000
if ( isStringOrNumericLiteralLike ( name . expression ) ) return escapeLeadingUnderscores ( name . expression . text ) ;
1001
- return Debug . fail ( "Text of property name cannot be read from non-literal-valued ComputedPropertyNames" ) ;
1001
+ return undefined ;
1002
1002
default :
1003
1003
return Debug . assertNever ( name ) ;
1004
1004
}
1005
1005
}
1006
1006
1007
+ export function getTextOfPropertyName ( name : PropertyName | NoSubstitutionTemplateLiteral ) : __String {
1008
+ return Debug . checkDefined ( tryGetTextOfPropertyName ( name ) ) ;
1009
+ }
1010
+
1007
1011
export function entityNameToString ( name : EntityNameOrEntityNameExpression | JSDocMemberName | JsxTagNameExpression | PrivateIdentifier ) : string {
1008
1012
switch ( name . kind ) {
1009
1013
case SyntaxKind . ThisKeyword :
@@ -1573,7 +1577,7 @@ namespace ts {
1573
1577
export function getPropertyAssignment ( objectLiteral : ObjectLiteralExpression , key : string , key2 ?: string ) : readonly PropertyAssignment [ ] {
1574
1578
return objectLiteral . properties . filter ( ( property ) : property is PropertyAssignment => {
1575
1579
if ( property . kind === SyntaxKind . PropertyAssignment ) {
1576
- const propName = getTextOfPropertyName ( property . name ) ;
1580
+ const propName = tryGetTextOfPropertyName ( property . name ) ;
1577
1581
return key === propName || ( ! ! key2 && key2 === propName ) ;
1578
1582
}
1579
1583
return false ;
0 commit comments