Skip to content

Commit ba66cf6

Browse files
committed
Extract findTagName() function
1 parent b84ffcf commit ba66cf6

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

lib/index.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,12 @@ async function runForPath(path, options = {}) {
105105
// find `tagName` property if it exists
106106
let properties = objectArg.get('properties');
107107

108-
let tagName = 'div';
109-
110-
let tagNameProperty = properties.filter(path => isProperty(path, 'tagName'))[0];
111-
if (tagNameProperty) {
112-
let tagNamePath = tagNameProperty.get('value');
113-
if (tagNamePath.value.type !== 'StringLiteral') {
114-
console.log(
115-
chalk.yellow(`${dimPath}: Unexpected \`tagName\` value: ${j(tagNamePath).toSource()}`)
116-
);
117-
continue;
118-
}
119-
120-
tagName = tagNamePath.value.value;
108+
let tagName = findTagName(properties);
109+
if (tagName.constructor.name === 'NodePath') {
110+
console.log(
111+
chalk.yellow(`${dimPath}: Unexpected \`tagName\` value: ${j(tagName).toSource()}`)
112+
);
113+
continue;
121114
}
122115

123116
// skip tagless components (silent)
@@ -176,4 +169,18 @@ function isMethod(path, name) {
176169
return node.type === 'ObjectMethod' && node.key.type === 'Identifier' && node.key.name === name;
177170
}
178171

172+
function findTagName(properties) {
173+
let tagNameProperty = properties.filter(path => isProperty(path, 'tagName'))[0];
174+
if (!tagNameProperty) {
175+
return 'div';
176+
}
177+
178+
let tagNamePath = tagNameProperty.get('value');
179+
if (tagNamePath.value.type === 'StringLiteral') {
180+
return tagNamePath.value.value;
181+
}
182+
183+
return tagNamePath;
184+
}
185+
179186
module.exports = { run };

0 commit comments

Comments
 (0)