Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

node annotation reconstruction works!

  • Loading branch information...
commit d66399b9e0020cd693f537ac8a99e8b687ed5aeb 1 parent 8cab588
James Halliday authored

Showing 1 changed file with 14 additions and 3 deletions. Show diff stats Hide diff stats

  1. +14 3 index.js
17 index.js
@@ -5,7 +5,7 @@ module.exports = function (src) {
5 5 var obj = JSON.parse(src);
6 6
7 7 var cursor = [ obj ];
8   - var root = [ Object.create(Object.getPrototypeOf(obj)) ];
  8 + var root = [ Array.isArray(obj) ? [] : {} ];
9 9
10 10 var path = [];
11 11 var prevPathLen = 0;
@@ -19,6 +19,7 @@ module.exports = function (src) {
19 19 if (this.path.length <= prevPathLen) {
20 20 path.pop();
21 21 cursor.shift();
  22 + root.shift();
22 23 prevPathLen = path.length;
23 24 }
24 25
@@ -39,12 +40,22 @@ module.exports = function (src) {
39 40 if (node.name === 'object' || node.name === 'array') {
40 41 prevPathLen = this.path.length;
41 42 path.push(key);
42   -console.log(key);
43   -console.dir(cursor[0]);
  43 +
  44 + root[0][key] = {
  45 + node : node.name,
  46 + value : node.name === 'array' ? [] : {}
  47 + };
  48 + root.unshift(root[0][key].value);
44 49 cursor.unshift(cursor[0][key]);
45 50 }
  51 + else {
  52 + root[0][key] = { node : node.name, value : cursor[0][key] };
  53 + }
46 54 });
47 55
  56 + root = root[root.length - 1];
  57 + console.log(JSON.stringify(root, null, 2));
  58 +
48 59 self.set = function (key, value) {
49 60 };
50 61

0 comments on commit d66399b

Please sign in to comment.
Something went wrong with that request. Please try again.