Skip to content

Commit 291ad33

Browse files
committed
Use const instead of let
1 parent 4464a41 commit 291ad33

2 files changed

Lines changed: 71 additions & 71 deletions

File tree

src/services/signatureHelp.ts

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ namespace ts.SignatureHelp {
162162
// // Did not find matching token
163163
// return null;
164164
//}
165-
let emptyArray: any[] = [];
165+
const emptyArray: any[] = [];
166166

167167
const enum ArgumentListKind {
168168
TypeArguments,
@@ -179,26 +179,26 @@ namespace ts.SignatureHelp {
179179
}
180180

181181
export function getSignatureHelpItems(program: Program, sourceFile: SourceFile, position: number, cancellationToken: CancellationToken): SignatureHelpItems {
182-
let typeChecker = program.getTypeChecker();
182+
const typeChecker = program.getTypeChecker();
183183

184184
// Decide whether to show signature help
185-
let startingToken = findTokenOnLeftOfPosition(sourceFile, position);
185+
const startingToken = findTokenOnLeftOfPosition(sourceFile, position);
186186
if (!startingToken) {
187187
// We are at the beginning of the file
188188
return undefined;
189189
}
190190

191-
let argumentInfo = getContainingArgumentInfo(startingToken, position, sourceFile);
191+
const argumentInfo = getContainingArgumentInfo(startingToken, position, sourceFile);
192192
cancellationToken.throwIfCancellationRequested();
193193

194194
// Semantic filtering of signature help
195195
if (!argumentInfo) {
196196
return undefined;
197197
}
198198

199-
let call = argumentInfo.invocation;
200-
let candidates = <Signature[]>[];
201-
let resolvedSignature = typeChecker.getResolvedSignature(call, candidates);
199+
const call = argumentInfo.invocation;
200+
const candidates = <Signature[]>[];
201+
const resolvedSignature = typeChecker.getResolvedSignature(call, candidates);
202202
cancellationToken.throwIfCancellationRequested();
203203

204204
if (!candidates.length) {
@@ -220,9 +220,9 @@ namespace ts.SignatureHelp {
220220
}
221221

222222
// See if we can find some symbol with the call expression name that has call signatures.
223-
let callExpression = <CallExpression>argumentInfo.invocation;
224-
let expression = callExpression.expression;
225-
let name = expression.kind === SyntaxKind.Identifier
223+
const callExpression = <CallExpression>argumentInfo.invocation;
224+
const expression = callExpression.expression;
225+
const name = expression.kind === SyntaxKind.Identifier
226226
? <Identifier>expression
227227
: expression.kind === SyntaxKind.PropertyAccessExpression
228228
? (<PropertyAccessExpression>expression).name
@@ -232,18 +232,18 @@ namespace ts.SignatureHelp {
232232
return undefined;
233233
}
234234

235-
let typeChecker = program.getTypeChecker();
236-
for (let sourceFile of program.getSourceFiles()) {
237-
let nameToDeclarations = sourceFile.getNamedDeclarations();
238-
let declarations = getProperty(nameToDeclarations, name.text);
235+
const typeChecker = program.getTypeChecker();
236+
for (const sourceFile of program.getSourceFiles()) {
237+
const nameToDeclarations = sourceFile.getNamedDeclarations();
238+
const declarations = getProperty(nameToDeclarations, name.text);
239239

240240
if (declarations) {
241-
for (let declaration of declarations) {
242-
let symbol = declaration.symbol;
241+
for (const declaration of declarations) {
242+
const symbol = declaration.symbol;
243243
if (symbol) {
244-
let type = typeChecker.getTypeOfSymbolAtLocation(symbol, declaration);
244+
const type = typeChecker.getTypeOfSymbolAtLocation(symbol, declaration);
245245
if (type) {
246-
let callSignatures = type.getCallSignatures();
246+
const callSignatures = type.getCallSignatures();
247247
if (callSignatures && callSignatures.length) {
248248
return createSignatureHelpItems(callSignatures, callSignatures[0], argumentInfo, typeChecker);
249249
}
@@ -260,7 +260,7 @@ namespace ts.SignatureHelp {
260260
*/
261261
function getImmediatelyContainingArgumentInfo(node: Node, position: number, sourceFile: SourceFile): ArgumentListInfo {
262262
if (node.parent.kind === SyntaxKind.CallExpression || node.parent.kind === SyntaxKind.NewExpression) {
263-
let callExpression = <CallExpression>node.parent;
263+
const callExpression = <CallExpression>node.parent;
264264
// There are 3 cases to handle:
265265
// 1. The token introduces a list, and should begin a sig help session
266266
// 2. The token is either not associated with a list, or ends a list, so the session should end
@@ -279,8 +279,8 @@ namespace ts.SignatureHelp {
279279
node.kind === SyntaxKind.OpenParenToken) {
280280
// Find the list that starts right *after* the < or ( token.
281281
// If the user has just opened a list, consider this item 0.
282-
let list = getChildListThatStartsWithOpenerToken(callExpression, node, sourceFile);
283-
let isTypeArgList = callExpression.typeArguments && callExpression.typeArguments.pos === list.pos;
282+
const list = getChildListThatStartsWithOpenerToken(callExpression, node, sourceFile);
283+
const isTypeArgList = callExpression.typeArguments && callExpression.typeArguments.pos === list.pos;
284284
Debug.assert(list !== undefined);
285285
return {
286286
kind: isTypeArgList ? ArgumentListKind.TypeArguments : ArgumentListKind.CallArguments,
@@ -297,13 +297,13 @@ namespace ts.SignatureHelp {
297297
// - Between the type arguments and the arguments (greater than token)
298298
// - On the target of the call (parent.func)
299299
// - On the 'new' keyword in a 'new' expression
300-
let listItemInfo = findListItemInfo(node);
300+
const listItemInfo = findListItemInfo(node);
301301
if (listItemInfo) {
302-
let list = listItemInfo.list;
303-
let isTypeArgList = callExpression.typeArguments && callExpression.typeArguments.pos === list.pos;
302+
const list = listItemInfo.list;
303+
const isTypeArgList = callExpression.typeArguments && callExpression.typeArguments.pos === list.pos;
304304

305-
let argumentIndex = getArgumentIndex(list, node);
306-
let argumentCount = getArgumentCount(list);
305+
const argumentIndex = getArgumentIndex(list, node);
306+
const argumentCount = getArgumentCount(list);
307307

308308
Debug.assert(argumentIndex === 0 || argumentIndex < argumentCount,
309309
`argumentCount < argumentIndex, ${argumentCount} < ${argumentIndex}`);
@@ -325,27 +325,27 @@ namespace ts.SignatureHelp {
325325
}
326326
}
327327
else if (node.kind === SyntaxKind.TemplateHead && node.parent.parent.kind === SyntaxKind.TaggedTemplateExpression) {
328-
let templateExpression = <TemplateExpression>node.parent;
329-
let tagExpression = <TaggedTemplateExpression>templateExpression.parent;
328+
const templateExpression = <TemplateExpression>node.parent;
329+
const tagExpression = <TaggedTemplateExpression>templateExpression.parent;
330330
Debug.assert(templateExpression.kind === SyntaxKind.TemplateExpression);
331331

332-
let argumentIndex = isInsideTemplateLiteral(<LiteralExpression>node, position) ? 0 : 1;
332+
const argumentIndex = isInsideTemplateLiteral(<LiteralExpression>node, position) ? 0 : 1;
333333

334334
return getArgumentListInfoForTemplate(tagExpression, argumentIndex, sourceFile);
335335
}
336336
else if (node.parent.kind === SyntaxKind.TemplateSpan && node.parent.parent.parent.kind === SyntaxKind.TaggedTemplateExpression) {
337-
let templateSpan = <TemplateSpan>node.parent;
338-
let templateExpression = <TemplateExpression>templateSpan.parent;
339-
let tagExpression = <TaggedTemplateExpression>templateExpression.parent;
337+
const templateSpan = <TemplateSpan>node.parent;
338+
const templateExpression = <TemplateExpression>templateSpan.parent;
339+
const tagExpression = <TaggedTemplateExpression>templateExpression.parent;
340340
Debug.assert(templateExpression.kind === SyntaxKind.TemplateExpression);
341341

342342
// If we're just after a template tail, don't show signature help.
343343
if (node.kind === SyntaxKind.TemplateTail && !isInsideTemplateLiteral(<LiteralExpression>node, position)) {
344344
return undefined;
345345
}
346346

347-
let spanIndex = templateExpression.templateSpans.indexOf(templateSpan);
348-
let argumentIndex = getArgumentIndexForTemplatePiece(spanIndex, node, position);
347+
const spanIndex = templateExpression.templateSpans.indexOf(templateSpan);
348+
const argumentIndex = getArgumentIndexForTemplatePiece(spanIndex, node, position);
349349

350350
return getArgumentListInfoForTemplate(tagExpression, argumentIndex, sourceFile);
351351
}
@@ -366,8 +366,8 @@ namespace ts.SignatureHelp {
366366
// that trailing comma in the list, and we'll have generated the appropriate
367367
// arg index.
368368
let argumentIndex = 0;
369-
let listChildren = argumentsList.getChildren();
370-
for (let child of listChildren) {
369+
const listChildren = argumentsList.getChildren();
370+
for (const child of listChildren) {
371371
if (child === node) {
372372
break;
373373
}
@@ -391,7 +391,7 @@ namespace ts.SignatureHelp {
391391
// we'll have: 'a' '<comma>' '<missing>'
392392
// That will give us 2 non-commas. We then add one for the last comma, givin us an
393393
// arg count of 3.
394-
let listChildren = argumentsList.getChildren();
394+
const listChildren = argumentsList.getChildren();
395395

396396
let argumentCount = countWhere(listChildren, arg => arg.kind !== SyntaxKind.CommaToken);
397397
if (listChildren.length > 0 && lastOrUndefined(listChildren).kind === SyntaxKind.CommaToken) {
@@ -427,7 +427,7 @@ namespace ts.SignatureHelp {
427427

428428
function getArgumentListInfoForTemplate(tagExpression: TaggedTemplateExpression, argumentIndex: number, sourceFile: SourceFile): ArgumentListInfo {
429429
// argumentCount is either 1 or (numSpans + 1) to account for the template strings array argument.
430-
let argumentCount = tagExpression.template.kind === SyntaxKind.NoSubstitutionTemplateLiteral
430+
const argumentCount = tagExpression.template.kind === SyntaxKind.NoSubstitutionTemplateLiteral
431431
? 1
432432
: (<TemplateExpression>tagExpression.template).templateSpans.length + 1;
433433

@@ -451,14 +451,14 @@ namespace ts.SignatureHelp {
451451
//
452452
// The applicable span is from the first bar to the second bar (inclusive,
453453
// but not including parentheses)
454-
let applicableSpanStart = argumentsList.getFullStart();
455-
let applicableSpanEnd = skipTrivia(sourceFile.text, argumentsList.getEnd(), /*stopAfterLineBreak*/ false);
454+
const applicableSpanStart = argumentsList.getFullStart();
455+
const applicableSpanEnd = skipTrivia(sourceFile.text, argumentsList.getEnd(), /*stopAfterLineBreak*/ false);
456456
return createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
457457
}
458458

459459
function getApplicableSpanForTaggedTemplate(taggedTemplate: TaggedTemplateExpression, sourceFile: SourceFile): TextSpan {
460-
let template = taggedTemplate.template;
461-
let applicableSpanStart = template.getStart();
460+
const template = taggedTemplate.template;
461+
const applicableSpanStart = template.getStart();
462462
let applicableSpanEnd = template.getEnd();
463463

464464
// We need to adjust the end position for the case where the template does not have a tail.
@@ -471,7 +471,7 @@ namespace ts.SignatureHelp {
471471
// This is because a Missing node has no width. However, what we actually want is to include trivia
472472
// leading up to the next token in case the user is about to type in a TemplateMiddle or TemplateTail.
473473
if (template.kind === SyntaxKind.TemplateExpression) {
474-
let lastSpan = lastOrUndefined((<TemplateExpression>template).templateSpans);
474+
const lastSpan = lastOrUndefined((<TemplateExpression>template).templateSpans);
475475
if (lastSpan.literal.getFullWidth() === 0) {
476476
applicableSpanEnd = skipTrivia(sourceFile.text, applicableSpanEnd, /*stopAfterLineBreak*/ false);
477477
}
@@ -492,7 +492,7 @@ namespace ts.SignatureHelp {
492492
Debug.fail("Node of kind " + n.kind + " is not a subspan of its parent of kind " + n.parent.kind);
493493
}
494494

495-
let argumentInfo = getImmediatelyContainingArgumentInfo(n, position, sourceFile);
495+
const argumentInfo = getImmediatelyContainingArgumentInfo(n, position, sourceFile);
496496
if (argumentInfo) {
497497
return argumentInfo;
498498
}
@@ -504,8 +504,8 @@ namespace ts.SignatureHelp {
504504
}
505505

506506
function getChildListThatStartsWithOpenerToken(parent: Node, openerToken: Node, sourceFile: SourceFile): Node {
507-
let children = parent.getChildren(sourceFile);
508-
let indexOfOpenerToken = children.indexOf(openerToken);
507+
const children = parent.getChildren(sourceFile);
508+
const indexOfOpenerToken = children.indexOf(openerToken);
509509
Debug.assert(indexOfOpenerToken >= 0 && children.length > indexOfOpenerToken + 1);
510510
return children[indexOfOpenerToken + 1];
511511
}
@@ -522,7 +522,7 @@ namespace ts.SignatureHelp {
522522
let maxParamsSignatureIndex = -1;
523523
let maxParams = -1;
524524
for (let i = 0; i < candidates.length; i++) {
525-
let candidate = candidates[i];
525+
const candidate = candidates[i];
526526

527527
if (candidate.hasRestParameter || candidate.parameters.length >= argumentCount) {
528528
return i;
@@ -538,43 +538,43 @@ namespace ts.SignatureHelp {
538538
}
539539

540540
function createSignatureHelpItems(candidates: Signature[], bestSignature: Signature, argumentListInfo: ArgumentListInfo, typeChecker: TypeChecker): SignatureHelpItems {
541-
let applicableSpan = argumentListInfo.argumentsSpan;
542-
let isTypeParameterList = argumentListInfo.kind === ArgumentListKind.TypeArguments;
543-
544-
let invocation = argumentListInfo.invocation;
545-
let callTarget = getInvokedExpression(invocation)
546-
let callTargetSymbol = typeChecker.getSymbolAtLocation(callTarget);
547-
let callTargetDisplayParts = callTargetSymbol && symbolToDisplayParts(typeChecker, callTargetSymbol, /*enclosingDeclaration*/ undefined, /*meaning*/ undefined);
548-
let items: SignatureHelpItem[] = map(candidates, candidateSignature => {
541+
const applicableSpan = argumentListInfo.argumentsSpan;
542+
const isTypeParameterList = argumentListInfo.kind === ArgumentListKind.TypeArguments;
543+
544+
const invocation = argumentListInfo.invocation;
545+
const callTarget = getInvokedExpression(invocation)
546+
const callTargetSymbol = typeChecker.getSymbolAtLocation(callTarget);
547+
const callTargetDisplayParts = callTargetSymbol && symbolToDisplayParts(typeChecker, callTargetSymbol, /*enclosingDeclaration*/ undefined, /*meaning*/ undefined);
548+
const items: SignatureHelpItem[] = map(candidates, candidateSignature => {
549549
let signatureHelpParameters: SignatureHelpParameter[];
550-
let prefixDisplayParts: SymbolDisplayPart[] = [];
551-
let suffixDisplayParts: SymbolDisplayPart[] = [];
550+
const prefixDisplayParts: SymbolDisplayPart[] = [];
551+
const suffixDisplayParts: SymbolDisplayPart[] = [];
552552

553553
if (callTargetDisplayParts) {
554554
addRange(prefixDisplayParts, callTargetDisplayParts);
555555
}
556556

557557
if (isTypeParameterList) {
558558
prefixDisplayParts.push(punctuationPart(SyntaxKind.LessThanToken));
559-
let typeParameters = candidateSignature.typeParameters;
559+
const typeParameters = candidateSignature.typeParameters;
560560
signatureHelpParameters = typeParameters && typeParameters.length > 0 ? map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray;
561561
suffixDisplayParts.push(punctuationPart(SyntaxKind.GreaterThanToken));
562-
let parameterParts = mapToDisplayParts(writer =>
562+
const parameterParts = mapToDisplayParts(writer =>
563563
typeChecker.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.thisType, candidateSignature.parameters, writer, invocation));
564564
addRange(suffixDisplayParts, parameterParts);
565565
}
566566
else {
567-
let typeParameterParts = mapToDisplayParts(writer =>
567+
const typeParameterParts = mapToDisplayParts(writer =>
568568
typeChecker.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, invocation));
569569
addRange(prefixDisplayParts, typeParameterParts);
570570
prefixDisplayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
571571

572-
let parameters = candidateSignature.parameters;
572+
const parameters = candidateSignature.parameters;
573573
signatureHelpParameters = parameters.length > 0 ? map(parameters, createSignatureHelpParameterForParameter) : emptyArray;
574574
suffixDisplayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
575575
}
576576

577-
let returnTypeParts = mapToDisplayParts(writer =>
577+
const returnTypeParts = mapToDisplayParts(writer =>
578578
typeChecker.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, invocation));
579579
addRange(suffixDisplayParts, returnTypeParts);
580580

@@ -588,10 +588,10 @@ namespace ts.SignatureHelp {
588588
};
589589
});
590590

591-
let argumentIndex = argumentListInfo.argumentIndex;
591+
const argumentIndex = argumentListInfo.argumentIndex;
592592

593593
// argumentCount is the *apparent* number of arguments.
594-
let argumentCount = argumentListInfo.argumentCount;
594+
const argumentCount = argumentListInfo.argumentCount;
595595

596596
let selectedItemIndex = candidates.indexOf(bestSignature);
597597
if (selectedItemIndex < 0) {
@@ -609,7 +609,7 @@ namespace ts.SignatureHelp {
609609
};
610610

611611
function createSignatureHelpParameterForParameter(parameter: Symbol): SignatureHelpParameter {
612-
let displayParts = mapToDisplayParts(writer =>
612+
const displayParts = mapToDisplayParts(writer =>
613613
typeChecker.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, invocation));
614614

615615
return {
@@ -621,7 +621,7 @@ namespace ts.SignatureHelp {
621621
}
622622

623623
function createSignatureHelpParameterForTypeParameter(typeParameter: TypeParameter): SignatureHelpParameter {
624-
let displayParts = mapToDisplayParts(writer =>
624+
const displayParts = mapToDisplayParts(writer =>
625625
typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplay(typeParameter, writer, invocation));
626626

627627
return {

0 commit comments

Comments
 (0)