@@ -315,14 +315,30 @@ api.createTermDefinition = (
315315 // now defining term
316316 defined . set ( term , false ) ;
317317
318- if ( api . isKeyword ( term ) ) {
318+ // get context term value
319+ let value ;
320+ if ( localCtx . hasOwnProperty ( term ) ) {
321+ value = localCtx [ term ] ;
322+ }
323+
324+ if ( term === '@type' &&
325+ _isObject ( value ) &&
326+ value [ '@container' ] === '@set' &&
327+ api . processingMode ( activeCtx , 1.1 ) ) {
328+
329+ const validKeys = [ '@container' , '@id' , '@protected' ] ;
330+ if ( Object . keys ( value ) . some ( k => ! validKeys . includes ( k ) ) ) {
331+ throw new JsonLdError (
332+ 'Invalid JSON-LD syntax; keywords cannot be overridden.' ,
333+ 'jsonld.SyntaxError' ,
334+ { code : 'keyword redefinition' , context : localCtx , term} ) ;
335+ }
336+ } else if ( api . isKeyword ( term ) ) {
319337 throw new JsonLdError (
320338 'Invalid JSON-LD syntax; keywords cannot be overridden.' ,
321339 'jsonld.SyntaxError' ,
322340 { code : 'keyword redefinition' , context : localCtx , term} ) ;
323- }
324-
325- if ( term === '' ) {
341+ } else if ( term === '' ) {
326342 throw new JsonLdError (
327343 'Invalid JSON-LD syntax; a term cannot be an empty string.' ,
328344 'jsonld.SyntaxError' ,
@@ -337,12 +353,6 @@ api.createTermDefinition = (
337353 activeCtx . mappings . delete ( term ) ;
338354 }
339355
340- // get context term value
341- let value ;
342- if ( localCtx . hasOwnProperty ( term ) ) {
343- value = localCtx [ term ] ;
344- }
345-
346356 // clear context entry
347357 if ( value === null || ( _isObject ( value ) && value [ '@id' ] === null ) ) {
348358 activeCtx . mappings . set ( term , null ) ;
@@ -468,6 +478,9 @@ api.createTermDefinition = (
468478 // term is an absolute IRI
469479 mapping [ '@id' ] = term ;
470480 }
481+ } else if ( term == '@type' ) {
482+ // Special case, were we've previously determined that container is @set
483+ mapping [ '@id' ] = term ;
471484 } else {
472485 // non-IRIs *must* define @ids if @vocab is not available
473486 if ( ! ( '@vocab' in activeCtx ) ) {
0 commit comments