private Node TransformVariables(VariableDeclaration node) { decompiler.AddToken(node.GetType()); TransformVariableInitializers(node); // Might be most robust to have parser record whether it was // a variable declaration statement, possibly as a node property. AstNode parent = node.GetParent(); if (!(parent is Loop) && !(parent is LetNode)) { decompiler.AddEOL(Token.SEMI); } return node; }
private Node TransformVariableInitializers(VariableDeclaration node) { IList<VariableInitializer> vars = node.GetVariables(); int size = vars.Count; int i = 0; foreach (VariableInitializer var in vars) { AstNode target = var.GetTarget(); AstNode init = var.GetInitializer(); Node left = null; if (var.IsDestructuring()) { Decompile(target); // decompile but don't transform left = target; } else { left = Transform(target); } Node right = null; if (init != null) { decompiler.AddToken(Token.ASSIGN); right = Transform(init); } if (var.IsDestructuring()) { if (right == null) { // TODO: should this ever happen? node.AddChildToBack(left); } else { Node d = CreateDestructuringAssignment(node.GetType(), left, right); node.AddChildToBack(d); } } else { if (right != null) { left.AddChildToBack(right); } node.AddChildToBack(left); } if (i++ < size - 1) { decompiler.AddToken(Token.COMMA); } } return node; }
/// <summary>Sets variable list.</summary> /// <remarks>Sets variable list. Sets list parent to this node.</remarks> /// <exception cref="System.ArgumentException"> /// if variables is /// <code>null</code> /// </exception> public virtual void SetVariables(VariableDeclaration variables) { AssertNotNull(variables); this.variables = variables; variables.SetParent(this); }