internal virtual void ValidateGeneratedNames() { // check all the variables defined within this scope. // we're looking for uncrunched generated fields. foreach (JSVariableField variableField in m_fieldTable) { JSLocalField localField = variableField as JSLocalField; if (localField != null && localField.IsGenerated && localField.CrunchedName == null) { // we need to rename this field. // first we need to walk all the child scopes depth-first // looking for references to this field. Once we find a reference, // we then need to add all the other variables referenced in those // scopes and all above them (from here) so we know what names we // can't use. Dictionary <string, string> avoidTable = new Dictionary <string, string>(); GenerateAvoidList(avoidTable, localField.Name); // now that we have our avoid list, create a crunch enumerator from it CrunchEnumerator crunchEnum = new CrunchEnumerator(avoidTable); // and use it to generate a new name localField.CrunchedName = crunchEnum.NextName(); } } // recursively traverse through our children foreach (ActivationObject scope in m_childScopes) { scope.ValidateGeneratedNames(); } }
internal virtual void HyperCrunch() { // if we're not known at compile time, then we can't crunch // the local variables in this scope, because we can't know if // something will reference any of it at runtime. // eval is something that will make the scope unknown because we // don't know what eval will evaluate to until runtime if (m_isKnownAtCompileTime) { // get an array of all the uncrunched local variables defined in this scope JSLocalField[] localFields = GetUncrunchedLocals(); if (localFields.Length > 0) { // create a crunch-name enumerator, taking into account our verboten set CrunchEnumerator crunchEnum = new CrunchEnumerator(Verboten); for (int ndx = 0; ndx < localFields.Length; ++ndx) { JSLocalField localField = localFields[ndx]; // if we are an unambiguous reference to a named function expression and we are not // referenced by anyone else, then we can just skip this variable because the // name will be stripped from the output anyway. // we also always want to crunch "placeholder" fields. if (localField.CanCrunch && (localField.RefCount > 0 || localField.IsDeclared || localField.IsPlaceholder || !(Parser.Settings.RemoveFunctionExpressionNames && Parser.Settings.IsModificationAllowed(TreeModifications.RemoveFunctionExpressionNames)))) { localFields[ndx].CrunchedName = crunchEnum.NextName(); } } } } // then traverse through our children foreach (ActivationObject scope in m_childScopes) { scope.HyperCrunch(); } }