Skip to content

Commit d241bb5

Browse files
author
Yannick Croissant
committed
Fix jsx-indent with multiline jsx in ternaries (fixes #966)
1 parent e67f3c5 commit d241bb5

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/rules/jsx-indent.js

+4
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ module.exports = {
233233
do {
234234
prevToken = sourceCode.getTokenBefore(prevToken);
235235
} while (prevToken.type === 'Punctuator');
236+
prevToken = sourceCode.getNodeByRangeIndex(prevToken.start);
237+
while (prevToken.parent && prevToken.parent.type !== 'ConditionalExpression') {
238+
prevToken = prevToken.parent;
239+
}
236240
}
237241
prevToken = prevToken.type === 'JSXExpressionContainer' ? prevToken.expression : prevToken;
238242

tests/lib/rules/jsx-indent.js

+15
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,21 @@ ruleTester.run('jsx-indent', rule, {
250250
' <Bar />'
251251
].join('\n'),
252252
parserOptions: parserOptions
253+
}, {
254+
// Multiline ternary
255+
// (multiline JSX, colon on its own line)
256+
code: [
257+
'{!foo ?',
258+
' <Foo',
259+
' onClick={this.onClick}',
260+
' />',
261+
':',
262+
' <Bar',
263+
' onClick={this.onClick}',
264+
' />',
265+
'}'
266+
].join('\n'),
267+
parserOptions: parserOptions
253268
}, {
254269
// Multiline ternary
255270
// (first expression on test line, colon at the end of the first expression)

0 commit comments

Comments
 (0)