merge method
Merges the results of another scan into this one.
Implementation
@override
void merge(ScanResults results) {
for (final MapEntry<String, List<dynamic>> asset in results.assets.entries) {
if (assets[asset.key]?[GraphIndex.assetDigest] == null) {
assets[asset.key] = asset.value;
}
}
// [type, src, stringUri, show, hide, prefix?, deferred?]]
for (final MapEntry<String, List<List<dynamic>>> directive in results.directives.entries) {
if (!directives.containsKey(directive.key)) {
directives[directive.key] = directive.value;
} else {
final List<List<dynamic>> newDirectives = directive.value;
final List<List<dynamic>> allDirections = List<List<dynamic>>.of(
directives[directive.key]!,
);
for (final List<dynamic> newDir in newDirectives) {
bool isDuplicate = false;
for (final List<dynamic> exDir in allDirections) {
final bool hasNameCombinator =
(newDir[GraphIndex.directiveType] == DirectiveStatement.export ||
newDir[GraphIndex.directiveType] == DirectiveStatement.import);
if (newDir[GraphIndex.directiveType] == exDir[GraphIndex.directiveType] &&
newDir[GraphIndex.directiveSrc] == exDir[GraphIndex.directiveSrc] &&
(!hasNameCombinator ||
(_listEquals(
newDir[GraphIndex.directiveShow],
exDir[GraphIndex.directiveShow],
) &&
_listEquals(
newDir[GraphIndex.directiveHide],
exDir[GraphIndex.directiveHide],
) &&
newDir.elementAtOrNull(GraphIndex.directivePrefix) ==
exDir.elementAtOrNull(
GraphIndex.directivePrefix,
)))) {
isDuplicate = true;
break;
}
}
// If the directive already exists, skip adding it
if (!isDuplicate) {
allDirections.add(newDir);
}
}
directives[directive.key] = allDirections;
}
}
identifiers.addAll(results.identifiers);
}