Skip to content

Commit 855e377

Browse files
committed
Correct logic on value detection.
1 parent d453bc5 commit 855e377

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

lib/expand.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -169,26 +169,21 @@ api.expand = ({
169169
(activeCtx.previousContext ? activeCtx : null);
170170
let keys = Object.keys(element).sort();
171171
let mustRevert = !insideIndex;
172-
if(mustRevert && typeScopedContext && keys[0] !== '@context') {
173-
// check if element is a subject reference
174-
if(keys.length === 1) {
172+
if(mustRevert && typeScopedContext && keys.length <= 2 &&
173+
!keys.includes('@context')) {
174+
for(const key of keys) {
175175
const expandedProperty = _expandIri(
176-
typeScopedContext, keys[0], {vocab: true}, options);
177-
if(expandedProperty === '@id') {
178-
// subject reference found, do not revert
176+
typeScopedContext, key, {vocab: true}, options);
177+
if(expandedProperty === '@value') {
178+
// value found, ensure type-scoped context is used to expand it
179179
mustRevert = false;
180+
activeCtx = typeScopedContext;
181+
break;
180182
}
181-
} else if(keys.length <= 2) {
182-
// check if element is a value
183-
for(const key of keys) {
184-
const expandedProperty = _expandIri(
185-
typeScopedContext, key, {vocab: true}, options);
186-
if(expandedProperty === '@value') {
187-
// value found, ensure type-scoped context is used to expand it
188-
mustRevert = false;
189-
activeCtx = typeScopedContext;
190-
break;
191-
}
183+
if(expandedProperty === '@id' && keys.length === 1) {
184+
// subject reference found, do not revert
185+
mustRevert = false;
186+
break;
192187
}
193188
}
194189
}

0 commit comments

Comments
 (0)