AST node for an Array literal.
AST node for an Array literal. The elements list will always be non- null , although the list will have no elements if the Array literal is empty.

Node type is Rhino.Token.ARRAYLIT .

ArrayLiteral : [ Elisionopt ] [ ElementList ] [ ElementList , Elisionopt ] ElementList : Elisionopt AssignmentExpression ElementList , Elisionopt AssignmentExpression Elision : , Elision ,
Inheritance: AstNode, DestructuringForm
Exemple #1
0
		private Node TransformArrayLiteral(ArrayLiteral node)
		{
			if (node.IsDestructuring())
			{
				return node;
			}
			decompiler.AddToken(Token.LB);
			IList<AstNode> elems = node.GetElements();
			Node array = new Node(Token.ARRAYLIT);
			IList<int> skipIndexes = null;
			for (int i = 0; i < elems.Count; ++i)
			{
				AstNode elem = elems[i];
				if (elem.GetType() != Token.EMPTY)
				{
					array.AddChildToBack(Transform(elem));
				}
				else
				{
					if (skipIndexes == null)
					{
						skipIndexes = new List<int>();
					}
					skipIndexes.Add(i);
				}
				if (i < elems.Count - 1)
				{
					decompiler.AddToken(Token.COMMA);
				}
			}
			decompiler.AddToken(Token.RB);
			array.PutIntProp(Node.DESTRUCTURING_ARRAY_LENGTH, node.GetDestructuringLength());
			if (skipIndexes != null)
			{
				int[] skips = new int[skipIndexes.Count];
				for (int i_1 = 0; i_1 < skipIndexes.Count; i_1++)
				{
					skips[i_1] = skipIndexes[i_1];
				}
				array.PutProp(Node.SKIP_INDEXES_PROP, skips);
			}
			return array;
		}
Exemple #2
0
		// used for destructuring forms, since we don't transform() them
		internal void DecompileArrayLiteral(ArrayLiteral node)
		{
			decompiler.AddToken(Token.LB);
			IList<AstNode> elems = node.GetElements();
			int size = elems.Count;
			for (int i = 0; i < size; i++)
			{
				AstNode elem = elems[i];
				Decompile(elem);
				if (i < size - 1)
				{
					decompiler.AddToken(Token.COMMA);
				}
			}
			decompiler.AddToken(Token.RB);
		}