TypeError: Cannot read property 'object' of undefined
Occurred while linting /Users/will.heslam/projects/foo/index.tsx:53
at JSXAttribute (/Users/will.heslam/projects/foo/node_modules/eslint-plugin-react/lib/rules/jsx-handler-names.js:113:52)
which is apparently this line
? !node.value.expression.body.callee.object
in
!checkLocal
&& (isInlineHandler(node)
? !node.value.expression.body.callee.object
: !node.value.expression.object
)
when parsing
const Foo = ({ fn }: { fn: () => number }) => <div>{fn()}</div>
const Bar = <div><Foo fn={() => 42} /></div>
though this is TypeScript, I don't think that matters - here's a recreation using a test example:
}, {
code: '<TestComponent onChange={() => this.handleChange()} />',
options: [{
checkInlineFunction: true
}]
+ }, {
+ code: '<TestComponent onChange={() => 42} />'
}, {
code: '<TestComponent onChange={this.props.onFoo} />'
}, {
in
https://github.com/willheslam/eslint-plugin-react/tree/jsx-handler-names-crash
comparison:
https://github.com/yannickcr/eslint-plugin-react/compare/master...willheslam:jsx-handler-names-crash?expand=1
Running npm test on that branch results in:
4619 passing (10s)
1 failing
1) jsx-handler-names
valid
<TestComponent onChange={() => 42} />:
TypeError: Cannot read property 'object' of undefined
Occurred while linting <input>:1
at JSXAttribute (lib/rules/jsx-handler-names.js:9:3602)
at /Users/will.heslam/eslint-plugin-react/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
I'm not sure what an appropriate fix would be yet!
I also just ran into this error - seems to occur in 7.21.0 but not 7.20.6
In my case, looks like it was from a component with a prop like this: onRenameFile={()=>{}}
Thanks, I'll see if I can get a fix for this out ASAP.
v7.21.1 is released. Thanks to @willheslam for the report and the test case!
Most helpful comment
v7.21.1 is released. Thanks to @willheslam for the report and the test case!