findAllReferences: Reduce node.getSourceFile() calls (#23524)

* findAllReferences: Reduce node.getSourceFile() calls

* Don't create extra object
This commit is contained in:
Andy
2018-04-18 15:24:02 -07:00
committed by GitHub
parent b271df1639
commit 8f1bdc7e18

View File

@@ -130,8 +130,7 @@ namespace ts.FindAllReferences {
const { node, name, kind, displayParts } = info;
const sourceFile = node.getSourceFile();
const textSpan = getTextSpan(isComputedPropertyName(node) ? node.expression : node, sourceFile);
return { containerKind: ScriptElementKind.unknown, containerName: "", fileName: sourceFile.fileName, kind, name, textSpan, displayParts };
return { containerKind: ScriptElementKind.unknown, containerName: "", fileName: sourceFile.fileName, kind, name, textSpan: getTextSpan(isComputedPropertyName(node) ? node.expression : node, sourceFile), displayParts };
}
function getDefinitionKindAndDisplayParts(symbol: Symbol, checker: TypeChecker, node: Node): { displayParts: SymbolDisplayPart[], kind: ScriptElementKind } {
@@ -148,21 +147,23 @@ namespace ts.FindAllReferences {
}
const { node, isInString } = entry;
const sourceFile = node.getSourceFile();
return {
fileName: node.getSourceFile().fileName,
textSpan: getTextSpan(node),
fileName: sourceFile.fileName,
textSpan: getTextSpan(node, sourceFile),
isWriteAccess: isWriteAccessForReference(node),
isDefinition: node.kind === SyntaxKind.DefaultKeyword
|| isAnyDeclarationName(node)
|| isLiteralComputedPropertyDeclarationName(node),
isInString
isInString,
};
}
function toImplementationLocation(entry: Entry, checker: TypeChecker): ImplementationLocation {
if (entry.type === "node") {
const { node } = entry;
return { textSpan: getTextSpan(node), fileName: node.getSourceFile().fileName, ...implementationKindDisplayParts(node, checker) };
const sourceFile = node.getSourceFile();
return { textSpan: getTextSpan(node, sourceFile), fileName: sourceFile.fileName, ...implementationKindDisplayParts(node, checker) };
}
else {
const { textSpan, fileName } = entry;
@@ -199,17 +200,17 @@ namespace ts.FindAllReferences {
}
const { node, isInString } = entry;
const fileName = entry.node.getSourceFile().fileName;
const sourceFile = node.getSourceFile();
const writeAccess = isWriteAccessForReference(node);
const span: HighlightSpan = {
textSpan: getTextSpan(node),
textSpan: getTextSpan(node, sourceFile),
kind: writeAccess ? HighlightSpanKind.writtenReference : HighlightSpanKind.reference,
isInString
};
return { fileName, span };
return { fileName: sourceFile.fileName, span };
}
function getTextSpan(node: Node, sourceFile?: SourceFile): TextSpan {
function getTextSpan(node: Node, sourceFile: SourceFile): TextSpan {
let start = node.getStart(sourceFile);
let end = node.getEnd();
if (node.kind === SyntaxKind.StringLiteral) {