IsExpressionClosure() public method

Returns whether this is a 1.8 function closure
public IsExpressionClosure ( ) : bool
return bool
Exemplo n.º 1
0
		private Node TransformGenExpr(GeneratorExpression node)
		{
			Node pn;
			FunctionNode fn = new FunctionNode();
			fn.SetSourceName(currentScriptOrFn.GetNextTempName());
			fn.SetIsGenerator();
			fn.SetFunctionType(FunctionNode.FUNCTION_EXPRESSION);
			fn.SetRequiresActivation();
			int functionType = fn.GetFunctionType();
			int start = decompiler.MarkFunctionStart(functionType);
			Node mexpr = DecompileFunctionHeader(fn);
			int index = currentScriptOrFn.AddFunction(fn);
			Parser.PerFunctionVariables savedVars = new Parser.PerFunctionVariables(this, fn);
			try
			{
				// If we start needing to record much more codegen metadata during
				// function parsing, we should lump it all into a helper class.
				Node destructuring = (Node)fn.GetProp(Node.DESTRUCTURING_PARAMS);
				fn.RemoveProp(Node.DESTRUCTURING_PARAMS);
				int lineno = node.lineno;
				++nestingOfFunction;
				// only for body, not params
				Node body = GenExprTransformHelper(node);
				if (!fn.IsExpressionClosure())
				{
					decompiler.AddToken(Token.RC);
				}
				fn.SetEncodedSourceBounds(start, decompiler.MarkFunctionEnd(start));
				if (functionType != FunctionNode.FUNCTION_EXPRESSION && !fn.IsExpressionClosure())
				{
					// Add EOL only if function is not part of expression
					// since it gets SEMI + EOL from Statement in that case
					decompiler.AddToken(Token.EOL);
				}
				if (destructuring != null)
				{
					body.AddChildToFront(new Node(Token.EXPR_VOID, destructuring, lineno));
				}
				int syntheticType = fn.GetFunctionType();
				pn = InitFunction(fn, index, body, syntheticType);
				if (mexpr != null)
				{
					pn = CreateAssignment(Token.ASSIGN, mexpr, pn);
					if (syntheticType != FunctionNode.FUNCTION_EXPRESSION)
					{
						pn = CreateExprStatementNoReturn(pn, fn.GetLineno());
					}
				}
			}
			finally
			{
				--nestingOfFunction;
				savedVars.Restore();
			}
			Node call = CreateCallOrNew(Token.CALL, pn);
			call.SetLineno(node.GetLineno());
			decompiler.AddToken(Token.LP);
			decompiler.AddToken(Token.RP);
			return call;
		}
Exemplo n.º 2
0
		internal Node DecompileFunctionHeader(FunctionNode fn)
		{
			Node mexpr = null;
			if (fn.GetFunctionName() != null)
			{
				decompiler.AddName(fn.GetName());
			}
			else
			{
				if (fn.GetMemberExprNode() != null)
				{
					mexpr = Transform(fn.GetMemberExprNode());
				}
			}
			decompiler.AddToken(Token.LP);
			IList<AstNode> @params = fn.GetParams();
			for (int i = 0; i < @params.Count; i++)
			{
				Decompile(@params[i]);
				if (i < @params.Count - 1)
				{
					decompiler.AddToken(Token.COMMA);
				}
			}
			decompiler.AddToken(Token.RP);
			if (!fn.IsExpressionClosure())
			{
				decompiler.AddEOL(Token.LC);
			}
			return mexpr;
		}