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

feat(rome_js_parser): check for missing children in parser tests #2176

Merged
merged 1 commit into from
May 10, 2022

Conversation

leops
Copy link
Contributor

@leops leops commented Feb 24, 2022

Summary

This adds an additional check in the tests of rome_js_parser to verify the parsed result doesn't contain syntax errors by printing out the debug representation of the AST and checking if the resulting text contains the missing (required) string

@github-actions
Copy link

github-actions bot commented Feb 24, 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%

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 12391 12391 0
Failed 3866 3866 0
Panics 0 0 0
Coverage 76.22% 76.22% 0.00%

let missing_children = if is_list {
quote! {
.chain(
self.#method_name().missing_children()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having a hard time getting my head around. Does this correctly handle separated lists?

Copy link
Contributor

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having somewhat conflicting feelings about this change.

It does achieve the goal but it results in a lot of additional code and start wondering if it instead would be useful to expose the metadata for each node in a different form. How many fields does a JS_MODULE have, which fields are mandatory or optional? Is it a separated list?

Something like this could also be useful when thinking about serializing/presenting nodes #2120

An alternative approach to this which I once planned to do but never came along is to add a contains_syntax_errors flags to SyntaxNode's and that flag gets set to true inside of the JsSyntaxFactory if any child node has that flag or if any required child is missing.

This wouldn't just be useful here but also in other places where we want to assert that a tree is valid. Ideally, adding a diagnostic would also toggle that flag but that will require some changes to the way we emit diagnostics today.

Comment on lines 182 to 187
let buffer = buffer.into_inner();
let mut buffer = String::from_utf8(buffer).unwrap();
for syntax_error in syntax_errors {
writeln!(buffer, "{}", syntax_error).expect("writing to a String cannot fail");
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be neat for debuggability if this would emit Diagnostic's too instead of writing to a string. But I can see why this is difficult.

A cheap way of implementing the same is to print the AST as a string and then assert that it doesn't contain missing (required).

@leops leops marked this pull request as draft February 25, 2022 15:25
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 28, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 814f083
Status: ✅  Deploy successful!
Preview URL: https://45a523de.tools-8rn.pages.dev

View logs

@MichaReiser
Copy link
Contributor

@leops is it OK if we close this PR for now?

@leops
Copy link
Contributor Author

leops commented May 9, 2022

Oh I completely forgot about this one. In the most recent version of this PR it just checked whether there was any "missing (required)" in the debug representation of the tree, so I think it worked as expected without adding too much new code but if I remember correctly I didn't move it out of draft at the time because TS support was incomplete at the time and the test was failing then. Now that's it's stable (and in preparation for the future other languages we want to add) maybe I could rebase it on the latest main ?

@MichaReiser
Copy link
Contributor

Oh, didn't notice you updated it. Yeah, that looks useful. Let's rebase it and see if all tests pass.

@leops leops force-pushed the feature/report-missing-children branch from c53b078 to 814f083 Compare May 10, 2022 07:42
@leops leops temporarily deployed to aws May 10, 2022 07:42 Inactive
@github-actions
Copy link

@leops leops marked this pull request as ready for review May 10, 2022 07:56
Copy link
Contributor

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, all tests are passing :) This will be helpful when working on the JSON parser

@leops leops changed the title feat(rslint_parser): check for missing children in parser tests feat(rome_js_parser): check for missing children in parser tests May 10, 2022
@leops leops merged commit e3ce4ce into main May 10, 2022
@leops leops deleted the feature/report-missing-children branch May 10, 2022 08:40
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.

2 participants