Skip to content

Commit 863f0b6

Browse files
committed
Merge pull request #2643 from Microsoft/checkForOmittedExpression
Check for omitted expressions when checking const and let declaration names
2 parents 189f07a + 238a33d commit 863f0b6

File tree

4 files changed

+94
-1
lines changed

4 files changed

+94
-1
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12596,7 +12596,9 @@ module ts {
1259612596
else {
1259712597
let elements = (<BindingPattern>name).elements;
1259812598
for (let element of elements) {
12599-
checkGrammarNameInLetOrConstDeclarations(element.name);
12599+
if (element.kind !== SyntaxKind.OmittedExpression) {
12600+
checkGrammarNameInLetOrConstDeclarations(element.name);
12601+
}
1260012602
}
1260112603
}
1260212604
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [arrayBindingPatternOmittedExpressions.ts]
2+
3+
var results: string[];
4+
5+
{
6+
let [, b, , a] = results;
7+
let x = {
8+
a,
9+
b
10+
}
11+
}
12+
13+
14+
function f([, a, , b, , , , s, , , ] = results) {
15+
a = s[1];
16+
b = s[2];
17+
}
18+
19+
//// [arrayBindingPatternOmittedExpressions.js]
20+
var results;
21+
{
22+
let [, b, , a] = results;
23+
let x = {
24+
a,
25+
b
26+
};
27+
}
28+
function f([, a, , b, , , , s, , ,] = results) {
29+
a = s[1];
30+
b = s[2];
31+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
=== tests/cases/compiler/arrayBindingPatternOmittedExpressions.ts ===
2+
3+
var results: string[];
4+
>results : string[]
5+
6+
{
7+
let [, b, , a] = results;
8+
>b : string
9+
>a : string
10+
>results : string[]
11+
12+
let x = {
13+
>x : { a: string; b: string; }
14+
>{ a, b } : { a: string; b: string; }
15+
16+
a,
17+
>a : string
18+
19+
b
20+
>b : string
21+
}
22+
}
23+
24+
25+
function f([, a, , b, , , , s, , , ] = results) {
26+
>f : ([, a, , b, , , , s, , , ]?: string[]) => void
27+
>a : string
28+
>b : string
29+
>s : string
30+
>results : string[]
31+
32+
a = s[1];
33+
>a = s[1] : string
34+
>a : string
35+
>s[1] : string
36+
>s : string
37+
38+
b = s[2];
39+
>b = s[2] : string
40+
>b : string
41+
>s[2] : string
42+
>s : string
43+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// @target: ES6
2+
3+
var results: string[];
4+
5+
{
6+
let [, b, , a] = results;
7+
let x = {
8+
a,
9+
b
10+
}
11+
}
12+
13+
14+
function f([, a, , b, , , , s, , , ] = results) {
15+
a = s[1];
16+
b = s[2];
17+
}

0 commit comments

Comments
 (0)