@@ -1043,18 +1043,96 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) {
1043
1043
1044
1044
if ( relativeTo . vocab && '@vocab' in activeCtx ) {
1045
1045
// prepend vocab
1046
- value = activeCtx [ '@vocab' ] + value ;
1046
+ const prependedResult = activeCtx [ '@vocab' ] + value ;
1047
+ let expansionMapResult = undefined ;
1048
+ if ( options && options . expansionMap ) {
1049
+ // if we are about to expand the value by prepending
1050
+ // @vocab then call the expansion map to inform
1051
+ // interested callers that this is occurring
1052
+
1053
+ // TODO: use `await` to support async
1054
+ expansionMapResult = options . expansionMap ( {
1055
+ prependedIri : {
1056
+ type : '@vocab' ,
1057
+ vocab : activeCtx [ '@vocab' ] ,
1058
+ value,
1059
+ result : prependedResult
1060
+ } ,
1061
+ activeCtx,
1062
+ options
1063
+ } ) ;
1064
+
1065
+ }
1066
+ if ( expansionMapResult !== undefined ) {
1067
+ value = expansionMapResult ;
1068
+ } else {
1069
+ // the null case preserves value as potentially relative
1070
+ value = prependedResult ;
1071
+ }
1047
1072
} else if ( relativeTo . base && '@base' in activeCtx ) {
1048
1073
// prepend base
1049
1074
if ( activeCtx [ '@base' ] ) {
1050
- // The null case preserves value as potentially relative
1051
- value = prependBase ( prependBase ( options . base , activeCtx [ '@base' ] ) , value ) ;
1075
+ const prependedResult = prependBase (
1076
+ prependBase ( options . base , activeCtx [ '@base' ] ) , value ) ;
1077
+
1078
+ let expansionMapResult = undefined ;
1079
+ if ( options && options . expansionMap ) {
1080
+ // if we are about to expand the value by prepending
1081
+ // @base then call the expansion map to inform
1082
+ // interested callers that this is occurring
1083
+
1084
+ // TODO: use `await` to support async
1085
+ expansionMapResult = options . expansionMap ( {
1086
+ prependedIri : {
1087
+ type : '@base' ,
1088
+ base : activeCtx [ '@base' ] ,
1089
+ value,
1090
+ result : prependedResult
1091
+ } ,
1092
+ activeCtx,
1093
+ options
1094
+ } ) ;
1095
+ }
1096
+ if ( expansionMapResult !== undefined ) {
1097
+ value = expansionMapResult ;
1098
+ } else {
1099
+ // the null case preserves value as potentially relative
1100
+ value = prependedResult ;
1101
+ }
1052
1102
}
1053
1103
} else if ( relativeTo . base ) {
1054
- value = prependBase ( options . base , value ) ;
1104
+ const prependedResult = prependBase ( options . base , value ) ;
1105
+ let expansionMapResult = undefined ;
1106
+ if ( options && options . expansionMap ) {
1107
+ // if we are about to expand the value by prepending
1108
+ // @base then call the expansion map to inform
1109
+ // interested callers that this is occurring
1110
+
1111
+ // TODO: use `await` to support async
1112
+ expansionMapResult = options . expansionMap ( {
1113
+ prependedIri : {
1114
+ type : '@base' ,
1115
+ base : options . base ,
1116
+ value,
1117
+ result : prependedResult
1118
+ } ,
1119
+ activeCtx,
1120
+ options
1121
+ } ) ;
1122
+ }
1123
+ if ( expansionMapResult !== undefined ) {
1124
+ value = expansionMapResult ;
1125
+ } else {
1126
+ value = prependedResult ;
1127
+ }
1055
1128
}
1056
1129
1057
- if ( ! _isAbsoluteIri ( value ) && options . expansionMap ) {
1130
+ if ( ! _isAbsoluteIri ( value ) && options && options . expansionMap ) {
1131
+ // if the result of the expansion is not an absolute iri then
1132
+ // call the expansion map to inform interested callers that
1133
+ // the resulting value is a relative iri, which can result in
1134
+ // it being dropped when converting to other RDF representations
1135
+
1058
1136
// TODO: use `await` to support async
1059
1137
const expandedResult = options . expansionMap ( {
1060
1138
relativeIri : value ,
0 commit comments