@@ -10,7 +10,7 @@ import traverse from "@babel/traverse";
10
10
import * as t from "@babel/types"
11
11
12
12
import { geneOrder } from '../util/util'
13
- import { isChildComp } from '../util/uast'
13
+ import { isChildComp , isTextElement } from '../util/uast'
14
14
15
15
import { ChildTemplateDataKeyPrefix , ChildTemplateNamePrefix } from '../constants'
16
16
@@ -96,6 +96,7 @@ export default function childrenToTemplate(ast, info) {
96
96
traverse ( ast , {
97
97
98
98
exit : path => {
99
+
99
100
if ( path . type === 'JSXElement'
100
101
&& ! isChildComp ( path . node . openingElement . name . name )
101
102
) {
@@ -111,16 +112,23 @@ export default function childrenToTemplate(ast, info) {
111
112
112
113
const datakey = `${ ChildTemplateDataKeyPrefix } ${ goForCTDK . next } `
113
114
115
+
116
+ const templateAttris = [
117
+ t . jsxAttribute ( t . jsxIdentifier ( 'datakey' ) , t . stringLiteral ( datakey ) ) ,
118
+ t . jsxAttribute ( t . jsxIdentifier ( 'tempVnode' ) , ele ) ,
119
+ t . jsxAttribute ( t . jsxIdentifier ( 'wx:if' ) , t . stringLiteral ( `{{${ datakey } }} !== undefined` ) ) ,
120
+ t . jsxAttribute ( t . jsxIdentifier ( 'is' ) , t . stringLiteral ( tempName ) ) ,
121
+ t . jsxAttribute ( t . jsxIdentifier ( 'data' ) , t . stringLiteral ( `{{d: ${ datakey } }}` ) )
122
+ ]
123
+
124
+ if ( isTextElement ( path . node . openingElement ) ) {
125
+ templateAttris . push ( t . jsxAttribute ( t . jsxIdentifier ( 'isTextElement' ) ) )
126
+ }
127
+
114
128
return t . jsxElement (
115
129
t . jsxOpeningElement (
116
130
t . jsxIdentifier ( 'template' ) ,
117
- [
118
- t . jsxAttribute ( t . jsxIdentifier ( 'datakey' ) , t . stringLiteral ( datakey ) ) ,
119
- t . jsxAttribute ( t . jsxIdentifier ( 'tempVnode' ) , ele ) ,
120
- t . jsxAttribute ( t . jsxIdentifier ( 'wx:if' ) , t . stringLiteral ( `{{${ datakey } }} !== undefined` ) ) ,
121
- t . jsxAttribute ( t . jsxIdentifier ( 'is' ) , t . stringLiteral ( tempName ) ) ,
122
- t . jsxAttribute ( t . jsxIdentifier ( 'data' ) , t . stringLiteral ( `{{d: ${ datakey } }}` ) )
123
- ]
131
+ templateAttris
124
132
) ,
125
133
t . jsxClosingElement (
126
134
t . jsxIdentifier ( 'template' )
0 commit comments