diff options
author | siikamiika <siikamiika@users.noreply.github.com> | 2020-05-06 19:44:56 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-06 19:44:56 +0300 |
commit | 253dcf8b38c6ef2bec1a524db70e30ac7b1817c5 (patch) | |
tree | 6f28335b0b30f8b89d0353bd17ee57a85455246c /ext/bg/js/conditions.js | |
parent | a1f8f0d1de7286a55c97a783504b23bd76740e50 (diff) |
Fix modifier key condition data (#506)
* save transformed data for modifier key conditions
* validate transformed input
* fix regression
* undo rename
* refactor transformInput handling
* don't overwrite value with null
Diffstat (limited to 'ext/bg/js/conditions.js')
-rw-r--r-- | ext/bg/js/conditions.js | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/ext/bg/js/conditions.js b/ext/bg/js/conditions.js index eb9582df..3f3c0a45 100644 --- a/ext/bg/js/conditions.js +++ b/ext/bg/js/conditions.js @@ -32,7 +32,15 @@ function conditionsValidateOptionValue(object, value) { return value; } -function conditionsNormalizeOptionValue(descriptors, type, operator, optionValue) { +function conditionsValidateOptionInputValue(object, value) { + if (hasOwn(object, 'transformInput')) { + return object.transformInput(value); + } + + return null; +} + +function conditionsNormalizeOptionValue(descriptors, type, operator, optionValue, isInput) { if (!hasOwn(descriptors, type)) { throw new Error('Invalid type'); } @@ -44,13 +52,34 @@ function conditionsNormalizeOptionValue(descriptors, type, operator, optionValue const operatorDescriptor = conditionDescriptor.operators[operator]; - let transformedValue = conditionsValidateOptionValue(conditionDescriptor, optionValue); - transformedValue = conditionsValidateOptionValue(operatorDescriptor, transformedValue); + const descriptorArray = [conditionDescriptor, operatorDescriptor]; + + let transformedValue = optionValue; + + let inputTransformedValue = null; + if (isInput) { + for (const descriptor of descriptorArray) { + let value = inputTransformedValue !== null ? inputTransformedValue : transformedValue; + value = conditionsValidateOptionInputValue(descriptor, value); + if (value !== null) { + inputTransformedValue = value; + } + } + + if (inputTransformedValue !== null) { + transformedValue = inputTransformedValue; + } + } + + for (const descriptor of descriptorArray) { + transformedValue = conditionsValidateOptionValue(descriptor, transformedValue); + } if (hasOwn(operatorDescriptor, 'transformReverse')) { transformedValue = operatorDescriptor.transformReverse(transformedValue); } - return transformedValue; + + return [transformedValue, inputTransformedValue]; } function conditionsTestValueThrowing(descriptors, type, operator, optionValue, value) { |