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
renaming does not respect scoping #20
Comments
See patch c595988 . I've made it simply return an error response in a situation like this. |
Thanks. This seems to fix half of the issue - renaming However, if I rename the first Other scope-related corner cases: renaming to or from |
This is for an editor, not a completely automated refactoring tool. I'd say it should allow renaming anything to anything (it would be helpful to get a warning for funny cases, but not refuse to rename; after all, you have "undo"). For example sometimes I rename a var to (not using Tern yet, but I have a simple tool that has a similar feature, based on UglifyJS). EDIT: just noticed this is allowed on ternjs.net too — cool. :-) |
Great, thanks! It is good to see you take these fundamental issues seriously - makes tern stand out from the average JS tool project. That leaves only the implicit variables: renaming |
My call is that providing too much 'safety' on a tool can get in the way and insult the intelligence of its users. Renaming from |
Having worked on real refactorers before (lead role on Haskell, advisory on Erlang), my call is that there is no such thing as too much safety, only too little flexibility: if a user asks for renaming, the tool should try its best to do a renaming, and only that; if a user asks for a search and replace that might profit in some obscure way from being partially scope-aware, that is either a separate refactoring or a separate code transformation building on the same infrastructure. In principle, you could separately offer the "scoped occurrence search" and "replace occurrences" phases of renaming, and users would know that they are doing something odd if they have to use that instead of simple renaming. But in our experience (the basic Haskell refactorer project ran for 3 years), there were always proper refactorings hiding behind those odd requests, and finding those offered the most benefit (eg, capturing arguments and lifting out a piece of a function). Given the number of JS coders running into difficulties with There is little enough safety that can be provided for refactoring JS, which, prior to ES5 strict, does not even respect static scoping, and since renaming touches static variables and dynamic properties, renaming in full is tricky to make safe (FYI, Tool-supported Refactoring for JavaScript has a sample analysis). |
consider this code
Tern's renaming simply takes all occurences of
y
and replaces them withx
, resulting in the erroneous resultSee estr for a scope-preserving renaming in Javascript (the repo has some more annoying test cases).
The text was updated successfully, but these errors were encountered: