add additional test for grammar and type checking

This commit is contained in:
Klaus Meinhardt
2018-07-28 08:50:08 +02:00
parent d4f6b9b0a6
commit 421a5f2698
19 changed files with 125 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
tests/cases/compiler/restParameterWithBindingPattern3.ts(1,16): error TS2322: Type '1' is not assignable to type 'string'.
tests/cases/compiler/restParameterWithBindingPattern3.ts(1,23): error TS2322: Type 'true' is not assignable to type 'string'.
==== tests/cases/compiler/restParameterWithBindingPattern3.ts (2 errors) ====
function a(...[a = 1, b = true]: string[]) { }
~
!!! error TS2322: Type '1' is not assignable to type 'string'.
~
!!! error TS2322: Type 'true' is not assignable to type 'string'.

View File

@@ -0,0 +1,11 @@
//// [restParameterWithBindingPattern3.ts]
function a(...[a = 1, b = true]: string[]) { }
//// [restParameterWithBindingPattern3.js]
function a() {
var _a = [];
for (var _i = 0; _i < arguments.length; _i++) {
_a[_i] = arguments[_i];
}
var _b = _a[0], a = _b === void 0 ? 1 : _b, _c = _a[1], b = _c === void 0 ? true : _c;
}

View File

@@ -0,0 +1,6 @@
=== tests/cases/compiler/restParameterWithBindingPattern3.ts ===
function a(...[a = 1, b = true]: string[]) { }
>a : Symbol(a, Decl(restParameterWithBindingPattern3.ts, 0, 0))
>a : Symbol(a, Decl(restParameterWithBindingPattern3.ts, 0, 15))
>b : Symbol(b, Decl(restParameterWithBindingPattern3.ts, 0, 21))

View File

@@ -0,0 +1,8 @@
=== tests/cases/compiler/restParameterWithBindingPattern3.ts ===
function a(...[a = 1, b = true]: string[]) { }
>a : (...[a, b]: string[]) => void
>a : string
>1 : 1
>b : string
>true : true

View File

@@ -0,0 +1,7 @@
tests/cases/compiler/restParameterWithBindingPattern4.ts(1,23): error TS1186: A rest element cannot have an initializer.
==== tests/cases/compiler/restParameterWithBindingPattern4.ts (1 errors) ====
function a(...[...foo = []]: string[]) { }
~
!!! error TS1186: A rest element cannot have an initializer.

View File

@@ -0,0 +1,11 @@
//// [restParameterWithBindingPattern4.ts]
function a(...[...foo = []]: string[]) { }
//// [restParameterWithBindingPattern4.js]
function a() {
var _a = [];
for (var _i = 0; _i < arguments.length; _i++) {
_a[_i] = arguments[_i];
}
var _b = _a.slice(0), foo = _b === void 0 ? [] : _b;
}

View File

@@ -0,0 +1,5 @@
=== tests/cases/compiler/restParameterWithBindingPattern4.ts ===
function a(...[...foo = []]: string[]) { }
>a : Symbol(a, Decl(restParameterWithBindingPattern4.ts, 0, 0))
>foo : Symbol(foo, Decl(restParameterWithBindingPattern4.ts, 0, 15))

View File

@@ -0,0 +1,6 @@
=== tests/cases/compiler/restParameterWithBindingPattern4.ts ===
function a(...[...foo = []]: string[]) { }
>a : (...[...foo]: string[]) => void
>foo : string[]
>[] : undefined[]

View File

@@ -0,0 +1,11 @@
//// [restParameterWithBindingPattern5.ts]
function a(...{0: a, length, 3: d}: [boolean, string, number]) { }
//// [restParameterWithBindingPattern5.js]
function a() {
var _a = [];
for (var _i = 0; _i < arguments.length; _i++) {
_a[_i] = arguments[_i];
}
var a = _a[0], length = _a.length, d = _a[3];
}

View File

@@ -0,0 +1,7 @@
=== tests/cases/compiler/restParameterWithBindingPattern5.ts ===
function a(...{0: a, length, 3: d}: [boolean, string, number]) { }
>a : Symbol(a, Decl(restParameterWithBindingPattern5.ts, 0, 0))
>a : Symbol(a, Decl(restParameterWithBindingPattern5.ts, 0, 15))
>length : Symbol(length, Decl(restParameterWithBindingPattern5.ts, 0, 20))
>d : Symbol(d, Decl(restParameterWithBindingPattern5.ts, 0, 28))

View File

@@ -0,0 +1,7 @@
=== tests/cases/compiler/restParameterWithBindingPattern5.ts ===
function a(...{0: a, length, 3: d}: [boolean, string, number]) { }
>a : (__0_0: boolean, __0_1: string, __0_2: number) => void
>a : boolean
>length : 3
>d : string | number | boolean

View File

@@ -0,0 +1,7 @@
tests/cases/compiler/restParameterWithBindingPattern6.ts(1,23): error TS2493: Tuple type '[boolean, string, number]' with length '3' cannot be assigned to tuple with length '4'.
==== tests/cases/compiler/restParameterWithBindingPattern6.ts (1 errors) ====
function a(...[a, , , d]: [boolean, string, number]) { }
~
!!! error TS2493: Tuple type '[boolean, string, number]' with length '3' cannot be assigned to tuple with length '4'.

View File

@@ -0,0 +1,11 @@
//// [restParameterWithBindingPattern6.ts]
function a(...[a, , , d]: [boolean, string, number]) { }
//// [restParameterWithBindingPattern6.js]
function a() {
var _a = [];
for (var _i = 0; _i < arguments.length; _i++) {
_a[_i] = arguments[_i];
}
var a = _a[0], d = _a[3];
}

View File

@@ -0,0 +1,6 @@
=== tests/cases/compiler/restParameterWithBindingPattern6.ts ===
function a(...[a, , , d]: [boolean, string, number]) { }
>a : Symbol(a, Decl(restParameterWithBindingPattern6.ts, 0, 0))
>a : Symbol(a, Decl(restParameterWithBindingPattern6.ts, 0, 15))
>d : Symbol(d, Decl(restParameterWithBindingPattern6.ts, 0, 21))

View File

@@ -0,0 +1,8 @@
=== tests/cases/compiler/restParameterWithBindingPattern6.ts ===
function a(...[a, , , d]: [boolean, string, number]) { }
>a : (__0_0: boolean, __0_1: string, __0_2: number) => void
>a : boolean
> : undefined
> : undefined
>d : any

View File

@@ -0,0 +1 @@
function a(...[a = 1, b = true]: string[]) { }

View File

@@ -0,0 +1 @@
function a(...[...foo = []]: string[]) { }

View File

@@ -0,0 +1 @@
function a(...{0: a, length, 3: d}: [boolean, string, number]) { }

View File

@@ -0,0 +1 @@
function a(...[a, , , d]: [boolean, string, number]) { }