public override string ToCode(ToCodeFormat format) { StringBuilder sb = new StringBuilder(); if (Parser.Settings.LocalRenaming != LocalRenaming.KeepAll && Parser.Settings.IsModificationAllowed(TreeModifications.LocalRenaming)) { // we're hyper-crunching. // we want to output our label as per our nested level. // top-level is "a", next level is "b", etc. // we don't need to worry about collisions with variables. sb.Append(CrunchEnumerator.CrunchedLabel(m_nestCount)); } else { // not hypercrunching -- just output our label sb.Append(m_label); } sb.Append(':'); if (m_statement != null) { // don't sent the AlwaysBraces down the chain -- we're handling it here. // but send any other formats down -- we don't know why they were sent. sb.Append(m_statement.ToCode(format)); } return(sb.ToString()); }
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(); } }
public override string ToCode(ToCodeFormat format) { StringBuilder sb = new StringBuilder(); sb.Append("continue"); if (m_label != null) { sb.Append(' '); if (Parser.Settings.LocalRenaming != LocalRenaming.KeepAll && Parser.Settings.IsModificationAllowed(TreeModifications.LocalRenaming)) { // hypercrunched -- only depends on nesting level sb.Append(CrunchEnumerator.CrunchedLabel(m_nestLevel)); } else { // not hypercrunched -- just output label sb.Append(m_label); } } return(sb.ToString()); }