Move grammar checking: switchStatement; there are still errors from incomplete grammar migration

This commit is contained in:
Yui T 2014-12-14 19:57:12 -08:00
parent 1cc0d184bb
commit a4f17b1417
4 changed files with 23 additions and 3 deletions

View file

@ -8182,8 +8182,26 @@ module ts {
}
function checkSwitchStatement(node: SwitchStatement) {
// Grammar checking
var firstDefaultClause: CaseOrDefaultClause;
var hasDuplicateDefaultClause = false;
var expressionType = checkExpression(node.expression);
forEach(node.clauses, clause => {
// Grammar check for duplicate default clauses, skip if we already report duplicate default clause
if (clause.kind === SyntaxKind.DefaultClause && !hasDuplicateDefaultClause) {
if (firstDefaultClause === undefined) {
firstDefaultClause = clause;
}
else {
var sourceFile = getSourceFileOfNode(node);
var start = skipTrivia(sourceFile.text, clause.pos);
var end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end;
grammarErrorAtPos(sourceFile, start, end - start, Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement);
hasDuplicateDefaultClause = true;
}
}
if (fullTypeCheck && clause.kind === SyntaxKind.CaseClause) {
var caseClause = <CaseClause>clause;
// TypeScript 1.0 spec (April 2014):5.9

View file

@ -76,7 +76,7 @@ module ts {
Type_expected: { code: 1110, category: DiagnosticCategory.Error, key: "Type expected.", isEarly: true },
A_constructor_implementation_cannot_be_declared_in_an_ambient_context: { code: 1111, category: DiagnosticCategory.Error, key: "A constructor implementation cannot be declared in an ambient context.", isEarly: true },
A_class_member_cannot_be_declared_optional: { code: 1112, category: DiagnosticCategory.Error, key: "A class member cannot be declared optional.", isEarly: true },
A_default_clause_cannot_appear_more_than_once_in_a_switch_statement: { code: 1113, category: DiagnosticCategory.Error, key: "A 'default' clause cannot appear more than once in a 'switch' statement." },
A_default_clause_cannot_appear_more_than_once_in_a_switch_statement: { code: 1113, category: DiagnosticCategory.Error, key: "A 'default' clause cannot appear more than once in a 'switch' statement.", isEarly: true },
Duplicate_label_0: { code: 1114, category: DiagnosticCategory.Error, key: "Duplicate label '{0}'", isEarly: true },
A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement: { code: 1115, category: DiagnosticCategory.Error, key: "A 'continue' statement can only jump to a label of an enclosing iteration statement.", isEarly: true },
A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement: { code: 1116, category: DiagnosticCategory.Error, key: "A 'break' statement can only jump to a label of an enclosing statement.", isEarly: true },

View file

@ -347,7 +347,8 @@
},
"A 'default' clause cannot appear more than once in a 'switch' statement.": {
"category": "Error",
"code": 1113
"code": 1113,
"isEarly": true
},
"Duplicate label '{0}'": {
"category": "Error",

View file

@ -4669,7 +4669,7 @@ module ts {
case SyntaxKind.SetAccessor: return checkSetAccessor(<MethodDeclaration>node);
case SyntaxKind.SourceFile: return checkSourceFile(<SourceFile>node);
//case SyntaxKind.ShorthandPropertyAssignment: return checkShorthandPropertyAssignment(<ShorthandPropertyAssignment>node);
case SyntaxKind.SwitchStatement: return checkSwitchStatement(<SwitchStatement>node);
//case SyntaxKind.SwitchStatement: return checkSwitchStatement(<SwitchStatement>node);
case SyntaxKind.TaggedTemplateExpression: return checkTaggedTemplateExpression(<TaggedTemplateExpression>node);
case SyntaxKind.ThrowStatement: return checkThrowStatement(<ThrowStatement>node);
case SyntaxKind.TypeReference: return checkTypeReference(<TypeReferenceNode>node);
@ -5694,6 +5694,7 @@ module ts {
var start = skipTrivia(file.text, clause.pos);
var end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end;
return grammarErrorAtPos(start, end - start, Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement);
}
}
}