@@ -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
@@ -808,7 +808,7 @@ namespace ts {
808808 public languageVersion : ScriptTarget ;
809809 public languageVariant : LanguageVariant ;
810810 public identifiers : Map < string > ;
811- public nameTable : Map < string > ;
811+ public nameTable : Map < number > ;
812812 public resolvedModules : Map < ResolvedModule > ;
813813 public imports : LiteralExpression [ ] ;
814814 public moduleAugmentations : LiteralExpression [ ] ;
@@ -1957,8 +1957,6 @@ namespace ts {
19571957 const text = scriptSnapshot . getText ( 0 , scriptSnapshot . getLength ( ) ) ;
19581958 const sourceFile = createSourceFile ( fileName , text , scriptTarget , setNodeParents ) ;
19591959 setSourceFileFields ( sourceFile , scriptSnapshot , version ) ;
1960- // after full parsing we can use table with interned strings as name table
1961- sourceFile . nameTable = sourceFile . identifiers ;
19621960 return sourceFile ;
19631961 }
19641962
@@ -3834,7 +3832,7 @@ namespace ts {
38343832
38353833 if ( isRightOfDot && isSourceFileJavaScript ( sourceFile ) ) {
38363834 const uniqueNames = getCompletionEntriesFromSymbols ( symbols , entries ) ;
3837- addRange ( entries , getJavaScriptCompletionEntries ( sourceFile , uniqueNames ) ) ;
3835+ addRange ( entries , getJavaScriptCompletionEntries ( sourceFile , location . pos , uniqueNames ) ) ;
38383836 }
38393837 else {
38403838 if ( ! symbols || symbols . length === 0 ) {
@@ -3867,12 +3865,17 @@ namespace ts {
38673865
38683866 return { isMemberCompletion, isNewIdentifierLocation, entries } ;
38693867
3870- function getJavaScriptCompletionEntries ( sourceFile : SourceFile , uniqueNames : Map < string > ) : CompletionEntry [ ] {
3868+ function getJavaScriptCompletionEntries ( sourceFile : SourceFile , position : number , uniqueNames : Map < string > ) : CompletionEntry [ ] {
38713869 const entries : CompletionEntry [ ] = [ ] ;
38723870 const target = program . getCompilerOptions ( ) . target ;
38733871
38743872 const nameTable = getNameTable ( sourceFile ) ;
38753873 for ( const name in nameTable ) {
3874+ // Skip identifiers produced only from the current location
3875+ if ( nameTable [ name ] === position ) {
3876+ continue ;
3877+ }
3878+
38763879 if ( ! uniqueNames [ name ] ) {
38773880 uniqueNames [ name ] = name ;
38783881 const displayName = getCompletionEntryDisplayName ( name , target , /*performCharacterChecks*/ true ) ;
@@ -5487,7 +5490,7 @@ namespace ts {
54875490
54885491 const nameTable = getNameTable ( sourceFile ) ;
54895492
5490- if ( lookUp ( nameTable , internedName ) ) {
5493+ if ( lookUp ( nameTable , internedName ) !== undefined ) {
54915494 result = result || [ ] ;
54925495 getReferencesInNode ( sourceFile , symbol , declaredName , node , searchMeaning , findInStrings , findInComments , result , symbolToIndex ) ;
54935496 }
@@ -7525,7 +7528,7 @@ namespace ts {
75257528 }
75267529
75277530 /* @internal */
7528- export function getNameTable ( sourceFile : SourceFile ) : Map < string > {
7531+ export function getNameTable ( sourceFile : SourceFile ) : Map < number > {
75297532 if ( ! sourceFile . nameTable ) {
75307533 initializeNameTable ( sourceFile ) ;
75317534 }
@@ -7534,15 +7537,15 @@ namespace ts {
75347537 }
75357538
75367539 function initializeNameTable ( sourceFile : SourceFile ) : void {
7537- const nameTable : Map < string > = { } ;
7540+ const nameTable : Map < number > = { } ;
75387541
75397542 walk ( sourceFile ) ;
75407543 sourceFile . nameTable = nameTable ;
75417544
75427545 function walk ( node : Node ) {
75437546 switch ( node . kind ) {
75447547 case SyntaxKind . Identifier :
7545- nameTable [ ( < Identifier > node ) . text ] = ( < Identifier > node ) . text ;
7548+ nameTable [ ( < Identifier > node ) . text ] = nameTable [ ( < Identifier > node ) . text ] === undefined ? node . pos : - 1 ;
75467549 break ;
75477550 case SyntaxKind . StringLiteral :
75487551 case SyntaxKind . NumericLiteral :
@@ -7554,7 +7557,7 @@ namespace ts {
75547557 node . parent . kind === SyntaxKind . ExternalModuleReference ||
75557558 isArgumentOfElementAccessExpression ( node ) ) {
75567559
7557- nameTable [ ( < LiteralExpression > node ) . text ] = ( < LiteralExpression > node ) . text ;
7560+ nameTable [ ( < LiteralExpression > node ) . text ] = nameTable [ ( < LiteralExpression > node ) . text ] === undefined ? node . pos : - 1 ;
75587561 }
75597562 break ;
75607563 default :
0 commit comments