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

Bug 474838

Summary: Variable re-declarations not flagged in named FunctionExpression
Product: [ECD] Orion Reporter: Mark Macdonald <mamacdon>
Component: JS ToolsAssignee: Michael Rennie <Michael_Rennie>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Michael_Rennie
Version: 9.0   
Target Milestone: 10.0   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Mark Macdonald CLA 2015-08-12 14:05:51 EDT
Create a .js file containing this code:

/*eslint no-unused-vars:0*/
(function fizz() {
	var a, a;
});

var _ = function fizz2() {
	var a, a;
};

(function fizz3() {
	var a, a;
}());


Expected result: The re-declaration of 'a' inside each function should be flagged.
Actual result: No warnings are shown

Strangely, this behavior hinges on the FunctionExpressions being named: if you delete the names, you get the expected 3 warnings.
Comment 1 Michael Rennie CLA 2015-08-12 14:51:26 EDT
Looks like the code in our rule is bogus:

if(node.type === "FunctionExpression" && node.id && node.id.name) {
  scope  = scope.upper;
}

if I take that code out it works as expected. 

I don't recall why we have this check in there, it looks like a hack to workaround an old bug in escope (maybe?), but with the version we are using now, the scopes returned from context.getScope() all seem fine.
Comment 2 Mark Macdonald CLA 2015-08-12 15:20:32 EDT
(In reply to Michael Rennie from comment #1)
> I don't recall why we have this check in there, it looks like a hack to
> workaround an old bug in escope (maybe?), but with the version we are using
> now, the scopes returned from context.getScope() all seem fine.

I don't remember either. It is probably an old workaround that can just be removed.