public virtual JSVariableField DeclareField(string name, object value, FieldAttributes attributes) { JSVariableField variableField; if (!NameTable.TryGetValue(name, out variableField)) { variableField = CreateField(name, value, attributes); AddField(variableField); } return(variableField); }
public virtual JSVariableField this[string name] { get { JSVariableField variableField; // check to see if this name is already defined in this scope if (!NameTable.TryGetValue(name, out variableField)) { // not in this scope variableField = null; } return(variableField); } }
public override JSVariableField DeclareField(string name, object value, FieldAttributes attributes) { JSVariableField variableField; if (!NameTable.TryGetValue(name, out variableField)) { // find the owning scope where variables are defined ActivationObject owningScope = Parent; while (owningScope is BlockScope) { owningScope = owningScope.Parent; } // create the variable in that scope variableField = owningScope.DeclareField(name, value, attributes); // and create an inner-reference in our scope variableField = CreateInnerField(variableField); } return(variableField); }
private void ManualRenameFields() { // if the local-renaming kill switch is on, we won't be renaming ANYTHING, so we'll have nothing to do. if (m_settings.IsModificationAllowed(TreeModifications.LocalRenaming)) { // if the parser settings has a list of rename pairs, we will want to go through and rename // any matches if (m_settings.HasRenamePairs) { // go through the list of fields in this scope. Anything defined in the script that // is in the parser rename map should be renamed and the auto-rename flag reset so // we don't change it later. foreach (var varField in NameTable.Values) { // don't rename outer fields (only actual fields), // and we're only concerned with global or local variables -- // those which are defined by the script (not predefined, not the arguments object) if (varField.OuterField == null && (varField.FieldType != FieldType.Arguments && varField.FieldType != FieldType.Predefined)) { // see if the name is in the parser's rename map string newName = m_settings.GetNewName(varField.Name); if (!string.IsNullOrEmpty(newName)) { // it is! Change the name of the field, but make sure we reset the CanCrunch flag // or setting the "crunched" name won't work. // and don't bother making sure the name doesn't collide with anything else that // already exists -- if it does, that's the developer's fault. // TODO: should we at least throw a warning? varField.CanCrunch = true; varField.CrunchedName = newName; // and make sure we don't crunch it later varField.CanCrunch = false; } } } } // if the parser settings has a list of no-rename names, then we will want to also mark any // fields that match and are still slated to rename as uncrunchable so they won't get renamed. // if the settings say we're not going to renaming anything automatically (KeepAll), then we // have nothing to do. if (m_settings.LocalRenaming != LocalRenaming.KeepAll) { foreach (var noRename in m_settings.NoAutoRenameCollection) { // don't rename outer fields (only actual fields), // and we're only concerned with fields that can still // be automatically renamed. If the field is all that AND is listed in // the collection, set the CanCrunch to false JSVariableField varField; if (NameTable.TryGetValue(noRename, out varField) && varField.OuterField == null && varField.CanCrunch) { // no, we don't want to crunch this field varField.CanCrunch = false; } } } } }