-
Notifications
You must be signed in to change notification settings - Fork 660
fix(rome_js_parser): Adding syntax error for new A?.b() #3118
fix(rome_js_parser): Adding syntax error for new A?.b() #3118
Conversation
if p.at(T!['(']) { | ||
parse_call_arguments(p).unwrap(); | ||
} else if p.at(T![?.]) && is_identifier_expression { | ||
let error = p | ||
.err_builder("Invalid optional chain from new expression.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add detailed error descriptions like Typescript
?That would introduce extra overhead, I think Invalid optional chain from new expression.
would be enough.
This seems to be a new error introduced with TypeScript 4.8. Please add a few more complicated tests where the optional chain isn't the first member
I'm not sure that it will be feasible to catch all those inside of the parser or if it would be better to implement them as a rule. |
crates/rome_js_parser/test_data/inline/err/invalid_optional_chain_from_new_expressions.rast
Outdated
Show resolved
Hide resolved
The testing has been updated. |
!bench_parser |
Parser Benchmark Results
|
@@ -1246,7 +1246,7 @@ pub(crate) fn parse_ts_type_arguments_in_expression(p: &mut Parser) -> ParsedSyn | |||
p.re_lex(ReLexContext::TypeArgumentLessThan); | |||
let arguments = parse_ts_type_arguments_impl(p, false); | |||
|
|||
if p.last() == Some(T![>]) && matches!(p.cur(), T!['('] | BACKTICK) { | |||
if p.last() == Some(T![>]) && matches!(p.cur(), T!['('] | BACKTICK | T![?.]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://www.typescriptlang.org/play?ts=4.8.0-beta#code/FAEwpgxgNghgTmABAMwK4DsIBcCWB7dRLMAZywB4AVAPgAoBKALkRnQE8BuD4YYs8snBzoA5tQD8AOj5YOQA, parse_ts_type_arguments_in_expression
follow a ?.
token is valid in typescript
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind adding a new test case showing when this is valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is related to instantiation expressions that our parser currently doesn't support. I recommend tackling this in a separate PR as it is more involved:
Adding |
This PR is stale because it has been open 14 days with no activity. |
b6ee4c0
to
5d3a82c
Compare
✅ Deploy Preview for docs-rometools ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
@MichaReiser, Since the main logic of |
You could refer to this patch pr of https://github.com/microsoft/TypeScript/pull/48656/files, pretty much just porting. |
The rest of two patch pr of instantiationExpression only modified https://github.com/microsoft/TypeScript/pull/48659/files#diff-12a6724be007eb1a19d80018c7a63bbc73525ca793a9b3e5da49a4e86bbf457cL5732-L5765 |
Why I want to push forward because this pr has been marked as stale, maybe closed a few days later. |
@@ -147,6 +147,6 @@ if ((this ?? {}).#bar) { foo.bar; } | |||
|
|||
(undefined && this ?? {}).#bar; | |||
(((typeof this) as string) || {}).#bar; | |||
(new foo || {}).bar; | |||
// (new foo || {}).bar; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why I disabled this test case , please refer to #3257
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I don't do this, the CI will crash. https://github.com/rome/tools/actions/runs/3090461304/jobs/4999289555
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could add // disabled because of https://github.com/rome/tools/issues/3257
to the comment, so we know the reason :)
!bench_parser |
Parser Benchmark Results
|
crates/rome_js_analyze/tests/specs/nursery/useOptionalChain/nullishAndLogicalOr.ts.snap
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/tests/specs/nursery/useOptionalChain/nullishAndLogicalOr.ts
Outdated
Show resolved
Hide resolved
@@ -768,6 +768,16 @@ 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)) | |||
{ | |||
if p.at(T![?.]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the error checking here because I don't want to clone the lhs.text(p)
. If put this branch here, https://github.com/rome/tools/pull/3118/files#diff-1ca6d1ff770e933910c550807255d1bf03cdebbf60bf469579b528c0c28c1537R797, you can't return a &str
of lhs.text(p)
because lhs is moved via lhs.undo_completion(p)
Summary
new A?.b()
Test Plan