Skip to content

Commit 095c91b

Browse files
committed
Merge pull request #374 from lukekarrys/373-jsx-key-crash
Fix crash in jsx-key (fixes #373)
2 parents 98541c5 + 50f4762 commit 095c91b

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lib/rules/jsx-key.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,24 @@ module.exports = function(context) {
4646

4747
// Array.prototype.map
4848
CallExpression: function (node) {
49-
if (node.callee.property.name !== 'map') {
49+
if (node.callee && node.callee.property && node.callee.property.name !== 'map') {
5050
return;
5151
}
5252

5353
var fn = node.arguments[0];
54-
var isFn = fn.type === 'FunctionExpression';
55-
var isArrFn = fn.type === 'ArrowFunctionExpression';
54+
var isFn = fn && fn.type === 'FunctionExpression';
55+
var isArrFn = fn && fn.type === 'ArrowFunctionExpression';
5656

5757
if (isArrFn && fn.body.type === 'JSXElement') {
5858
checkIteratorElement(fn.body);
5959
}
6060

6161
if (isFn || isArrFn) {
6262
if (fn.body.type === 'BlockStatement') {
63-
checkIteratorElement(
64-
getReturnStatement(fn.body.body).argument
65-
);
63+
var returnStatement = getReturnStatement(fn.body.body);
64+
if (returnStatement) {
65+
checkIteratorElement(returnStatement.argument);
66+
}
6667
}
6768
}
6869
}

tests/lib/rules/jsx-key.js

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ var parserOptions = {
2525
var ruleTester = new RuleTester();
2626
ruleTester.run('jsx-key', rule, {
2727
valid: [
28+
{code: 'fn()', parserOptions: parserOptions},
29+
{code: '[1, 2, 3].map(function () {})', parserOptions: parserOptions},
2830
{code: '<App />;', parserOptions: parserOptions},
2931
{code: '[<App key={0} />, <App key={1} />];', parserOptions: parserOptions},
3032
{code: '[1, 2, 3].map(function(x) { return <App key={x} /> });', parserOptions: parserOptions},

0 commit comments

Comments
 (0)