Skip to content

Commit d25a918

Browse files
committed
[fix] - Add ConditionalExpression expression handler.
1 parent a62360d commit d25a918

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
import getValue from './index';
4+
5+
6+
7+
/**
8+
* Extractor function for a ConditionalExpression type value node.
9+
*
10+
* @param - value - AST Value object with type `ConditionalExpression`
11+
* @returns - The extracted value converted to correct type.
12+
*/
13+
export default function extractValueFromConditionalExpression(value) {
14+
const {
15+
test,
16+
alternate,
17+
consequent
18+
} = value;
19+
20+
return getValue(test) ? getValue(alternate) : getValue(consequent);
21+
}

src/util/values/expressions/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import MemberExpression from './MemberExpression';
1111
import CallExpression from './CallExpression';
1212
import UnaryExpression from './UnaryExpression';
1313
import ThisExpression from './ThisExpression';
14+
import ConditionalExpression from './ConditionalExpression';
1415

1516

1617

@@ -25,7 +26,8 @@ const TYPES = {
2526
MemberExpression,
2627
CallExpression,
2728
UnaryExpression,
28-
ThisExpression
29+
ThisExpression,
30+
ConditionalExpression
2931
};
3032

3133
const noop = () => null;
@@ -52,7 +54,8 @@ const LITERAL_TYPES = assign({}, TYPES, {
5254
const extractedVal = TYPES.UnaryExpression(value);
5355
return extractedVal === undefined ? null : extractedVal;
5456
},
55-
ThisExpression: noop
57+
ThisExpression: noop,
58+
ConditionalExpression: noop
5659
});
5760

5861
/**

tests/src/rules/aria-proptypes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ ruleTester.run('aria-proptypes', rule, {
6969
{ code: '<div aria-label={`Close`} />', parserOptions },
7070
{ code: '<div aria-label={foo} />', parserOptions },
7171
{ code: '<div aria-label={foo.bar} />', parserOptions },
72+
{ code: '<input aria-invalid={error ? "true" : "false"} />', parserOptions },
73+
{ code: '<input aria-invalid={undefined ? "true" : "false"} />', parserOptions },
7274

7375
// TRISTATE
7476
{ code: '<div aria-checked={true} />', parserOptions },

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ ruleTester.run('img-has-alt', rule, {
7272
{ code: '<img alt={undefined} role="presentation" />;', parserOptions },
7373
{ code: '<img alt role="presentation" />;', parserOptions },
7474
{ code: '<img alt="this is lit..." role="presentation" />', parserOptions },
75+
{ code: '<img alt={error ? "not working": "working"} />', parserOptions },
76+
{ code: '<img alt={undefined ? "working": "not working"} />', parserOptions },
7577

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

0 commit comments

Comments
 (0)