mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 13:52:43 +00:00 
			
		
		
		
	 602190f66f
			
		
	
	
		602190f66f
		
	
	
	
	
		
			
			The same expression is not allowed to contain both the logical && and || operators, and the coalescing ?? operator. This patch changes how "forbidden" tokens are handled, using a finite set instead of an Vector. This supports much more efficient merging of the forbidden tokens when propagating forward, and allowing the return of forbidden tokens to parent contexts.
		
			
				
	
	
		
			28 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| test("mixing coalescing and logical operators isn't allowed", () => {
 | |
|     expect("if (0) a ?? b || c").not.toEval();
 | |
|     expect("if (0) a ?? b && c").not.toEval();
 | |
|     expect("if (0) a ?? b * c || d").not.toEval();
 | |
|     expect("if (0) a ?? b * c && d").not.toEval();
 | |
|     expect("if (0) a && b ?? c").not.toEval();
 | |
|     expect("if (0) a || b ?? c").not.toEval();
 | |
|     expect("if (0) a && b * c ?? d").not.toEval();
 | |
|     expect("if (0) a || b * c ?? d").not.toEval();
 | |
| });
 | |
| 
 | |
| test("mixing coalescing and logical operators with parens", () => {
 | |
|     expect("if (0) a ?? (b || c)").toEval();
 | |
|     expect("if (0) (a ?? b) && c").toEval();
 | |
|     expect("if (0) a ?? (b * c || d)").toEval();
 | |
|     expect("if (0) (a ?? b * c) && d").toEval();
 | |
|     expect("if (0) a && (b ?? c)").toEval();
 | |
|     expect("if (0) (a || b) ?? c").toEval();
 | |
|     expect("if (0) a && (b * c) ?? d").not.toEval();
 | |
|     expect("if (0) a || (b * c) ?? d").not.toEval();
 | |
| });
 | |
| 
 | |
| test("mixing coalescing and logical operators when 'in' isn't allowed", () => {
 | |
|     expect("for (a ?? b || c in a; false;);").not.toEval();
 | |
|     expect("for (a ?? b && c in a; false;);").not.toEval();
 | |
|     expect("for (a || b ?? c in a; false;);").not.toEval();
 | |
|     expect("for (a && b ?? c in a; false;);").not.toEval();
 | |
| });
 |