refactor: Update parsing logic for JIT components

This commit is contained in:
Max 2024-07-08 02:21:36 +08:00
parent 78d8d9fbc2
commit d188f967d0
2 changed files with 5 additions and 4 deletions

View file

@ -39,6 +39,7 @@ func init() {
// parseComponent parse the component
func (parser *TemplateParser) parseComponent(sel *goquery.Selection) {
parser.parsed(sel)
comp, props, slots, err := parser.getComponent(sel)
if err != nil {
parser.errors = append(parser.errors, err)

View file

@ -316,8 +316,8 @@ func (parser *TemplateParser) transElementNode(sel *goquery.Selection) {
}
}
// Remove the slot tag and replace it with the children
func (parser *TemplateParser) removeSlotWrapper(sel *goquery.Selection) {
// Remove the tag and replace it with the children
func (parser *TemplateParser) removeWrapper(sel *goquery.Selection) {
children := sel.Children()
if children.Length() == 0 {
sel.Remove()
@ -648,9 +648,9 @@ func (parser *TemplateParser) tidy(s *goquery.Selection) {
s.Contents().Each(func(i int, child *goquery.Selection) {
node := child.Get(0)
if node.Data == "slot" {
if _, exist := child.Attr("s:jit"); node.Data == "slot" || exist {
parser.tidy(child)
parser.removeSlotWrapper(child)
parser.removeWrapper(child)
return
}