@@ -610,14 +610,19 @@ async function _expandObject({
610610 } else if ( container . includes ( '@index' ) && _isObject ( value ) ) {
611611 // handle index container (skip if value is not an object)
612612 const asGraph = container . includes ( '@graph' ) ;
613+ const indexKey = _getContextValue ( termCtx , key , '@index' ) || '@index' ;
614+ const propertyIndex = indexKey !== '@index' &&
615+ _expandIri ( activeCtx , indexKey , { vocab : true } , options ) ;
616+
613617 expandedValue = await _expandIndexMap ( {
614618 activeCtx : termCtx ,
615619 options,
616620 activeProperty : key ,
617621 value,
618622 expansionMap,
619623 asGraph,
620- indexKey : '@index'
624+ indexKey : indexKey ,
625+ propertyIndex
621626 } ) ;
622627 } else if ( container . includes ( '@id' ) && _isObject ( value ) ) {
623628 // handle id container (skip if value is not an object)
@@ -890,7 +895,7 @@ function _expandLanguageMap(activeCtx, languageMap, options) {
890895
891896async function _expandIndexMap (
892897 { activeCtx, options, activeProperty, value, expansionMap, asGraph,
893- indexKey} ) {
898+ indexKey, propertyIndex } ) {
894899 const rval = [ ] ;
895900 const keys = Object . keys ( value ) . sort ( ) ;
896901 const isTypeIndex = indexKey === '@type' ;
@@ -913,15 +918,6 @@ async function _expandIndexMap(
913918 val = [ val ] ;
914919 }
915920
916- // expand for @type , but also for @none
917- const expandedKey = _expandIri ( activeCtx , key , { vocab : true } , options ) ;
918- if ( indexKey === '@id' ) {
919- // expand document relative
920- key = _expandIri ( activeCtx , key , { base : true } , options ) ;
921- } else if ( isTypeIndex ) {
922- key = expandedKey ;
923- }
924-
925921 val = await api . expand ( {
926922 activeCtx,
927923 activeProperty,
@@ -931,6 +927,26 @@ async function _expandIndexMap(
931927 insideIndex : true ,
932928 expansionMap
933929 } ) ;
930+
931+ // expand for @type , but also for @none
932+ let expandedKey ;
933+ if ( propertyIndex ) {
934+ if ( key === '@none' ) {
935+ expandedKey = '@none'
936+ } else {
937+ expandedKey = _expandValue ( { activeCtx, activeProperty : indexKey , value : key , options} ) ;
938+ }
939+ } else {
940+ expandedKey = _expandIri ( activeCtx , key , { vocab : true } , options ) ;
941+ }
942+
943+ if ( indexKey === '@id' ) {
944+ // expand document relative
945+ key = _expandIri ( activeCtx , key , { base : true } , options ) ;
946+ } else if ( isTypeIndex ) {
947+ key = expandedKey ;
948+ }
949+
934950 for ( let item of val ) {
935951 // If this is also a @graph container, turn items into graphs
936952 if ( asGraph && ! _isGraph ( item ) ) {
@@ -944,6 +960,20 @@ async function _expandIndexMap(
944960 } else {
945961 item [ '@type' ] = [ key ] ;
946962 }
963+ } else if ( _isValue ( item ) && ! [ '@language' , '@type' , '@index' ] . includes ( indexKey ) ) {
964+ throw new JsonLdError (
965+ 'Invalid JSON-LD syntax; Attempt to add illegal key to value object: ${indexKey}.' ,
966+ 'jsonld.SyntaxError' ,
967+ { code : 'invalid value object' , value : item } ) ;
968+ } else if ( propertyIndex ) {
969+ // index is a property to be expanded, and values interpreted for that property
970+ if ( expandedKey !== '@none' ) {
971+ // expand key as a value
972+ _addValue ( item , propertyIndex , expandedKey , {
973+ propertyIsArray : true ,
974+ prependValue : true
975+ } ) ;
976+ }
947977 } else if ( expandedKey !== '@none' && ! ( indexKey in item ) ) {
948978 item [ indexKey ] = key ;
949979 }
0 commit comments