File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,22 @@ const elementName = (node) => {
27
27
return reversedIdentifiers . reverse ( ) . join ( '.' ) ;
28
28
} ;
29
29
30
+ const hasAllowedParent = ( parent , allowedElements ) => {
31
+ let curNode = parent ;
32
+
33
+ while ( curNode ) {
34
+ if ( curNode . type === 'JSXElement' ) {
35
+ const name = elementName ( curNode ) ;
36
+ if ( allowedElements . includes ( name ) ) {
37
+ return true ;
38
+ }
39
+ }
40
+ curNode = curNode . parent ;
41
+ }
42
+
43
+ return false ;
44
+ } ;
45
+
30
46
function create ( context ) {
31
47
const options = context . options [ 0 ] || { } ;
32
48
@@ -50,7 +66,7 @@ function create(context) {
50
66
51
67
const hasOnlyLineBreak = ( value ) => / ^ [ \r \n \t \f \v ] + $ / . test ( value . replace ( / / g, '' ) ) ;
52
68
53
- const getValidation = ( node ) => ! allowedElements . includes ( elementName ( node . parent ) ) ;
69
+ const getValidation = ( node ) => ! hasAllowedParent ( node . parent , allowedElements ) ;
54
70
55
71
return {
56
72
Literal ( node ) {
Original file line number Diff line number Diff line change @@ -114,6 +114,12 @@ const tests = {
114
114
}
115
115
` ,
116
116
} ,
117
+ {
118
+ // Testing nested components inside an allowed component
119
+ code : `
120
+ <Text>Some text <>More text</></Text>
121
+ ` ,
122
+ } ,
117
123
] ,
118
124
invalid : [
119
125
{
You can’t perform that action at this time.
0 commit comments