Bug 423083 - [occurrences] Mark use of object properties
Summary: [occurrences] Mark use of object properties
Status: RESOLVED FIXED
Alias: None
Product: Orion (Archived)
Classification: ECD
Component: JS Tools (show other bugs)
Version: 5.0   Edit
Hardware: PC Mac OS X
: P3 enhancement (vote)
Target Milestone: 6.0 RC1   Edit
Assignee: Curtis Windatt CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy
Depends on:
Blocks: 418866
  Show dependency tree
 
Reported: 2013-12-03 13:41 EST by Michael Rennie CLA
Modified: 2014-06-12 14:45 EDT (History)
2 users (show)

See Also:


Attachments
Work in progress (10.81 KB, patch)
2014-06-05 17:18 EDT, Curtis Windatt CLA
no flags Details | Diff
updated (10.81 KB, patch)
2014-06-09 11:48 EDT, Michael Rennie CLA
no flags Details | Diff
another refresh (10.81 KB, patch)
2014-06-09 12:19 EDT, Michael Rennie CLA
no flags Details | Diff
Update to handle nested object expressions (11.71 KB, patch)
2014-06-09 17:11 EDT, Curtis Windatt CLA
no flags Details | Diff
Patch for nested contents and ignored punctuators (16.04 KB, application/octet-stream)
2014-06-11 14:31 EDT, Curtis Windatt CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Rennie CLA 2013-12-03 13:41:33 EST
Consider the following snippet:

var Baz = {
	one: function() {
		return 'one';
	},
	
	two: function() {
		return this.one();
	},
	
	three: function() {
		return this.one();
	}
};

var Bar.one = Baz.one;

If you place the carat in 'one:' I would expect the two uses of 'this.one' to be marked. For bonus points if would be awesome if the use of Baz.one could be marked also.
Comment 1 Michael Rennie CLA 2013-12-03 13:45:04 EST
(In reply to Michael Rennie from comment #0)
> For bonus points if would be awesome if the use of Baz.one
> could be marked also.

This should actually be simple-ish (in this case anyway) since we can look ahead when we hit the VariableDeclarator to compose the member expression name and match it. Although that might introduce a performance hit, since we have code to short-circuit when we leave the defining scope.
Comment 2 Curtis Windatt CLA 2014-06-05 17:18:04 EDT
Created attachment 244019 [details]
Work in progress

This patch adds support for object properties and some tests, but it comes with a few caveats:
- Treats object property selection separately similar to 'this' selection
- To determine whether an object property is selected, we have to use findNode() instead of findToken(), possible performance impact
- There appears to be a bug in the findNode() with parents option that when selecting object property values returns the node itself as its own parent. i.e. {c: c}, select the right hand side c, it's parent is also the identifier c. The patch gets around this most of the time by asking for the node's direct parent, not searching the array of parents.

Unless there is a major concern with the performance issue, I suggest cleaning up the work and pushing it next week as it is very helpful when working on Orion files.
Comment 3 Michael Rennie CLA 2014-06-09 11:48:14 EDT
Created attachment 244090 [details]
updated

This patch is an update with the latest changes from master merged in.
Comment 4 Michael Rennie CLA 2014-06-09 12:19:22 EDT
Created attachment 244096 [details]
another refresh

Another refresh to merge WhileStatement changes
Comment 5 Curtis Windatt CLA 2014-06-09 17:11:17 EDT
Created attachment 244099 [details]
Update to handle nested object expressions

This patch includes a change to fix occurrences with nested object expressions (with properties of the same name).  We need to skip object expressions that don't enclose the selection and we need to not stop looking for occurrences just because we have found a matching property definition (a nested scope may redefine).

Even when working with large files, the performance impact was not noticeable.  However, the use of findNode causes a much bigger problem.  The node range will always include everything up until the next node.  As punctuators aren't included in the AST, selecting whitespace, semicolons, etc. will still mark occurrences of the closest node.
Comment 6 Curtis Windatt CLA 2014-06-11 14:31:24 EDT
Created attachment 244165 [details]
Patch for nested contents and ignored punctuators

This patch tweaks the fix for nested object expressions and fixes the problem of not recognizing punctuators by getting both the ast node and the token.  The patch also adds tests for all these scenarios.

Unfortunately, the fix makes the performance impact noticeable.  While not substantial (maybe a half second loss at the end of the 27k line js file), it can be noticed.  A fix for Bug 436191 could eliminate this cost.
Comment 7 Curtis Windatt CLA 2014-06-12 14:45:50 EDT
(In reply to Curtis Windatt from comment #6)
> Unfortunately, the fix makes the performance impact noticeable.  While not
> substantial (maybe a half second loss at the end of the 27k line js file),
> it can be noticed.  A fix for Bug 436191 could eliminate this cost.

I overstated the performance impact. After some minor tweaking, I can no longer tell a noticeable difference in occurrence calculation with my changes.  On a 27k long file, occurrences still take time to show up, but this change does not make it noticeably longer.

I also found a bug in the findNode function where it does not remove the found node from the parents list if it was the last node in the ast.  This is only evident in the tests as the ast nodes have a correct parent node when in the editor (I used the parent node if available, otherwise checking the parents array).

http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=e415f79293d7909205b7af309565b82f77624757
Pushed the final changes to master.