diff --git a/lib/ParsingContext.ts b/lib/ParsingContext.ts index f7b6955..91ff27a 100644 --- a/lib/ParsingContext.ts +++ b/lib/ParsingContext.ts @@ -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']; diff --git a/lib/entryhandler/keyword/EntryHandlerKeywordType.ts b/lib/entryhandler/keyword/EntryHandlerKeywordType.ts index ac292b7..2283ce3 100644 --- a/lib/entryhandler/keyword/EntryHandlerKeywordType.ts +++ b/lib/entryhandler/keyword/EntryHandlerKeywordType.ts @@ -69,15 +69,11 @@ 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; - } - // 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 (c.getContextRaw()['@propagate'] !== true) { + return new JsonLdContextNormalized({ ...c.getContextRaw(), '@propagate': false, '@__propagateFallback': context.getContextRaw() }); } return c; diff --git a/package.json b/package.json index 1e69542..9553d3c 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "buffer": "^6.0.3", "canonicalize": "^1.0.1", "http-link-header": "^1.0.2", - "jsonld-context-parser": "^2.3.3", + "jsonld-context-parser": "^2.4.0", "rdf-data-factory": "^1.1.0", "readable-stream": "^4.0.0" }, diff --git a/test/ParsingContext-test.ts b/test/ParsingContext-test.ts index 8ac412e..91d7d23 100644 --- a/test/ParsingContext-test.ts +++ b/test/ParsingContext-test.ts @@ -1,4 +1,4 @@ -import {JsonLdContextNormalized} from "jsonld-context-parser"; +import {JsonLdContextNormalized, ContextParser} from "jsonld-context-parser"; import {ParsingContext} from "../lib/ParsingContext"; import {ParsingContextMocked} from "../mocks/ParsingContextMocked"; @@ -607,22 +607,20 @@ describe('ParsingContext', () => { describe('for type-scoped and property-scoped contexts', () => { beforeEach(() => { - parsingContext.contextTree.setContext(['', 'a'], Promise.resolve(new JsonLdContextNormalized({ - '@__propagateFallback': { fallback: true }, - '@propagate': false, + const contextParser = new ContextParser(); + parsingContext.contextTree.setContext(['', 'a'], contextParser.parse({ '@vocab': 'http://bla.org/', 'bar': { '@context': { baz: { '@type': '@vocab' }, }, }, - }))); + })); }); it('should consider the applicable property-scoped context', async () => { return expect(await parsingContext.getContext(['', 'a', 'bar'], 0)) .toEqual(new JsonLdContextNormalized({ - '@__propagateFallback': { fallback: true }, '@vocab': 'http://bla.org/', 'bar': { '@id': 'http://bla.org/bar' }, 'baz': { '@type': '@vocab', '@id': 'http://bla.org/baz' }, diff --git a/yarn.lock b/yarn.lock index 1fa95e5..39fb8f3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2518,14 +2518,13 @@ jsonld-context-parser@^2.0.2, jsonld-context-parser@^2.1.3: http-link-header "^1.0.2" relative-to-absolute-iri "^1.0.5" -jsonld-context-parser@^2.3.3: - version "2.3.3" - resolved "https://registry.yarnpkg.com/jsonld-context-parser/-/jsonld-context-parser-2.3.3.tgz#0bdab9eb5cb4b7e68aa7d6c38e58455363caaf9c" - integrity sha512-H+REInOx7XI2ciF8wJV31D20Bh+ofBmEjN2Tkds51vypqDJIiD341E5g+hYyrEInIKRnbW58TN/Ehz+ACT0l0w== +jsonld-context-parser@^2.4.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/jsonld-context-parser/-/jsonld-context-parser-2.4.0.tgz#fae15a56c5ceabd1c4520ab1a9cc12c9a0a8b67d" + integrity sha512-ZYOfvh525SdPd9ReYY58dxB3E2RUEU4DJ6ZibO8AitcowPeBH4L5rCAitE2om5G1P+HMEgYEYEr4EZKbVN4tpA== dependencies: "@types/http-link-header" "^1.0.1" "@types/node" "^18.0.0" - canonicalize "^1.0.1" cross-fetch "^3.0.6" http-link-header "^1.0.2" relative-to-absolute-iri "^1.0.5"