@@ -365,16 +365,9 @@ api.createTermDefinition = ({
365365 activeCtx . mappings . delete ( term ) ;
366366 }
367367
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-
375368 // convert short-hand value to object w/@id
376369 let simpleTerm = false ;
377- if ( _isString ( value ) ) {
370+ if ( _isString ( value ) || value === null ) {
378371 simpleTerm = true ;
379372 value = { '@id' : value } ;
380373 }
@@ -448,13 +441,16 @@ api.createTermDefinition = ({
448441 mapping . reverse = true ;
449442 } else if ( '@id' in value ) {
450443 let id = value [ '@id' ] ;
451- if ( ! _isString ( id ) ) {
444+ if ( id && ! _isString ( id ) ) {
452445 throw new JsonLdError (
453446 'Invalid JSON-LD syntax; a @context @id value must be an array ' +
454447 'of strings or a string.' ,
455448 'jsonld.SyntaxError' , { code : 'invalid IRI mapping' , context : localCtx } ) ;
456449 }
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 ) {
458454 // expand and add @id mapping
459455 id = _expandIri (
460456 activeCtx , id , { vocab : true , base : false } , localCtx , defined , options ) ;
@@ -470,10 +466,12 @@ api.createTermDefinition = ({
470466 if ( term . match ( / (?: : [ ^ : ] ) | \/ / ) ) {
471467 const termDefined = new Map ( defined ) . set ( term , true ) ;
472468 const termIri = _expandIri (
473- activeCtx , term , { vocab : true , base : false } , localCtx , termDefined , options ) ;
469+ activeCtx , term , { vocab : true , base : false } ,
470+ localCtx , termDefined , options ) ;
474471 if ( termIri !== id ) {
475472 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.' ,
477475 'jsonld.SyntaxError' ,
478476 { code : 'invalid IRI mapping' , context : localCtx } ) ;
479477 }
@@ -942,6 +940,9 @@ api.getInitialContext = options => {
942940 let container = mapping [ '@container' ] || '@none' ;
943941 container = [ ] . concat ( container ) . sort ( ) . join ( '' ) ;
944942
943+ if ( mapping [ '@id' ] === null ) {
944+ continue ;
945+ }
945946 // iterate over every IRI in the mapping
946947 const ids = _asArray ( mapping [ '@id' ] ) ;
947948 for ( const iri of ids ) {
0 commit comments