@@ -341,7 +341,7 @@ api.expand = ({
341341
342342 if ( container . includes ( '@language' ) && _isObject ( value ) ) {
343343 // handle language map container (skip if value is not an object)
344- expandedValue = _expandLanguageMap ( value ) ;
344+ expandedValue = _expandLanguageMap ( termCtx , value ) ;
345345 } else if ( container . includes ( '@index' ) && _isObject ( value ) ) {
346346 // handle index container (skip if value is not an object)
347347 const asGraph = container . includes ( '@graph' ) ;
@@ -665,21 +665,21 @@ function _expandValue({activeCtx, activeProperty, value}) {
665665/**
666666 * Expands a language map.
667667 *
668+ * @param activeCtx the active context to use.
668669 * @param languageMap the language map to expand.
669670 *
670671 * @return the expanded language map.
671672 */
672- function _expandLanguageMap ( languageMap ) {
673+ function _expandLanguageMap ( activeCtx , languageMap ) {
673674 const rval = [ ] ;
674675 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 } )
677678 let val = languageMap [ key ] ;
678679 if ( ! _isArray ( val ) ) {
679680 val = [ val ] ;
680681 }
681- for ( let vi = 0 ; vi < val . length ; ++ vi ) {
682- const item = val [ vi ] ;
682+ for ( let item of val ) {
683683 if ( item === null ) {
684684 // null values are allowed (8.5) but ignored (3.1)
685685 continue ;
@@ -690,10 +690,11 @@ function _expandLanguageMap(languageMap) {
690690 'jsonld.SyntaxError' ,
691691 { code : 'invalid language map value' , languageMap : languageMap } ) ;
692692 }
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 ) ;
697698 }
698699 }
699700 return rval ;
@@ -703,21 +704,27 @@ function _expandIndexMap(
703704 { activeCtx, options, activeProperty, value, expansionMap, asGraph, indexKey} ) {
704705 const rval = [ ] ;
705706 const keys = Object . keys ( value ) . sort ( ) ;
706- for ( let ki = 0 ; ki < keys . length ; ++ ki ) {
707+ for ( let key of keys ) {
707708 // 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' ) ;
709710 if ( ctx ) {
710711 activeCtx = _processContext ( { activeCtx, localCtx : ctx , options} ) ;
711712 }
712713
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 ] ;
718715 if ( ! _isArray ( val ) ) {
719716 val = [ val ] ;
720717 }
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+
721728 val = api . expand ( {
722729 activeCtx,
723730 activeProperty,
@@ -726,20 +733,20 @@ function _expandIndexMap(
726733 insideList : false ,
727734 expansionMap
728735 } ) ;
729- for ( let vi = 0 ; vi < val . length ; ++ vi ) {
730- let item = val [ vi ] ;
731-
736+ for ( let item of val ) {
732737 // If this is also a @graph container, turn items into graphs
733738 if ( asGraph && ! _isGraph ( item ) ) {
734739 item = { '@graph' : [ item ] } ;
735740 }
736741 if ( indexKey === '@type' ) {
737- if ( item [ '@type' ] ) {
742+ if ( expandedKey === '@none' ) {
743+ // ignore @none
744+ } else if ( item [ '@type' ] ) {
738745 item [ '@type' ] = [ key ] . concat ( item [ '@type' ] ) ;
739746 } else {
740747 item [ '@type' ] = [ key ] ;
741748 }
742- } else if ( ! ( indexKey in item ) ) {
749+ } else if ( expandedKey !== '@none' && ! ( indexKey in item ) ) {
743750 item [ indexKey ] = key ;
744751 }
745752 rval . push ( item ) ;
0 commit comments