@@ -50,7 +50,7 @@ module.exports = api;
50
50
* @param element the element to expand.
51
51
* @param options the expansion options.
52
52
* @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,
54
54
* false if not.
55
55
* @param expansionMap(info) a function that can be used to custom map
56
56
* unmappable values (or to throw an error when they are detected);
@@ -65,7 +65,7 @@ api.expand = ({
65
65
element,
66
66
options = { } ,
67
67
insideList = false ,
68
- insideTypeContainer = false ,
68
+ insideIndex = false ,
69
69
expansionMap = ( ) => undefined
70
70
} ) => {
71
71
// nothing to expand
@@ -115,7 +115,7 @@ api.expand = ({
115
115
element : element [ i ] ,
116
116
options,
117
117
expansionMap,
118
- insideTypeContainer
118
+ insideIndex
119
119
} ) ;
120
120
if ( insideList && ( _isArray ( e ) || _isList ( e ) ) ) {
121
121
// lists of lists are illegal
@@ -152,7 +152,7 @@ api.expand = ({
152
152
153
153
// recursively expand object:
154
154
155
- if ( ! insideTypeContainer ) {
155
+ if ( ! insideIndex ) {
156
156
// revert type scoped terms
157
157
activeCtx = activeCtx . revertTypeScopedTerms ( ) ;
158
158
}
@@ -613,7 +613,8 @@ function _expandObject({
613
613
} else if ( container . includes ( '@type' ) && _isObject ( value ) ) {
614
614
// handle type container (skip if value is not an object)
615
615
expandedValue = _expandIndexMap ( {
616
- activeCtx : termCtx ,
616
+ // since container is `@type`, revert type scoped terms when expanding
617
+ activeCtx : termCtx . revertTypeScopedTerms ( ) ,
617
618
options,
618
619
activeProperty : key ,
619
620
value,
@@ -854,19 +855,19 @@ function _expandIndexMap(
854
855
indexKey} ) {
855
856
const rval = [ ] ;
856
857
const keys = Object . keys ( value ) . sort ( ) ;
858
+ const isTypeIndex = indexKey === '@type' ;
857
859
for ( let key of keys ) {
858
860
// 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
+ }
870
871
}
871
872
872
873
let val = value [ key ] ;
@@ -879,7 +880,7 @@ function _expandIndexMap(
879
880
if ( indexKey === '@id' ) {
880
881
// expand document relative
881
882
key = _expandIri ( activeCtx , key , { base : true } , options ) ;
882
- } else if ( indexKey === '@type' ) {
883
+ } else if ( isTypeIndex ) {
883
884
key = expandedKey ;
884
885
}
885
886
@@ -889,7 +890,7 @@ function _expandIndexMap(
889
890
element : val ,
890
891
options,
891
892
insideList : false ,
892
- insideTypeContainer : indexKey === '@type' ,
893
+ insideIndex : true ,
893
894
expansionMap
894
895
} ) ;
895
896
for ( let item of val ) {
0 commit comments