@@ -219,31 +219,47 @@ api.compact = async ({
219
219
for ( const expandedProperty of keys ) {
220
220
const expandedValue = element [ expandedProperty ] ;
221
221
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' ) {
229
224
let compactedValue = _asArray ( expandedValue ) . map (
230
225
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 ,
232
248
iri : expandedIri ,
233
- relativeTo : { vocab : isType }
249
+ relativeTo : { vocab : true }
234
250
} ) ) ;
235
251
if ( compactedValue . length === 1 ) {
236
252
compactedValue = compactedValue [ 0 ] ;
237
253
}
238
254
239
255
// use keyword alias and add value
240
256
const alias = api . compactIri (
241
- { activeCtx, iri : expandedProperty , relativeTo : { vocab : true } } ) ;
257
+ { activeCtx, iri : '@type' , relativeTo : { vocab : true } } ) ;
242
258
const container = _getContextValue (
243
259
activeCtx , alias , '@container' ) || [ ] ;
244
260
245
261
// treat as array for @type if @container includes @set
246
- const typeAsSet = isType &&
262
+ const typeAsSet =
247
263
container . includes ( '@set' ) &&
248
264
_processingMode ( activeCtx , 1.1 ) ;
249
265
const isArray =
0 commit comments