Skip to content

Commit 25fe686

Browse files
jessebeachbeefancohen
authored andcommitted
propName should always return a value (#50)
* propName should always return a value * Fix Array.includes failures in Node 4 and 5
1 parent bc61ce9 commit 25fe686

File tree

4 files changed

+9
-23
lines changed

4 files changed

+9
-23
lines changed

__tests__/src/eventHandlers-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-env mocha */
22
import assert from 'assert';
3+
import includes from 'array-includes';
34
import eventHandlers, { eventHandlersByType } from '../../src/eventHandlers';
45

56
describe('eventHandlers', () => {
@@ -74,7 +75,7 @@ describe('eventHandlers', () => {
7475
'onAnimationEnd',
7576
'onAnimationIteration',
7677
'onTransitionEnd',
77-
].every(handlerName => eventHandlers.includes(handlerName)));
78+
].every(handlerName => includes(eventHandlers, handlerName)));
7879
});
7980
});
8081

__tests__/src/propName-test.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,4 @@ describe('propName', () => {
3636

3737
assert.equal(expected, actual);
3838
});
39-
40-
// Note: this shouldn't happen, but safe guard anyway.
41-
it('should return undefined if prop name is not JSXIdentifier or JSXNamespacedName', () => {
42-
const prop = {
43-
type: 'JSXAttribute',
44-
name: {
45-
type: 'Literal',
46-
},
47-
};
48-
49-
const expected = undefined;
50-
const actual = propName(prop);
51-
52-
assert.equal(expected, actual);
53-
});
5439
});

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,8 @@
5252
"/node_modules/",
5353
"helper.js"
5454
]
55+
},
56+
"dependencies": {
57+
"array-includes": "^3.0.3"
5558
}
5659
}

src/propName.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ export default function propName(prop = {}) {
66
throw new Error('The prop must be a JSXAttribute collected by the AST parser.');
77
}
88

9-
switch (prop.name.type) {
10-
case 'JSXIdentifier':
11-
return prop.name.name;
12-
case 'JSXNamespacedName':
13-
return `${prop.name.namespace.name}:${prop.name.name.name}`;
14-
default:
15-
return undefined;
9+
if (prop.name.type === 'JSXNamespacedName') {
10+
return `${prop.name.namespace.name}:${prop.name.name.name}`;
1611
}
12+
13+
return prop.name.name;
1714
}

0 commit comments

Comments
 (0)