| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | describe("correct behavior", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     test("basic functionality", () => { | 
					
						
							|  |  |  |         class A { | 
					
						
							|  |  |  |             static get x() { | 
					
						
							|  |  |  |                 return this._x; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             static set x(value) { | 
					
						
							|  |  |  |                 this._x = value * 2; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(A.x).toBeUndefined(); | 
					
						
							|  |  |  |         expect(A).not.toHaveProperty("_x"); | 
					
						
							|  |  |  |         A.x = 3; | 
					
						
							|  |  |  |         expect(A.x).toBe(6); | 
					
						
							|  |  |  |         expect(A).toHaveProperty("_x", 6); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test("name", () => { | 
					
						
							|  |  |  |         class A { | 
					
						
							|  |  |  |             static set x(v) {} | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const d = Object.getOwnPropertyDescriptor(A, "x"); | 
					
						
							|  |  |  |         expect(d.set.name).toBe("set x"); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test("extended name syntax", () => { | 
					
						
							| 
									
										
										
										
											2020-07-07 21:39:36 -07:00
										 |  |  |         const s = Symbol("foo"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |         class A { | 
					
						
							|  |  |  |             static set "method with space"(value) { | 
					
						
							|  |  |  |                 this.a = value; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             static set 12(value) { | 
					
						
							|  |  |  |                 this.b = value; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             static set [`he${"llo"}`](value) { | 
					
						
							|  |  |  |                 this.c = value; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-07-07 21:39:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |             static set [s](value) { | 
					
						
							|  |  |  |                 this.d = value; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         A["method with space"] = 1; | 
					
						
							|  |  |  |         A[12] = 2; | 
					
						
							|  |  |  |         A.hello = 3; | 
					
						
							| 
									
										
										
										
											2020-07-07 21:39:36 -07:00
										 |  |  |         A[s] = 4; | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |         expect(A.a).toBe(1); | 
					
						
							|  |  |  |         expect(A.b).toBe(2); | 
					
						
							|  |  |  |         expect(A.c).toBe(3); | 
					
						
							| 
									
										
										
										
											2020-07-07 21:39:36 -07:00
										 |  |  |         expect(A.d).toBe(4); | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test("inherited static setter", () => { | 
					
						
							|  |  |  |         class Parent { | 
					
						
							|  |  |  |             static get x() { | 
					
						
							|  |  |  |                 return this._x; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             static set x(value) { | 
					
						
							|  |  |  |                 this._x = value * 2; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         class Child extends Parent {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(Child.x).toBeUndefined(); | 
					
						
							|  |  |  |         Child.x = 10; | 
					
						
							|  |  |  |         expect(Child.x).toBe(20); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test("inherited static setter overriding", () => { | 
					
						
							|  |  |  |         class Parent { | 
					
						
							|  |  |  |             static get x() { | 
					
						
							|  |  |  |                 return this._x; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             static set x(value) { | 
					
						
							|  |  |  |                 this._x = value * 2; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         class Child extends Parent { | 
					
						
							|  |  |  |             static get x() { | 
					
						
							|  |  |  |                 return this._x; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             static set x(value) { | 
					
						
							|  |  |  |                 this._x = value * 3; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(Child.x).toBeUndefined(); | 
					
						
							|  |  |  |         Child.x = 10; | 
					
						
							|  |  |  |         expect(Child.x).toBe(30); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe("errors", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     test('"set static" is a syntax error', () => { | 
					
						
							|  |  |  |         expect(`
 | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     class A { | 
					
						
							|  |  |  |       set static foo(value) {} | 
					
						
							|  |  |  |     }`).not.toEval();
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); |