Update to latest jsonld.js.
authorDave Longley <dlongley@digitalbazaar.com>
Fri, 27 Apr 2012 17:29:20 -0400
changeset 583 0473f1e22b67
parent 582 fd549c3a67a7
child 584 3d8f9d7fbc3e
Update to latest jsonld.js.
playground/jsonld.js
--- a/playground/jsonld.js	Fri Apr 27 13:40:58 2012 -0700
+++ b/playground/jsonld.js	Fri Apr 27 17:29:20 2012 -0400
@@ -950,8 +950,7 @@
     if(_isSubjectReference(element)) {
       var type = jsonld.getContextValue(ctx, property, '@type');
       if(type === '@id' || property === '@graph') {
-        element = _compactIri(ctx, element['@id']);
-        return element;
+        return _compactIri(ctx, element['@id']);
       }
     }
 
@@ -987,7 +986,9 @@
       // preserve empty arrays
       if(value.length === 0) {
         var prop = _compactIri(ctx, key);
-        jsonld.addValue(rval, prop, [], true);
+        if(prop !== null) {
+          jsonld.addValue(rval, prop, [], true);
+        }
       }
 
       // recusively process array values
@@ -998,6 +999,11 @@
         // compact property
         var prop = _compactIri(ctx, key, v);
 
+        // skip null properties
+        if(prop === null) {
+          continue;
+        }
+
         // remove @list for recursion (will be re-added if necessary)
         if(isList) {
           v = v['@list'];
@@ -2703,8 +2709,13 @@
     }
   }
 
-  // no matching terms, use IRI
+  // no matching terms
   if(terms.length === 0) {
+    // return null if a null mapping exists
+    if(iri in ctx.mappings && ctx.mappings[iri]['@id'] === null) {
+      return null;
+    }
+    // use iri
     return iri;
   }
 
@@ -2786,8 +2797,8 @@
         var aliases = activeCtx.keywords[kw];
         aliases.splice(aliases.indexOf(key), 1);
       }
-      delete activeCtx.mappings[key];
     }
+    activeCtx.mappings[key] = {'@id': null};
     defined[key] = true;
     return;
   }
@@ -2808,7 +2819,7 @@
         aliases.sort(_compareShortestLeast);
       }
     }
-    else {
+    else if(value !== null) {
       // expand value to a full IRI
       value = _expandContextIri(activeCtx, ctx, value, base, defined);
     }
@@ -2908,8 +2919,10 @@
     mapping['@language'] = language;
   }
 
-  // merge onto parent mapping if one exists for a prefix
-  if(prefix !== null && prefix in activeCtx.mappings) {
+  // if not a null mapping, merge onto parent mapping if one exists for a
+  // prefix
+  if(mapping['@id'] !== null &&
+    prefix !== null && prefix in activeCtx.mappings) {
     var child = mapping;
     var mapping = _clone(activeCtx.mappings[prefix]);
     for(var k in child) {
@@ -2943,8 +2956,8 @@
   // recurse if value is a term
   if(value in activeCtx.mappings) {
     var id = activeCtx.mappings[value]['@id'];
-    // value is already an absolute IRI
-    if(value === id) {
+    // value is already an absolute IRI or id is null mapping
+    if(value === id || id === null) {
       return value;
     }
     return _expandContextIri(activeCtx, ctx, id, base, defined);
@@ -2974,7 +2987,9 @@
     // recurse if prefix is defined
     if(prefix in activeCtx.mappings) {
       var id = activeCtx.mappings[prefix]['@id'];
-      return _expandContextIri(activeCtx, ctx, id, base, defined) + suffix;
+      if(id !== null) {
+        return _expandContextIri(activeCtx, ctx, id, base, defined) + suffix;
+      }
     }
 
     // consider value an absolute IRI