Skip to content

Commit 9460fb5

Browse files
Use 'lastOrUndefined' where appropriate in the services layer.
1 parent 4ebfee2 commit 9460fb5

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

src/services/breakpoints.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,14 @@ module ts.BreakpointResolver {
446446
// fall through.
447447

448448
case SyntaxKind.CatchClause:
449-
return spanInNode((<Block>node.parent).statements[(<Block>node.parent).statements.length - 1]);;
449+
return spanInNode(lastOrUndefined((<Block>node.parent).statements));;
450450

451451
case SyntaxKind.CaseBlock:
452452
// breakpoint in last statement of the last clause
453453
let caseBlock = <CaseBlock>node.parent;
454-
let lastClause = caseBlock.clauses[caseBlock.clauses.length - 1];
454+
let lastClause = lastOrUndefined(caseBlock.clauses);
455455
if (lastClause) {
456-
return spanInNode(lastClause.statements[lastClause.statements.length - 1]);
456+
return spanInNode(lastOrUndefined(lastClause.statements));
457457
}
458458
return undefined;
459459

src/services/formatting/formattingScanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module ts.formatting {
5151
if (isStarted) {
5252
if (trailingTrivia) {
5353
Debug.assert(trailingTrivia.length !== 0);
54-
wasNewLine = trailingTrivia[trailingTrivia.length - 1].kind === SyntaxKind.NewLineTrivia;
54+
wasNewLine = lastOrUndefined(trailingTrivia).kind === SyntaxKind.NewLineTrivia;
5555
}
5656
else {
5757
wasNewLine = false;

src/services/services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ module ts {
848848
// Overwrite the last declaration if it was an overload
849849
// and this one is an implementation.
850850
if (functionDeclaration.body && !(<FunctionLikeDeclaration>lastDeclaration).body) {
851-
declarations[declarations.length - 1] = functionDeclaration;
851+
lastOrUndefined(declarations) = functionDeclaration;
852852
}
853853
}
854854
else {
@@ -4058,7 +4058,7 @@ module ts {
40584058
return true;
40594059
}
40604060
else if (declarations.length) {
4061-
result.push(createDefinitionInfo(declarations[declarations.length - 1], symbolKind, symbolName, containerName));
4061+
result.push(createDefinitionInfo(lastOrUndefined(declarations), symbolKind, symbolName, containerName));
40624062
return true;
40634063
}
40644064

src/services/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ module ts {
200200
function nodeEndsWith(n: Node, expectedLastToken: SyntaxKind, sourceFile: SourceFile): boolean {
201201
let children = n.getChildren(sourceFile);
202202
if (children.length) {
203-
let last = children[children.length - 1];
203+
let last = lastOrUndefined(children);
204204
if (last.kind === expectedLastToken) {
205205
return true;
206206
}

0 commit comments

Comments
 (0)