| 
									
										
										
										
											2020-12-26 16:24:24 +01:00
										 |  |  | // prettier-ignore
 | 
					
						
							| 
									
										
										
										
											2020-07-03 14:39:25 -07:00
										 |  |  | test("new-expression parsing", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     function Foo() { | 
					
						
							|  |  |  |         this.x = 1; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     let foo = new Foo(); | 
					
						
							|  |  |  |     expect(foo.x).toBe(1); | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     foo = new Foo | 
					
						
							|  |  |  |     expect(foo.x).toBe(1); | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     foo = new | 
					
						
							|  |  |  |     Foo | 
					
						
							|  |  |  |     (); | 
					
						
							|  |  |  |     expect(foo.x).toBe(1); | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     foo = new Foo + 2 | 
					
						
							|  |  |  |     expect(foo).toBe("[object Object]2"); | 
					
						
							| 
									
										
										
										
											2020-07-03 14:39:25 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-05-28 15:10:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-26 16:24:24 +01:00
										 |  |  | // prettier-ignore
 | 
					
						
							| 
									
										
										
										
											2020-07-03 14:39:25 -07:00
										 |  |  | test("new-expressions with object keys", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     let a = { | 
					
						
							|  |  |  |         b: function () { | 
					
						
							|  |  |  |             this.x = 2; | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     foo = new a.b(); | 
					
						
							|  |  |  |     expect(foo.x).toBe(2); | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     foo = new a.b; | 
					
						
							|  |  |  |     expect(foo.x).toBe(2); | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     foo = new | 
					
						
							|  |  |  |     a.b(); | 
					
						
							|  |  |  |     expect(foo.x).toBe(2); | 
					
						
							| 
									
										
										
										
											2020-07-03 14:39:25 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-05-28 15:10:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 14:39:25 -07:00
										 |  |  | test("new-expressions with function calls", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     function funcGetter() { | 
					
						
							|  |  |  |         return function (a, b) { | 
					
						
							|  |  |  |             this.x = a + b; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     foo = new funcGetter()(1, 5); | 
					
						
							|  |  |  |     expect(foo).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     foo = new (funcGetter())(1, 5); | 
					
						
							|  |  |  |     expect(foo.x).toBe(6); | 
					
						
							| 
									
										
										
										
											2020-07-03 14:39:25 -07:00
										 |  |  | }); |