@@ -108,32 +108,39 @@ export const collectAndInitDirectives = (
108
108
return [ directives , removeDupesFromArray ( nodeDeps ) ] ;
109
109
} ;
110
110
111
- export const flattenNodeChildren = (
112
- rootNode : HTMLElement ,
111
+ export const flattenElementChildren = (
112
+ rootElement : HTMLElement ,
113
113
isListGroup = false ,
114
- ignoreRootNode = false
114
+ ignoreRootElement = false
115
115
) : HTMLElement [ ] => {
116
116
const collection : HTMLElement [ ] = [ ] ;
117
- const isList = isListRenderScope ( rootNode ) ;
118
- const isUnderList = isUnderListRenderScope ( rootNode ) ;
117
+ const isList = isListRenderScope ( rootElement ) ;
118
+ const isUnderList = isUnderListRenderScope ( rootElement ) ;
119
119
120
120
// Return nothing if it isn't list compilation and is a list or under a list
121
121
if ( ! isListGroup && ( isList || isUnderList ) ) return collection ;
122
- // Add root node to return array if it isn't a list or under a list
123
- if ( ! ignoreRootNode && ( ! isListGroup || ! isList ) ) collection . push ( rootNode ) ;
122
+ // Add root elem to return array if it isn't a list or under a list
123
+ if ( ! ignoreRootElement && ( ! isListGroup || ! isList ) ) collection . push ( rootElement ) ;
124
124
125
125
// Is not a list or under a list, but pass if is a list group
126
126
if ( isListGroup || ( ! isList && ! isUnderList ) ) {
127
- for ( const childNode of rootNode . childNodes ) {
128
- if ( childNode . nodeType === Node . ELEMENT_NODE ) {
129
- if ( ! isListGroup && isListRenderScope ( childNode as HTMLElement ) ) {
127
+ for ( const childElement of rootElement . children ) {
128
+ // Check if childElement has attributes
129
+ if ( childElement instanceof HTMLElement ) {
130
+ if ( ! isListGroup && isListRenderScope ( childElement ) ) {
130
131
// Push root if it is a list render (don't want to push unrendered template)
131
- collection . push ( childNode as HTMLElement ) ;
132
+ collection . push ( childElement ) ;
132
133
} else {
133
134
// Skip over nested components (independent compile request)
134
- if ( ( childNode as HTMLElement ) . hasAttribute ( `${ DIRECTIVE_PREFIX } state` ) ) continue ;
135
+ if ( childElement . hasAttribute ( `${ DIRECTIVE_PREFIX } state` ) ) continue ;
135
136
// Push all children into array (recursive flattening)
136
- collection . push ( ...flattenNodeChildren ( childNode as HTMLElement , isListGroup ) ) ;
137
+ collection . push (
138
+ ...flattenElementChildren (
139
+ childElement ,
140
+ isListGroup ,
141
+ childElement . attributes . length === 0
142
+ )
143
+ ) ;
137
144
}
138
145
}
139
146
}
@@ -142,20 +149,26 @@ export const flattenNodeChildren = (
142
149
return collection ;
143
150
} ;
144
151
145
- export const compile = ( el : HTMLElement , state : State = { } , ignoreRootNode = false ) : ASTNode [ ] => {
152
+ export const compile = (
153
+ el : HTMLElement ,
154
+ state : State = { } ,
155
+ ignoreRootElement = false
156
+ ) : ASTNode [ ] => {
146
157
const ast : ASTNode [ ] = [ ] ;
147
158
const isListGroup =
148
159
getElementCustomProp ( el , COMPONENT_FLAG ) !== undefined && isListRenderScope ( el ) ;
149
- const nodes : HTMLElement [ ] = flattenNodeChildren ( el , isListGroup , ignoreRootNode ) ;
160
+ const elements : HTMLElement [ ] = flattenElementChildren ( el , isListGroup , ignoreRootElement ) ;
150
161
const maskDirective = `${ DIRECTIVE_PREFIX } mask` ;
151
162
163
+ console . log ( elements ) ;
164
+
152
165
/* istanbul ignore next */
153
- nodes . forEach ( ( node ) => {
154
- if ( node . hasAttribute ( maskDirective ) ) {
155
- node . removeAttribute ( maskDirective ) ;
166
+ elements . forEach ( ( element ) => {
167
+ if ( element . hasAttribute ( maskDirective ) ) {
168
+ element . removeAttribute ( maskDirective ) ;
156
169
}
157
- if ( hasDirectiveRE ( ) . test ( node . outerHTML ) ) {
158
- const newASTNode = createASTNode ( node , state ) ;
170
+ if ( hasDirectiveRE ( ) . test ( element . outerHTML ) ) {
171
+ const newASTNode = createASTNode ( element , state ) ;
159
172
if ( newASTNode ) ast . push ( newASTNode ) ;
160
173
}
161
174
} ) ;
0 commit comments