Skip to content

Commit

Permalink
Use 'lastOrUndefined' where appropriate in the services layer.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRosenwasser committed May 2, 2015
1 parent 161261e commit a9c46e7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/services/breakpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,14 @@ module ts.BreakpointResolver {
// fall through.

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

case SyntaxKind.CaseBlock:
// breakpoint in last statement of the last clause
let caseBlock = <CaseBlock>node.parent;
let lastClause = caseBlock.clauses[caseBlock.clauses.length - 1];
let lastClause = lastOrUndefined(caseBlock.clauses);
if (lastClause) {
return spanInNode(lastClause.statements[lastClause.statements.length - 1]);
return spanInNode(lastOrUndefined(lastClause.statements));
}
return undefined;

Expand Down
2 changes: 1 addition & 1 deletion src/services/formatting/formattingScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module ts.formatting {
if (isStarted) {
if (trailingTrivia) {
Debug.assert(trailingTrivia.length !== 0);
wasNewLine = trailingTrivia[trailingTrivia.length - 1].kind === SyntaxKind.NewLineTrivia;
wasNewLine = lastOrUndefined(trailingTrivia).kind === SyntaxKind.NewLineTrivia;
}
else {
wasNewLine = false;
Expand Down
4 changes: 2 additions & 2 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ module ts {
// Overwrite the last declaration if it was an overload
// and this one is an implementation.
if (functionDeclaration.body && !(<FunctionLikeDeclaration>lastDeclaration).body) {
declarations[declarations.length - 1] = functionDeclaration;
lastOrUndefined(declarations) = functionDeclaration;
}
}
else {
Expand Down Expand Up @@ -4058,7 +4058,7 @@ module ts {
return true;
}
else if (declarations.length) {
result.push(createDefinitionInfo(declarations[declarations.length - 1], symbolKind, symbolName, containerName));
result.push(createDefinitionInfo(lastOrUndefined(declarations), symbolKind, symbolName, containerName));
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ module ts {
function nodeEndsWith(n: Node, expectedLastToken: SyntaxKind, sourceFile: SourceFile): boolean {
let children = n.getChildren(sourceFile);
if (children.length) {
let last = children[children.length - 1];
let last = lastOrUndefined(children);
if (last.kind === expectedLastToken) {
return true;
}
Expand Down

0 comments on commit a9c46e7

Please sign in to comment.