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