Merge pull request #714 from trheyi/main

Optimize SUI core to copy json-attr- to the prop in newJitComponentSe…
This commit is contained in:
Max 2024-07-27 08:12:11 +08:00 committed by GitHub
commit 7f41be9a70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -88,7 +88,6 @@ func (parser *TemplateParser) newJitComponentSel(sel *goquery.Selection, comp *J
for key, val := range props { for key, val := range props {
var v interface{} = val var v interface{} = val
if props[fmt.Sprintf("json-attr-%s", key)] == "true" { if props[fmt.Sprintf("json-attr-%s", key)] == "true" {
fmt.Println("json-attr-", key)
err := jsoniter.UnmarshalFromString(val, &v) err := jsoniter.UnmarshalFromString(val, &v)
if err != nil { if err != nil {
v = fmt.Sprintf(`"%s"`, val) v = fmt.Sprintf(`"%s"`, val)
@ -104,10 +103,15 @@ func (parser *TemplateParser) newJitComponentSel(sel *goquery.Selection, comp *J
compSel := doc.Find("body").Children().First() compSel := doc.Find("body").Children().First()
data.replaceNodeUse(propTokens, compSel.Nodes[0]) data.replaceNodeUse(propTokens, compSel.Nodes[0])
for key, val := range props { for key, val := range props {
if strings.HasPrefix(key, "s:") || strings.HasPrefix(key, "json-attr-") || key == "parsed" { if strings.HasPrefix(key, "s:") || key == "parsed" {
compSel.SetAttr(key, val) compSel.SetAttr(key, val)
continue continue
} }
// copy the json-attr- to the prop:
if strings.HasPrefix(key, "json-attr-") {
compSel.SetAttr(fmt.Sprintf("json-attr-prop:%s", key[10:]), val)
continue
}
compSel.SetAttr(fmt.Sprintf("prop:%s", key), val) compSel.SetAttr(fmt.Sprintf("prop:%s", key), val)
} }