in src/SourceMapToolkit.CallstackDeminifier/FunctionFinderVisitor.cs [47:94]
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;
}