Skip to content

Commit

Permalink
[Fix] no-arrow-function-lifecycle: prevent crashing on ClassProperty
Browse files Browse the repository at this point in the history
Fixes #3093
  • Loading branch information
AriPerkkio authored and ljharb committed Oct 5, 2021
1 parent f93f90a commit c70163d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/rules/no-arrow-function-lifecycle.js
Expand Up @@ -44,6 +44,10 @@ module.exports = {
*/
function reportNoArrowFunctionLifecycle(properties) {
properties.forEach((node) => {
if (!node || !node.value) {
return;
}

const propertyName = astUtil.getPropertyName(node);
const nodeType = node.value.type;
const isLifecycleMethod = (
Expand Down
13 changes: 12 additions & 1 deletion tests/lib/rules/no-arrow-function-lifecycle.js
Expand Up @@ -348,7 +348,18 @@ ruleTester.run('no-arrow-function-lifecycle', rule, {
});
`,
},
],
].concat(
parsers.TS([
{
code: `
class MyComponent extends React.Component {
onChange: () => void;
}
`,
parser: parsers['@TYPESCRIPT_ESLINT'],
},
])
),

invalid: [
{
Expand Down

0 comments on commit c70163d

Please sign in to comment.