[FunctionSearch] name functions based on their var
We currently treat this case obj.me = function() {} obj.me = () => {} as anonymous functions. In these cases we should use the assignment to find the name me.
Here's a failing test to help someone get started
diff --git a/src/utils/tests/parser.js b/src/utils/tests/parser.js
index 6c0cbba..84d5194 100644
--- a/src/utils/tests/parser.js
+++ b/src/utils/tests/parser.js
@@ -82,6 +82,8 @@ const SOURCES = {
}
};
+ Obj.property = () => {}
+
class Ultra {
constructor() {
this.awesome = true;
@@ -165,6 +167,7 @@ describe("parser", () => {
"incrementCounter",
"sum",
"doThing",
+ "property",
"doOtherThing",
"constructor",
"beAwesome"
@@ -174,6 +177,7 @@ describe("parser", () => {
"count",
"counter",
"sum",
+ "property",
"a",
"b",
"Obj",
screenshot
I had considered adding this and wasn't sure whether to consider these functions or variables when I was adding the variable search capability. Is it okay to have them appear in both result lists or should we exclude from variables?
Showing up in both places is fine although in this case I don't know if we should show all the properties in variable search. It's something to talk about in another issue
Not sure if I've understood this clearly,
- but by typing "a" in search, we shouldn't be showing any output as "anonymous function" which are assigned to members
- "property" if searched should list / reference to that anonymous fn
@ruturajv We should still have functions output as anonymous. The following situations should be anonymous
(function() {
console.log("IIFE");
})();
const things = [1, 2, 3];
const thingsSqrd = things.map(function(i) { return i * i }); // if this were an arrow function it'd still be anonymous
This is only when you have a function that is assigned to a variable so
const doThing = () => console.log("hey");
const doOtherThing = function() { console.log("HI"); };
Regarding properties, don't worry, that's a different discussion and already handled in our function searching logic. 😄
Hope that clarifies.
@wldcordeiro - thanks ! Pretty much clarifies it. :)
@jasonLaster - is the screenshot a mock ? cause when I created a simple HTML
<html>
<head>
<title>Function References</title>
</head>
<body>
<script type="text/javascript">
(function() {
console.log("IIFE");
})();
const things = [1, 2, 3];
// if this were an arrow function it'd still be anonymous
const thingsSqrd = things.map(function(i) { return i * i });
const doThing = () => console.log("hey");
const doOtherThing = function() { console.log("HI"); };
function commonFunction() {
console.log("I just relax...");
}
</script>
</body>
</html>
and tried to search commonFunction or anon, It didn't find anything.

Can you try with .html as well as .php? I'm not sure if we are treating php files as sources like we do html.
No, it doesn't work with .html either

Hmm I think you're running into #2378.