Unverified Commit 2c82615b authored by 강동윤's avatar 강동윤 Committed by GitHub

Fix transform of ` in styled-jsx (#29136)

parent c7e187f8
...@@ -1756,9 +1756,9 @@ dependencies = [ ...@@ -1756,9 +1756,9 @@ dependencies = [
[[package]] [[package]]
name = "swc_ecma_codegen" name = "swc_ecma_codegen"
version = "0.70.2" version = "0.70.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7940bff62e5caf62fe6732ce4f07e52c3c208cb58cd9299f7f7c92dddab2bf72" checksum = "bb2aca48c8369b19864bbf5ffb6a1e5e8784e451606c48c39f241a7da0751815"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"num-bigint", "num-bigint",
......
...@@ -583,7 +583,8 @@ fn get_style_expr(el: &JSXElement) -> &Expr { ...@@ -583,7 +583,8 @@ fn get_style_expr(el: &JSXElement) -> &Expr {
.struct_span_err( .struct_span_err(
el.span, el.span,
&format!( &format!(
"Expected one child under JSX style tag, but got {} (eg: <style jsx>{{`hi`}}</style>)", "Expected one child under JSX style tag, but got {} (eg: <style \
jsx>{{`hi`}}</style>)",
non_whitespace_children.len() non_whitespace_children.len()
), ),
) )
...@@ -604,8 +605,8 @@ fn get_style_expr(el: &JSXElement) -> &Expr { ...@@ -604,8 +605,8 @@ fn get_style_expr(el: &JSXElement) -> &Expr {
handler handler
.struct_span_err( .struct_span_err(
el.span, el.span,
"Expected a single child of type JSXExpressionContainer under JSX Style tag (eg: <style \ "Expected a single child of type JSXExpressionContainer under JSX Style tag (eg: \
jsx>{{`hi`}}</style>)", <style jsx>{{`hi`}}</style>)",
) )
.emit() .emit()
}); });
......
...@@ -79,7 +79,7 @@ pub fn transform_css( ...@@ -79,7 +79,7 @@ pub fn transform_css(
.map(|quasi| TplElement { .map(|quasi| TplElement {
cooked: None, // ? Do we need cooked as well cooked: None, // ? Do we need cooked as well
raw: Str { raw: Str {
value: (*quasi).into(), value: quasi.replace('`', "\\`").into(),
span: DUMMY_SP, span: DUMMY_SP,
has_escape: false, has_escape: false,
kind: StrKind::Synthesized {}, kind: StrKind::Synthesized {},
...@@ -154,12 +154,10 @@ impl Namespacer { ...@@ -154,12 +154,10 @@ impl Namespacer {
}); });
return match complex_selectors { return match complex_selectors {
Ok(complex_selectors) => Ok( Ok(complex_selectors) => Ok(complex_selectors[0].selectors[1..]
complex_selectors[0].selectors[1..]
.iter() .iter()
.cloned() .cloned()
.collect(), .collect()),
),
Err(_) => bail!("Failed to transform one off global selector"), Err(_) => bail!("Failed to transform one off global selector"),
}; };
} else if pseudo_index.is_none() { } else if pseudo_index.is_none() {
......
export default class {
render() {
return (
<div>
<p>test</p>
<style jsx>{`
p {
content: '\`'
}
`}</style>
</div>
)
}
}
import _JSXStyle from "styled-jsx/style";
export default class {
render() {
return <div className={"jsx-1f6cef12199c3a8f"}>
<p className={"jsx-1f6cef12199c3a8f"}>test</p>
<_JSXStyle id={"1f6cef12199c3a8f"}>{"p.jsx-1f6cef12199c3a8f {content:'`'}"}</_JSXStyle>
</div>;
}
}
\ No newline at end of file
export default function Home({ fontFamily }) {
return (
<div>
<style jsx global>
{`
body {
font-family: ${fontFamily};
}
code:before,
code:after {
content: '\`';
}
`}
</style>
</div>
)
}
\ No newline at end of file
import _JSXStyle from "styled-jsx/style";
export default function Home({ fontFamily }) {
return <div className={_JSXStyle.dynamic([
"2566fdd7bc25c35",
[
fontFamily
]
])}>
<_JSXStyle id={"2566fdd7bc25c35"} dynamic={[
fontFamily
]}>{`body {font-family:${fontFamily}}
code:before, code:after {content:'\`'}`}</_JSXStyle>
</div>;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment