diff --git a/src/util/values/expressions/index.js b/src/util/values/expressions/index.js index 065a9ce22..9e5933996 100644 --- a/src/util/values/expressions/index.js +++ b/src/util/values/expressions/index.js @@ -12,6 +12,9 @@ import CallExpression from './CallExpression'; import UnaryExpression from './UnaryExpression'; import ThisExpression from './ThisExpression'; import ConditionalExpression from './ConditionalExpression'; +import BinaryExpression from './BinaryExpression'; +import ObjectExpression from './ObjectExpression'; +import NewExpression from './NewExpression'; @@ -27,7 +30,10 @@ const TYPES = { CallExpression, UnaryExpression, ThisExpression, - ConditionalExpression + ConditionalExpression, + BinaryExpression, + ObjectExpression, + NewExpression }; const noop = () => null; @@ -55,9 +61,16 @@ const LITERAL_TYPES = assign({}, TYPES, { return extractedVal === undefined ? null : extractedVal; }, ThisExpression: noop, - ConditionalExpression: noop + ConditionalExpression: noop, + BinaryExpression: noop, + ObjectExpression: noop, + NewExpression: noop }); +const ERROR_MESSAGE = expression => + `The prop value with an expression type of ${expression} could not be resolved. + Please file issue to get this fixed immediately.`; + /** * This function maps an AST value node * to its correct extractor function for its @@ -71,8 +84,13 @@ const LITERAL_TYPES = assign({}, TYPES, { export default function extract(value) { // Value will not have the expression property when we recurse. const expression = value.expression || value; + const { type } = expression; + + if (TYPES[type] === undefined) { + throw new Error(ERROR_MESSAGE(type)); + } - return TYPES[expression.type](expression); + return TYPES[type](expression); } /** @@ -86,7 +104,13 @@ export default function extract(value) { * @returns The extracted value. */ export function extractLiteral(value) { + // Value will not have the expression property when we recurse. const expression = value.expression || value; + const { type } = expression; + + if (LITERAL_TYPES[type] === undefined) { + throw new Error(ERROR_MESSAGE(type)); + } - return LITERAL_TYPES[expression.type](expression); + return LITERAL_TYPES[type](expression); } diff --git a/tests/src/rules/img-has-alt.js b/tests/src/rules/img-has-alt.js index 29f216c3e..4e81d5b80 100644 --- a/tests/src/rules/img-has-alt.js +++ b/tests/src/rules/img-has-alt.js @@ -74,6 +74,7 @@ ruleTester.run('img-has-alt', rule, { { code: 'this is lit...', parserOptions }, { code: '{error', parserOptions }, { code: '{undefined', parserOptions }, + { code: '{plugin.name', parserOptions }, // CUSTOM ELEMENT TESTS FOR STRING OPTION { code: ';', options: string, parserOptions }, diff --git a/tests/src/rules/onclick-has-focus.js b/tests/src/rules/onclick-has-focus.js index c9102b883..145d6c90e 100644 --- a/tests/src/rules/onclick-has-focus.js +++ b/tests/src/rules/onclick-has-focus.js @@ -36,6 +36,14 @@ ruleTester.run('onclick-has-focus', rule, { valid: [ { code: '
', parserOptions }, { code: '
void 0} />', parserOptions }, + { code: '
void 0} />', parserOptions }, + { code: '
void 0} />', parserOptions }, + { code: '
void 0} />', parserOptions }, + { code: '
void 0} />', parserOptions }, + { code: '
void 0} />', parserOptions }, + { code: '
void 0} />', parserOptions }, + { code: '
1} onClick={() => void 0} />', parserOptions }, + { code: '
= 1} onClick={() => void 0} />', parserOptions }, { code: ' void 0} />', parserOptions }, { code: ' void 0} tabIndex="-1" />', parserOptions }, { code: ' void 0} />', parserOptions },