From 057f1db2442a732e86d75fa82905388b85a4e31d Mon Sep 17 00:00:00 2001 From: Yannick Croissant Date: Mon, 24 Jun 2019 18:07:45 +0200 Subject: [PATCH] [Fix] : fix crash on for...of destructuring Fixes #2326 --- lib/util/usedPropTypes.js | 2 +- tests/lib/rules/prop-types.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/util/usedPropTypes.js b/lib/util/usedPropTypes.js index 9e5fffbfe5..9e19fe8b14 100755 --- a/lib/util/usedPropTypes.js +++ b/lib/util/usedPropTypes.js @@ -452,7 +452,7 @@ module.exports = function usedPropTypesInstructions(context, components, utils) } // Only handles destructuring - if (node.id.type !== 'ObjectPattern') { + if (node.id.type !== 'ObjectPattern' || !node.init) { return; } diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index bcb48a09dc..b8d5bd7e3d 100755 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -2349,6 +2349,12 @@ ruleTester.run('prop-types', rule, { } `, parser: parsers.BABEL_ESLINT + }, + { + // issue #2326 + code: ` + for (const {result} of results) {} + ` } ],