Skip to content

Commit a6771c9

Browse files
gkelloggdavidlehn
authored andcommitted
Improve support for @preserve when compacting.
1 parent 84fbd04 commit a6771c9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/compact.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,21 @@ api.compact = ({
216216
continue;
217217
}
218218

219+
if(expandedProperty === '@preserve') {
220+
// compact using activeProperty
221+
const compactedValue = api.compact({
222+
activeCtx,
223+
activeProperty,
224+
element: expandedValue,
225+
options,
226+
compactionMap});
227+
228+
if(!(_isArray(compactedValue) && compactedValue.length === 0)) {
229+
_addValue(rval, expandedProperty, compactedValue);
230+
}
231+
continue;
232+
}
233+
219234
// handle @index property
220235
if(expandedProperty === '@index') {
221236
// drop @index if inside an @index container
@@ -511,6 +526,11 @@ api.compactIri = ({
511526
containers.push('@index', '@index@set');
512527
}
513528

529+
// if value is a preserve object, use its value
530+
if(_isObject(value) && '@preserve' in value) {
531+
value = value['@preserve'][0];
532+
}
533+
514534
// prefer most specific container including @graph, prefering @set variations
515535
if(_isGraph(value)) {
516536
// favor indexmap if the graph is indexed

0 commit comments

Comments
 (0)