Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Match spec error code "invalid context entry" vs "invalid context member".
- Keywords may not be used as prefixes.
- Handle term definition on `@type` with empty map.
- Handling of `@` values for `@reverse`.

### Changed
- Keep term definitions mapping to null so they may be protected.
Expand Down
24 changes: 12 additions & 12 deletions lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,18 +506,7 @@ api.createTermDefinition = ({
'jsonld.SyntaxError', {code: 'invalid IRI mapping', context: localCtx});
}

// expand and add @id mapping
const id = _expandIri(
activeCtx, reverse, {vocab: true, base: false}, localCtx, defined,
options);
if(!_isAbsoluteIri(id)) {
throw new JsonLdError(
'Invalid JSON-LD syntax; a @context @reverse value must be an ' +
'absolute IRI or a blank node identifier.',
'jsonld.SyntaxError', {code: 'invalid IRI mapping', context: localCtx});
}

if(reverse.match(KEYWORD_PATTERN)) {
if(!api.isKeyword(reverse) && reverse.match(KEYWORD_PATTERN)) {
// FIXME: remove logging and use a handler
console.warn('WARNING: values beginning with "@" are reserved' +
' for future use and ignored', {reverse});
Expand All @@ -529,6 +518,17 @@ api.createTermDefinition = ({
return;
}

// expand and add @id mapping
const id = _expandIri(
activeCtx, reverse, {vocab: true, base: false}, localCtx, defined,
options);
if(!_isAbsoluteIri(id)) {
throw new JsonLdError(
'Invalid JSON-LD syntax; a @context @reverse value must be an ' +
'absolute IRI or a blank node identifier.',
'jsonld.SyntaxError', {code: 'invalid IRI mapping', context: localCtx});
}

mapping['@id'] = id;
mapping.reverse = true;
} else if('@id' in value) {
Expand Down