Skip to content

Commit eaefeec

Browse files
committed
Split isPropertyTermScopedContext flag out of options.
- The flag does not need to be passed recursively so it is simpler and more efficient to pass it independently.
1 parent 82791e0 commit eaefeec

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

lib/compact.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ api.compact = ({
106106
activeCtx = _processContext({
107107
activeCtx,
108108
localCtx: ctx,
109-
options: {...options, isPropertyTermScopedContext: true}
109+
isPropertyTermScopedContext: true,
110+
options
110111
});
111112
}
112113

lib/context.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ api.cache = new ActiveContextCache();
4242
* @param activeCtx the current active context.
4343
* @param localCtx the local context to process.
4444
* @param options the context processing options.
45+
* @param isPropertyTermScopedContext `true` if `localCtx` is a scoped context
46+
* from a property term.
4547
*
4648
* @return the new active context.
4749
*/
48-
api.process = ({activeCtx, localCtx, options}) => {
50+
api.process = (
51+
{activeCtx, localCtx, options, isPropertyTermScopedContext = false}) => {
4952
// normalize local context to an array of @context objects
5053
if(_isObject(localCtx) && '@context' in localCtx &&
5154
_isArray(localCtx['@context'])) {
@@ -80,7 +83,7 @@ api.process = ({activeCtx, localCtx, options}) => {
8083
if(ctx === null) {
8184
// We can't nullify if there are protected terms and we're
8285
// not processing a property term scoped context
83-
if(!options.isPropertyTermScopedContext &&
86+
if(!isPropertyTermScopedContext &&
8487
Object.keys(activeCtx.protected).length !== 0) {
8588
const protectedMode = (options && options.protectedMode) || 'error';
8689
if(protectedMode === 'error') {
@@ -229,7 +232,8 @@ api.process = ({activeCtx, localCtx, options}) => {
229232

230233
// process all other keys
231234
for(const key in ctx) {
232-
api.createTermDefinition(rval, ctx, key, defined, options);
235+
api.createTermDefinition(
236+
rval, ctx, key, defined, options, isPropertyTermScopedContext);
233237
}
234238

235239
// cache result
@@ -253,8 +257,12 @@ api.process = ({activeCtx, localCtx, options}) => {
253257
* @param {string} [options.protectedMode="error"] - "error" to throw error
254258
* on `@protected` constraint violation, "warn" to allow violations and
255259
* signal a warning.
260+
* @param isPropertyTermScopedContext `true` if `localCtx` is a scoped context
261+
* from a property term.
256262
*/
257-
api.createTermDefinition = (activeCtx, localCtx, term, defined, options) => {
263+
api.createTermDefinition = (
264+
activeCtx, localCtx, term, defined, options,
265+
isPropertyTermScopedContext = false) => {
258266
if(term in defined) {
259267
// term already defined
260268
if(defined[term]) {
@@ -285,7 +293,7 @@ api.createTermDefinition = (activeCtx, localCtx, term, defined, options) => {
285293
}
286294

287295
// FIXME if(1.1) ... ?
288-
if(term in activeCtx.protected && !options.isPropertyTermScopedContext) {
296+
if(term in activeCtx.protected && !isPropertyTermScopedContext) {
289297
const protectedMode = (options && options.protectedMode) || 'error';
290298
if(protectedMode === 'error') {
291299
throw new JsonLdError(

lib/expand.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,8 @@ function _expandObject({
562562
termCtx = _processContext({
563563
activeCtx,
564564
localCtx: ctx,
565-
options: {...options, isPropertyTermScopedContext: true}
565+
isPropertyTermScopedContext: true,
566+
options
566567
});
567568
}
568569

0 commit comments

Comments
 (0)