Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Javascript] Go to definition doesn't work for functions in objects passed as parameters #29716

Closed
csnv opened this issue Feb 4, 2019 · 5 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@csnv
Copy link

csnv commented Feb 4, 2019

VSCode version: 1.30.2
OS: Mac OS 10.13.6

Search terms: Go to definition, object functions, function arguments

Steps to reproduce:
With the following code, right click on this.funcA() and choose "Go to definition".

Code:

var testFn = function(myProps) { };

testFn({
	funcA: function() {},
	funcB: function() {
		this.funcA();
	}
});

Expected behavior:
Editor jumps to funcA definition.

Actual result:
Editor does nothing.

The same example works fine if the object is outside the function call:

var testObj = {
	funcA: function() {},
	funcB: function() {
		this.funcA();
	}
};

Does this issue occur when all extensions are disabled?: Yes

@Mcfloy
Copy link

Mcfloy commented Feb 4, 2019

How does it concern Typescript ?

@csnv
Copy link
Author

csnv commented Feb 4, 2019

How does it concern Typescript ?

This issue occurs in VS Code. The following issues under Typescript are similar, but concerns Javascript instead:
#29292
#29232
#26666
#18171

AFAIK, the typescript server for definitions is the same for Javascript. Nonetheless, I'm ok with closing this issue and opening it in the correct project if it does not belong here.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Feb 5, 2019
@RyanCavanaugh
Copy link
Member

The TS/JS inference engine doesn't assume that this in an object literal refers to the surrounding object - this isn't at all guaranteed and will vary by how the function is called.

@csnv
Copy link
Author

csnv commented Feb 6, 2019

Can we have it as an option? Or maybe can we assume that this is refering to the object itself, if nothing else is found?
WebStorm (for example) identifies this case pretty well.

@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants