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

Bug 476326

Summary: Rename element seems to miss the last occurrence
Product: [ECD] Orion Reporter: Eric Moffatt <emoffatt>
Component: JS ToolsAssignee: Michael Rennie <Michael_Rennie>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: Michael_Rennie, steve_northover
Version: 10.0   
Target Milestone: 10.0   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
note that the last ref to 'property' isn't selected none

Description Eric Moffatt CLA 2015-09-01 09:58:04 EDT
Created attachment 256291 [details]
note that the last ref to 'property' isn't selected

I was just coding and tried to use the Rename Element...it missed the last occurrence (see attached image)...
Comment 1 Eric Moffatt CLA 2015-09-01 10:15:18 EDT
Here's the offending code...

		run: function run(server, query) {
			var property = this._getDefNode(server, query);
			while (property) {
				var fileName = property.value.sourceFile.name;
				var newQuery = {start: property.value.range[0],
								end: property.value.range[1],
								type: "definition", //$NON-NLS-1$
								file: fileName};
				if (property.value.type === "FunctionExpression") {
					return {implementation: newQuery};
				} else if (property.value.type === "Identifier") {
					property = this._getDefNode(server, newQuery);
				}
			}
			return {implementation: {}};
		},
Comment 2 Steve Northover CLA 2015-09-01 15:01:34 EDT
Curtis, can you fix this one (or determine that it is not a regression at least)?  This is basic functionality that is broken.  Is it also broken in prod etc.?  Sorry I don't have time to chase it down.
Comment 3 Michael Rennie CLA 2015-09-01 16:03:11 EDT
(In reply to Steve Northover from comment #2)
> Curtis, can you fix this one (or determine that it is not a regression at
> least)?  This is basic functionality that is broken.  Is it also broken in
> prod etc.?  Sorry I don't have time to chase it down.

Here is a simple snippet to reproduce:

var foo = {
	run: function () {
		var property = {};
		if (property.value.type === "Identifier") {
			property = {};
		}
	}
}

It is not a regression. I have too many changes in my workspace right now to try the latest version of Tern to see if it is fixed.
Comment 4 Michael Rennie CLA 2015-09-01 16:44:46 EDT
This was indeed a bug in Tern. It was not visiting the variable pattern.

Fixed in: http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=0c4b2adccf0825b0ae080bb5c707667ca4ee800a

I also confirmed it is fixed in the latest version of Tern:

https://github.com/marijnh/tern/blob/master/lib/infer.js#L2067