/// <summary> /// Gets the name and location information related to the function name binding for a FunctionObject node /// </summary> private IReadOnlyList <BindingInformation> GetBindings(FunctionObject node) { List <BindingInformation> result = new List <BindingInformation>(); // Gets the name of an object property that a function is bound to, like the static method foo in the example "object.foo = function () {}" if (node.Parent is BinaryOperator parentBinaryOperator) { result.AddRange(ExtractBindingsFromBinaryOperator(parentBinaryOperator)); return(result); } // Gets the name of an object property that a function is bound to against the prototype, like the instance method foo in the example "object.prototype = {foo: function () {}}" if (node.Parent is ObjectLiteralProperty parentObjectLiteralProperty) { // See if we can get the name of the object that this method belongs to ObjectLiteral objectLiteralParent = parentObjectLiteralProperty.Parent?.Parent as ObjectLiteral; if (objectLiteralParent != null && objectLiteralParent.Parent is BinaryOperator binaryOperator) { result.AddRange(ExtractBindingsFromBinaryOperator(binaryOperator)); } result.Add( new BindingInformation( name: parentObjectLiteralProperty.Name.Name, sourcePosition: new SourcePosition( zeroBasedLineNumber: parentObjectLiteralProperty.Context.StartLineNumber - 1, zeroBasedColumnNumber: parentObjectLiteralProperty.Context.StartColumn))); return(result); } // Gets the name of a variable that a function is bound to, like foo in the example "var foo = function () {}" BindingIdentifier bindingIdentifier = (node.Parent is VariableDeclaration parentVariableDeclaration) ? parentVariableDeclaration.Binding as BindingIdentifier : node.Binding; // Gets the name bound to the function, like foo in the example "function foo() {} if (bindingIdentifier != null) { result.Add( new BindingInformation( name: bindingIdentifier.Name, sourcePosition: new SourcePosition( zeroBasedLineNumber: bindingIdentifier.Context.StartLineNumber - 1, // Souce maps work with zero based line and column numbers, the AST works with one based line numbers. We want to use zero-based everywhere. zeroBasedColumnNumber: bindingIdentifier.Context.StartColumn))); return(result); } return(null); }
private static Lookup ConvertFromBindingIdentifier(BindingIdentifier bindingIdentifier) { Lookup lookup = null; if (bindingIdentifier != null) { lookup = new Lookup(bindingIdentifier.Context) { Name = bindingIdentifier.Name, VariableField = bindingIdentifier.VariableField }; // the binding is now referenced from the lookup bindingIdentifier.VariableField.IfNotNull(v => v.References.Add(lookup)); } return(lookup); }
private static BindingIdentifier ConvertToBindingIdentifier(Lookup lookup) { BindingIdentifier bindingIdentifier = null; if (lookup != null) { bindingIdentifier = new BindingIdentifier(lookup.Context) { Name = lookup.Name, VariableField = lookup.VariableField }; // the field now has another declaration, and one less reference lookup.VariableField.IfNotNull(v => { v.Declarations.Add(bindingIdentifier); v.References.Remove(lookup); }); } return(bindingIdentifier); }
public void Visit(BindingIdentifier node) { // not applicable; terminate }
public void Visit(BindingIdentifier node) { // we're good }
public virtual void Visit(BindingIdentifier node) { // no children }
public void Visit(BindingIdentifier node) { // binding identifier, so we don't care }
public void Visit(BindingIdentifier node) { // the binding identifier is the individual bound name node.IfNotNull(n => m_bindings.Add(n)); }
public void Visit(BindingIdentifier node) { Debug.Fail("shouldn't get here"); }
public void Visit(BindingIdentifier node) { // invalid! ignore IsValid = false; }