@@ -365,16 +365,9 @@ api.createTermDefinition = ({
365
365
activeCtx . mappings . delete ( term ) ;
366
366
}
367
367
368
- // clear context entry
369
- if ( value === null || ( _isObject ( value ) && value [ '@id' ] === null ) ) {
370
- activeCtx . mappings . set ( term , null ) ;
371
- defined . set ( term , true ) ;
372
- return ;
373
- }
374
-
375
368
// convert short-hand value to object w/@id
376
369
let simpleTerm = false ;
377
- if ( _isString ( value ) ) {
370
+ if ( _isString ( value ) || value === null ) {
378
371
simpleTerm = true ;
379
372
value = { '@id' : value } ;
380
373
}
@@ -448,13 +441,16 @@ api.createTermDefinition = ({
448
441
mapping . reverse = true ;
449
442
} else if ( '@id' in value ) {
450
443
let id = value [ '@id' ] ;
451
- if ( ! _isString ( id ) ) {
444
+ if ( id && ! _isString ( id ) ) {
452
445
throw new JsonLdError (
453
446
'Invalid JSON-LD syntax; a @context @id value must be an array ' +
454
447
'of strings or a string.' ,
455
448
'jsonld.SyntaxError' , { code : 'invalid IRI mapping' , context : localCtx } ) ;
456
449
}
457
- if ( id !== term ) {
450
+ if ( id === null ) {
451
+ // reserve a null term, which may be protected
452
+ mapping [ '@id' ] = null ;
453
+ } else if ( id !== term ) {
458
454
// expand and add @id mapping
459
455
id = _expandIri (
460
456
activeCtx , id , { vocab : true , base : false } , localCtx , defined , options ) ;
@@ -470,10 +466,12 @@ api.createTermDefinition = ({
470
466
if ( term . match ( / (?: : [ ^ : ] ) | \/ / ) ) {
471
467
const termDefined = new Map ( defined ) . set ( term , true ) ;
472
468
const termIri = _expandIri (
473
- activeCtx , term , { vocab : true , base : false } , localCtx , termDefined , options ) ;
469
+ activeCtx , term , { vocab : true , base : false } ,
470
+ localCtx , termDefined , options ) ;
474
471
if ( termIri !== id ) {
475
472
throw new JsonLdError (
476
- 'Invalid JSON-LD syntax; term in form of IRI must expand to definition.' ,
473
+ 'Invalid JSON-LD syntax; term in form of IRI must ' +
474
+ 'expand to definition.' ,
477
475
'jsonld.SyntaxError' ,
478
476
{ code : 'invalid IRI mapping' , context : localCtx } ) ;
479
477
}
@@ -942,6 +940,9 @@ api.getInitialContext = options => {
942
940
let container = mapping [ '@container' ] || '@none' ;
943
941
container = [ ] . concat ( container ) . sort ( ) . join ( '' ) ;
944
942
943
+ if ( mapping [ '@id' ] === null ) {
944
+ continue ;
945
+ }
945
946
// iterate over every IRI in the mapping
946
947
const ids = _asArray ( mapping [ '@id' ] ) ;
947
948
for ( const iri of ids ) {
0 commit comments