@@ -62,7 +62,7 @@ namespace ts {
6262 export interface SourceFile {
6363 /* @internal */ version : string ;
6464 /* @internal */ scriptSnapshot : IScriptSnapshot ;
65- /* @internal */ nameTable : Map < string > ;
65+ /* @internal */ nameTable : Map < number > ;
6666
6767 /* @internal */ getNamedDeclarations ( ) : Map < Declaration [ ] > ;
6868
@@ -809,7 +809,7 @@ namespace ts {
809809 public languageVersion : ScriptTarget ;
810810 public languageVariant : LanguageVariant ;
811811 public identifiers : Map < string > ;
812- public nameTable : Map < string > ;
812+ public nameTable : Map < number > ;
813813 public resolvedModules : Map < ResolvedModule > ;
814814 public imports : LiteralExpression [ ] ;
815815 public moduleAugmentations : LiteralExpression [ ] ;
@@ -1955,8 +1955,6 @@ namespace ts {
19551955 const text = scriptSnapshot . getText ( 0 , scriptSnapshot . getLength ( ) ) ;
19561956 const sourceFile = createSourceFile ( fileName , text , scriptTarget , setNodeParents ) ;
19571957 setSourceFileFields ( sourceFile , scriptSnapshot , version ) ;
1958- // after full parsing we can use table with interned strings as name table
1959- sourceFile . nameTable = sourceFile . identifiers ;
19601958 return sourceFile ;
19611959 }
19621960
@@ -3835,7 +3833,7 @@ namespace ts {
38353833
38363834 if ( isRightOfDot && isSourceFileJavaScript ( sourceFile ) ) {
38373835 const uniqueNames = getCompletionEntriesFromSymbols ( symbols , entries ) ;
3838- addRange ( entries , getJavaScriptCompletionEntries ( sourceFile , uniqueNames ) ) ;
3836+ addRange ( entries , getJavaScriptCompletionEntries ( sourceFile , location . pos , uniqueNames ) ) ;
38393837 }
38403838 else {
38413839 if ( ! symbols || symbols . length === 0 ) {
@@ -3868,12 +3866,17 @@ namespace ts {
38683866
38693867 return { isMemberCompletion, isNewIdentifierLocation, entries } ;
38703868
3871- function getJavaScriptCompletionEntries ( sourceFile : SourceFile , uniqueNames : Map < string > ) : CompletionEntry [ ] {
3869+ function getJavaScriptCompletionEntries ( sourceFile : SourceFile , position : number , uniqueNames : Map < string > ) : CompletionEntry [ ] {
38723870 const entries : CompletionEntry [ ] = [ ] ;
38733871 const target = program . getCompilerOptions ( ) . target ;
38743872
38753873 const nameTable = getNameTable ( sourceFile ) ;
38763874 for ( const name in nameTable ) {
3875+ // Skip identifiers produced only from the current location
3876+ if ( nameTable [ name ] === position ) {
3877+ continue ;
3878+ }
3879+
38773880 if ( ! uniqueNames [ name ] ) {
38783881 uniqueNames [ name ] = name ;
38793882 const displayName = getCompletionEntryDisplayName ( name , target , /*performCharacterChecks*/ true ) ;
@@ -5488,7 +5491,7 @@ namespace ts {
54885491
54895492 const nameTable = getNameTable ( sourceFile ) ;
54905493
5491- if ( lookUp ( nameTable , internedName ) ) {
5494+ if ( lookUp ( nameTable , internedName ) !== undefined ) {
54925495 result = result || [ ] ;
54935496 getReferencesInNode ( sourceFile , symbol , declaredName , node , searchMeaning , findInStrings , findInComments , result , symbolToIndex ) ;
54945497 }
@@ -7514,7 +7517,7 @@ namespace ts {
75147517 }
75157518
75167519 /* @internal */
7517- export function getNameTable ( sourceFile : SourceFile ) : Map < string > {
7520+ export function getNameTable ( sourceFile : SourceFile ) : Map < number > {
75187521 if ( ! sourceFile . nameTable ) {
75197522 initializeNameTable ( sourceFile ) ;
75207523 }
@@ -7523,15 +7526,15 @@ namespace ts {
75237526 }
75247527
75257528 function initializeNameTable ( sourceFile : SourceFile ) : void {
7526- const nameTable : Map < string > = { } ;
7529+ const nameTable : Map < number > = { } ;
75277530
75287531 walk ( sourceFile ) ;
75297532 sourceFile . nameTable = nameTable ;
75307533
75317534 function walk ( node : Node ) {
75327535 switch ( node . kind ) {
75337536 case SyntaxKind . Identifier :
7534- nameTable [ ( < Identifier > node ) . text ] = ( < Identifier > node ) . text ;
7537+ nameTable [ ( < Identifier > node ) . text ] = nameTable [ ( < Identifier > node ) . text ] === undefined ? node . pos : - 1 ;
75357538 break ;
75367539 case SyntaxKind . StringLiteral :
75377540 case SyntaxKind . NumericLiteral :
@@ -7543,7 +7546,7 @@ namespace ts {
75437546 node . parent . kind === SyntaxKind . ExternalModuleReference ||
75447547 isArgumentOfElementAccessExpression ( node ) ) {
75457548
7546- nameTable [ ( < LiteralExpression > node ) . text ] = ( < LiteralExpression > node ) . text ;
7549+ nameTable [ ( < LiteralExpression > node ) . text ] = nameTable [ ( < LiteralExpression > node ) . text ] === undefined ? node . pos : - 1 ;
75477550 }
75487551 break ;
75497552 default :
0 commit comments