fix(rome_js_parser): Adding syntax error for new A?.b()
MODIFY
crates/rome_js_analyze/tests/specs/nursery/useOptionalChain/nullishAndLogicalOr.ts
crates/rome_js_analyze/tests/specs/nursery/useOptionalChain/nullishAndLogicalOr.ts
@@ -147,6 +147,6 @@ if ((this ?? {}).#bar) { foo.bar; }
(undefined && this ?? {}).#bar;
(((typeof this) as string) || {}).#bar;
-(new foo || {}).bar;
+// (new foo || {}).bar; // tracked here https://github.com/rome/tools/issues/3257
(foo() || {}).bar;
((foo || {}).bar() || {}).baz;

MODIFY
crates/rome_js_parser/src/syntax/expr.rs
crates/rome_js_parser/src/syntax/expr.rs
@@ -768,6 +768,23 @@ fn parse_new_expr(p: &mut Parser, context: ExpressionContext) -> ParsedSyntax {
.or_add_diagnostic(p, expected_expression)
.map(|expr| parse_member_expression_rest(p, expr, context, false, &mut false))
{
+ // test_err ts invalid_optional_chain_from_new_expressions
+ // new Test<string>?.test();
+ // new Test?.test();
+ // new A.b?.c()
+ // new (A.b)?.c()
+ // new (A.b?.()).c()
+ // new A.b?.()()
+ if p.at(T![?.]) {
+ let error = p
+ .err_builder("Invalid optional chain from new expression.")
+ .primary(
+ p.cur_range(),
+ &format!("Did you mean to call '{}()'?", lhs.text(p)),
+ );
+
+ p.error(error);
+ }
if let TS_INSTANTIATION_EXPRESSION = lhs.kind() {
lhs.undo_completion(p).abandon(p)
};

ADD
crates/rome_js_parser/test_data/inline/err/invalid_optional_chain_from_new_expressions.ts
+new Test<string>?.test();
+new Test?.test();
+new A.b?.c()
+new (A.b)?.c()
+new (A.b?.()).c()
+new A.b?.()()

fix(rome_js_parser): Adding syntax error for new A?.b() (#3118)