debugger icon indicating copy to clipboard operation
debugger copied to clipboard

[FunctionSearch] Variables not listed in 'variables' list

Open ruturajv opened this issue 9 years ago • 9 comments

variables

The following variables should've been listed as variables

  • fn1
  • noDeclaredString
  • nonDeclaredVariable
  • someMember

@jasonLaster @wldcordeiro - I've figured out what needs to be done, just need someone's confirmation if this bug holds true

ruturajv avatar Mar 29 '17 05:03 ruturajv

I think those are technically syntax errors? They're undeclared so I don't think it makes sense to include them in the lists.

wldcordeiro avatar Mar 29 '17 05:03 wldcordeiro

Doesn't JS allow undeclared variables (I know its a bad practice, throws error in use strict) ? I know we shouldn't support use of that, but... isnt' it theoretically a variable 😄

and someMember ?

ruturajv avatar Mar 29 '17 06:03 ruturajv

someMember is part of an undeclared variable so it's by association there. I'm not sure what the best opinion here is since JS does create those variables on the global scope.

wldcordeiro avatar Mar 29 '17 08:03 wldcordeiro

I was thinking that our main concern might be that developers want to search for these variables despite them being syntactically incorrect. This could actually be a good path for people searching for errors.

clarkbw avatar Mar 30 '17 01:03 clarkbw

Based on @clarkbw comment, I wonder if we could do something like below - highlight incorrectly created variables. selection_008

ruturajv avatar Mar 30 '17 10:03 ruturajv

Thanks @ruturajv , this is an interesting problem.

I think we're limited by what babel offers. If it's in the AST we can do it...

If not, we can always offer a link at the bottom of search results to search the text: "10 matches in file"...

jasonLaster avatar Mar 30 '17 15:03 jasonLaster

noDeclaredString = "howdy!";
var declaredString = "abc";
let letString = "abc";

for the above, the first line comes as ExpressionStatement and the next two lines are VariableDeclaration in AST

ruturajv avatar Mar 31 '17 04:03 ruturajv

hmm - do we show ExpressionStatement in the variables list? I'd be okay doing that if we're in an assignment expression

jasonLaster avatar Mar 31 '17 22:03 jasonLaster

Hey @ruturajv,

  1. it looks like functions are picked up here

  2. I worry we'll pick up every variable assignment which will lead to a lot of duplication:

  3. we'll miss global variables assigned this way, but that's probably okay for now. Given we'll have a simpler system for the time being.

let a = 2;
a = 3;
a = 4;

jasonLaster avatar Apr 17 '17 15:04 jasonLaster