ladybird/Userland/Libraries/LibJS/Tests/syntax
Linus Groh 3709d11212 LibJS: Parse secondary expressions with the original forbidden token set
Instead of passing the continuously merged initial forbidden token set
(with the new additional forbidden tokens from each parsed secondary
expression) to the next call of parse_secondary_expression(), keep a
copy of the original set and use it as the base for parsing the next
secondary expression.

This bug prevented us from properly parsing the following expression:

```js
0 ?? 0 ? 0 : 0 || 0
```

...due to LogicalExpression with LogicalOp::NullishCoalescing returning
both DoubleAmpersand and DoublePipe in its forbidden token set.

The following correct AST is now generated:

Program
  (Children)
    ExpressionStatement
      ConditionalExpression
        (Test)
          LogicalExpression
            NumericLiteral 0
            ??
            NumericLiteral 0
        (Consequent)
          NumericLiteral 0
        (Alternate)
          LogicalExpression
            NumericLiteral 0
            ||
            NumericLiteral 0

An alternate solution I explored was only merging the original forbidden
token set with the one of the last parsed secondary expression which is
then passed to match_secondary_expression(); however that led to an
incorrect AST (note the alternate expression):

Program
  (Children)
    ExpressionStatement
      LogicalExpression
        ConditionalExpression
          (Test)
            LogicalExpression
              NumericLiteral 0
              ??
              NumericLiteral 0
          (Consequent)
            NumericLiteral 0
          (Alternate)
            NumericLiteral 0
        ||
        NumericLiteral 0

Truth be told, I don't know enough about the inner workings of the
parser to fully explain the difference. AFAICT this patch has no
unintended side effects in its current form though.

Fixes #18087.
2023-04-02 06:45:37 +02:00
..
async-await.js LibJS: Disallow async generator functions called 'await' or 'yield' 2021-12-21 14:04:23 +01:00
async-generators.js LibJS: Disallow async generator functions called 'await' or 'yield' 2021-12-21 14:04:23 +01:00
coalesce-logic-expression-mixing.js LibJS: Parse secondary expressions with the original forbidden token set 2023-04-02 06:45:37 +02:00
destructuring-assignment.js LibJS: Allow BigInts as destructuring property names 2022-08-24 23:27:17 +01:00
dynamic-import-usage.js LibJS: Don't VERIFY that the token after 'import' is one of '.' and '(' 2021-12-29 16:57:23 +01:00
for-loop-invalid-in.js LibJS: Fix cases where we incorrectly allowed 'in' in for loops 2022-02-15 10:31:41 +00:00
function-hoisting.js LibJS: No longer hoist if parent scope has a function with the same name 2022-11-17 16:05:20 +00:00
functions-in-tree-order-non-strict.js LibJS: Initialize functions in spec order 2022-11-17 16:05:20 +00:00
functions-in-tree-order-strict.js LibJS: Initialize functions in spec order 2022-11-17 16:05:20 +00:00
generators.js LibJS: Disallow async generator functions called 'await' or 'yield' 2021-12-21 14:04:23 +01:00
if-statement-empty-completion.js LibJS: Add missing undefined fallback to IfStatement completions 2021-12-31 15:39:25 +01:00
numeric-separator.js LibJS: Disallow numerical separators in octal numbers and after '.' 2021-11-30 17:05:32 +00:00
optional-chaining.js LibJS: Implement parsing and execution of optional chains 2021-09-14 20:03:27 +01:00
slash-after-block.js LibJS: Treat private identifier as divisible token 2021-11-30 17:05:32 +00:00
switch-as-statement.js LibJS: Make scoping follow the spec 2021-09-30 08:16:32 +01:00