@@ -161,12 +161,15 @@ api.compact = ({
161
161
if ( types . length > 1 ) {
162
162
types = Array . from ( types ) . sort ( ) ;
163
163
}
164
+ // find all type-scoped contexts based on current context, prior to
165
+ // updating it
166
+ const typeContext = activeCtx ;
164
167
for ( const type of types ) {
165
168
const compactedType = api . compactIri (
166
- { activeCtx, iri : type , relativeTo : { vocab : true } } ) ;
169
+ { activeCtx : typeContext , iri : type , relativeTo : { vocab : true } } ) ;
167
170
168
171
// Use any type-scoped context defined on this value
169
- const ctx = _getContextValue ( activeCtx , compactedType , '@context' ) ;
172
+ const ctx = _getContextValue ( typeContext , compactedType , '@context' ) ;
170
173
if ( ! _isUndefined ( ctx ) ) {
171
174
activeCtx = _processContext ( {
172
175
activeCtx,
@@ -184,13 +187,16 @@ api.compact = ({
184
187
185
188
// compact @id and @type(s)
186
189
if ( expandedProperty === '@id' || expandedProperty === '@type' ) {
190
+ // if using a type-scoped context, resolve type values against previous
191
+ // context
192
+ const isType = expandedProperty === '@type' ;
193
+ const valueContext = isType ?
194
+ ( activeCtx . previousContext || activeCtx ) : activeCtx ;
187
195
let compactedValue = _asArray ( expandedValue ) . map (
188
196
expandedIri => api . compactIri ( {
189
- activeCtx,
197
+ activeCtx : valueContext ,
190
198
iri : expandedIri ,
191
- relativeTo : {
192
- vocab : expandedProperty === '@type'
193
- }
199
+ relativeTo : { vocab : isType }
194
200
} ) ) ;
195
201
if ( compactedValue . length === 1 ) {
196
202
compactedValue = compactedValue [ 0 ] ;
0 commit comments