Skip to content

this-function parameter can be renamed #9037

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

Closed
sandersn opened this issue Jun 8, 2016 · 8 comments
Closed

this-function parameter can be renamed #9037

sandersn opened this issue Jun 8, 2016 · 8 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@sandersn
Copy link
Member

sandersn commented Jun 8, 2016

function(this/**/: string, x: number) {
  return this.length;
}

Now try to rename or find all references at /**/.

Expected: Message "You cannot rename this element".

Actual: Rename just the parameter, nothing in the body. Find all references just finds one reference, the definition.

Probably this needs to be classified as ThisKeyword by the parser as long as that doesn't break anything else.

@sandersn
Copy link
Member Author

sandersn commented Jun 8, 2016

Thanks to @weswigham for coming up with this one.

@mhegazy mhegazy added the Bug A bug in TypeScript label Jun 8, 2016
@mhegazy mhegazy added this to the TypeScript 2.0 milestone Jun 8, 2016
@DanielRosenwasser
Copy link
Member

I dunno, I like the flexibility here - for instance, imagine I want to stop using this and want to start passing in an object explicitly? As long as this stays contained to the function and doesn't leak into other scopes that have their own this, I feel like this is fine.

@sandersn
Copy link
Member Author

Unfortunately it would be a lot of work because this isn't treated like a normal identifier anywhere else. Notice that the current behaviour doesn't rename body thises. That's because those occurrences aren't linked to the parameter via a symbol, but ad-hoc code in checkThisExpression.

@weswigham
Copy link
Member

weswigham commented Jun 14, 2016

So, for consistency, we should probably just change the parameter to be a this-keyword, then if we actually want renaming capabilities, add a branch in find all references/rename where inputting a value-position this yields all similarly-scoped value-position thises.

The other option being to leave it as a parameter and add special cases for parameters named 'this' in a bunch of places, which seems hackier to me, IMO.

@basarat
Copy link
Contributor

basarat commented Jun 15, 2016

imagine I want to stop using this and want to start passing in an object explicitly

I end up adding this: {} and then fix the errors for this access and then after fixing I delete the this: {} annotation. Just a workflow that's worked for me personally ;) 🌹

@ghost
Copy link

ghost commented Jun 17, 2016

This is related to #9198, so do you mind if I take this?

@sandersn
Copy link
Member Author

Sure, although #9198 is a lot bigger than this issue. The fix in #9171 just prevents rename for this identifiers, and the alternate approach of parsing a ThisKeyword as a parameter makes the possibility of renaming Just Working even less likely.

@mhegazy mhegazy assigned ghost and unassigned sandersn Jun 22, 2016
@ghost ghost closed this as completed in #9270 Jun 24, 2016
@RyanCavanaugh
Copy link
Member

Is this fixed?

@ghost ghost added the Fixed A PR has been merged for this issue label Jun 24, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants