Skip to content

Commit 3da6eb3

Browse files
committed
[Fix] jsx-indent: avoid a crash on non-string literals
Fixes #2561.
1 parent 000d6b8 commit 3da6eb3

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/rules/jsx-indent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ module.exports = {
306306
const value = node.value;
307307
const regExp = indentType === 'space' ? /\n( *)[\t ]*\S/g : /\n(\t*)[\t ]*\S/g;
308308
const nodeIndentsPerLine = Array.from(
309-
matchAll(value, regExp),
309+
matchAll(String(value), regExp),
310310
match => (match[1] ? match[1].length : 0)
311311
);
312312
const hasFirstInLineNode = nodeIndentsPerLine.length > 0;

tests/lib/rules/jsx-indent.js

+13
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,19 @@ const Component = () => (
976976
'</App>'
977977
].join('\n'),
978978
options: ['tab']
979+
}, {
980+
code: [
981+
'<App>',
982+
'\t{undefined}',
983+
'\t{null}',
984+
'\t{true}',
985+
'\t{false}',
986+
'\t{42}',
987+
'\t{NaN}',
988+
'\t{"foo"}',
989+
'</App>'
990+
].join('\n'),
991+
options: ['tab']
979992
}],
980993

981994
invalid: [{

0 commit comments

Comments
 (0)