DeclareVariable() private method

Declares a variable or function in this scope. This will be initialized with the value of the given expression.
private DeclareVariable ( string name, Jurassic.Compiler.Expression valueAtTopOfScope = null, bool writable = true, bool deletable = false ) : DeclaredVariable
name string The name of the variable.
valueAtTopOfScope Jurassic.Compiler.Expression The value of the variable at the top of the scope. /// Can be null to indicate the variable does not need initializing.
writable bool true if the variable can be modified; false /// otherwise. Defaults to true.
deletable bool true if the variable can be deleted; false /// otherwise. Defaults to true.
return DeclaredVariable
コード例 #1
0
ファイル: Scope.cs プロジェクト: oujunke/jurassic
        /// <summary>
        /// Creates a new declarative scope for use inside a function body (and within function
        /// argument default values).
        /// </summary>
        /// <param name="functionName"> The name of the function.  Can be empty for an anonymous function. </param>
        /// <param name="argumentNames"> The names of each of the function arguments.  Can be <c>null</c>. </param>
        /// <returns> A new DeclarativeScope instance. </returns>
        internal static Scope CreateFunctionScope(string functionName, IEnumerable <string> argumentNames)
        {
            var result = new Scope(null, (argumentNames != null ? argumentNames.Count() : 0) + 3);

            result.Type = ScopeType.TopLevelFunction;
            if (functionName != null)
            {
                result.DeclareVariable(KeywordToken.Var, functionName);
            }
            result.DeclareVariable(KeywordToken.Var, "arguments");
            if (argumentNames != null)
            {
                foreach (var argumentName in argumentNames)
                {
                    result.DeclareVariable(KeywordToken.Var, argumentName);
                }
            }
            return(result);
        }