git » jacl.git » commit 90f9d4a

Fix parent/children for %NEW, %THROW, %IF

author Alan Dipert
2020-04-11 06:51:37 UTC
committer Alan Dipert
2020-04-11 06:51:37 UTC
parent c30fa90a19171fa9400942dc97f0b0448c630ab8

Fix parent/children for %NEW, %THROW, %IF

jacl.js +13 -11

diff --git a/jacl.js b/jacl.js
index 64c67ac..ccfdd17 100644
--- a/jacl.js
+++ b/jacl.js
@@ -1282,14 +1282,14 @@ const analyzeSpecials = new Map([
     const node = makeNode('new', { env: env, parent: parent, form: form });
     node.ctor = analyze(env.withContext('expr'), node, ctor);
     node.args = args.map(x => analyze(env.withContext('expr'), node, x));
-    node.children = [ctor, ...args];
+    node.children = [node.ctor, ...node.args];
     return node;
   }],
   [JACLPKG.intern('%THROW'), (env, parent, form) => {
     const [, obj] = form;
     const node = makeNode('throw', { env: env, parent: parent, form: form });
     node.obj = analyze(env.withContext('expr'), node, obj);
-    node.children = [obj];
+    node.children = [node.obj];
     return node;
   }],
   [JACLPKG.intern('%LET'), (env, parent, form) => {
@@ -1427,20 +1427,22 @@ const analyzeSpecials = new Map([
     if ([...form].length < 4) throw new Error(`IF requires at least 3 args`);
     const [, pred, expr0, expr1] = form;
     const childEnv = env.context === 'return' ? env.withContext('expr') : env;
-    const testNode = analyze(env.withContext('expr'), null, pred),
-          thenNode = analyze(childEnv, null, expr0),
-          elseNode = analyze(childEnv, null, expr1);
+
     const node = makeNode('if', {
       env: env,
       parent: parent,
-      form: form,
-      testNode: testNode,
-      thenNode: thenNode,
-      elseNode: elseNode,
-      children: [testNode, thenNode, elseNode]
+      form: form
     });
 
-    testNode.parent = thenNode.parent = elseNode.parent = node;
+    const testNode = analyze(env.withContext('expr'), node, pred),
+          thenNode = analyze(childEnv, node, expr0),
+          elseNode = analyze(childEnv, node, expr1);
+
+    node.testNode = testNode;
+    node.thenNode = thenNode;
+    node.elseNode = elseNode;
+    node.children = [testNode, thenNode, elseNode];
+
     return node;
   }]
 ]);