-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Utkarsh Chaudhary
committed
Aug 2, 2024
1 parent
7b42677
commit c7b3fa4
Showing
3 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Function to merge errors for a11y-engine. | ||
// Handles errors differently for check_errors and other errors. | ||
// It also adds the target selector to the errors for better identification. | ||
|
||
function mergeErrors(mergedErrors, frameErrors, frameSpec) { | ||
for (const [key, value] of Object.entries(frameErrors)) { | ||
if (key === 'check_errors') { | ||
if (!mergedErrors[key]) { | ||
mergedErrors[key] = {}; | ||
} | ||
|
||
for (const [checkNameKey, checkNameValue] of Object.entries(value)) { | ||
// Add the target if not present. If present then append parents target. | ||
checkNameValue.forEach(checkNameValueError => { | ||
if (!checkNameValueError.target && frameSpec) { | ||
checkNameValueError.target = frameSpec?.selector; | ||
} else if (checkNameValueError.target && frameSpec) { | ||
checkNameValueError.target = [ | ||
...frameSpec.selector, | ||
...checkNameValueError.target | ||
]; | ||
} | ||
}); | ||
if (mergedErrors[key][checkNameKey]) { | ||
mergedErrors[key][checkNameKey].push(...checkNameValue); | ||
} else { | ||
mergedErrors[key][checkNameKey] = Array.isArray(checkNameValue) | ||
? [...checkNameValue] | ||
: [checkNameValue]; | ||
} | ||
} | ||
} else { | ||
// Add the target if not present. If present then append parents target. | ||
value.forEach(errorValue => { | ||
if (!errorValue.target && frameSpec) { | ||
errorValue.target = frameSpec?.selector; | ||
} else if (errorValue.target && frameSpec) { | ||
errorValue.target = [...frameSpec.selector, ...errorValue.target]; | ||
} | ||
}); | ||
if (mergedErrors[key]) { | ||
mergedErrors[key] = [...mergedErrors[key], ...value]; | ||
} else { | ||
mergedErrors[key] = value; | ||
} | ||
} | ||
} | ||
|
||
return mergedErrors; | ||
} | ||
|
||
export default mergeErrors; |