| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("basic functionality", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const A = class { | 
					
						
							|  |  |  |         constructor(x) { | 
					
						
							| 
									
										
										
										
											2020-12-26 16:24:24 +01:00
										 |  |  |             this.x = x; | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |         getX() { | 
					
						
							| 
									
										
										
										
											2020-12-26 16:24:24 +01:00
										 |  |  |             return this.x * 2; | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(new A(10).getX()).toBe(20); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("inline instantiation", () => { | 
					
						
							| 
									
										
										
										
											2020-12-26 16:24:24 +01:00
										 |  |  |     // prettier-ignore
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const a = new class { | 
					
						
							|  |  |  |         constructor() { | 
					
						
							|  |  |  |             this.x = 10; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |         getX() { | 
					
						
							|  |  |  |             return this.x * 2; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(a.getX()).toBe(20); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("inline instantiation with argument", () => { | 
					
						
							| 
									
										
										
										
											2020-12-26 16:24:24 +01:00
										 |  |  |     // prettier-ignore
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const a = new class { | 
					
						
							|  |  |  |         constructor(x) { | 
					
						
							|  |  |  |             this.x = x; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |         getX() { | 
					
						
							|  |  |  |             return this.x * 2; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }(10); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(a.getX()).toBe(20); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("extending class expressions", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class A extends class { | 
					
						
							|  |  |  |         constructor(x) { | 
					
						
							|  |  |  |             this.x = x; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } { | 
					
						
							|  |  |  |         constructor(y) { | 
					
						
							|  |  |  |             super(y); | 
					
						
							|  |  |  |             this.y = y * 2; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-12-26 16:24:24 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const a = new A(10); | 
					
						
							|  |  |  |     expect(a.x).toBe(10); | 
					
						
							|  |  |  |     expect(a.y).toBe(20); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("class expression name", () => { | 
					
						
							| 
									
										
										
										
											2020-12-26 16:24:24 +01:00
										 |  |  |     let A = class {}; | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(A.name).toBe("A"); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-26 16:24:24 +01:00
										 |  |  |     let B = class C {}; | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(B.name).toBe("C"); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); |