Add warning message empty THEN clause

This commit is contained in:
Martin Všetička 2015-10-23 08:36:36 +02:00
parent 3ad29eafe3
commit 1e2108854b
9 changed files with 107 additions and 1 deletions

View file

@ -12227,6 +12227,11 @@ namespace ts {
checkExpression(node.expression);
checkSourceElement(node.thenStatement);
if (node.thenStatement.kind === SyntaxKind.EmptyStatement) {
error(node.thenStatement, Diagnostics.The_body_of_an_if_statement_cannot_be_the_empty_statement);
}
checkSourceElement(node.elseStatement);
}

View file

@ -799,7 +799,11 @@
"'=' can only be used in an object literal property inside a destructuring assignment.": {
"category": "Error",
"code": 1312
},
},
"The body of an 'if' statement cannot be the empty statement.": {
"category": "Error",
"code": 1313
},
"Duplicate identifier '{0}'.": {
"category": "Error",
"code": 2300

View file

@ -0,0 +1,15 @@
tests/cases/compiler/emptyThenWarning.ts(1,6): error TS1313: The body of an 'if' statement cannot be the empty statement.
tests/cases/compiler/emptyThenWarning.ts(4,19): error TS1313: The body of an 'if' statement cannot be the empty statement.
==== tests/cases/compiler/emptyThenWarning.ts (2 errors) ====
if(1);
~
!!! error TS1313: The body of an 'if' statement cannot be the empty statement.
let x = 0;
if (true === true); {
~
!!! error TS1313: The body of an 'if' statement cannot be the empty statement.
x = 1;
}

View file

@ -0,0 +1,17 @@
//// [emptyThenWarning.ts]
if(1);
let x = 0;
if (true === true); {
x = 1;
}
//// [emptyThenWarning.js]
if (1)
;
var x = 0;
if (true === true)
;
{
x = 1;
}

View file

@ -0,0 +1,16 @@
//// [emptyThenWithoutWarning.ts]
let a = 4;
if(a === 1 || a === 2 || a === 3) {
}
else {
let message = "Ooops";
}
//// [emptyThenWithoutWarning.js]
var a = 4;
if (a === 1 || a === 2 || a === 3) {
}
else {
var message = "Ooops";
}

View file

@ -0,0 +1,13 @@
=== tests/cases/compiler/emptyThenWithoutWarning.ts ===
let a = 4;
>a : Symbol(a, Decl(emptyThenWithoutWarning.ts, 0, 3))
if(a === 1 || a === 2 || a === 3) {
>a : Symbol(a, Decl(emptyThenWithoutWarning.ts, 0, 3))
>a : Symbol(a, Decl(emptyThenWithoutWarning.ts, 0, 3))
>a : Symbol(a, Decl(emptyThenWithoutWarning.ts, 0, 3))
}
else {
let message = "Ooops";
>message : Symbol(message, Decl(emptyThenWithoutWarning.ts, 5, 7))
}

View file

@ -0,0 +1,23 @@
=== tests/cases/compiler/emptyThenWithoutWarning.ts ===
let a = 4;
>a : number
>4 : number
if(a === 1 || a === 2 || a === 3) {
>a === 1 || a === 2 || a === 3 : boolean
>a === 1 || a === 2 : boolean
>a === 1 : boolean
>a : number
>1 : number
>a === 2 : boolean
>a : number
>2 : number
>a === 3 : boolean
>a : number
>3 : number
}
else {
let message = "Ooops";
>message : string
>"Ooops" : string
}

View file

@ -0,0 +1,6 @@
if(1);
let x = 0;
if (true === true); {
x = 1;
}

View file

@ -0,0 +1,7 @@
let a = 4;
if(a === 1 || a === 2 || a === 3) {
}
else {
let message = "Ooops";
}