Skip to content

Commit 7463ebc

Browse files
tplookerdavidlehn
authored andcommitted
fix: call expansion map from _expandIri instead of _expandObject
1 parent ac309fe commit 7463ebc

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

lib/context.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,18 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) {
10531053
return prependBase(prependBase(options.base, activeCtx['@base']), value);
10541054
}
10551055
} else if(relativeTo.base) {
1056-
return prependBase(options.base, value);
1056+
value = prependBase(options.base, value);
1057+
}
1058+
1059+
if(!_isAbsoluteIri(value) && options.expansionMap) {
1060+
// TODO: use `await` to support async
1061+
const expandedResult = options.expansionMap({
1062+
relativeIri: value,
1063+
activeCtx,
1064+
});
1065+
if(expandedResult !== undefined) {
1066+
value = expandedResult;
1067+
}
10571068
}
10581069

10591070
return value;

lib/expand.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ async function _expandObject({
420420
const nests = [];
421421
let unexpandedValue;
422422

423+
// Add expansion map to the processing options
424+
options = {...options, expansionMap};
425+
423426
// Figure out if this is the type for a JSON literal
424427
const isJsonType = element[typeKey] &&
425428
_expandIri(activeCtx,

tests/misc.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ describe('expansionMap', () => {
534534

535535
let expansionMapCalled = false;
536536
const expansionMap = info => {
537-
if(info.relativeIri && info.relativeIri.value === 'relativeiri') {
537+
if(info.relativeIri === 'relativeiri') {
538538
expansionMapCalled = true;
539539
}
540540
};
@@ -557,7 +557,7 @@ describe('expansionMap', () => {
557557

558558
let expansionMapCalled = false;
559559
const expansionMap = info => {
560-
if(info.relativeIri && info.relativeIri.value === 'relativeiri') {
560+
if(info.relativeIri === 'relativeiri') {
561561
expansionMapCalled = true;
562562
}
563563
};
@@ -579,7 +579,7 @@ describe('expansionMap', () => {
579579

580580
let expansionMapCalled = false;
581581
const expansionMap = info => {
582-
if(info.relativeIri && info.relativeIri.value === 'relativeiri') {
582+
if(info.relativeIri === 'relativeiri') {
583583
expansionMapCalled = true;
584584
}
585585
};
@@ -601,7 +601,7 @@ describe('expansionMap', () => {
601601

602602
let expansionMapCalled = false;
603603
const expansionMap = info => {
604-
if(info.relativeIri && info.relativeIri.value === 'relativeiri') {
604+
if(info.relativeIri === 'relativeiri') {
605605
expansionMapCalled = true;
606606
}
607607
};
@@ -624,16 +624,15 @@ describe('expansionMap', () => {
624624

625625
let expansionMapCalledTimes = 0;
626626
const expansionMap = info => {
627-
if(info.relativeIri &&
628-
(info.relativeIri.value === 'relativeiri' ||
629-
info.relativeIri.value === 'anotherRelativeiri')) {
627+
if(info.relativeIri === 'relativeiri' ||
628+
info.relativeIri === 'anotherRelativeiri') {
630629
expansionMapCalledTimes++;
631630
}
632631
};
633632

634633
await jsonld.expand(docWithRelativeIriId, {expansionMap});
635634

636-
assert.equal(expansionMapCalledTimes, 2);
635+
assert.equal(expansionMapCalledTimes, 3);
637636
});
638637

639638
it('should be called on relative iri for \
@@ -649,7 +648,7 @@ describe('expansionMap', () => {
649648

650649
let expansionMapCalled = false;
651650
const expansionMap = info => {
652-
if(info.relativeIri && info.relativeIri.value === 'relativeiri') {
651+
if(info.relativeIri === 'relativeiri') {
653652
expansionMapCalled = true;
654653
}
655654
};
@@ -672,7 +671,7 @@ describe('expansionMap', () => {
672671

673672
let expansionMapCalled = false;
674673
const expansionMap = info => {
675-
if(info.relativeIri && info.relativeIri.value === 'relativeiri') {
674+
if(info.relativeIri === 'relativeiri') {
676675
expansionMapCalled = true;
677676
}
678677
};

0 commit comments

Comments
 (0)