mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 10:08:10 +00:00
LibJS: Fix mixing of logical and coalescing operators
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.
This commit is contained in:
parent
9c78c1bf81
commit
602190f66f
3 changed files with 160 additions and 19 deletions
|
@ -0,0 +1,28 @@
|
|||
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();
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue