Skip to content

Commit 421a5f2

Browse files
committed
add additional test for grammar and type checking
1 parent d4f6b9b commit 421a5f2

19 files changed

+125
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
tests/cases/compiler/restParameterWithBindingPattern3.ts(1,16): error TS2322: Type '1' is not assignable to type 'string'.
2+
tests/cases/compiler/restParameterWithBindingPattern3.ts(1,23): error TS2322: Type 'true' is not assignable to type 'string'.
3+
4+
5+
==== tests/cases/compiler/restParameterWithBindingPattern3.ts (2 errors) ====
6+
function a(...[a = 1, b = true]: string[]) { }
7+
~
8+
!!! error TS2322: Type '1' is not assignable to type 'string'.
9+
~
10+
!!! error TS2322: Type 'true' is not assignable to type 'string'.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [restParameterWithBindingPattern3.ts]
2+
function a(...[a = 1, b = true]: string[]) { }
3+
4+
//// [restParameterWithBindingPattern3.js]
5+
function a() {
6+
var _a = [];
7+
for (var _i = 0; _i < arguments.length; _i++) {
8+
_a[_i] = arguments[_i];
9+
}
10+
var _b = _a[0], a = _b === void 0 ? 1 : _b, _c = _a[1], b = _c === void 0 ? true : _c;
11+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/compiler/restParameterWithBindingPattern3.ts ===
2+
function a(...[a = 1, b = true]: string[]) { }
3+
>a : Symbol(a, Decl(restParameterWithBindingPattern3.ts, 0, 0))
4+
>a : Symbol(a, Decl(restParameterWithBindingPattern3.ts, 0, 15))
5+
>b : Symbol(b, Decl(restParameterWithBindingPattern3.ts, 0, 21))
6+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/restParameterWithBindingPattern3.ts ===
2+
function a(...[a = 1, b = true]: string[]) { }
3+
>a : (...[a, b]: string[]) => void
4+
>a : string
5+
>1 : 1
6+
>b : string
7+
>true : true
8+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
tests/cases/compiler/restParameterWithBindingPattern4.ts(1,23): error TS1186: A rest element cannot have an initializer.
2+
3+
4+
==== tests/cases/compiler/restParameterWithBindingPattern4.ts (1 errors) ====
5+
function a(...[...foo = []]: string[]) { }
6+
~
7+
!!! error TS1186: A rest element cannot have an initializer.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [restParameterWithBindingPattern4.ts]
2+
function a(...[...foo = []]: string[]) { }
3+
4+
//// [restParameterWithBindingPattern4.js]
5+
function a() {
6+
var _a = [];
7+
for (var _i = 0; _i < arguments.length; _i++) {
8+
_a[_i] = arguments[_i];
9+
}
10+
var _b = _a.slice(0), foo = _b === void 0 ? [] : _b;
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/compiler/restParameterWithBindingPattern4.ts ===
2+
function a(...[...foo = []]: string[]) { }
3+
>a : Symbol(a, Decl(restParameterWithBindingPattern4.ts, 0, 0))
4+
>foo : Symbol(foo, Decl(restParameterWithBindingPattern4.ts, 0, 15))
5+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/compiler/restParameterWithBindingPattern4.ts ===
2+
function a(...[...foo = []]: string[]) { }
3+
>a : (...[...foo]: string[]) => void
4+
>foo : string[]
5+
>[] : undefined[]
6+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [restParameterWithBindingPattern5.ts]
2+
function a(...{0: a, length, 3: d}: [boolean, string, number]) { }
3+
4+
//// [restParameterWithBindingPattern5.js]
5+
function a() {
6+
var _a = [];
7+
for (var _i = 0; _i < arguments.length; _i++) {
8+
_a[_i] = arguments[_i];
9+
}
10+
var a = _a[0], length = _a.length, d = _a[3];
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/compiler/restParameterWithBindingPattern5.ts ===
2+
function a(...{0: a, length, 3: d}: [boolean, string, number]) { }
3+
>a : Symbol(a, Decl(restParameterWithBindingPattern5.ts, 0, 0))
4+
>a : Symbol(a, Decl(restParameterWithBindingPattern5.ts, 0, 15))
5+
>length : Symbol(length, Decl(restParameterWithBindingPattern5.ts, 0, 20))
6+
>d : Symbol(d, Decl(restParameterWithBindingPattern5.ts, 0, 28))
7+

0 commit comments

Comments
 (0)