Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parser/html): correctly parse void elements #3854

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

dyc3
Copy link
Contributor

@dyc3 dyc3 commented Sep 11, 2024

Summary

Void elements are elements whose content model is "nothing", meaning that they should not have an end tag, and therefore, have no children.
In browsers, this requirement is imposed very forgivingly. Given that Biome doesn't aim to write browser-grade parsers, we can afford to be a little more strict.

The parser now checks the tag name to know if it should be self closing. If it encounters a closing tag for a void element, it will emit a diagnostic.

Test Plan

Added snapshot tests.

See the HTML spec: https://html.spec.whatwg.org/#void-elements

@github-actions github-actions bot added A-Tooling Area: internal tools L-HTML Language: HTML labels Sep 11, 2024
@dyc3 dyc3 force-pushed the 09-11-feat_parser_html_correctly_parse_void_elements branch from 39f7456 to d18dfff Compare September 11, 2024 22:38
Copy link
Contributor

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 48516 48516 0
Passed 47325 47325 0
Failed 1191 1191 0
Panics 0 0 0
Coverage 97.55% 97.55% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 40 40 0
Passed 37 37 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.50% 92.50% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 6569 6569 0
Passed 2202 2202 0
Failed 4367 4367 0
Panics 0 0 0
Coverage 33.52% 33.52% 0.00%

ts/babel

Test result main count This PR count Difference
Total 671 671 0
Passed 599 599 0
Failed 72 72 0
Panics 0 0 0
Coverage 89.27% 89.27% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 18424 18424 0
Passed 14106 14106 0
Failed 4318 4318 0
Panics 0 0 0
Coverage 76.56% 76.56% 0.00%

Copy link

codspeed-hq bot commented Sep 11, 2024

CodSpeed Performance Report

Merging #3854 will not alter performance

Comparing 09-11-feat_parser_html_correctly_parse_void_elements (a11d6c3) with main (39a820e)

Summary

✅ 107 untouched benchmarks

@dyc3 dyc3 force-pushed the 09-11-feat_parser_html_correctly_parse_void_elements branch from d18dfff to a11d6c3 Compare September 11, 2024 23:35
@dyc3 dyc3 marked this pull request as ready for review September 12, 2024 11:03
@dyc3 dyc3 requested review from a team September 12, 2024 11:03
@dyc3 dyc3 added the A-Parser Area: parser label Sep 13, 2024
@dyc3 dyc3 merged commit 4c8c264 into main Sep 13, 2024
16 checks passed
@dyc3 dyc3 deleted the 09-11-feat_parser_html_correctly_parse_void_elements branch September 13, 2024 09:03
@ematipico
Copy link
Member

Given that Biome doesn't aim to write browser-grade parsers, we can afford to be a little more strict.

I would like to bring this topic to the table and discuss it, eventually. I would be open to make the parser a bit more forgiving, and still emitting warnings/errors, using our error resilience parser.

FYI, Astro's parser is way closer to a browser parser, because they can enable streaming during rendering.

I believe that also Svelte recently changed their approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Parser Area: parser A-Tooling Area: internal tools L-HTML Language: HTML
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants