Skip to content

Commit

Permalink
[Fix] jsx-indent: avoid a crash on non-string literals
Browse files Browse the repository at this point in the history
Fixes #2561.
  • Loading branch information
ljharb committed Feb 2, 2020
1 parent 000d6b8 commit 3da6eb3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/jsx-indent.js
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions tests/lib/rules/jsx-indent.js
Expand Up @@ -976,6 +976,19 @@ const Component = () => (
'</App>'
].join('\n'),
options: ['tab']
}, {
code: [
'<App>',
'\t{undefined}',
'\t{null}',
'\t{true}',
'\t{false}',
'\t{42}',
'\t{NaN}',
'\t{"foo"}',
'</App>'
].join('\n'),
options: ['tab']
}],

invalid: [{
Expand Down

0 comments on commit 3da6eb3

Please sign in to comment.