Skip to content

Commit

Permalink
language: unflattenLanguageSpec: no lonely '_' keys
Browse files Browse the repository at this point in the history
This might be a crude implementation, but keeps language results
from including {_: 'some string...'} objects that don't have any
other keys, even when preventing so causes a mismatch with the
reference spec/layout. (Of course, the "mismatch" is only
presentationally and not semantically, and we already make other
presentational differences because we output JSON and not YAML
in this function.)
  • Loading branch information
towerofnix committed Dec 29, 2024
1 parent 9d34998 commit 4dc27c4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/data/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ export function unflattenLanguageSpec(flat, reference) {
return {[firstKey]: result};
}

const resultKeys = Object.keys(result);
if (resultKeys.length === 1 && resultKeys[0] === '_') {
return {[firstKey]: result._};
}

if (refKeys.length > 1) {
return withEntries(result, entries =>
entries.map(([key, value]) => [`${firstKey}.${key}`, value]));
Expand Down

0 comments on commit 4dc27c4

Please sign in to comment.