@@ -161,12 +161,15 @@ api.compact = ({
161161 if ( types . length > 1 ) {
162162 types = Array . from ( types ) . sort ( ) ;
163163 }
164+ // find all type-scoped contexts based on current context, prior to
165+ // updating it
166+ const typeContext = activeCtx ;
164167 for ( const type of types ) {
165168 const compactedType = api . compactIri (
166- { activeCtx, iri : type , relativeTo : { vocab : true } } ) ;
169+ { activeCtx : typeContext , iri : type , relativeTo : { vocab : true } } ) ;
167170
168171 // Use any type-scoped context defined on this value
169- const ctx = _getContextValue ( activeCtx , compactedType , '@context' ) ;
172+ const ctx = _getContextValue ( typeContext , compactedType , '@context' ) ;
170173 if ( ! _isUndefined ( ctx ) ) {
171174 activeCtx = _processContext ( {
172175 activeCtx,
@@ -184,13 +187,16 @@ api.compact = ({
184187
185188 // compact @id and @type(s)
186189 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 ;
187195 let compactedValue = _asArray ( expandedValue ) . map (
188196 expandedIri => api . compactIri ( {
189- activeCtx,
197+ activeCtx : valueContext ,
190198 iri : expandedIri ,
191- relativeTo : {
192- vocab : expandedProperty === '@type'
193- }
199+ relativeTo : { vocab : isType }
194200 } ) ) ;
195201 if ( compactedValue . length === 1 ) {
196202 compactedValue = compactedValue [ 0 ] ;
0 commit comments