Add warning message empty THEN clause
This commit is contained in:
parent
3ad29eafe3
commit
1e2108854b
9 changed files with 107 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
15
tests/baselines/reference/emptyThenWarning.errors.txt
Normal file
15
tests/baselines/reference/emptyThenWarning.errors.txt
Normal 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;
|
||||
}
|
17
tests/baselines/reference/emptyThenWarning.js
Normal file
17
tests/baselines/reference/emptyThenWarning.js
Normal 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;
|
||||
}
|
16
tests/baselines/reference/emptyThenWithoutWarning.js
Normal file
16
tests/baselines/reference/emptyThenWithoutWarning.js
Normal 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";
|
||||
}
|
13
tests/baselines/reference/emptyThenWithoutWarning.symbols
Normal file
13
tests/baselines/reference/emptyThenWithoutWarning.symbols
Normal 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))
|
||||
}
|
23
tests/baselines/reference/emptyThenWithoutWarning.types
Normal file
23
tests/baselines/reference/emptyThenWithoutWarning.types
Normal 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
|
||||
}
|
6
tests/cases/compiler/emptyThenWarning.ts
Normal file
6
tests/cases/compiler/emptyThenWarning.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
if(1);
|
||||
|
||||
let x = 0;
|
||||
if (true === true); {
|
||||
x = 1;
|
||||
}
|
7
tests/cases/compiler/emptyThenWithoutWarning.ts
Normal file
7
tests/cases/compiler/emptyThenWithoutWarning.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
let a = 4;
|
||||
|
||||
if(a === 1 || a === 2 || a === 3) {
|
||||
}
|
||||
else {
|
||||
let message = "Ooops";
|
||||
}
|
Loading…
Reference in a new issue