Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tangy-dancers-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/react": patch
---

Fix error like `Unterminated string constant` when using multi-line JSX StringLiteral.
43 changes: 31 additions & 12 deletions packages/react/transform/src/swc_plugin_snapshot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,20 @@ where
.for_each(|attr_or_spread| match attr_or_spread {
JSXAttrOrSpread::SpreadElement(_) => todo!(),
JSXAttrOrSpread::JSXAttr(JSXAttr { name, value, .. }) => {
if let Some(JSXAttrValue::Lit(lit)) = value {
match lit {
Lit::Str(s) => {
let transformed_value = transform_jsx_attr_str(&s.value);
*value = Some(JSXAttrValue::Lit(Lit::Str(Str {
span: s.span,
raw: None,
value: transformed_value.into(),
})));
}
_ => {}
}
}

match name {
JSXAttrName::Ident(ident_name) => {
let attr_name = AttrName::from(<IdentName as Into<Ident>>::into(ident_name.clone()));
Expand Down Expand Up @@ -786,18 +800,6 @@ where
match value {
None => {}
Some(JSXAttrValue::Lit(value)) => {
let value = match &value {
Lit::Str(s) => {
let value = transform_jsx_attr_str(&s.value);

Lit::Str(Str {
span: s.span,
raw: None,
value: value.into(),
})
}
_ => value.clone(),
};
let stmt = quote!(
r#"__SetClasses($element, $value)"# as Stmt,
element: Expr = el.clone(),
Expand Down Expand Up @@ -2911,6 +2913,23 @@ mod tests {
<view className="123 456"></view>
<view className="123 456"></view>
<view className="123\t456"></view>
<svg
content='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
<path d="M14.3723 11.9999L7.53902 5.16659C7.34376 4.97133 7.34376 4.65475 7.53902 4.45948L8.45826 3.54025C8.65353 3.34498 8.97011 3.34498 9.16537 3.54025L17.2714 11.6463C17.4667 11.8416 17.4667 12.1582 17.2714 12.3534L9.16537 20.4595C8.97011 20.6547 8.65353 20.6547 8.45826 20.4595L7.53902 19.5402C7.34376 19.345 7.34376 19.0284 7.53903 18.8331L14.3723 11.9999Z" fill="white"/>
</svg>'
style={{
width: "24rpx",
height: "24rpx",
opacity: "0.4",
}}
id="x
y"
data-attr="x
y"
__lynx_timing_flag="
aaaaa
"
></svg>
</view>
"#
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const __snapshot_da39a_test_1 = ReactLynx.createSnapshot("__snapshot_da39a_test_
const el7 = __CreateView(pageId);
__SetClasses(el7, "123\\t456");
__AppendElement(el, el7);
const el8 = __CreateElement("svg", pageId);
__SetAttribute(el8, "content", '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"> <path d="M14.3723 11.9999L7.53902 5.16659C7.34376 4.97133 7.34376 4.65475 7.53902 4.45948L8.45826 3.54025C8.65353 3.34498 8.97011 3.34498 9.16537 3.54025L17.2714 11.6463C17.4667 11.8416 17.4667 12.1582 17.2714 12.3534L9.16537 20.4595C8.97011 20.6547 8.65353 20.6547 8.45826 20.4595L7.53902 19.5402C7.34376 19.345 7.34376 19.0284 7.53903 18.8331L14.3723 11.9999Z" fill="white"/> </svg>');
__SetInlineStyles(el8, "width:24rpx;height:24rpx;opacity:0.4");
__SetID(el8, "x y");
__AddDataset(el8, "attr", "x y");
__AppendElement(el, el8);
return [
el,
el1,
Expand All @@ -31,7 +37,18 @@ const __snapshot_da39a_test_1 = ReactLynx.createSnapshot("__snapshot_da39a_test_
el4,
el5,
el6,
el7
el7,
el8
];
}, null, null, undefined, globDynamicComponentEntry);
<__snapshot_da39a_test_1/>;
}, [
function(ctx) {
if (ctx.__elements) {
__SetAttribute(ctx.__elements[8], '__lynx_timing_flag', ctx.__values[0].__ltf);
}
}
], null, undefined, globDynamicComponentEntry);
<__snapshot_da39a_test_1 values={[
{
__ltf: " aaaaa "
}
]}/>;