diff --git a/lib/rules/no-setup-props-reactivity-loss.js b/lib/rules/no-setup-props-reactivity-loss.js index fc0406ba9..b8e896075 100644 --- a/lib/rules/no-setup-props-reactivity-loss.js +++ b/lib/rules/no-setup-props-reactivity-loss.js @@ -78,7 +78,8 @@ module.exports = { if ( left.type !== 'ArrayPattern' && left.type !== 'ObjectPattern' && - rightNode.type !== 'MemberExpression' + rightNode.type !== 'MemberExpression' && + rightNode.type !== 'ConditionalExpression' ) { return } @@ -91,6 +92,14 @@ module.exports = { if (rightId.type === 'Identifier' && propsReferences.refs.has(rightId)) { report(left, 'getProperty', propsReferences.scopeName) } + if ( + rightId.type === 'ConditionalExpression' && + (isPropsMemberAccessed(rightId.test, propsReferences) || + isPropsMemberAccessed(rightId.consequent, propsReferences) || + isPropsMemberAccessed(rightId.alternate, propsReferences)) + ) { + report(right, 'getProperty', propsReferences.scopeName) + } } /** diff --git a/tests/lib/rules/no-setup-props-reactivity-loss.js b/tests/lib/rules/no-setup-props-reactivity-loss.js index 408ccb09e..6321ea573 100644 --- a/tests/lib/rules/no-setup-props-reactivity-loss.js +++ b/tests/lib/rules/no-setup-props-reactivity-loss.js @@ -113,6 +113,28 @@ tester.run('no-setup-props-reactivity-loss', rule, { ` }, + { + filename: 'test.vue', + code: ` + + ` + }, { filename: 'test.vue', code: ` @@ -680,6 +702,21 @@ tester.run('no-setup-props-reactivity-loss', rule, { line: 6 } ] + }, + { + filename: 'test.vue', + code: ` + + `, + errors: [ + { + messageId: 'getProperty', + line: 4 + } + ] } ] })