@@ -2800,7 +2800,11 @@ namespace ts {
2800
2800
return program . getOptionsDiagnostics ( ) . concat ( program . getGlobalDiagnostics ( ) ) ;
2801
2801
}
2802
2802
2803
- /// Completion
2803
+ /**
2804
+ * Get the name to be display in completion from a given symbol.
2805
+ *
2806
+ * @return undefined if the name is of external module otherwise a name with striped of any quote
2807
+ */
2804
2808
function getCompletionEntryDisplayNameForSymbol ( symbol : Symbol , target : ScriptTarget , performCharacterChecks : boolean , location : Node ) : string {
2805
2809
let displayName : string ;
2806
2810
@@ -2832,37 +2836,37 @@ namespace ts {
2832
2836
return getCompletionEntryDisplayName ( displayName , target , performCharacterChecks ) ;
2833
2837
}
2834
2838
2835
- function getCompletionEntryDisplayName ( displayName : string , target : ScriptTarget , performCharacterChecks : boolean ) : string {
2836
- if ( ! displayName ) {
2839
+ /**
2840
+ * Get a displayName from a given for completion list, performing any necessary quotes stripping
2841
+ * and checking whether the name is valid identifier name.
2842
+ */
2843
+ function getCompletionEntryDisplayName ( name : string , target : ScriptTarget , performCharacterChecks : boolean ) : string {
2844
+ if ( ! name ) {
2837
2845
return undefined ;
2838
2846
}
2839
2847
2840
- let firstCharCode = displayName . charCodeAt ( 0 ) ;
2841
- if ( displayName . length >= 2 &&
2842
- firstCharCode === displayName . charCodeAt ( displayName . length - 1 ) &&
2843
- ( firstCharCode === CharacterCodes . singleQuote || firstCharCode === CharacterCodes . doubleQuote ) ) {
2844
- // If the user entered name for the symbol was quoted, removing the quotes is not enough, as the name could be an
2845
- // invalid identifier name. We need to check if whatever was inside the quotes is actually a valid identifier name.
2846
- displayName = displayName . substring ( 1 , displayName . length - 1 ) ;
2847
- }
2848
+ name = stripQuotes ( name ) ;
2848
2849
2849
- if ( ! displayName ) {
2850
+ // We can simply return name with strip quotes because the name could be an invalid identifier name
2851
+ // e.g "b a" is valid quoted name but when we strip off the quotes, it is invalid.
2852
+ // We, thus, need to check if whatever was inside the quotes is actually a valid identifier name.
2853
+ if ( ! name ) {
2850
2854
return undefined ;
2851
2855
}
2852
2856
2853
2857
if ( performCharacterChecks ) {
2854
- if ( ! isIdentifierStart ( displayName . charCodeAt ( 0 ) , target ) ) {
2858
+ if ( ! isIdentifierStart ( name . charCodeAt ( 0 ) , target ) ) {
2855
2859
return undefined ;
2856
2860
}
2857
2861
2858
- for ( let i = 1 , n = displayName . length ; i < n ; i ++ ) {
2859
- if ( ! isIdentifierPart ( displayName . charCodeAt ( i ) , target ) ) {
2862
+ for ( let i = 1 , n = name . length ; i < n ; i ++ ) {
2863
+ if ( ! isIdentifierPart ( name . charCodeAt ( i ) , target ) ) {
2860
2864
return undefined ;
2861
2865
}
2862
2866
}
2863
2867
}
2864
2868
2865
- return unescapeIdentifier ( displayName ) ;
2869
+ return unescapeIdentifier ( name ) ;
2866
2870
}
2867
2871
2868
2872
function getCompletionData ( fileName : string , position : number ) {
0 commit comments