@@ -341,7 +341,7 @@ api.expand = ({
341
341
342
342
if ( container . includes ( '@language' ) && _isObject ( value ) ) {
343
343
// handle language map container (skip if value is not an object)
344
- expandedValue = _expandLanguageMap ( value ) ;
344
+ expandedValue = _expandLanguageMap ( termCtx , value ) ;
345
345
} else if ( container . includes ( '@index' ) && _isObject ( value ) ) {
346
346
// handle index container (skip if value is not an object)
347
347
const asGraph = container . includes ( '@graph' ) ;
@@ -665,21 +665,21 @@ function _expandValue({activeCtx, activeProperty, value}) {
665
665
/**
666
666
* Expands a language map.
667
667
*
668
+ * @param activeCtx the active context to use.
668
669
* @param languageMap the language map to expand.
669
670
*
670
671
* @return the expanded language map.
671
672
*/
672
- function _expandLanguageMap ( languageMap ) {
673
+ function _expandLanguageMap ( activeCtx , languageMap ) {
673
674
const rval = [ ] ;
674
675
const keys = Object . keys ( languageMap ) . sort ( ) ;
675
- for ( let ki = 0 ; ki < keys . length ; ++ ki ) {
676
- const key = keys [ ki ] ;
676
+ for ( let key of keys ) {
677
+ const expandedKey = _expandIri ( activeCtx , key , { vocab : true } )
677
678
let val = languageMap [ key ] ;
678
679
if ( ! _isArray ( val ) ) {
679
680
val = [ val ] ;
680
681
}
681
- for ( let vi = 0 ; vi < val . length ; ++ vi ) {
682
- const item = val [ vi ] ;
682
+ for ( let item of val ) {
683
683
if ( item === null ) {
684
684
// null values are allowed (8.5) but ignored (3.1)
685
685
continue ;
@@ -690,10 +690,11 @@ function _expandLanguageMap(languageMap) {
690
690
'jsonld.SyntaxError' ,
691
691
{ code : 'invalid language map value' , languageMap : languageMap } ) ;
692
692
}
693
- rval . push ( {
694
- '@value' : item ,
695
- '@language' : key . toLowerCase ( )
696
- } ) ;
693
+ const val = { '@value' : item } ;
694
+ if ( expandedKey !== '@none' ) {
695
+ val [ '@language' ] = key . toLowerCase ( ) ;
696
+ }
697
+ rval . push ( val ) ;
697
698
}
698
699
}
699
700
return rval ;
@@ -703,21 +704,27 @@ function _expandIndexMap(
703
704
{ activeCtx, options, activeProperty, value, expansionMap, asGraph, indexKey} ) {
704
705
const rval = [ ] ;
705
706
const keys = Object . keys ( value ) . sort ( ) ;
706
- for ( let ki = 0 ; ki < keys . length ; ++ ki ) {
707
+ for ( let key of keys ) {
707
708
// if indexKey is @type , there may be a context defined for it
708
- const ctx = _getContextValue ( activeCtx , keys [ ki ] , '@context' ) ;
709
+ const ctx = _getContextValue ( activeCtx , key , '@context' ) ;
709
710
if ( ctx ) {
710
711
activeCtx = _processContext ( { activeCtx, localCtx : ctx , options} ) ;
711
712
}
712
713
713
- // if indexKey is @id or @type, expand the key appropriately
714
- const key = ( indexKey === '@id' || indexKey === '@type' ) ?
715
- _expandIri ( activeCtx , keys [ ki ] , { vocab : ( indexKey === '@type' ) , base : true } ) :
716
- keys [ ki ] ;
717
- let val = value [ keys [ ki ] ] ;
714
+ let val = value [ key ] ;
718
715
if ( ! _isArray ( val ) ) {
719
716
val = [ val ] ;
720
717
}
718
+
719
+ // expand for @type , but also for @none
720
+ const expandedKey = _expandIri ( activeCtx , key , { vocab : true } )
721
+ if ( indexKey === '@id' ) {
722
+ // expand document relative
723
+ key = _expandIri ( activeCtx , key , { base : true } ) ;
724
+ } else if ( indexKey === '@type' ) {
725
+ key = expandedKey ;
726
+ }
727
+
721
728
val = api . expand ( {
722
729
activeCtx,
723
730
activeProperty,
@@ -726,20 +733,20 @@ function _expandIndexMap(
726
733
insideList : false ,
727
734
expansionMap
728
735
} ) ;
729
- for ( let vi = 0 ; vi < val . length ; ++ vi ) {
730
- let item = val [ vi ] ;
731
-
736
+ for ( let item of val ) {
732
737
// If this is also a @graph container, turn items into graphs
733
738
if ( asGraph && ! _isGraph ( item ) ) {
734
739
item = { '@graph' : [ item ] } ;
735
740
}
736
741
if ( indexKey === '@type' ) {
737
- if ( item [ '@type' ] ) {
742
+ if ( expandedKey === '@none' ) {
743
+ // ignore @none
744
+ } else if ( item [ '@type' ] ) {
738
745
item [ '@type' ] = [ key ] . concat ( item [ '@type' ] ) ;
739
746
} else {
740
747
item [ '@type' ] = [ key ] ;
741
748
}
742
- } else if ( ! ( indexKey in item ) ) {
749
+ } else if ( expandedKey !== '@none' && ! ( indexKey in item ) ) {
743
750
item [ indexKey ] = key ;
744
751
}
745
752
rval . push ( item ) ;
0 commit comments