From 495f86caf9a0112b0d0895ad141f17ceae9556b1 Mon Sep 17 00:00:00 2001
From: Thomas Wood <thomas.wood09@imperial.ac.uk>
Date: Wed, 9 Mar 2016 11:50:36 +0000
Subject: [PATCH] esprima-to-ast: toString function shouldn't mutate ast

---
 esprima-to-ast.js | 1 +
 test/parser.js    | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/esprima-to-ast.js b/esprima-to-ast.js
index 7dfb967..b64b506 100644
--- a/esprima-to-ast.js
+++ b/esprima-to-ast.js
@@ -531,6 +531,7 @@ function toString(ast, maxDepth) {
 
     if (typeof value === "object") {
       if (depth > 0) {
+        value = Object.assign({}, value);
         for (var nestKey in value) {
           value[nestKey] = ASTErrorJSONReplacer(nestKey, value[nestKey], depth - 1);
         }
diff --git a/test/parser.js b/test/parser.js
index d58cd8f..0384e9c 100644
--- a/test/parser.js
+++ b/test/parser.js
@@ -183,7 +183,7 @@ function typecheckAST(ast) {
       assert.instanceOf(value, Array);
       t.forEach((type, index) => typecheck(type, value[index]));
     } else {
-      assert.strictEqual(value.type, t._typeName);
+      assert(value.type === t._typeName, errorMsg(value, "was expected to have type of " + t._typeName));
       assert.notStrictEqual(value.tag, "_typeName");
       assert(t.hasOwnProperty(value.tag), value.tag + " is a not a valid constructor of " + t._typeName);
 
-- 
GitLab