Skip to content

Commit 35040b9

Browse files
Use 'let' in the services code.
1 parent 20e1e3a commit 35040b9

8 files changed

Lines changed: 720 additions & 712 deletions

File tree

src/services/breakpoints.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ module ts.BreakpointResolver {
1313
return undefined;
1414
}
1515

16-
var tokenAtLocation = getTokenAtPosition(sourceFile, position);
17-
var lineOfPosition = sourceFile.getLineAndCharacterOfPosition(position).line;
16+
let tokenAtLocation = getTokenAtPosition(sourceFile, position);
17+
let lineOfPosition = sourceFile.getLineAndCharacterOfPosition(position).line;
1818
if (sourceFile.getLineAndCharacterOfPosition(tokenAtLocation.getStart()).line > lineOfPosition) {
1919
// Get previous token if the token is returned starts on new line
20-
// eg: var x =10; |--- cursor is here
21-
// var y = 10;
22-
// token at position will return var keyword on second line as the token but we would like to use
20+
// eg: let x =10; |--- cursor is here
21+
// let y = 10;
22+
// token at position will return let keyword on second line as the token but we would like to use
2323
// token on same line if trailing trivia (comments or white spaces on same line) part of the last token on that line
2424
tokenAtLocation = findPrecedingToken(tokenAtLocation.pos, sourceFile);
2525

@@ -275,9 +275,9 @@ module ts.BreakpointResolver {
275275
return spanInNode(variableDeclaration.parent.parent);
276276
}
277277

278-
var isParentVariableStatement = variableDeclaration.parent.parent.kind === SyntaxKind.VariableStatement;
279-
var isDeclarationOfForStatement = variableDeclaration.parent.parent.kind === SyntaxKind.ForStatement && contains((<VariableDeclarationList>(<ForStatement>variableDeclaration.parent.parent).initializer).declarations, variableDeclaration);
280-
var declarations = isParentVariableStatement
278+
let isParentVariableStatement = variableDeclaration.parent.parent.kind === SyntaxKind.VariableStatement;
279+
let isDeclarationOfForStatement = variableDeclaration.parent.parent.kind === SyntaxKind.ForStatement && contains((<VariableDeclarationList>(<ForStatement>variableDeclaration.parent.parent).initializer).declarations, variableDeclaration);
280+
let declarations = isParentVariableStatement
281281
? (<VariableStatement>variableDeclaration.parent.parent).declarationList.declarations
282282
: isDeclarationOfForStatement
283283
? (<VariableDeclarationList>(<ForStatement>variableDeclaration.parent.parent).initializer).declarations
@@ -287,12 +287,12 @@ module ts.BreakpointResolver {
287287
if (variableDeclaration.initializer || (variableDeclaration.flags & NodeFlags.Export)) {
288288
if (declarations && declarations[0] === variableDeclaration) {
289289
if (isParentVariableStatement) {
290-
// First declaration - include var keyword
290+
// First declaration - include let keyword
291291
return textSpan(variableDeclaration.parent, variableDeclaration);
292292
}
293293
else {
294294
Debug.assert(isDeclarationOfForStatement);
295-
// Include var keyword from for statement declarations in the span
295+
// Include let keyword from for statement declarations in the span
296296
return textSpan(findPrecedingToken(variableDeclaration.pos, sourceFile, variableDeclaration.parent), variableDeclaration);
297297
}
298298
}
@@ -303,7 +303,7 @@ module ts.BreakpointResolver {
303303
}
304304
else if (declarations && declarations[0] !== variableDeclaration) {
305305
// If we cant set breakpoint on this declaration, set it on previous one
306-
var indexOfCurrentDeclaration = indexOf(declarations, variableDeclaration);
306+
let indexOfCurrentDeclaration = indexOf(declarations, variableDeclaration);
307307
return spanInVariableDeclaration(declarations[indexOfCurrentDeclaration - 1]);
308308
}
309309
}
@@ -319,8 +319,8 @@ module ts.BreakpointResolver {
319319
return textSpan(parameter);
320320
}
321321
else {
322-
var functionDeclaration = <FunctionLikeDeclaration>parameter.parent;
323-
var indexOfParameter = indexOf(functionDeclaration.parameters, parameter);
322+
let functionDeclaration = <FunctionLikeDeclaration>parameter.parent;
323+
let indexOfParameter = indexOf(functionDeclaration.parameters, parameter);
324324
if (indexOfParameter) {
325325
// Not a first parameter, go to previous parameter
326326
return spanInParameterDeclaration(functionDeclaration.parameters[indexOfParameter - 1]);
@@ -353,7 +353,7 @@ module ts.BreakpointResolver {
353353
}
354354

355355
function spanInFunctionBlock(block: Block): TextSpan {
356-
var nodeForSpanInBlock = block.statements.length ? block.statements[0] : block.getLastToken();
356+
let nodeForSpanInBlock = block.statements.length ? block.statements[0] : block.getLastToken();
357357
if (canFunctionHaveSpanInWholeDeclaration(<FunctionLikeDeclaration>block.parent)) {
358358
return spanInNodeIfStartsOnSameLine(block.parent, nodeForSpanInBlock);
359359
}
@@ -387,7 +387,7 @@ module ts.BreakpointResolver {
387387
function spanInForStatement(forStatement: ForStatement): TextSpan {
388388
if (forStatement.initializer) {
389389
if (forStatement.initializer.kind === SyntaxKind.VariableDeclarationList) {
390-
var variableDeclarationList = <VariableDeclarationList>forStatement.initializer;
390+
let variableDeclarationList = <VariableDeclarationList>forStatement.initializer;
391391
if (variableDeclarationList.declarations.length > 0) {
392392
return spanInNode(variableDeclarationList.declarations[0]);
393393
}
@@ -409,11 +409,11 @@ module ts.BreakpointResolver {
409409
function spanInOpenBraceToken(node: Node): TextSpan {
410410
switch (node.parent.kind) {
411411
case SyntaxKind.EnumDeclaration:
412-
var enumDeclaration = <EnumDeclaration>node.parent;
412+
let enumDeclaration = <EnumDeclaration>node.parent;
413413
return spanInNodeIfStartsOnSameLine(findPrecedingToken(node.pos, sourceFile, node.parent), enumDeclaration.members.length ? enumDeclaration.members[0] : enumDeclaration.getLastToken(sourceFile));
414414

415415
case SyntaxKind.ClassDeclaration:
416-
var classDeclaration = <ClassDeclaration>node.parent;
416+
let classDeclaration = <ClassDeclaration>node.parent;
417417
return spanInNodeIfStartsOnSameLine(findPrecedingToken(node.pos, sourceFile, node.parent), classDeclaration.members.length ? classDeclaration.members[0] : classDeclaration.getLastToken(sourceFile));
418418

419419
case SyntaxKind.CaseBlock:
@@ -449,8 +449,8 @@ module ts.BreakpointResolver {
449449

450450
case SyntaxKind.CaseBlock:
451451
// breakpoint in last statement of the last clause
452-
var caseBlock = <CaseBlock>node.parent;
453-
var lastClause = caseBlock.clauses[caseBlock.clauses.length - 1];
452+
let caseBlock = <CaseBlock>node.parent;
453+
let lastClause = caseBlock.clauses[caseBlock.clauses.length - 1];
454454
if (lastClause) {
455455
return spanInNode(lastClause.statements[lastClause.statements.length - 1]);
456456
}

src/services/navigateTo.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ module ts.NavigateTo {
22
type RawNavigateToItem = { name: string; fileName: string; matchKind: PatternMatchKind; isCaseSensitive: boolean; declaration: Declaration };
33

44
export function getNavigateToItems(program: Program, cancellationToken: CancellationTokenObject, searchValue: string, maxResultCount: number): NavigateToItem[] {
5-
var patternMatcher = createPatternMatcher(searchValue);
6-
var rawItems: RawNavigateToItem[] = [];
5+
let patternMatcher = createPatternMatcher(searchValue);
6+
let rawItems: RawNavigateToItem[] = [];
77

88
// Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[]
99
forEach(program.getSourceFiles(), sourceFile => {
1010
cancellationToken.throwIfCancellationRequested();
1111

12-
var declarations = sourceFile.getNamedDeclarations();
12+
let declarations = sourceFile.getNamedDeclarations();
1313
for (let declaration of declarations) {
1414
var name = getDeclarationName(declaration);
1515
if (name !== undefined) {
1616

1717
// First do a quick check to see if the name of the declaration matches the
1818
// last portion of the (possibly) dotted name they're searching for.
19-
var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name);
19+
let matches = patternMatcher.getMatchesForLastSegmentOfPattern(name);
2020

2121
if (!matches) {
2222
continue;
@@ -25,7 +25,7 @@ module ts.NavigateTo {
2525
// It was a match! If the pattern has dots in it, then also see if hte
2626
// declaration container matches as well.
2727
if (patternMatcher.patternContainsDots) {
28-
var containers = getContainers(declaration);
28+
let containers = getContainers(declaration);
2929
if (!containers) {
3030
return undefined;
3131
}
@@ -37,8 +37,8 @@ module ts.NavigateTo {
3737
}
3838
}
3939

40-
var fileName = sourceFile.fileName;
41-
var matchKind = bestMatchKind(matches);
40+
let fileName = sourceFile.fileName;
41+
let matchKind = bestMatchKind(matches);
4242
rawItems.push({ name, fileName, matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration });
4343
}
4444
}
@@ -49,7 +49,7 @@ module ts.NavigateTo {
4949
rawItems = rawItems.slice(0, maxResultCount);
5050
}
5151

52-
var items = map(rawItems, createNavigateToItem);
52+
let items = map(rawItems, createNavigateToItem);
5353

5454
return items;
5555

@@ -67,13 +67,13 @@ module ts.NavigateTo {
6767
}
6868

6969
function getDeclarationName(declaration: Declaration): string {
70-
var result = getTextOfIdentifierOrLiteral(declaration.name);
70+
let result = getTextOfIdentifierOrLiteral(declaration.name);
7171
if (result !== undefined) {
7272
return result;
7373
}
7474

7575
if (declaration.name.kind === SyntaxKind.ComputedPropertyName) {
76-
var expr = (<ComputedPropertyName>declaration.name).expression;
76+
let expr = (<ComputedPropertyName>declaration.name).expression;
7777
if (expr.kind === SyntaxKind.PropertyAccessExpression) {
7878
return (<PropertyAccessExpression>expr).name.text;
7979
}
@@ -97,7 +97,7 @@ module ts.NavigateTo {
9797

9898
function tryAddSingleDeclarationName(declaration: Declaration, containers: string[]) {
9999
if (declaration && declaration.name) {
100-
var text = getTextOfIdentifierOrLiteral(declaration.name);
100+
let text = getTextOfIdentifierOrLiteral(declaration.name);
101101
if (text !== undefined) {
102102
containers.unshift(text);
103103
}
@@ -117,7 +117,7 @@ module ts.NavigateTo {
117117
//
118118
// [X.Y.Z]() { }
119119
function tryAddComputedPropertyName(expression: Expression, containers: string[], includeLastPortion: boolean): boolean {
120-
var text = getTextOfIdentifierOrLiteral(expression);
120+
let text = getTextOfIdentifierOrLiteral(expression);
121121
if (text !== undefined) {
122122
if (includeLastPortion) {
123123
containers.unshift(text);
@@ -126,7 +126,7 @@ module ts.NavigateTo {
126126
}
127127

128128
if (expression.kind === SyntaxKind.PropertyAccessExpression) {
129-
var propertyAccess = <PropertyAccessExpression>expression;
129+
let propertyAccess = <PropertyAccessExpression>expression;
130130
if (includeLastPortion) {
131131
containers.unshift(propertyAccess.name.text);
132132
}
@@ -138,7 +138,7 @@ module ts.NavigateTo {
138138
}
139139

140140
function getContainers(declaration: Declaration) {
141-
var containers: string[] = [];
141+
let containers: string[] = [];
142142

143143
// First, if we started with a computed property name, then add all but the last
144144
// portion into the container array.
@@ -164,10 +164,10 @@ module ts.NavigateTo {
164164

165165
function bestMatchKind(matches: PatternMatch[]) {
166166
Debug.assert(matches.length > 0);
167-
var bestMatchKind = PatternMatchKind.camelCase;
167+
let bestMatchKind = PatternMatchKind.camelCase;
168168

169169
for (let match of matches) {
170-
var kind = match.kind;
170+
let kind = match.kind;
171171
if (kind < bestMatchKind) {
172172
bestMatchKind = kind;
173173
}
@@ -177,7 +177,7 @@ module ts.NavigateTo {
177177
}
178178

179179
// This means "compare in a case insensitive manner."
180-
var baseSensitivity: Intl.CollatorOptions = { sensitivity: "base" };
180+
let baseSensitivity: Intl.CollatorOptions = { sensitivity: "base" };
181181
function compareNavigateToItems(i1: RawNavigateToItem, i2: RawNavigateToItem) {
182182
// TODO(cyrusn): get the gamut of comparisons that VS already uses here.
183183
// Right now we just sort by kind first, and then by name of the item.
@@ -189,8 +189,8 @@ module ts.NavigateTo {
189189
}
190190

191191
function createNavigateToItem(rawItem: RawNavigateToItem): NavigateToItem {
192-
var declaration = rawItem.declaration;
193-
var container = <Declaration>getContainerNode(declaration);
192+
let declaration = rawItem.declaration;
193+
let container = <Declaration>getContainerNode(declaration);
194194
return {
195195
name: rawItem.name,
196196
kind: getNodeKind(declaration),

0 commit comments

Comments
 (0)