Update to latest jsonld.js.
authorDave Longley <dlongley@digitalbazaar.com>
Sat, 05 May 2012 14:50:15 -0400
changeset 629 e2e631832856
parent 628 0817b55ad343
child 630 43422f90d725
Update to latest jsonld.js.
playground/jsonld.js
--- a/playground/jsonld.js	Sun May 06 00:27:45 2012 +0800
+++ b/playground/jsonld.js	Sat May 05 14:50:15 2012 -0400
@@ -1029,9 +1029,7 @@
       // preserve empty arrays
       if(value.length === 0) {
         var prop = _compactIri(ctx, key);
-        if(prop !== null) {
-          jsonld.addValue(rval, prop, [], true);
-        }
+        jsonld.addValue(rval, prop, [], true);
       }
 
       // recusively process array values
@@ -1042,11 +1040,6 @@
         // 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'];
@@ -1703,6 +1696,10 @@
   var rval = _clone(activeCtx);
 
   // normalize local context to an array
+  if(_isObject(localCtx) && '@context' in localCtx &&
+    _isArray(localCtx['@context'])) {
+    localCtx = localCtx['@context'];
+  }
   var ctxs = _isArray(localCtx) ? localCtx : [localCtx];
 
   // process each context in order
@@ -2028,6 +2025,7 @@
  * @return the new hash.
  */
 function _hashStatements(id, bnodes, namer) {
+  // return cached hash
   if('hash' in bnodes[id]) {
     return bnodes[id].hash;
   }
@@ -2956,10 +2954,6 @@
 
   // 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;
   }
@@ -3034,7 +3028,7 @@
   }
 
   // clear context entry
-  if(value === null) {
+  if(value === null || (_isObject(value) && value['@id'] === null)) {
     if(key in activeCtx.mappings) {
       // if key is a keyword alias, remove it
       var kw = activeCtx.mappings[key]['@id'];
@@ -3042,8 +3036,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;
   }
@@ -3064,7 +3058,7 @@
         aliases.sort(_compareShortestLeast);
       }
     }
-    else if(value !== null) {
+    else {
       // expand value to a full IRI
       value = _expandContextIri(activeCtx, ctx, value, base, defined);
     }
@@ -3164,10 +3158,8 @@
     mapping['@language'] = language;
   }
 
-  // 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) {
+  // merge onto parent mapping if one exists for a prefix
+  if(prefix !== null && prefix in activeCtx.mappings) {
     var child = mapping;
     var mapping = _clone(activeCtx.mappings[prefix]);
     for(var k in child) {
@@ -3201,8 +3193,8 @@
   // recurse if value is a term
   if(value in activeCtx.mappings) {
     var id = activeCtx.mappings[value]['@id'];
-    // value is already an absolute IRI or id is null mapping
-    if(value === id || id === null) {
+    // value is already an absolute IRI
+    if(value === id) {
       return value;
     }
     return _expandContextIri(activeCtx, ctx, id, base, defined);
@@ -3232,9 +3224,7 @@
     // recurse if prefix is defined
     if(prefix in activeCtx.mappings) {
       var id = activeCtx.mappings[prefix]['@id'];
-      if(id !== null) {
-        return _expandContextIri(activeCtx, ctx, id, base, defined) + suffix;
-      }
+      return _expandContextIri(activeCtx, ctx, id, base, defined) + suffix;
     }
 
     // consider value an absolute IRI
@@ -3927,12 +3917,7 @@
   }
   // normalization mode
   else if(bnode) {
-    if(s.nominalValue === bnode) {
-      quad += '_:a';
-    }
-    else {
-      quad += '_:z';
-    }
+    quad += (s.nominalValue === bnode) ? '_:a' : '_:z';
   }
   // normal mode
   else {
@@ -3949,12 +3934,7 @@
   else if(o.interfaceName === 'BlankNode') {
     // normalization mode
     if(bnode) {
-      if(o.nominalValue === bnode) {
-        quad += '_:a';
-      }
-      else {
-        quad += '_:z';
-      }
+      quad += (o.nominalValue === bnode) ? '_:a' : '_:z';
     }
     // normal mode
     else {