Skip to content

Commit 6a69d99

Browse files
author
Ethan Cohen
committed
Form MemberExpression property values.
1 parent f9ea90b commit 6a69d99

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/util/getAttributeValue.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const getValue = value => {
88
} else if (value.type === 'Identifier') {
99
return value.name === "" ? undefined : value.name;
1010
} else if (value.type === 'JSXExpressionContainer') {
11-
const expression = value.expression;
11+
const { expression } = value;
1212

1313
switch (expression.type) {
1414
case 'Literal':
@@ -21,7 +21,13 @@ const getValue = value => {
2121
case 'FunctionExpression':
2222
return () => void 0;
2323
case 'LogicalExpression':
24-
return getValue(expression.left) && getValue(expression.right);
24+
const { operator, left, right } = expression;
25+
const leftVal = getValue(left);
26+
const rightVal = getValue(right);
27+
28+
return operator == '&&' ? leftVal && rightVal : leftVal || rightVal;
29+
case 'MemberExpression':
30+
return `${getValue(expression.object)}.${expression.property}`;
2531
default:
2632
return undefined;
2733
}

tests/src/rules/img-uses-alt.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ ruleTester.run('img-uses-alt', rule, {
5656
{ code: '<IMG />', parserOptions },
5757
{ code: '<UX.Layout>test</UX.Layout>', parserOptions },
5858
{ code: '<img alt={alt || "Alt text" } />', parserOptions },
59+
{ code: '<img alt={photo.caption} />;', parserOptions },
60+
{ code: '<img alt=" " />', parserOptions }, // For decorative images.
5961

6062
// CUSTOM ELEMENT TESTS FOR STRING OPTION
6163
{ code: '<Avatar alt="foo" />;', options: string, parserOptions },

0 commit comments

Comments
 (0)