Exemplo n.º 1
0
        public JsVariableDeclarator HoistVariable(LiftedVariableKey symbol)
        {
            var identifier = symbol.Identifier;

            if (hoistedVariables.ContainsKey(symbol) || hoistedVariables.ContainsKey(new LiftedVariableKey(symbol.Identifier)))
            {
                identifier = GenerateNewNamePrivate(symbol);
                symbol     = new LiftedVariableKey(identifier, symbol.Symbol);
            }

            // Register the variable so we avoid collisions.
            hoistedVariables[symbol] = identifier;
            if (symbol.Symbol == null)
            {
                hoistedVariables[new LiftedVariableKey(symbol.Identifier)] = identifier;
            }

            // Declare a local variable (of the top-level function so available as closures to the state
            // machine) to store the symbol.
            var declaration = stateMachineBody.Local(identifier, Js.Null());

            // If we have a true symbol associated with the key, then declare it in the base transformer
            if (symbol.Symbol != null)
            {
                transformer.DeclareInCurrentScope(symbol.Symbol, declaration);
            }

            return(declaration);
        }
Exemplo n.º 2
0
        protected string UniqueName(string identifier)
        {
            var key = new LiftedVariableKey(identifier);

            if (hoistedVariables.ContainsKey(key))
            {
                identifier            = GenerateNewNamePrivate(key);
                hoistedVariables[key] = identifier;
            }
            return(identifier);
        }
Exemplo n.º 3
0
        private string GenerateNewNamePrivate(LiftedVariableKey symbol)
        {
            var counter = 2;

            do
            {
                var currentName = symbol.Identifier + counter++;
                if (!hoistedVariables.ContainsKey(new LiftedVariableKey(SyntaxFactory.Identifier(currentName))))
                {
                    return(currentName);
                }
            }while (true);
        }
Exemplo n.º 4
0
 public bool Equals(LiftedVariableKey other)
 {
     return(string.Equals(identifier, other.identifier) && (Equals(symbol, other.symbol) || symbol == null || other.symbol == null));
 }