Skip to content

Commit 2e0bc2f

Browse files
gkelloggdavidlehn
authored andcommitted
Improve container ordering for term selection due to json-ld/json-ld.org#569.
1 parent 5ee8969 commit 2e0bc2f

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/compact.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ api.compactIri = ({
501501
containers.push(
502502
'@graph@id', '@graph@id@set');
503503
}
504-
containers.push('@graph', '@graph@set');
504+
containers.push('@graph', '@graph@set', '@set');
505505
// allow indexmap if the graph is not indexed
506506
if(!('@index' in value)) {
507507
containers.push('@graph@index', '@graph@index@set', '@index', '@index@set');
@@ -586,23 +586,29 @@ api.compactIri = ({
586586
} else if('@type' in value) {
587587
typeOrLanguage = '@type';
588588
typeOrLanguageValue = value['@type'];
589-
} else if(!('@index' in value)) {
590-
// allw indexing by language even if no language present
591-
containers.push('@language', '@language@set');
592589
}
593590
} else {
594591
typeOrLanguage = '@type';
595592
typeOrLanguageValue = '@id';
596593
}
597-
if(_isObject(value) && !('@index' in value)) {
598-
// allow indexing even if no @index present
599-
containers.push('@index', '@index@set');
600-
}
601594
containers.push('@set');
602595
}
603596

604597
// do term selection
605598
containers.push('@none');
599+
600+
// an index map can be used to index values using @none, so add as a low priority
601+
if(_isObject(value) && !('@index' in value)) {
602+
// allow indexing even if no @index present
603+
containers.push('@index', '@index@set');
604+
}
605+
606+
// values without type or language can use @language map
607+
if(_isValue(value) && Object.keys(value).length === 1) {
608+
// allow indexing even if no @index present
609+
containers.push('@language', '@language@set');
610+
}
611+
606612
const term = _selectTerm(
607613
activeCtx, iri, value, containers, typeOrLanguage, typeOrLanguageValue);
608614
if(term !== null) {

0 commit comments

Comments
 (0)