@@ -20,6 +20,24 @@ function isObjectWithProperties(node) {
2020  return  true ; 
2121} 
2222
23+ function  getComponentFromNode ( node )  { 
24+   if  ( isDefaultExport ( node )  &&  isObjectWithProperties ( node . declaration ) )  { 
25+     return  node . declaration ; 
26+   } 
27+ 
28+   if  ( node . expression )  { 
29+     const  { 
30+       left, 
31+       right, 
32+     }  =  node . expression ; 
33+     if  ( isModuleExports ( left )  &&  isObjectWithProperties ( right ) )  { 
34+       return  right ; 
35+     } 
36+   } 
37+ 
38+   return  null ; 
39+ } 
40+ 
2341// Objects can contain key names surrounded by quotes, or not 
2442// propertyArray is the array of Property nodes in the component object 
2543function  astIncludesProperty ( name ,  propertyArray )  { 
@@ -44,20 +62,7 @@ function findPropertyWithName(name, propertyArray) {
4462
4563// Does a component contain the right property? e.g. key, version 
4664function  componentContainsPropertyCheck ( context ,  node ,  propertyName ,  message )  { 
47-   let  component ; 
48-   if  ( isDefaultExport ( node )  &&  isObjectWithProperties ( node . declaration ) )  { 
49-     component  =  node . declaration ; 
50-   } 
51- 
52-   if  ( node . expression )  { 
53-     const  { 
54-       left, 
55-       right, 
56-     }  =  node . expression ; 
57-     if  ( isModuleExports ( left )  &&  isObjectWithProperties ( right ) )  { 
58-       component  =  right ; 
59-     } 
60-   } 
65+   const  component  =  getComponentFromNode ( node ) ; 
6166
6267  if  ( ! component )  return ; 
6368  if  ( ! astIncludesProperty ( propertyName ,  component . properties ) )  { 
@@ -80,19 +85,7 @@ function getProps(moduleProperties) {
8085
8186// Do component props contain the right properties? e.g. label, description 
8287function  componentPropsContainsPropertyCheck ( context ,  node ,  propertyName )  { 
83-   let  component ; 
84-   if  ( isDefaultExport ( node )  &&  isObjectWithProperties ( node . declaration ) )  { 
85-     component  =  node . declaration ; 
86-   } 
87-   if  ( node . expression )  { 
88-     const  { 
89-       left, 
90-       right, 
91-     }  =  node . expression ; 
92-     if  ( isModuleExports ( left )  &&  isObjectWithProperties ( right ) )  { 
93-       component  =  right ; 
94-     } 
95-   } 
88+   const  component  =  getComponentFromNode ( node ) ; 
9689
9790  if  ( ! component )  return ; 
9891
@@ -119,20 +112,7 @@ function componentPropsContainsPropertyCheck(context, node, propertyName) {
119112} 
120113
121114function  optionalComponentPropsHaveDefaultProperty ( context ,  node )  { 
122-   let  component ; 
123-   if  ( isDefaultExport ( node )  &&  isObjectWithProperties ( node . declaration ) )  { 
124-     component  =  node . declaration ; 
125-   } 
126- 
127-   if  ( node . expression )  { 
128-     const  { 
129-       left, 
130-       right, 
131-     }  =  node . expression ; 
132-     if  ( isModuleExports ( left )  &&  isObjectWithProperties ( right ) )  { 
133-       component  =  right ; 
134-     } 
135-   } 
115+   const  component  =  getComponentFromNode ( node ) ; 
136116
137117  if  ( ! component )  return ; 
138118  const  {  properties }  =  component ; 
@@ -166,20 +146,7 @@ function optionalComponentPropsHaveDefaultProperty(context, node) {
166146// Checks to confirm the component is a source, and returns 
167147// the node with the name specified by the user 
168148function  checkComponentIsSourceAndReturnTargetProp ( node ,  propertyName )  { 
169-   let  component ; 
170-   if  ( isDefaultExport ( node )  &&  isObjectWithProperties ( node . declaration ) )  { 
171-     component  =  node . declaration ; 
172-   } 
173- 
174-   if  ( node . expression )  { 
175-     const  { 
176-       left, 
177-       right, 
178-     }  =  node . expression ; 
179-     if  ( isModuleExports ( left )  &&  isObjectWithProperties ( right ) )  { 
180-       component  =  right ; 
181-     } 
182-   } 
149+   const  component  =  getComponentFromNode ( node ) ; 
183150
184151  if  ( ! component )  return ; 
185152  const  {  properties }  =  component ; 
@@ -215,20 +182,7 @@ function componentSourceDescriptionCheck(context, node) {
215182} 
216183
217184function  componentVersionTsMacroCheck ( context ,  node )  { 
218-   let  component ; 
219-   if  ( isDefaultExport ( node )  &&  isObjectWithProperties ( node . declaration ) )  { 
220-     component  =  node . declaration ; 
221-   } 
222- 
223-   if  ( node . expression )  { 
224-     const  { 
225-       left, 
226-       right, 
227-     }  =  node . expression ; 
228-     if  ( isModuleExports ( left )  &&  isObjectWithProperties ( right ) )  { 
229-       component  =  right ; 
230-     } 
231-   } 
185+   const  component  =  getComponentFromNode ( node ) ; 
232186
233187  if  ( ! component )  return ; 
234188  const  {  properties }  =  component ; 
0 commit comments