@@ -2800,7 +2800,11 @@ namespace ts {
28002800 return program . getOptionsDiagnostics ( ) . concat ( program . getGlobalDiagnostics ( ) ) ;
28012801 }
28022802
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+ */
28042808 function getCompletionEntryDisplayNameForSymbol ( symbol : Symbol , target : ScriptTarget , performCharacterChecks : boolean , location : Node ) : string {
28052809 let displayName : string ;
28062810
@@ -2832,37 +2836,37 @@ namespace ts {
28322836 return getCompletionEntryDisplayName ( displayName , target , performCharacterChecks ) ;
28332837 }
28342838
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 ) {
28372845 return undefined ;
28382846 }
28392847
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 ) ;
28482849
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 ) {
28502854 return undefined ;
28512855 }
28522856
28532857 if ( performCharacterChecks ) {
2854- if ( ! isIdentifierStart ( displayName . charCodeAt ( 0 ) , target ) ) {
2858+ if ( ! isIdentifierStart ( name . charCodeAt ( 0 ) , target ) ) {
28552859 return undefined ;
28562860 }
28572861
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 ) ) {
28602864 return undefined ;
28612865 }
28622866 }
28632867 }
28642868
2865- return unescapeIdentifier ( displayName ) ;
2869+ return unescapeIdentifier ( name ) ;
28662870 }
28672871
28682872 function getCompletionData ( fileName : string , position : number ) {
0 commit comments