From 3da6eb36327f77adfdd856296c3d663bffe288ee Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 1 Feb 2020 19:06:21 -0800 Subject: [PATCH] [Fix] `jsx-indent`: avoid a crash on non-string literals Fixes #2561. --- lib/rules/jsx-indent.js | 2 +- tests/lib/rules/jsx-indent.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/rules/jsx-indent.js b/lib/rules/jsx-indent.js index bbdeaabce0..7c8cbac5d2 100644 --- a/lib/rules/jsx-indent.js +++ b/lib/rules/jsx-indent.js @@ -306,7 +306,7 @@ module.exports = { const value = node.value; const regExp = indentType === 'space' ? /\n( *)[\t ]*\S/g : /\n(\t*)[\t ]*\S/g; const nodeIndentsPerLine = Array.from( - matchAll(value, regExp), + matchAll(String(value), regExp), match => (match[1] ? match[1].length : 0) ); const hasFirstInLineNode = nodeIndentsPerLine.length > 0; diff --git a/tests/lib/rules/jsx-indent.js b/tests/lib/rules/jsx-indent.js index 9a245f1e18..0bb6d8e877 100644 --- a/tests/lib/rules/jsx-indent.js +++ b/tests/lib/rules/jsx-indent.js @@ -976,6 +976,19 @@ const Component = () => ( '' ].join('\n'), options: ['tab'] + }, { + code: [ + '', + '\t{undefined}', + '\t{null}', + '\t{true}', + '\t{false}', + '\t{42}', + '\t{NaN}', + '\t{"foo"}', + '' + ].join('\n'), + options: ['tab'] }], invalid: [{