From 9639d821741748d6c7a41bb4e7a9d822cfe8de78 Mon Sep 17 00:00:00 2001 From: golopot Date: Mon, 24 Jun 2019 08:37:44 +0800 Subject: [PATCH] [Fix] `prop-types`: fix crash on multiple destructuring --- lib/util/usedPropTypes.js | 2 +- tests/lib/rules/no-unused-prop-types.js | 16 ++++++++++++++++ tests/lib/rules/prop-types.js | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/util/usedPropTypes.js b/lib/util/usedPropTypes.js index b783bbaf1a..9e5fffbfe5 100755 --- a/lib/util/usedPropTypes.js +++ b/lib/util/usedPropTypes.js @@ -489,7 +489,7 @@ module.exports = function usedPropTypesInstructions(context, components, utils) // let {firstname} = thing, where thing is defined by const thing = this.props.**.* if (propVariables.get(node.init.name)) { - markPropTypesAsUsed(node, propVariables.get(node.init.name)); + markPropTypesAsUsed(node.id, propVariables.get(node.init.name)); } }, diff --git a/tests/lib/rules/no-unused-prop-types.js b/tests/lib/rules/no-unused-prop-types.js index 952d6763c5..ab327ce4b8 100644 --- a/tests/lib/rules/no-unused-prop-types.js +++ b/tests/lib/rules/no-unused-prop-types.js @@ -492,6 +492,22 @@ ruleTester.run('no-unused-prop-types', rule, { `, options: [{skipShapeProps: false}], parser: parsers.BABEL_ESLINT + }, { + code: ` + function Foo({ a }) { + const { b } = a + return <>{ b.c } + } + Foo.propTypes = { + a: PropTypes.shape({ + b: PropType.shape({ + c: PropTypes.string, + }), + }) + } + `, + options: [{skipShapeProps: false}], + parser: parsers.BABEL_ESLINT }, { // Destructured assignment with Shape propTypes with skipShapeProps off issue #816 code: ` diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index 6685103fa1..bcb48a09dc 100755 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -2472,6 +2472,25 @@ ruleTester.run('prop-types', rule, { {message: "'a.nope' is missing in props validation"} ] }, + { + code: ` + function Foo({ a }) { + const { b } = a + return

{ b.nope }

+ } + + Foo.propTypes = { + a: PropTypes.shape({ + b: PropType.shape({ + _: PropType.string, + }), + }) + } + `, + errors: [ + {message: "'a.b.nope' is missing in props validation"} + ] + }, { code: ` function Foo(props) {