@@ -139,32 +139,26 @@ function isMethod(path, name) {
139139 return node . type === 'ObjectMethod' && node . key . type === 'Identifier' && node . key . name === name ;
140140}
141141
142- function findTagName ( properties ) {
143- let tagNameProperty = properties . filter ( path => isProperty ( path , 'tagName' ) ) [ 0 ] ;
144- if ( ! tagNameProperty ) {
145- return 'div' ;
142+ function findStringProperty ( properties , name , defaultValue = null ) {
143+ let propertyPath = properties . filter ( path => isProperty ( path , name ) ) [ 0 ] ;
144+ if ( ! propertyPath ) {
145+ return defaultValue ;
146146 }
147147
148- let elementIdPath = tagNameProperty . get ( 'value' ) ;
149- if ( elementIdPath . value . type !== 'StringLiteral' ) {
150- throw new SilentError ( `Unexpected \`tagName \` value: ${ j ( elementIdPath ) . toSource ( ) } ` ) ;
148+ let valuePath = propertyPath . get ( 'value' ) ;
149+ if ( valuePath . value . type !== 'StringLiteral' ) {
150+ throw new SilentError ( `Unexpected \`${ name } \` value: ${ j ( valuePath ) . toSource ( ) } ` ) ;
151151 }
152152
153- return elementIdPath . value . value ;
153+ return valuePath . value . value ;
154154}
155155
156- function findElementId ( properties ) {
157- let elementIdProperty = properties . filter ( path => isProperty ( path , 'elementId' ) ) [ 0 ] ;
158- if ( ! elementIdProperty ) {
159- return null ;
160- }
161-
162- let elementIdPath = elementIdProperty . get ( 'value' ) ;
163- if ( elementIdPath . value . type !== 'StringLiteral' ) {
164- throw new SilentError ( `Unexpected \`elementId\` value: ${ j ( elementIdPath ) . toSource ( ) } ` ) ;
165- }
156+ function findTagName ( properties ) {
157+ return findStringProperty ( properties , 'tagName' , 'div' ) ;
158+ }
166159
167- return elementIdPath . value . value ;
160+ function findElementId ( properties ) {
161+ return findStringProperty ( properties , 'elementId' ) ;
168162}
169163
170164function findAttributeBindings ( properties ) {
0 commit comments