AST node for an Object literal (also called an Object initialiser in Ecma-262).
AST node for an Object literal (also called an Object initialiser in Ecma-262). The elements list will always be non- null , although the list will have no elements if the Object literal is empty.

Node type is Rhino.Token.OBJECTLIT .

ObjectLiteral : {} { PropertyNameAndValueList } PropertyNameAndValueList : PropertyName : AssignmentExpression PropertyNameAndValueList , PropertyName : AssignmentExpression PropertyName : Identifier StringLiteral NumericLiteral
Inheritance: AstNode, DestructuringForm
示例#1
0
		// only used for destructuring forms
		internal void DecompileObjectLiteral(ObjectLiteral node)
		{
			decompiler.AddToken(Token.LC);
			IList<ObjectProperty> props = node.GetElements();
			int size = props.Count;
			for (int i = 0; i < size; i++)
			{
				ObjectProperty prop = props[i];
				bool destructuringShorthand = true.Equals(prop.GetProp(Node.DESTRUCTURING_SHORTHAND));
				Decompile(prop.GetLeft());
				if (!destructuringShorthand)
				{
					decompiler.AddToken(Token.COLON);
					Decompile(prop.GetRight());
				}
				if (i < size - 1)
				{
					decompiler.AddToken(Token.COMMA);
				}
			}
			decompiler.AddToken(Token.RC);
		}
示例#2
0
		private Node TransformObjectLiteral(ObjectLiteral node)
		{
			if (node.IsDestructuring())
			{
				return node;
			}
			// createObjectLiteral rewrites its argument as object
			// creation plus object property entries, so later compiler
			// stages don't need to know about object literals.
			decompiler.AddToken(Token.LC);
			IList<ObjectProperty> elems = node.GetElements();
			Node @object = new Node(Token.OBJECTLIT);
			object[] properties;
			if (elems.IsEmpty())
			{
				properties = ScriptRuntime.emptyArgs;
			}
			else
			{
				int size = elems.Count;
				int i = 0;
				properties = new object[size];
				foreach (ObjectProperty prop in elems)
				{
					if (prop.IsGetter())
					{
						decompiler.AddToken(Token.GET);
					}
					else
					{
						if (prop.IsSetter())
						{
							decompiler.AddToken(Token.SET);
						}
					}
					properties[i++] = GetPropKey(prop.GetLeft());
					// OBJECTLIT is used as ':' in object literal for
					// decompilation to solve spacing ambiguity.
					if (!(prop.IsGetter() || prop.IsSetter()))
					{
						decompiler.AddToken(Token.OBJECTLIT);
					}
					Node right = Transform(prop.GetRight());
					if (prop.IsGetter())
					{
						right = CreateUnary(Token.GET, right);
					}
					else
					{
						if (prop.IsSetter())
						{
							right = CreateUnary(Token.SET, right);
						}
					}
					@object.AddChildToBack(right);
					if (i < size)
					{
						decompiler.AddToken(Token.COMMA);
					}
				}
			}
			decompiler.AddToken(Token.RC);
			@object.PutProp(Node.OBJECT_IDS_PROP, properties);
			return @object;
		}
示例#3
0
		/// <summary>Sets initializer object.</summary>
		/// <remarks>
		/// Sets initializer object.  Rhino supports an experimental syntax
		/// of the form
		/// <code>new expr [ ( arglist ) ] [initializer]</code>
		/// ,
		/// in which initializer is an object literal that is used to set
		/// additional properties on the newly-created
		/// <code>expr</code>
		/// object.
		/// </remarks>
		/// <param name="initializer">
		/// extra initializer object.
		/// Can be
		/// <code>null</code>
		/// .
		/// </param>
		public virtual void SetInitializer(ObjectLiteral initializer)
		{
			this.initializer = initializer;
			if (initializer != null)
			{
				initializer.SetParent(this);
			}
		}