Skip to content

Commit 892baf0

Browse files
committed
use Identifiers list from the parser to filter getReferences instead of bloomFilters
1 parent 6953794 commit 892baf0

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/compiler/parser.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,10 @@ module ts {
814814
return createNode(SyntaxKind.Missing);
815815
}
816816

817+
function internIdentifier(text: string): string {
818+
return hasProperty(identifiers, text) ? identifiers[text] : (identifiers[text] = text);
819+
}
820+
817821
// An identifier that starts with two underscores has an extra underscore character prepended to it to avoid issues
818822
// with magic property names like '__proto__'. The 'identifiers' object is used to share a single string instance for
819823
// each identifier in order to reduce memory consumption.
@@ -822,7 +826,7 @@ module ts {
822826
if (isIdentifier) {
823827
var node = <Identifier>createNode(SyntaxKind.Identifier);
824828
var text = escapeIdentifier(scanner.getTokenValue());
825-
node.text = hasProperty(identifiers, text) ? identifiers[text] : (identifiers[text] = text);
829+
node.text = internIdentifier(text);
826830
nextToken();
827831
return finishNode(node);
828832
}
@@ -844,7 +848,7 @@ module ts {
844848

845849
function parsePropertyName(): Identifier {
846850
if (token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral) {
847-
return <LiteralExpression>parsePrimaryExpression();
851+
return parseLiteralNode(/*internName:*/ true);
848852
}
849853
return parseIdentifierName();
850854
}
@@ -1125,9 +1129,11 @@ module ts {
11251129
return finishNode(node);
11261130
}
11271131

1128-
function parseLiteralNode(): LiteralExpression {
1132+
function parseLiteralNode(internName?:boolean): LiteralExpression {
11291133
var node = <LiteralExpression>createNode(token);
1130-
node.text = scanner.getTokenValue();
1134+
var text = scanner.getTokenValue();
1135+
node.text = internName ? internIdentifier(text) : text;
1136+
11311137
var tokenPos = scanner.getTokenPos();
11321138
nextToken();
11331139
finishNode(node);
@@ -1154,7 +1160,7 @@ module ts {
11541160
}
11551161

11561162
function parseStringLiteral(): LiteralExpression {
1157-
if (token === SyntaxKind.StringLiteral) return parseLiteralNode();
1163+
if (token === SyntaxKind.StringLiteral) return parseLiteralNode(/*internName:*/ true);
11581164
error(Diagnostics.String_literal_expected);
11591165
return <LiteralExpression>createMissingNode();
11601166
}
@@ -2058,6 +2064,10 @@ module ts {
20582064
}
20592065
else {
20602066
indexedAccess.index = parseExpression();
2067+
if (indexedAccess.index.kind === SyntaxKind.StringLiteral || indexedAccess.index.kind === SyntaxKind.NumericLiteral) {
2068+
var literal = <LiteralExpression>indexedAccess.index;
2069+
literal.text = internIdentifier(literal.text);
2070+
}
20612071
parseExpected(SyntaxKind.CloseBracketToken);
20622072
}
20632073

@@ -3611,6 +3621,7 @@ module ts {
36113621
file.version = version;
36123622
file.isOpen = isOpen;
36133623
file.languageVersion = languageVersion;
3624+
file.identifiers = identifiers;
36143625
return file;
36153626
}
36163627

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ module ts {
537537
isOpen: boolean;
538538
version: number;
539539
languageVersion: ScriptTarget;
540+
identifiers: Map<string>;
540541
}
541542

542543
export interface Program {

src/services/services.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ module ts {
322322
public version: number;
323323
public isOpen: boolean;
324324
public languageVersion: ScriptTarget;
325+
public identifiers: Map<string>;
325326

326327
private syntaxTree: TypeScript.SyntaxTree;
327328
private scriptSnapshot: TypeScript.IScriptSnapshot;
@@ -2155,10 +2156,10 @@ module ts {
21552156
forEach(program.getSourceFiles(), sourceFile => {
21562157
cancellationToken.throwIfCancellationRequested();
21572158

2158-
//if (sourceFile.getBloomFilter().probablyContains(symbolName)) {
2159+
if (lookUp(sourceFile.identifiers, symbolName)) {
21592160
result = result || [];
21602161
getReferencesInNode(sourceFile, symbol, symbolName, node, searchMeaning, result);
2161-
//}
2162+
}
21622163
});
21632164
}
21642165

0 commit comments

Comments
 (0)