+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_js_syntax): Node factories for unknown nodes #3033

Merged
merged 1 commit into from
Aug 9, 2022

Conversation

MichaReiser
Copy link
Contributor

This PR adds node factory methods for unknown nodes. This is certainly more of an edge case, but I have a use case in the formatter when encountering an invalid parenthesized expression in which case the node should be replaced
as an unknown node so, for as far as the formatter is concerned, parenthesized expressions do not exist.

The new API can be used like this:

let unknown = rome_js_factory::make::js_unknown_expression(
    root.slots().map(|slot| slot.into_syntax_element()),
);

Alternatives

An alternative would be to directly use the SyntaxNode::new_detached APIs. This works but is less accessible and
it might be convenient to search for all places where we construct unknown nodes.

This PR adds node factory methods for unknown nodes. This is certainly more of an edge case, but I have a use case in the formatter when encountering an invalid parenthesized expression in which case the node should be replaced
as an unknown node so, for as far as the formatter is concerned, parenthesized expressions do not exist.

The new API can be used like this:

```rust
let unknown = rome_js_factory::make::js_unknown_expression(
    root.slots().map(|slot| slot.into_syntax_element()),
);
 ```

## Alternatives

An alternative would be to directly use the `SyntaxNode::new_detached` APIs. This works but is less accessible and
it might be convenient to search for all places where we construct unknown nodes.
@MichaReiser MichaReiser requested review from leops and a team August 9, 2022 06:22
@MichaReiser MichaReiser temporarily deployed to aws August 9, 2022 06:22 Inactive
@github-actions
Copy link

github-actions bot commented Aug 9, 2022

@github-actions
Copy link

github-actions bot commented Aug 9, 2022

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 45878 45878 0
Passed 44938 44938 0
Failed 940 940 0
Panics 0 0 0
Coverage 97.95% 97.95% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 39 39 0
Passed 36 36 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.31% 92.31% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5946 5946 0
Passed 395 395 0
Failed 5551 5551 0
Panics 0 0 0
Coverage 6.64% 6.64% 0.00%

ts/babel

Test result main count This PR count Difference
Total 588 588 0
Passed 519 519 0
Failed 69 69 0
Panics 0 0 0
Coverage 88.27% 88.27% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 16257 16257 0
Passed 12397 12397 0
Failed 3860 3860 0
Panics 0 0 0
Coverage 76.26% 76.26% 0.00%

@cloudflare-workers-and-pages
Copy link

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1d78646
Status: ✅  Deploy successful!
Preview URL: https://33ed544d.tools-8rn.pages.dev
Branch Preview URL: https://feat-unknown-node-factory.tools-8rn.pages.dev

View logs

@ematipico
Copy link
Contributor

ematipico commented Aug 9, 2022

This is certainly more of an edge case, but I have a use case in the formatter when encountering an invalid parenthesized expression in which case the node should be replaced
as an unknown node

Shouldn't we change how the parser emits the CST/AST in this case? To accommodate the use case?

@MichaReiser MichaReiser merged commit f7e2c10 into main Aug 9, 2022
@MichaReiser MichaReiser deleted the feat/unknown-node-factory branch August 9, 2022 15:01
IWANABETHATGUY pushed a commit to IWANABETHATGUY/tools that referenced this pull request Aug 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载