Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 438317

Summary: [occurrences] Ignore redefines when inside nested scopes and handle hoisting
Product: [ECD] Orion Reporter: Curtis Windatt <curtis.windatt.public>
Component: JS ToolsAssignee: Curtis Windatt <curtis.windatt.public>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Michael_Rennie
Version: 6.0   
Target Milestone: 7.0   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 411721, 428133    

Description Curtis Windatt CLA 2014-06-26 16:14:21 EDT
If we encounter a redefine, we try to take the last redefine before the selection start.  To do so we clear the list of occurrences found in the scope.  However, if we are inside a nested scope, we can't clear previous occurrences outside of the scope.

var a;
function f(){
	var a;
}
log(a);  // select a

OR 

function f() {
	function f(){};
    console.log(g);
}
f(); // select f

In these cases we should not mark defines at all inside the nested scope (assuming selection is outside of that scope).

We should also test cases where additional occurrences can be found inside nested scopes.  Perhaps we should be skipping the scope entirely if we encounter a redefine.
Comment 1 Michael Rennie CLA 2014-09-23 12:10:54 EDT
Here is another example of it not working:

var foo = 10;
function func() {
    var bar = foo; // select foo - selects nested redefines (WRONG)
    var foo = 3;
    function baz() {
        var foo = 4;
        var barrz = foo+10;
        var o = {
            one: function() {
                var foo = 5;
                var bazz = foo;
            }
        };
    }
    var bag = foo; //select foo - selects almost everything (WRONG)
}
Comment 2 Curtis Windatt CLA 2014-09-24 12:14:30 EDT
On top of not skipping scopes once we find a redefine, we also use the selection location.  However, due to 'hoisting', the var redefine should always be considered at the top of the scope.  This means we can't short circuit simply because the carat location has been passed.

var a = 1;
function g(){
  a = 2;  // Selection here
  var a;
}

Selection a=2 should select the inner variable.

http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html
Comment 3 Curtis Windatt CLA 2014-09-25 14:01:03 EDT
http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=446e075b0a44fdc1d072928a0051e71093499e63
Fixed in master with new tests

This will also fix the problematic test cases in Bug 428133