mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-12 03:20:56 -06:00
Fixed issue where findAllRefs on identifiers starting with 2+ underscores failed.
This commit is contained in:
parent
dc3bd6a932
commit
7836ae82b7
@ -3887,39 +3887,54 @@ module ts {
|
||||
var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations);
|
||||
|
||||
// Get the text to search for, we need to normalize it as external module names will have quote
|
||||
var symbolName = getNormalizedSymbolName(symbol.name, declarations);
|
||||
var declaredName = getDeclaredName(symbol);
|
||||
|
||||
// Get syntactic diagnostics
|
||||
// Try to get the smallest valid scope that we can limit our search to;
|
||||
// otherwise we'll need to search globally (i.e. include each file).
|
||||
var scope = getSymbolScope(symbol);
|
||||
|
||||
if (scope) {
|
||||
result = [];
|
||||
getReferencesInNode(scope, symbol, symbolName, node, searchMeaning, findInStrings, findInComments, result);
|
||||
getReferencesInNode(scope, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result);
|
||||
}
|
||||
else {
|
||||
var internedName = getInternedName(symbol, declarations)
|
||||
forEach(sourceFiles, sourceFile => {
|
||||
cancellationToken.throwIfCancellationRequested();
|
||||
|
||||
if (lookUp(sourceFile.identifiers, symbolName)) {
|
||||
if (lookUp(sourceFile.identifiers, internedName)) {
|
||||
result = result || [];
|
||||
getReferencesInNode(sourceFile, symbol, symbolName, node, searchMeaning, findInStrings, findInComments, result);
|
||||
getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
function getNormalizedSymbolName(symbolName: string, declarations: Declaration[]): string {
|
||||
function getDeclaredName(symbol: Symbol) {
|
||||
var name = typeInfoResolver.symbolToString(symbol);
|
||||
|
||||
return stripQuotes(name);
|
||||
}
|
||||
|
||||
function getInternedName(symbol: Symbol, declarations: Declaration[]): string {
|
||||
// Special case for function expressions, whose names are solely local to their bodies.
|
||||
var functionExpression = forEach(declarations, d => d.kind === SyntaxKind.FunctionExpression ? <FunctionExpression>d : undefined);
|
||||
|
||||
// When a name gets interned into a SourceFile's 'identifiers' Map,
|
||||
// its name is escaped and stored in the same way its symbol name/identifier
|
||||
// name should be stored.
|
||||
if (functionExpression && functionExpression.name) {
|
||||
var name = functionExpression.name.text;
|
||||
}
|
||||
else {
|
||||
var name = symbolName;
|
||||
var name = symbol.name;
|
||||
}
|
||||
|
||||
return stripQuotes(name);
|
||||
}
|
||||
|
||||
function stripQuotes(name: string) {
|
||||
var length = name.length;
|
||||
if (length >= 2 && name.charCodeAt(0) === CharacterCodes.doubleQuote && name.charCodeAt(length - 1) === CharacterCodes.doubleQuote) {
|
||||
return name.substring(1, length - 1);
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////class Foo {
|
||||
//// public [|_bar|]() { return 0; }
|
||||
////}
|
||||
////
|
||||
////var x: Foo;
|
||||
////x.[|_bar|];
|
||||
|
||||
|
||||
test.ranges().forEach(r1 => {
|
||||
goTo.position(r1.start);
|
||||
verify.referencesCountIs(2);
|
||||
|
||||
test.ranges().forEach(r2 => {
|
||||
verify.referencesAtPositionContains(r2);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////class Foo {
|
||||
//// public [|__bar|]() { return 0; }
|
||||
////}
|
||||
////
|
||||
////var x: Foo;
|
||||
////x.[|__bar|];
|
||||
|
||||
|
||||
test.ranges().forEach(r1 => {
|
||||
goTo.position(r1.start);
|
||||
verify.referencesCountIs(2);
|
||||
|
||||
test.ranges().forEach(r2 => {
|
||||
verify.referencesAtPositionContains(r2);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////class Foo {
|
||||
//// public [|___bar|]() { return 0; }
|
||||
////}
|
||||
////
|
||||
////var x: Foo;
|
||||
////x.[|___bar|];
|
||||
|
||||
|
||||
test.ranges().forEach(r1 => {
|
||||
goTo.position(r1.start);
|
||||
verify.referencesCountIs(2);
|
||||
|
||||
test.ranges().forEach(r2 => {
|
||||
verify.referencesAtPositionContains(r2);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////class Foo {
|
||||
//// public [|____bar|]() { return 0; }
|
||||
////}
|
||||
////
|
||||
////var x: Foo;
|
||||
////x.[|____bar|];
|
||||
|
||||
|
||||
test.ranges().forEach(r1 => {
|
||||
goTo.position(r1.start);
|
||||
verify.referencesCountIs(2);
|
||||
|
||||
test.ranges().forEach(r2 => {
|
||||
verify.referencesAtPositionContains(r2);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,24 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////class Foo {
|
||||
//// public _bar;
|
||||
//// public __bar;
|
||||
//// public [|___bar|];
|
||||
//// public ____bar;
|
||||
////}
|
||||
////
|
||||
////var x: Foo;
|
||||
////x._bar;
|
||||
////x.__bar;
|
||||
////x.[|___bar|];
|
||||
////x.____bar;
|
||||
|
||||
|
||||
test.ranges().forEach(r1 => {
|
||||
goTo.position(r1.start);
|
||||
verify.referencesCountIs(2);
|
||||
|
||||
test.ranges().forEach(r2 => {
|
||||
verify.referencesAtPositionContains(r2);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,24 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////class Foo {
|
||||
//// public _bar;
|
||||
//// public [|__bar|];
|
||||
//// public ___bar;
|
||||
//// public ____bar;
|
||||
////}
|
||||
////
|
||||
////var x: Foo;
|
||||
////x._bar;
|
||||
////x.[|__bar|];
|
||||
////x.___bar;
|
||||
////x.____bar;
|
||||
|
||||
|
||||
test.ranges().forEach(r1 => {
|
||||
goTo.position(r1.start);
|
||||
verify.referencesCountIs(2);
|
||||
|
||||
test.ranges().forEach(r2 => {
|
||||
verify.referencesAtPositionContains(r2);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////function [|__foo|]() {
|
||||
//// [|__foo|]();
|
||||
////}
|
||||
|
||||
test.ranges().forEach(r => {
|
||||
goTo.position(r.start);
|
||||
verify.referencesCountIs(2);
|
||||
|
||||
test.ranges().forEach(range => {
|
||||
verify.referencesAtPositionContains(range);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////(function [|__foo|]() {
|
||||
//// [|__foo|]();
|
||||
////})
|
||||
|
||||
test.ranges().forEach(r => {
|
||||
goTo.position(r.start);
|
||||
verify.referencesCountIs(2);
|
||||
|
||||
test.ranges().forEach(range => {
|
||||
verify.referencesAtPositionContains(range);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////(function [|___foo|]() {
|
||||
//// [|___foo|]();
|
||||
////})
|
||||
|
||||
test.ranges().forEach(r => {
|
||||
goTo.position(r.start);
|
||||
verify.referencesCountIs(2);
|
||||
|
||||
test.ranges().forEach(range => {
|
||||
verify.referencesAtPositionContains(range);
|
||||
});
|
||||
});
|
||||
@ -1,9 +1,16 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////(function f/**/oo(): number {
|
||||
////(function [|foo|](): number {
|
||||
//// var x = [|foo|];
|
||||
//// return 0;
|
||||
////})
|
||||
|
||||
|
||||
goTo.marker();
|
||||
verify.occurrencesAtPositionCount(1);
|
||||
test.ranges().forEach(r => {
|
||||
goTo.position(r.start);
|
||||
verify.occurrencesAtPositionCount(2);
|
||||
|
||||
test.ranges().forEach(range => {
|
||||
verify.occurrencesAtPositionContains(range);
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user