| Summary: | [occurrences] Ignore redefines when inside nested scopes and handle hoisting | ||
|---|---|---|---|
| Product: | [ECD] Orion | Reporter: | Curtis Windatt <curtis.windatt.public> |
| Component: | JS Tools | Assignee: | 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 | ||
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)
}
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
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 |
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.