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

fix(js_parser): handle unterminated JSX_STRING_LITERAL properly #4425

Merged
merged 5 commits into from
Oct 29, 2024

Conversation

denbezrukov
Copy link
Contributor

Summary

Fix another crash from #342 (comment)

export default function Home() {
    return (
                <a
                    rel="   <---- here we have unterminated string but now we think it's a valid JSX_STRING_LITERAL token

It happens because the static_value.rs text method has a safety invariant for JSX_STRING_LITERAL:

StaticValue::String(token) => {
let text = token.text_trimmed();
if matches!(
token.kind(),
JsSyntaxKind::JS_STRING_LITERAL | JsSyntaxKind::JSX_STRING_LITERAL
) {
// SAFETY: string literal token have a delimiters at the start and the end of the string
return &text[1..text.len() - 1];
}
text
}
StaticValue::EmptyString(_) => "",

We have the same logic for JS_STRING_LITERAL :

QOT => {
if self.consume_str_literal(false) {
JS_STRING_LITERAL
} else {
ERROR_TOKEN
}
}

Test Plan

cargo test -p biome_js_parser

@github-actions github-actions bot added A-Parser Area: parser L-JavaScript Language: JavaScript and super languages A-Changelog Area: changelog labels Oct 29, 2024
Copy link
Contributor

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 48421 48421 0
Passed 47221 47221 0
Failed 1200 1200 0
Panics 0 0 0
Coverage 97.52% 97.52% 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 6580 6580 0
Passed 2205 2205 0
Failed 4375 4375 0
Panics 0 0 0
Coverage 33.51% 33.51% 0.00%

ts/babel

Test result main count This PR count Difference
Total 680 680 0
Passed 607 607 0
Failed 73 73 0
Panics 0 0 0
Coverage 89.26% 89.26% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 18508 18508 0
Passed 14168 14168 0
Failed 4340 4340 0
Panics 0 0 0
Coverage 76.55% 76.55% 0.00%

Copy link

codspeed-hq bot commented Oct 29, 2024

CodSpeed Performance Report

Merging #4425 will create unknown performance changes

Comparing fix/jsx-unterminate-string (1dac180) with main (6a8ff77)

Summary

🆕 99 new benchmarks

Benchmarks breakdown

Benchmark main fix/jsx-unterminate-string Change
🆕 css_analyzer[bootstrap_18416142857265205439.css] N/A 219.3 ms N/A
🆕 css_analyzer[bulma_5641719244145477318.css] N/A 621.7 ms N/A
🆕 css_analyzer[foundation_11602414662825430680.css] N/A 149.4 ms N/A
🆕 css_analyzer[tachyons_11778168428173736564.css] N/A 122 ms N/A
🆕 css_formatter[bootstrap_18416142857265205439.css] N/A 122 ms N/A
🆕 css_formatter[bulma_5641719244145477318.css] N/A 388.3 ms N/A
🆕 css_formatter[foundation_11602414662825430680.css] N/A 80.3 ms N/A
🆕 css_formatter[full_5814491140539129161.css] N/A 1.3 s N/A
🆕 css_formatter[materialize_5526761731747548557.css] N/A 88.2 ms N/A
🆕 css_formatter[pure_9395922602181450299.css] N/A 9.8 ms N/A
🆕 css_formatter[semantic_4685287698740288120.css] N/A 384.8 ms N/A
🆕 css_formatter[tachyons_11778168428173736564.css] N/A 39.4 ms N/A
🆕 bootstrap_18416142857265205439.css[cached] N/A 39.9 ms N/A
🆕 bootstrap_18416142857265205439.css[uncached] N/A 43.7 ms N/A
🆕 bulma_5641719244145477318.css[cached] N/A 122 ms N/A
🆕 bulma_5641719244145477318.css[uncached] N/A 130.2 ms N/A
🆕 foundation_11602414662825430680.css[cached] N/A 26 ms N/A
🆕 foundation_11602414662825430680.css[uncached] N/A 28.6 ms N/A
🆕 full_5814491140539129161.css[cached] N/A 447.5 ms N/A
🆕 full_5814491140539129161.css[uncached] N/A 471.8 ms N/A
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

@denbezrukov denbezrukov merged commit fe792ed into main Oct 29, 2024
13 checks passed
@denbezrukov denbezrukov deleted the fix/jsx-unterminate-string branch October 29, 2024 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-Parser Area: parser L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants