@@ -219,31 +219,47 @@ api.compact = async ({
219219 for ( const expandedProperty of keys ) {
220220 const expandedValue = element [ expandedProperty ] ;
221221
222- // compact @id and @type(s)
223- if ( expandedProperty === '@id' || expandedProperty === '@type' ) {
224- // if using a type-scoped context, resolve type values against previous
225- // context
226- const isType = expandedProperty === '@type' ;
227- const valueContext = isType ?
228- ( activeCtx . previousContext || activeCtx ) : activeCtx ;
222+ // compact @id
223+ if ( expandedProperty === '@id' ) {
229224 let compactedValue = _asArray ( expandedValue ) . map (
230225 expandedIri => api . compactIri ( {
231- activeCtx : valueContext ,
226+ activeCtx,
227+ iri : expandedIri ,
228+ relativeTo : { vocab : false }
229+ } ) ) ;
230+ if ( compactedValue . length === 1 ) {
231+ compactedValue = compactedValue [ 0 ] ;
232+ }
233+
234+ // use keyword alias and add value
235+ const alias = api . compactIri (
236+ { activeCtx, iri : '@id' , relativeTo : { vocab : true } } ) ;
237+
238+ rval [ alias ] = compactedValue ;
239+ continue ;
240+ }
241+
242+ // compact @type (s)
243+ if ( expandedProperty === '@type' ) {
244+ // resolve type values against previous context
245+ let compactedValue = _asArray ( expandedValue ) . map (
246+ expandedIri => api . compactIri ( {
247+ activeCtx : inputCtx ,
232248 iri : expandedIri ,
233- relativeTo : { vocab : isType }
249+ relativeTo : { vocab : true }
234250 } ) ) ;
235251 if ( compactedValue . length === 1 ) {
236252 compactedValue = compactedValue [ 0 ] ;
237253 }
238254
239255 // use keyword alias and add value
240256 const alias = api . compactIri (
241- { activeCtx, iri : expandedProperty , relativeTo : { vocab : true } } ) ;
257+ { activeCtx, iri : '@type' , relativeTo : { vocab : true } } ) ;
242258 const container = _getContextValue (
243259 activeCtx , alias , '@container' ) || [ ] ;
244260
245261 // treat as array for @type if @container includes @set
246- const typeAsSet = isType &&
262+ const typeAsSet =
247263 container . includes ( '@set' ) &&
248264 _processingMode ( activeCtx , 1.1 ) ;
249265 const isArray =
0 commit comments