Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: test/mjsunit/harmony/typesystem/method-definitions.js

Issue 1841093002: Add optional types to function/method declarations (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@types-1817353007-typ-mod
Patch Set: More tests, disallow optional setter parameter Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/harmony/typesystem/function-declarations.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Flags: --harmony-types
6
7
8 load("test/mjsunit/harmony/typesystem/testgen.js");
9
10
11 (function TestMethodDefinitions() {
12 // Normal methods.
13 CheckValid("class C { m(a: number, b: number) { return a+b; } }");
14 CheckValid("class C { m(a: number, b?: number) { return a; } }");
15 CheckValid("class C { m(a?: number, b?: number) { return 42; } }");
16 CheckValid("class C { m(a: number, ...rest: number[]) {} }");
17 CheckValid("class C { m(a?: number, ...rest: number[]) {} }");
18 CheckValid("class C { m() : boolean { return true; } }");
19 CheckValid("class C { m(a: number, b: number) : boolean { return true; } }");
20 CheckValid("class C { m(a: number, b?: number) : boolean { return true; } }");
21 CheckValid("class C { m(a?: number, b?: number) : boolean { return true; } }") ;
22 CheckValid("class C { m(a: number, ...rest: number[]) : void {} }");
23 CheckValid("class C { m(a: number, ...rest: number[]) : void {} }");
24 CheckValid("class C { m([first, ...rest]: number[]) : void {} }");
25 CheckValid("class C { m(a: number = 7, b: number) { return a+b; } }");
26 CheckValid("class C { m(a: number = 1, b?: number) { return a; } }");
27 CheckValid("class C { m(a: number = 2, ...rest: number[]) {} }");
28 CheckValid("class C { m(a: number = 1, b: number) : boolean { return true; } } ");
29 CheckValid("class C { m(a: number = 1, b?: number) : boolean { return true; } }");
30 CheckValid("class C { m(a: number = 1, ...rest: number[]) : void {} }");
31 CheckValid("class C { m([first, ...rest]: number[] = [1]) : void {} }");
32 // Type parametric.
33 CheckValid("class C { m <A>(a: A, b: A) { return a+b; } }");
34 CheckValid("class C { m <A extends number>(a: A, b: A) { return a+b; } }");
35 CheckValid("class C { m <A, B>(a: A, b: B) { return a+b; } }");
36 CheckValid("class C { m <A extends number, B extends number>(a: A, b: B) { ret urn a+b; } }");
37 // Constructors.
38 CheckValid("class C { constructor () {} }");
39 CheckValid("class C { constructor (a : number) {} }");
40 CheckValid("class C { constructor (a? : number) {} }");
41 CheckValid("class C { constructor (a : number, b : string) {} }");
42 CheckValid("class C { constructor (a, b? : string) {} }");
43 CheckValid("class C { constructor (a, b? : string, ...rest: any[]) {} }");
44 // Getters.
45 CheckValid("class C { get x () { return 42; } }");
46 CheckValid("class C { get x () : number { return 42; } }");
47 // Setters.
48 CheckValid("class C { set x (a) {} }");
49 CheckValid("class C { set x (a = 42) {} }");
50 CheckValid("class C { set x (a) : void {} }");
51 CheckValid("class C { set x (a = 42) : void {} }");
52 CheckValid("class C { set x (a : number) {} }");
53 CheckValid("class C { set x (a : number = 42) {} }");
54 CheckValid("class C { set x (a : number) : void {} }");
55 CheckValid("class C { set x (a : number = 42) : void {} }");
56 // Invalid constructors.
57 CheckInvalid("class C { constructor (a : number) : boolean {} }");
58 CheckInvalid("class C { constructor <A>(a : A) {} }");
59 // Invalid getters.
60 CheckInvalid("class C { get x (a) { return 42; } }");
61 CheckInvalid("class C { get x (a?) { return 42; } }");
62 CheckInvalid("class C { get x (a) : number { return 42; } }");
63 CheckInvalid("class C { get x (a?) : number { return 42; } }");
64 CheckInvalid("class C { get x (a, b) { return 42; } }");
65 CheckInvalid("class C { get x (a, b) : number { return 42; } }");
66 CheckInvalid("class C { get x (a : number) { return 42; } }");
67 CheckInvalid("class C { get x (a? : number) { return 42; } }");
68 CheckInvalid("class C { get x (a : number) : number { return 42; } }");
69 CheckInvalid("class C { get x (a? : number) : number { return 42; } }");
70 CheckInvalid("class C { get x (...rest) { return 42; } }");
71 CheckInvalid("class C { get x (...rest : number[]) { return 42; } }");
72 CheckInvalid("class C { get x (...rest) : number { return 42; } }");
73 CheckInvalid("class C { get x (...rest : number[]) : number { return 42; } }") ;
74 CheckInvalid("class C { get x <A>() { return 42; } }");
75 // Invalid setters.
76 CheckInvalid("class C { set x () {} }");
77 CheckInvalid("class C { set x () : void {} }");
78 CheckInvalid("class C { set x (a?) {} }");
79 CheckInvalid("class C { set x (a? : number) : void {} }");
80 CheckInvalid("class C { set x (a? = 42) {} }");
81 CheckInvalid("class C { set x (a? = 42 : number) : void {} }");
82 CheckInvalid("class C { set x (a : number, b : number) {} }");
83 CheckInvalid("class C { set x (a : number, b : number) : void {} }");
84 CheckInvalid("class C { set x (...rest) {} }");
85 CheckInvalid("class C { set x (...rest : string[]) : void {} }");
86 CheckInvalid("class C { set x <A>(a : A) {} }");
87 })();
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/typesystem/function-declarations.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698