Update to latest jsonld.js.
authorDave Longley <dlongley@digitalbazaar.com>
Thu, 28 Mar 2013 12:12:52 -0400
changeset 1505 64502923dd06
parent 1504 a1bc3776ed3a
child 1506 f5b8de15850c
Update to latest jsonld.js.
playground/jsonld.js
--- a/playground/jsonld.js	Thu Mar 28 15:51:20 2013 +0100
+++ b/playground/jsonld.js	Thu Mar 28 12:12:52 2013 -0400
@@ -3181,23 +3181,18 @@
     return;
   }
 
-  // add entries for @type
-  if('@type' in input) {
-    var types = input['@type'];
-    if(!_isArray(types)) {
-      types = [types];
-    }
-    for(var ti = 0; ti < types.length; ++ti) {
-      var type = types[ti];
-      var id = (type.indexOf('_:') === 0) ? namer.getName(type) : type;
-      if(!(id in graphs[graph])) {
-        graphs[graph][id] = {'@id': id};
-      }
-    }
-  }
-
   // add values to list
   if(_isValue(input)) {
+    if('@type' in input) {
+      var type = input['@type'];
+      // rename @type blank node
+      if(type.indexOf('_:') === 0) {
+        input['@type'] = type = namer.getName(type);
+      }
+      if(!(type in graphs[graph])) {
+        graphs[graph][type] = {'@id': type};
+      }
+    }
     if(list) {
       list.push(input);
     }
@@ -3277,6 +3272,14 @@
     for(var oi = 0; oi < objects.length; ++oi) {
       var o = objects[oi];
 
+      if(property === '@type') {
+        // rename @type blank nodes
+        o = (o.indexOf('_:') === 0) ? namer.getName(o) : o;
+        if(!(o in graphs[graph])) {
+          graphs[graph][o] = {'@id': o};
+        }
+      }
+
       // handle embedded subject or subject reference
       if(_isSubject(o) || _isSubjectReference(o)) {
         // rename blank node @id
@@ -4369,21 +4372,19 @@
         return mapping['@id'] + suffix;
       }
     }
-  }
-
-  // already absolute IRI
-  if(_isAbsoluteIri(value)) {
+
+    // already absolute IRI
     return value;
   }
 
-  var rval = value;
-
   // prepend vocab
   if(relativeTo.vocab && '@vocab' in activeCtx) {
-    rval = activeCtx['@vocab'] + rval;
-  }
+    return activeCtx['@vocab'] + value;
+  }
+
   // prepend base
-  else if(relativeTo.base) {
+  var rval = value;
+  if(relativeTo.base) {
     rval = _prependBase(activeCtx['@base'], rval);
   }