Skip to content

Commit b84ffcf

Browse files
committed
Extract isProperty/Method() functions
1 parent 02b2e77 commit b84ffcf

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

lib/index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,7 @@ async function runForPath(path, options = {}) {
107107

108108
let tagName = 'div';
109109

110-
let tagNameProperty = properties.filter(
111-
({ value: node }) =>
112-
node.type === 'ObjectProperty' &&
113-
node.key.type === 'Identifier' &&
114-
node.key.name === 'tagName'
115-
)[0];
110+
let tagNameProperty = properties.filter(path => isProperty(path, 'tagName'))[0];
116111
if (tagNameProperty) {
117112
let tagNamePath = tagNameProperty.get('value');
118113
if (tagNamePath.value.type !== 'StringLiteral') {
@@ -147,12 +142,7 @@ async function runForPath(path, options = {}) {
147142

148143
// skip components that use `click()` etc.
149144
for (let methodName of EVENT_HANDLER_METHODS) {
150-
let handlerMethod = properties.filter(
151-
({ value: node }) =>
152-
node.type === 'ObjectMethod' &&
153-
node.key.type === 'Identifier' &&
154-
node.key.name === methodName
155-
)[0];
145+
let handlerMethod = properties.filter(path => isMethod(path, methodName))[0];
156146
if (handlerMethod) {
157147
console.log(
158148
chalk.yellow(
@@ -176,4 +166,14 @@ async function runForPath(path, options = {}) {
176166
debug('runForPath() finished');
177167
}
178168

169+
function isProperty(path, name) {
170+
let node = path.value;
171+
return node.type === 'ObjectProperty' && node.key.type === 'Identifier' && node.key.name === name;
172+
}
173+
174+
function isMethod(path, name) {
175+
let node = path.value;
176+
return node.type === 'ObjectMethod' && node.key.type === 'Identifier' && node.key.name === name;
177+
}
178+
179179
module.exports = { run };

0 commit comments

Comments
 (0)