1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:47:44 +00:00

LibJS: Correctly handle parentheses and new Object

Parses `new Object()?.foo`, `(new Object)?.foo`
and shows syntax error on `new Object?.foo`
This commit is contained in:
Malik Ammar Faisal 2023-06-15 15:13:48 +05:30 committed by Andreas Kling
parent acaf2368ad
commit 5c913d9cc4
3 changed files with 51 additions and 23 deletions

View file

@ -3348,7 +3348,7 @@ ThrowCompletionOr<OptionalChain::ReferenceAndValue> OptionalChain::to_reference_
[&](Call const& call) -> NonnullRefPtr<Expression const> {
return CallExpression::create(source_range(),
create_ast_node<SyntheticReferenceExpression>(source_range(), base_reference, base),
call.arguments);
call.arguments, InvocationStyleEnum::Parenthesized, InsideParenthesesEnum::NotInsideParentheses);
},
[&](ComputedReference const& ref) -> NonnullRefPtr<Expression const> {
return create_ast_node<MemberExpression>(source_range(),
@ -4965,14 +4965,14 @@ DeprecatedString SourceRange::filename() const
return code->filename().to_deprecated_string();
}
NonnullRefPtr<CallExpression> CallExpression::create(SourceRange source_range, NonnullRefPtr<Expression const> callee, ReadonlySpan<Argument> arguments)
NonnullRefPtr<CallExpression> CallExpression::create(SourceRange source_range, NonnullRefPtr<Expression const> callee, ReadonlySpan<Argument> arguments, InvocationStyleEnum invocation_style, InsideParenthesesEnum inside_parens)
{
return ASTNodeWithTailArray::create<CallExpression>(arguments.size(), move(source_range), move(callee), arguments);
return ASTNodeWithTailArray::create<CallExpression>(arguments.size(), move(source_range), move(callee), arguments, invocation_style, inside_parens);
}
NonnullRefPtr<NewExpression> NewExpression::create(SourceRange source_range, NonnullRefPtr<Expression const> callee, ReadonlySpan<Argument> arguments)
NonnullRefPtr<NewExpression> NewExpression::create(SourceRange source_range, NonnullRefPtr<Expression const> callee, ReadonlySpan<Argument> arguments, InvocationStyleEnum invocation_style, InsideParenthesesEnum inside_parens)
{
return ASTNodeWithTailArray::create<NewExpression>(arguments.size(), move(source_range), move(callee), arguments);
return ASTNodeWithTailArray::create<NewExpression>(arguments.size(), move(source_range), move(callee), arguments, invocation_style, inside_parens);
}
}