I have polluted one of my classes with too many functions. Now, I want to clean it up by introducing several namespaces.
Consider following example:
const Tool = {};
tool.fct1 = function() { /* ... */ };
tool.fct2 = function() { /* ... */ };
// ...
tool.fctN = function() { /* ... */ };
where many external modules make use of these functions
import {Tool} from '/path/to/tool.js'
const result = Tool.fctN();
Now, introducing namespaces would cause Tool to be more structured like this:
const Tool = {};
Tool.ns1 = {};
Tool.ns2 = {};
Tool.ns1.fct1 = function() { /* ... */ };
Tool.ns1.fct2 = function() { /* ... */ };
// ...
Tool.ns2.fctN = function() { /* ... */ };
So, the depending code has to change to the following structure:
import {Tool} from '/path/to/tool.js'
const result = Tool.ns2.fctN();
The problem is
that I tried several refactoring functionality in WebStorm but none allowed me to automatically co-refactor depending code.
Refactor.Rename
Obviously the first thing to try. Refactor -> rename fct1 to ns1.fct1
Result: WS prevented me from doing that and showed a message ns1.fct1 is not a valid identifier. (Works neither when ns1 being property of Tool nor when being not.)
Refactor.Change-siganture
Obviously changes only signature and not properties / variables.
Refactor.Move, Refactor.Copy, Refactor.Safe-Delete
No ways of changing code in this file as described above.
Refactor.extract
Extracting either does not change anything related to the current variable or extracts an inner variable, which does not help to introduce a namespace at all.
Refactor.Inline
Trying inline on Tool.fct1 shows message cannot inline complex expression evaluation.
Anybody found a solution to this so that I don't need to rewrite all my code by hand?