debugger icon indicating copy to clipboard operation
debugger copied to clipboard

[FunctionSearch] name functions based on their var

Open jasonLaster opened this issue 9 years ago • 9 comments

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

jasonLaster avatar Mar 10 '17 11:03 jasonLaster

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?

wldcordeiro avatar Mar 11 '17 05:03 wldcordeiro

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

jasonLaster avatar Mar 11 '17 08:03 jasonLaster

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 avatar Mar 12 '17 04:03 ruturajv

@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 avatar Mar 12 '17 05:03 wldcordeiro

@wldcordeiro - thanks ! Pretty much clarifies it. :)

ruturajv avatar Mar 12 '17 08:03 ruturajv

@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. search

ruturajv avatar Mar 15 '17 06:03 ruturajv

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.

wldcordeiro avatar Mar 15 '17 07:03 wldcordeiro

No, it doesn't work with .html either

html-debug

ruturajv avatar Mar 15 '17 07:03 ruturajv

Hmm I think you're running into #2378.

jasonLaster avatar Mar 15 '17 23:03 jasonLaster