@@ -756,20 +756,22 @@ export default class CSharpEmitterContext {
756
756
757
757
private buildCoreNamespace ( aliasSymbol : ts . Symbol ) {
758
758
let suffix = '' ;
759
- for ( const decl of aliasSymbol . declarations ) {
760
- let fileName = path . basename ( decl . getSourceFile ( ) . fileName ) . toLowerCase ( ) ;
761
- if ( fileName . startsWith ( 'lib.' ) && fileName . endsWith ( '.d.ts' ) ) {
762
- fileName = fileName . substring ( 4 , fileName . length - 5 ) ;
763
- if ( fileName . length ) {
764
- suffix = fileName . split ( '.' ) . map ( s => {
765
- if ( s . match ( / e s [ 0 - 9 ] { 4 } / ) ) {
766
- return '.' + this . toPascalCase ( 'ecmaScript' ) ;
767
- }
768
- if ( s . match ( / e s [ 0 - 9 ] { 1 } / ) ) {
769
- return '.' + this . toPascalCase ( 'ecmaScript' ) ;
770
- }
771
- return '.' + this . toPascalCase ( s ) ;
772
- } ) [ 0 ] ;
759
+ if ( aliasSymbol . declarations ) {
760
+ for ( const decl of aliasSymbol . declarations ) {
761
+ let fileName = path . basename ( decl . getSourceFile ( ) . fileName ) . toLowerCase ( ) ;
762
+ if ( fileName . startsWith ( 'lib.' ) && fileName . endsWith ( '.d.ts' ) ) {
763
+ fileName = fileName . substring ( 4 , fileName . length - 5 ) ;
764
+ if ( fileName . length ) {
765
+ suffix = fileName . split ( '.' ) . map ( s => {
766
+ if ( s . match ( / e s [ 0 - 9 ] { 4 } / ) ) {
767
+ return '.' + this . toPascalCase ( 'ecmaScript' ) ;
768
+ }
769
+ if ( s . match ( / e s [ 0 - 9 ] { 1 } / ) ) {
770
+ return '.' + this . toPascalCase ( 'ecmaScript' ) ;
771
+ }
772
+ return '.' + this . toPascalCase ( s ) ;
773
+ } ) [ 0 ] ;
774
+ }
773
775
}
774
776
}
775
777
}
@@ -935,9 +937,14 @@ export default class CSharpEmitterContext {
935
937
936
938
// unwrap symbol of expression to get declared type
937
939
let symbol = this . typeChecker . getSymbolAtLocation ( expression ) ;
938
- if ( ! symbol || ! symbol . declarations || symbol . declarations . length === 0 ) {
940
+ if ( ! symbol ) {
941
+ return undefined ;
942
+ }
943
+ const declarations = symbol . declarations ;
944
+ if ( ! declarations || declarations . length === 0 ) {
939
945
return undefined ;
940
946
}
947
+
941
948
if ( symbol . flags & ts . SymbolFlags . Alias ) {
942
949
symbol = this . typeChecker . getAliasedSymbol ( symbol ) ;
943
950
}
@@ -946,7 +953,7 @@ export default class CSharpEmitterContext {
946
953
}
947
954
948
955
// declared type must be nullable
949
- let declaredType = this . typeChecker . getTypeAtLocation ( symbol . declarations [ 0 ] ) ;
956
+ let declaredType = this . typeChecker . getTypeAtLocation ( declarations [ 0 ] ) ;
950
957
if ( ! this . isNullableType ( declaredType ) ) {
951
958
return undefined ;
952
959
}
@@ -991,7 +998,11 @@ export default class CSharpEmitterContext {
991
998
// we consider the expression as smart casted if the declared symbol has a different
992
999
// contextual type than the declared type.
993
1000
let symbol = this . typeChecker . getSymbolAtLocation ( expression ) ;
994
- if ( ! symbol || ! symbol . declarations || symbol . declarations . length === 0 ) {
1001
+ if ( ! symbol ) {
1002
+ return false ;
1003
+ }
1004
+ const declarations = symbol . declarations ;
1005
+ if ( ! declarations || declarations . length === 0 ) {
995
1006
return false ;
996
1007
}
997
1008
@@ -1008,7 +1019,7 @@ export default class CSharpEmitterContext {
1008
1019
return false ;
1009
1020
}
1010
1021
1011
- let declaredType = this . typeChecker . getTypeAtLocation ( symbol . declarations [ 0 ] ) ;
1022
+ let declaredType = this . typeChecker . getTypeAtLocation ( declarations [ 0 ] ) ;
1012
1023
if ( ! this . isNullableType ( declaredType ) ) {
1013
1024
return false ;
1014
1025
}
@@ -1037,7 +1048,11 @@ export default class CSharpEmitterContext {
1037
1048
// we consider the expression as smart casted if the declared symbol has a different
1038
1049
// contextual type than the declared type.
1039
1050
let symbol = this . typeChecker . getSymbolAtLocation ( expression ) ;
1040
- if ( ! symbol || ! symbol . declarations || symbol . declarations . length === 0 ) {
1051
+ if ( ! symbol ) {
1052
+ return null ;
1053
+ }
1054
+ const declarations = symbol . declarations ;
1055
+ if ( ! declarations || declarations . length === 0 ) {
1041
1056
return null ;
1042
1057
}
1043
1058
@@ -1057,7 +1072,7 @@ export default class CSharpEmitterContext {
1057
1072
}
1058
1073
}
1059
1074
1060
- let declaredType = this . typeChecker . getTypeAtLocation ( symbol . declarations [ 0 ] ) ;
1075
+ let declaredType = this . typeChecker . getTypeAtLocation ( declarations [ 0 ] ) ;
1061
1076
1062
1077
let contextualTypeNullable = contextualType ;
1063
1078
contextualType = this . typeChecker . getNonNullableType ( contextualType ) ;
@@ -1363,7 +1378,7 @@ export default class CSharpEmitterContext {
1363
1378
public isStaticSymbol ( tsSymbol : ts . Symbol ) {
1364
1379
return (
1365
1380
( tsSymbol . flags & ts . SymbolFlags . EnumMember ) !== 0 ||
1366
- ! ! tsSymbol . declarations . find (
1381
+ ! ! tsSymbol . declarations ? .find (
1367
1382
d => d . modifiers && ! ! d . modifiers . find ( m => m . kind === ts . SyntaxKind . StaticKeyword )
1368
1383
)
1369
1384
) ;
0 commit comments