Skip to content

Commit

Permalink
Revert #20 causing regression and add tests for reviver (#26)
Browse files Browse the repository at this point in the history
* Revert "Remove trailing spaces"

This reverts commit 0db9d7b.

* Revert "refactor(test): remove debugger breakpoint"

This reverts commit 9ab247e.

* Revert "fix(test): assert on deserialized object with references which should be resolved"

This reverts commit 2f76353.

* Revert "refactor(immutable-test): remove const with var for old verions of js engines"

This reverts commit 0e9cc5d.

* Revert "Update package-lock.json"

This reverts commit bba3737.

* Revert "fix(mocha): revert mocha package version for old versions of node"

This reverts commit 0ab7902.

* Revert "test(immutable): add integration tests for remotedev-serialize"

* Revert "fix(parse): resolve jsan references before transformation"

* Add unit test for reviver

* Test also if reviver function has any effect
  • Loading branch information
zalmoxisus authored Dec 1, 2018
1 parent 4ed4402 commit 13a206a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 364 deletions.
27 changes: 20 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
var cycle = require('./cycle');

exports.stringify = function stringify(value, replacer, space, _options) {

if (arguments.length < 4) {
try {
if (arguments.length === 1) {
return JSON.stringify(value);
} else {
return JSON.stringify.apply(JSON, arguments);
}
} catch (e) {}
}

var options = _options || false;
if (typeof options === 'boolean') {
options = {
Expand Down Expand Up @@ -28,12 +39,14 @@ exports.stringify = function stringify(value, replacer, space, _options) {

exports.parse = function parse(text, reviver) {
var needsRetrocycle = /"\$jsan"/.test(text);
var replaced = JSON.parse(text);
var resolved = cycle.retrocycle(replaced);
if(reviver) {
var temp = JSON.stringify(resolved);
var parsed = JSON.parse(temp, reviver);
return parsed;
var parsed;
if (arguments.length === 1) {
parsed = JSON.parse(text);
} else {
parsed = JSON.parse(text, reviver);
}
if (needsRetrocycle) {
parsed = cycle.retrocycle(parsed);
}
return resolved;
return parsed;
}
322 changes: 0 additions & 322 deletions package-lock.json

This file was deleted.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
"devDependencies": {
"benchmark": "^2.1.2",
"circular-json": "^0.3.0",
"immutable": "^3.8.2",
"immutable": "^3.7.6",
"json-stringify-safe": "^5.0.1",
"mobx": "^2.4.1",
"mocha": "^2.2.1",
"rimraf": "^2.5.2",
"remotedev-serialize": "^0.1.1"
"rimraf": "^2.5.2"
},
"dependencies": {},
"repository": {
Expand Down
Loading

0 comments on commit 13a206a

Please sign in to comment.