Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'object' of undefined in jsx-handler-names #2803

Closed
willheslam opened this issue Sep 23, 2020 · 3 comments
Closed

Comments

@willheslam
Copy link
Contributor

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!

@dylanlan
Copy link

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={()=>{}}

@ljharb
Copy link
Member

ljharb commented Sep 23, 2020

Thanks, I'll see if I can get a fix for this out ASAP.

@ljharb ljharb closed this as completed in 67699eb Sep 23, 2020
@ljharb
Copy link
Member

ljharb commented Sep 23, 2020

v7.21.1 is released. Thanks to @willheslam for the report and the test case!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants