Skip to content

Commit

Permalink
fix: analyze command should detect missing enums
Browse files Browse the repository at this point in the history
  • Loading branch information
Tienisto committed Oct 20, 2024
1 parent e94f93a commit 116d01e
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions slang/lib/src/runner/analyze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,25 @@ void _getMissingTranslationsForOneLocaleRecursive({
final isOutdated = handleOutdated &&
currChild?.modifiers.containsKey(NodeModifiers.outdated) == true;
if (isOutdated || !_checkEquality(baseChild, currChild)) {
// Add whole base node which is expected
_addNodeRecursive(
node: baseChild,
resultMap: resultMap,
addOutdatedModifier: isOutdated,
);
if (baseChild is ContextNode && currChild is ContextNode) {
// Only add missing enums
for (final baseEnum in baseChild.entries.keys) {
if (!currChild.entries.containsKey(baseEnum)) {
_addNodeRecursive(
node: baseChild.entries[baseEnum]!,
resultMap: resultMap,
addOutdatedModifier: isOutdated,
);
}
}
} else {
// Add whole base node which is expected
_addNodeRecursive(
node: baseChild,
resultMap: resultMap,
addOutdatedModifier: isOutdated,
);
}
} else if (baseChild is ObjectNode && !baseChild.isMap) {
// [currChild] passed the previous equality check.
// In this case, both [baseChild] and [currChild] are ObjectNodes
Expand Down Expand Up @@ -282,6 +295,14 @@ bool _checkEquality(Node? a, Node? b) {
if (a is TextNode &&
b is TextNode &&
!_setEquality.equals(a.params, b.params)) {
// different params
return false;
}

if (a is ContextNode &&
b is ContextNode &&
!_setEquality.equals(a.entries.keys.toSet(), b.entries.keys.toSet())) {
// different enums
return false;
}

Expand Down

0 comments on commit 116d01e

Please sign in to comment.