@@ -50,7 +50,7 @@ module.exports = api;
5050 * @param element the element to expand.
5151 * @param options the expansion options.
5252 * @param insideList true if the element is a list, false if not.
53- * @param insideTypeContainer true if the element is inside a type container,
53+ * @param insideIndex true if the element is inside an index container,
5454 * false if not.
5555 * @param expansionMap(info) a function that can be used to custom map
5656 * unmappable values (or to throw an error when they are detected);
@@ -65,7 +65,7 @@ api.expand = ({
6565 element,
6666 options = { } ,
6767 insideList = false ,
68- insideTypeContainer = false ,
68+ insideIndex = false ,
6969 expansionMap = ( ) => undefined
7070} ) => {
7171 // nothing to expand
@@ -115,7 +115,7 @@ api.expand = ({
115115 element : element [ i ] ,
116116 options,
117117 expansionMap,
118- insideTypeContainer
118+ insideIndex
119119 } ) ;
120120 if ( insideList && ( _isArray ( e ) || _isList ( e ) ) ) {
121121 // lists of lists are illegal
@@ -152,7 +152,7 @@ api.expand = ({
152152
153153 // recursively expand object:
154154
155- if ( ! insideTypeContainer ) {
155+ if ( ! insideIndex ) {
156156 // revert type scoped terms
157157 activeCtx = activeCtx . revertTypeScopedTerms ( ) ;
158158 }
@@ -613,7 +613,8 @@ function _expandObject({
613613 } else if ( container . includes ( '@type' ) && _isObject ( value ) ) {
614614 // handle type container (skip if value is not an object)
615615 expandedValue = _expandIndexMap ( {
616- activeCtx : termCtx ,
616+ // since container is `@type`, revert type scoped terms when expanding
617+ activeCtx : termCtx . revertTypeScopedTerms ( ) ,
617618 options,
618619 activeProperty : key ,
619620 value,
@@ -854,19 +855,19 @@ function _expandIndexMap(
854855 indexKey} ) {
855856 const rval = [ ] ;
856857 const keys = Object . keys ( value ) . sort ( ) ;
858+ const isTypeIndex = indexKey === '@type' ;
857859 for ( let key of keys ) {
858860 // if indexKey is @type , there may be a context defined for it
859- const ctx = _getContextValue ( activeCtx , key , '@context' ) ;
860- if ( ! _isUndefined ( ctx ) ) {
861- // TODO: check that `key` is for `@type` once property indexes
862- // are permitted -- and pass `isPropertyTermScopedContext: true` if
863- // key is a property not an `@type`
864- activeCtx = _processContext ( {
865- activeCtx,
866- localCtx : ctx ,
867- isTypeScopedContext : true ,
868- options
869- } ) ;
861+ if ( isTypeIndex ) {
862+ const ctx = _getContextValue ( activeCtx , key , '@context' ) ;
863+ if ( ! _isUndefined ( ctx ) ) {
864+ activeCtx = _processContext ( {
865+ activeCtx,
866+ localCtx : ctx ,
867+ isTypeScopedContext : true ,
868+ options
869+ } ) ;
870+ }
870871 }
871872
872873 let val = value [ key ] ;
@@ -879,7 +880,7 @@ function _expandIndexMap(
879880 if ( indexKey === '@id' ) {
880881 // expand document relative
881882 key = _expandIri ( activeCtx , key , { base : true } , options ) ;
882- } else if ( indexKey === '@type' ) {
883+ } else if ( isTypeIndex ) {
883884 key = expandedKey ;
884885 }
885886
@@ -889,7 +890,7 @@ function _expandIndexMap(
889890 element : val ,
890891 options,
891892 insideList : false ,
892- insideTypeContainer : indexKey === '@type' ,
893+ insideIndex : true ,
893894 expansionMap
894895 } ) ;
895896 for ( let item of val ) {
0 commit comments