diff --git a/CHANGELOG.md b/CHANGELOG.md index 970d234a..abdf87de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # jsonld ChangeLog +### Fixed +- More support for "@type": "@none" + ## 2.0.1 - 2019-12-10 ### Fixed diff --git a/lib/compact.js b/lib/compact.js index 58145f89..4f12bb63 100644 --- a/lib/compact.js +++ b/lib/compact.js @@ -952,7 +952,7 @@ api.compactValue = ({activeCtx, activeProperty, value, options}) => { const preserveIndex = '@index' in value && !container.includes('@index'); // if there's no @index to preserve ... - if(!preserveIndex) { + if(!preserveIndex && type !== '@none') { // matching @type or @language specified in context, compact value if(value['@type'] === type || value['@language'] === language) { return value['@value']; @@ -971,6 +971,7 @@ api.compactValue = ({activeCtx, activeProperty, value, options}) => { const hasNullMapping = (activeCtx.mappings.has(activeProperty) && activeCtx.mappings.get(activeProperty)['@language'] === null); if(isValueOnlyKey && + type !== '@none' && (!hasDefaultLanguage || !isValueString || hasNullMapping)) { return value['@value']; } @@ -1169,17 +1170,15 @@ function _selectTerm( prefs.push('@none'); const containerMap = activeCtx.inverse[iri]; - for(let ci = 0; ci < containers.length; ++ci) { + for(const container of containers) { // if container not available in the map, continue - const container = containers[ci]; if(!(container in containerMap)) { continue; } const typeOrLanguageValueMap = containerMap[container][typeOrLanguage]; - for(let pi = 0; pi < prefs.length; ++pi) { + for(const pref of prefs) { // if type/language option not available in the map, continue - const pref = prefs[pi]; if(!(pref in typeOrLanguageValueMap)) { continue; } diff --git a/lib/context.js b/lib/context.js index 8d24b481..09aedfd9 100644 --- a/lib/context.js +++ b/lib/context.js @@ -527,7 +527,15 @@ api.createTermDefinition = ({ {code: 'invalid type mapping', context: localCtx}); } - if(type !== '@id' && type !== '@vocab' && type !== '@json') { + if((type === '@json' || type === '@none')) { + if(api.processingMode(activeCtx, 1.0)) { + throw new JsonLdError( + 'Invalid JSON-LD syntax; an @context @type value must not be ' + + `"${type}" in JSON-LD 1.0 mode.`, + 'jsonld.SyntaxError', + {code: 'invalid type mapping', context: localCtx}); + } + } else if(type !== '@id' && type !== '@vocab') { // expand @type to full IRI type = _expandIri( activeCtx, type, {vocab: true, base: false}, localCtx, defined, @@ -959,6 +967,10 @@ api.getInitialContext = options => { if(mapping.reverse) { // term is preferred for values using @reverse _addPreferredTerm(term, entry['@type'], '@reverse'); + } else if(mapping['@type'] === '@none') { + _addPreferredTerm(term, entry['@any'], '@none'); + _addPreferredTerm(term, entry['@language'], '@none'); + _addPreferredTerm(term, entry['@type'], '@none'); } else if('@type' in mapping) { // term is preferred for values using specific type _addPreferredTerm(term, entry['@type'], mapping['@type']); diff --git a/lib/expand.js b/lib/expand.js index c8e985b3..7cf27bf7 100644 --- a/lib/expand.js +++ b/lib/expand.js @@ -855,7 +855,7 @@ function _expandValue({activeCtx, activeProperty, value, options}) { const rval = {}; - if(type && !['@id', '@vocab'].includes(type)) { + if(type && !['@id', '@vocab', '@none'].includes(type)) { // other type rval['@type'] = type; } else if(_isString(value)) { diff --git a/tests/test-common.js b/tests/test-common.js index 81149cc1..296e5a5d 100644 --- a/tests/test-common.js +++ b/tests/test-common.js @@ -32,10 +32,6 @@ const TEST_TYPES = { specVersion: ['json-ld-1.0'], // FIXME idRegex: [ - // @type: @none - /compact-manifest.jsonld#ttn01$/, - /compact-manifest.jsonld#ttn02$/, - /compact-manifest.jsonld#ttn03$/, // included /compact-manifest.jsonld#tin01$/, /compact-manifest.jsonld#tin02$/, @@ -106,8 +102,6 @@ const TEST_TYPES = { /expand-manifest.jsonld#thc03$/, /expand-manifest.jsonld#thc04$/, /expand-manifest.jsonld#thc05$/, - // @type: @none - /expand-manifest.jsonld#ttn02$/, // misc /expand-manifest.jsonld#te043$/, /expand-manifest.jsonld#te044$/, @@ -404,8 +398,6 @@ const TEST_TYPES = { /toRdf-manifest.jsonld#tso08$/, /toRdf-manifest.jsonld#tso10$/, /toRdf-manifest.jsonld#tso11$/, - // type:none - /toRdf-manifest.jsonld#ttn02$/, // colliding keyword /toRdf-manifest.jsonld#te114$/, // included