Skip to content

Commit 09032fb

Browse files
committed
Improve container ordering for term selection due to json-ld/json-ld.org#569.
1 parent 4aa55b3 commit 09032fb

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
@@ -500,7 +500,7 @@ api.compactIri = ({
500500
containers.push(
501501
'@graph@id', '@graph@id@set');
502502
}
503-
containers.push('@graph', '@graph@set');
503+
containers.push('@graph', '@graph@set', '@set');
504504
// allow indexmap if the graph is not indexed
505505
if(!('@index' in value)) {
506506
containers.push('@graph@index', '@graph@index@set', '@index', '@index@set');
@@ -585,23 +585,29 @@ api.compactIri = ({
585585
} else if('@type' in value) {
586586
typeOrLanguage = '@type';
587587
typeOrLanguageValue = value['@type'];
588-
} else if(!('@index' in value)) {
589-
// allw indexing by language even if no language present
590-
containers.push('@language', '@language@set');
591588
}
592589
} else {
593590
typeOrLanguage = '@type';
594591
typeOrLanguageValue = '@id';
595592
}
596-
if(_isObject(value) && !('@index' in value)) {
597-
// allow indexing even if no @index present
598-
containers.push('@index', '@index@set');
599-
}
600593
containers.push('@set');
601594
}
602595

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

0 commit comments

Comments
 (0)