Skip to content

Commit c7a50bb

Browse files
gkelloggdavidlehn
authored andcommitted
More support for "@type": "@none"
1 parent 1ff2017 commit c7a50bb

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Fixed
66
- JSON literal value handling issues.
7+
- More support for "@type": "@none"
78

89
## 2.0.0 - 2019-12-09
910

lib/compact.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ api.compactValue = ({activeCtx, activeProperty, value, options}) => {
952952
const preserveIndex = '@index' in value && !container.includes('@index');
953953

954954
// if there's no @index to preserve ...
955-
if(!preserveIndex) {
955+
if(!preserveIndex && type !== '@none') {
956956
// matching @type or @language specified in context, compact value
957957
if(value['@type'] === type || value['@language'] === language) {
958958
return value['@value'];
@@ -971,6 +971,7 @@ api.compactValue = ({activeCtx, activeProperty, value, options}) => {
971971
const hasNullMapping = (activeCtx.mappings.has(activeProperty) &&
972972
activeCtx.mappings.get(activeProperty)['@language'] === null);
973973
if(isValueOnlyKey &&
974+
type !== '@none' &&
974975
(!hasDefaultLanguage || !isValueString || hasNullMapping)) {
975976
return value['@value'];
976977
}
@@ -1169,17 +1170,15 @@ function _selectTerm(
11691170
prefs.push('@none');
11701171

11711172
const containerMap = activeCtx.inverse[iri];
1172-
for(let ci = 0; ci < containers.length; ++ci) {
1173+
for(const container of containers) {
11731174
// if container not available in the map, continue
1174-
const container = containers[ci];
11751175
if(!(container in containerMap)) {
11761176
continue;
11771177
}
11781178

11791179
const typeOrLanguageValueMap = containerMap[container][typeOrLanguage];
1180-
for(let pi = 0; pi < prefs.length; ++pi) {
1180+
for(const pref of prefs) {
11811181
// if type/language option not available in the map, continue
1182-
const pref = prefs[pi];
11831182
if(!(pref in typeOrLanguageValueMap)) {
11841183
continue;
11851184
}

lib/context.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,15 @@ api.createTermDefinition = ({
527527
{code: 'invalid type mapping', context: localCtx});
528528
}
529529

530-
if(type !== '@id' && type !== '@vocab' && type !== '@json') {
530+
if((type === '@json' || type === '@none')) {
531+
if(api.processingMode(activeCtx, 1.0)) {
532+
throw new JsonLdError(
533+
'Invalid JSON-LD syntax; an @context @type value not be ' +
534+
'#{type} in JSON-LD 1.0 mode.',
535+
'jsonld.SyntaxError',
536+
{code: 'invalid type mapping', context: localCtx});
537+
}
538+
} else if(type !== '@id' && type !== '@vocab') {
531539
// expand @type to full IRI
532540
type = _expandIri(
533541
activeCtx, type, {vocab: true, base: false}, localCtx, defined,
@@ -959,6 +967,10 @@ api.getInitialContext = options => {
959967
if(mapping.reverse) {
960968
// term is preferred for values using @reverse
961969
_addPreferredTerm(term, entry['@type'], '@reverse');
970+
} else if(mapping['@type'] === '@none') {
971+
_addPreferredTerm(term, entry['@any'], '@none');
972+
_addPreferredTerm(term, entry['@language'], '@none');
973+
_addPreferredTerm(term, entry['@type'], '@none');
962974
} else if('@type' in mapping) {
963975
// term is preferred for values using specific type
964976
_addPreferredTerm(term, entry['@type'], mapping['@type']);

lib/expand.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ function _expandValue({activeCtx, activeProperty, value, options}) {
855855

856856
const rval = {};
857857

858-
if(type && !['@id', '@vocab'].includes(type)) {
858+
if(type && !['@id', '@vocab', '@none'].includes(type)) {
859859
// other type
860860
rval['@type'] = type;
861861
} else if(_isString(value)) {

tests/test-common.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ const TEST_TYPES = {
3232
specVersion: ['json-ld-1.0'],
3333
// FIXME
3434
idRegex: [
35-
// @type: @none
36-
/compact-manifest.jsonld#ttn01$/,
37-
/compact-manifest.jsonld#ttn02$/,
38-
/compact-manifest.jsonld#ttn03$/,
3935
// included
4036
/compact-manifest.jsonld#tin01$/,
4137
/compact-manifest.jsonld#tin02$/,
@@ -108,8 +104,6 @@ const TEST_TYPES = {
108104
/expand-manifest.jsonld#thc03$/,
109105
/expand-manifest.jsonld#thc04$/,
110106
/expand-manifest.jsonld#thc05$/,
111-
// @type: @none
112-
/expand-manifest.jsonld#ttn02$/,
113107
// misc
114108
/expand-manifest.jsonld#te043$/,
115109
/expand-manifest.jsonld#te044$/,
@@ -408,8 +402,6 @@ const TEST_TYPES = {
408402
/toRdf-manifest.jsonld#tso08$/,
409403
/toRdf-manifest.jsonld#tso10$/,
410404
/toRdf-manifest.jsonld#tso11$/,
411-
// type:none
412-
/toRdf-manifest.jsonld#ttn02$/,
413405
// colliding keyword
414406
/toRdf-manifest.jsonld#te114$/,
415407
// included

0 commit comments

Comments
 (0)