Skip to content

Commit

Permalink
[fix] - Add ConditionalExpression expression handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
beefancohen committed Apr 28, 2016
1 parent a62360d commit d25a918
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/util/values/expressions/ConditionalExpression.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

import getValue from './index';



/**
* Extractor function for a ConditionalExpression type value node.
*
* @param - value - AST Value object with type `ConditionalExpression`
* @returns - The extracted value converted to correct type.
*/
export default function extractValueFromConditionalExpression(value) {
const {
test,
alternate,
consequent
} = value;

return getValue(test) ? getValue(alternate) : getValue(consequent);
}
7 changes: 5 additions & 2 deletions src/util/values/expressions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import MemberExpression from './MemberExpression';
import CallExpression from './CallExpression';
import UnaryExpression from './UnaryExpression';
import ThisExpression from './ThisExpression';
import ConditionalExpression from './ConditionalExpression';



Expand All @@ -25,7 +26,8 @@ const TYPES = {
MemberExpression,
CallExpression,
UnaryExpression,
ThisExpression
ThisExpression,
ConditionalExpression
};

const noop = () => null;
Expand All @@ -52,7 +54,8 @@ const LITERAL_TYPES = assign({}, TYPES, {
const extractedVal = TYPES.UnaryExpression(value);
return extractedVal === undefined ? null : extractedVal;
},
ThisExpression: noop
ThisExpression: noop,
ConditionalExpression: noop
});

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/src/rules/aria-proptypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ ruleTester.run('aria-proptypes', rule, {
{ code: '<div aria-label={`Close`} />', parserOptions },
{ code: '<div aria-label={foo} />', parserOptions },
{ code: '<div aria-label={foo.bar} />', parserOptions },
{ code: '<input aria-invalid={error ? "true" : "false"} />', parserOptions },
{ code: '<input aria-invalid={undefined ? "true" : "false"} />', parserOptions },

// TRISTATE
{ code: '<div aria-checked={true} />', parserOptions },
Expand Down
2 changes: 2 additions & 0 deletions tests/src/rules/img-has-alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ ruleTester.run('img-has-alt', rule, {
{ code: '<img alt={undefined} role="presentation" />;', parserOptions },
{ code: '<img alt role="presentation" />;', parserOptions },
{ code: '<img alt="this is lit..." role="presentation" />', parserOptions },
{ code: '<img alt={error ? "not working": "working"} />', parserOptions },
{ code: '<img alt={undefined ? "working": "not working"} />', parserOptions },

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

0 comments on commit d25a918

Please sign in to comment.