Skip to content

Commit ba1e1f1

Browse files
ahejlsbergConnormiha
authored andcommitted
CR feedback + Consistent error spans on case/default clauses
1 parent d6d2061 commit ba1e1f1

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/compiler/checker.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -31054,10 +31054,7 @@ namespace ts {
3105431054
firstDefaultClause = clause;
3105531055
}
3105631056
else {
31057-
const sourceFile = getSourceFileOfNode(node);
31058-
const start = skipTrivia(sourceFile.text, clause.pos);
31059-
const end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end;
31060-
grammarErrorAtPos(sourceFile, start, end - start, Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement);
31057+
grammarErrorOnNode(clause, Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement);
3106131058
hasDuplicateDefaultClause = true;
3106231059
}
3106331060
}
@@ -31080,7 +31077,7 @@ namespace ts {
3108031077
}
3108131078
forEach(clause.statements, checkSourceElement);
3108231079
if (compilerOptions.noFallthroughCasesInSwitch && clause.fallthroughFlowNode && isReachableFlowNode(clause.fallthroughFlowNode)) {
31083-
grammarErrorOnFirstToken(clause, Diagnostics.Fallthrough_case_in_switch);
31080+
error(clause, Diagnostics.Fallthrough_case_in_switch);
3108431081
}
3108531082
});
3108631083
if (node.caseBlock.locals) {

src/compiler/utilities.ts

+5
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,11 @@ namespace ts {
961961
break;
962962
case SyntaxKind.ArrowFunction:
963963
return getErrorSpanForArrowFunction(sourceFile, <ArrowFunction>node);
964+
case SyntaxKind.CaseClause:
965+
case SyntaxKind.DefaultClause:
966+
const start = skipTrivia(sourceFile.text, (<CaseOrDefaultClause>node).pos);
967+
const end = (<CaseOrDefaultClause>node).statements.length > 0 ? (<CaseOrDefaultClause>node).statements[0].pos : (<CaseOrDefaultClause>node).end;
968+
return createTextSpanFromBounds(start, end);
964969
}
965970

966971
if (errorNode === undefined) {

0 commit comments

Comments
 (0)