Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is professional quality JavaScript refactoring plugin for Eclipse (or Intellij IDEA)?

Today when I tried to do simple renaming refactor in JavaScript using intellij IDEA 10, I was shocked what it did. It renamed that Class attribute everywhere regardless the attribute belonged to that class or not! For example Baz.attr1 renamed to Baz.attribute1, it also renamed Box.attr1 to Box.attribute1. Refactor Preview does not help here because there are hundreds of places in which the same attribute name is used under different situations like this.attr1 type of references.

Eclipse does not even have JavaScript rename refactoring.

In additional to renaming I am looking to refactor a group of functions and move them to Object Literal notations such as

function foo() {

}
function bar() {
}

refactor to :

var MyCompany.Baz = {
 foo: function() {
  },
 bar: function() {
 }

}

It should refactor all references to those function calls in all the files including HTML and JSP files like foo(); changing to MyCompany.Baz.foo();

There is no such thing in either IDE.

Is there high quality plugin available for JavaScript for Eclipse (prefer) or Intellij IDEA that would do the kinds refactorings of I am talking about?

like image 799
ace Avatar asked Feb 24 '23 10:02

ace


1 Answers

I believe that the kind of rename refactoring that you want is not possible in a dynamic language.

Let's say that you have your classes Baz and Box with the attr1 attribute.

If we write something like:

var b;
if (someCondition) {
    b = createBox();
} else {
    b = createBaz();
}
b.attr1 = "value";

What should the refactoring program do?

Given that the type of the variable is only known when the corresponding code is executed, and that this type can differ at each invocation of that code, the computer is unable to determine to which definition an invocation of the attribute 'attr1' should be linked to.

like image 90
Jean Hominal Avatar answered Apr 29 '23 05:04

Jean Hominal