fix(codegen): choose the right quote for jsx attribute string (#4236)

This commit is contained in:
Boshen 2024-07-12 17:30:24 +00:00
parent be82c286d6
commit c65198fa15
2 changed files with 4 additions and 4 deletions

View file

@ -2238,9 +2238,10 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for JSXAttributeValue<'a> {
Self::Fragment(fragment) => fragment.gen(p, ctx), Self::Fragment(fragment) => fragment.gen(p, ctx),
Self::Element(el) => el.gen(p, ctx), Self::Element(el) => el.gen(p, ctx),
Self::StringLiteral(lit) => { Self::StringLiteral(lit) => {
p.print_char(b'"'); let quote = if lit.value.contains('"') { b'\'' } else { b'"' };
p.print_char(quote);
p.print_str(&lit.value); p.print_str(&lit.value);
p.print_char(b'"'); p.print_char(quote);
} }
Self::ExpressionContainer(expr_container) => expr_container.gen(p, ctx), Self::ExpressionContainer(expr_container) => expr_container.gen(p, ctx),
} }

View file

@ -2,5 +2,4 @@ commit: d8086f14
codegen_typescript Summary: codegen_typescript Summary:
AST Parsed : 5283/5283 (100.00%) AST Parsed : 5283/5283 (100.00%)
Positive Passed: 5282/5283 (99.98%) Positive Passed: 5283/5283 (100.00%)
Normal failed: "conformance/jsx/tsxReactEmitEntities.tsx"