Skip to content

Commit 22f3638

Browse files
authored
Merge pull request jsx-eslint#1077 from iancmyers/fix-jsx-indent-template-conditional
Fix error caused by templates in ConditionalExpressions (jsx-indent)
2 parents a4b6a85 + c6f4a5e commit 22f3638

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/rules/jsx-indent.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ module.exports = {
275275
do {
276276
prevToken = sourceCode.getTokenBefore(prevToken);
277277
} while (prevToken.type === 'Punctuator');
278-
prevToken = sourceCode.getNodeByRangeIndex(prevToken.start);
278+
prevToken = sourceCode.getNodeByRangeIndex(prevToken.range[0]);
279+
279280
while (prevToken.parent && prevToken.parent.type !== 'ConditionalExpression') {
280281
prevToken = prevToken.parent;
281282
}

tests/lib/rules/jsx-indent.js

+41
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,47 @@ ruleTester.run('jsx-indent', rule, {
410410
].join('\n'),
411411
options: [4, {indentLogicalExpressions: true}],
412412
parserOptions: parserOptions
413+
}, {
414+
code: [
415+
'<span>',
416+
' {condition ?',
417+
' <Thing',
418+
' foo={`bar`}',
419+
' /> :',
420+
' <Thing/>',
421+
' }',
422+
'</span>'
423+
].join('\n'),
424+
options: [2],
425+
parserOptions: parserOptions
426+
}, {
427+
code: [
428+
'<span>',
429+
' {condition ?',
430+
' <Thing',
431+
' foo={"bar"}',
432+
' /> :',
433+
' <Thing/>',
434+
' }',
435+
'</span>'
436+
].join('\n'),
437+
options: [2],
438+
parserOptions: parserOptions
439+
}, {
440+
code: [
441+
'function foo() {',
442+
' <span>',
443+
' {condition ?',
444+
' <Thing',
445+
' foo={super}',
446+
' /> :',
447+
' <Thing/>',
448+
' }',
449+
' </span>',
450+
'}'
451+
].join('\n'),
452+
options: [2],
453+
parserOptions: parserOptions
413454
}],
414455

415456
invalid: [{

0 commit comments

Comments
 (0)