title: How to avoid "`this` has been rewritten to `undefined`" warning when bundling Scala.js file with rollup?
body: <p>I'm using a Scala.js file with ECMAScript modules inside a Svelte project. When building the project with rollup I get the warning</p>
  <blockquote>
  <p><code>this</code> has been rewritten to <code>undefined</code></p>
  </blockquote>
  <p>With pointing at last line of code here</p>
  <pre><code>var $linkingInfo = Object.freeze({
    &quot;esVersion&quot;: 6,
    &quot;assumingES6&quot;: true,
    &quot;productionMode&quot;: true,
    &quot;linkerVersion&quot;: &quot;1.7.1&quot;,
    &quot;fileLevelThis&quot;: this
  });
  </code></pre>
  <p>and linking to <a href="https://rollupjs.org/guide/en/#error-this-is-undefined" rel="nofollow noreferrer">this section</a> of the documentation</p>
  <blockquote>
  <p>Error: &quot;this is undefined&quot;
  In a JavaScript module, this is undefined at the top level (i.e., outside functions). Because of that, Rollup will rewrite any this references to undefined so that the resulting behaviour matches what will happen when modules are natively supported.
  There are occasional valid reasons for this to mean something else. If you're getting errors in your bundle, you can use <strong>options.context</strong> and options.moduleContext to change this behaviour.</p>
  </blockquote>
  <p>In the context section I find</p>
  <blockquote>
  <p>By default, the context of a module – i.e., the value of <code>this</code> at the top level – is <code>undefined</code>. In rare cases you might need to change this to something else, like 'window'.</p>
  </blockquote>
  <p>Is changing the context from <code>this</code> to <code>window</code> the right thing to do in this case?
  And how exactly do I add the option to rollup?<br />
  The documentation gives this info <code>CLI: --context &lt;contextVariable&gt;</code>, When adding the option like this the error persists:</p>
  <pre><code>[package.json]
  
  &quot;scripts&quot;: {
    &quot;build&quot;: &quot;rollup -c --context window&quot;,
    &quot;dev&quot;: &quot;rollup -c -w --context window&quot;
  ...
  }
  </code></pre>
  <p>When adding this line to the rollup.config file</p>
  <pre><code>export default {
      input: ...,
      output: {...},
      plugins: [...],
      watch: {...},
  
      context: &quot;window&quot;
  };
  </code></pre>
  <p>the warning vanishes - is this the right thing to do?</p>