A list of one or more var, const or let declarations.
A list of one or more var, const or let declarations. Node type is Rhino.Token.VAR , Rhino.Token.CONST or Rhino.Token.LET .

If the node is for var or const , the node position is the beginning of the var or const keyword. For let declarations, the node position coincides with the first VariableInitializer child.

A standalone variable declaration in a statement context returns true from its IsStatement() method.

Inheritance: AstNode
Ejemplo n.º 1
0
		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;
		}
Ejemplo n.º 2
0
		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;
		}
Ejemplo n.º 3
0
		/// <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);
		}