Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: don't mutate contexts
  • Loading branch information
jeswr committed Oct 28, 2023
commit fb38a6db685ce1487c92d0d5827882476c0a7b99
2 changes: 1 addition & 1 deletion lib/ParsingContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class ParsingContext {
|| scopedContext[key]['@context']['@propagate']; // Propagation is true by default

if (propagate !== false || i === keysOriginal.length - 1 - offset) {
contextRaw = scopedContext;
contextRaw = { ...scopedContext };

// Clean up final context
delete contextRaw['@propagate'];
Expand Down
10 changes: 4 additions & 6 deletions lib/entryhandler/keyword/EntryHandlerKeywordType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,16 @@ export class EntryHandlerKeywordType extends EntryHandlerKeyword {
if (hasTypedScopedContext) {
// Do not propagate by default
scopedContext = scopedContext.then((c) => {
if (!('@propagate' in c.getContextRaw())) {
c.getContextRaw()['@propagate'] = false;
}
let rawContext = c.getContextRaw();

// Set the original context at this depth as a fallback
// This is needed when a context was already defined at the given depth,
// and this context needs to remain accessible from child nodes when propagation is disabled.
if (c.getContextRaw()['@propagate'] === false) {
c.getContextRaw()['@__propagateFallback'] = context.getContextRaw();
if (rawContext['@propagate'] !== true) {
rawContext = { ...rawContext, '@propagate': false, '@__propagateFallback': context.getContextRaw() };
}

return c;
return new JsonLdContextNormalized(rawContext);
});

// Set the new context in the context tree
Expand Down