<p dir="auto">Can not be run properly because when broken output of --module system.<br>
Version of tsc problems occur 1.7.5 and 1.8.0.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// bug.ts
export var test = false;

if (!test) {
  test = false;
}"><pre class="notranslate"><span class="pl-c">// bug.ts</span>
<span class="pl-k">export</span> <span class="pl-k">var</span> <span class="pl-s1">test</span> <span class="pl-c1">=</span> <span class="pl-c1">false</span><span class="pl-kos">;</span>

<span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-s1">test</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-s1">test</span> <span class="pl-c1">=</span> <span class="pl-c1">false</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">tsc --module system bug.ts</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// bug.js
System.register([], function(exports_1) {
    var test;
    return {
        setters:[],
        execute: function() {
            exports_1(&quot;test&quot;, test = false);
            if (exports_1(&quot;test&quot;, !test)) { // &lt;- broken output
                exports_1(&quot;test&quot;, test = false); // &lt;- broken output
            }
        }
    }
});"><pre class="notranslate"><span class="pl-c">// bug.js</span>
<span class="pl-v">System</span><span class="pl-kos">.</span><span class="pl-en">register</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">exports_1</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">var</span> <span class="pl-s1">test</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-kos">{</span>
        <span class="pl-c1">setters</span>:<span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
        <span class="pl-en">execute</span>: <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-s1">exports_1</span><span class="pl-kos">(</span><span class="pl-s">"test"</span><span class="pl-kos">,</span> <span class="pl-s1">test</span> <span class="pl-c1">=</span> <span class="pl-c1">false</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">exports_1</span><span class="pl-kos">(</span><span class="pl-s">"test"</span><span class="pl-kos">,</span> <span class="pl-c1">!</span><span class="pl-s1">test</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-c">// &lt;- broken output</span>
                <span class="pl-s1">exports_1</span><span class="pl-kos">(</span><span class="pl-s">"test"</span><span class="pl-kos">,</span> <span class="pl-s1">test</span> <span class="pl-c1">=</span> <span class="pl-c1">false</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// &lt;- broken output</span>
            <span class="pl-kos">}</span>
        <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Don't understand why this code:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import { enableProdMode } from 'angular2/core';

export var DEBUG: boolean = false;

if (!DEBUG) {
    enableProdMode();
}"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-s1">enableProdMode</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'angular2/core'</span><span class="pl-kos">;</span>

<span class="pl-k">export</span> <span class="pl-k">var</span> <span class="pl-smi">DEBUG</span>: <span class="pl-smi">boolean</span> <span class="pl-c1">=</span> <span class="pl-c1">false</span><span class="pl-kos">;</span>

<span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-smi">DEBUG</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-en">enableProdMode</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Transpiles to this one, which in fact makes DEBUG to be true at the end! (tried also with <code class="notranslate">export const DEBUG: boolean = false;</code> with exactly the same result)</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="System.register(['angular2/core'], function(exports_1) {
    var core_1;
    var DEBUG;
    return {
    setters:[
            function (core_1_1) {
                core_1 = core_1_1;
            }],
        execute: function() {
            exports_1(&quot;DEBUG&quot;, DEBUG = false);
            if (exports_1(&quot;DEBUG&quot;, !DEBUG)) {
                core_1.enableProdMode();
            }
    }
    }
});"><pre class="notranslate"><span class="pl-v">System</span><span class="pl-kos">.</span><span class="pl-en">register</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-s">'angular2/core'</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">exports_1</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">var</span> <span class="pl-s1">core_1</span><span class="pl-kos">;</span>
    <span class="pl-k">var</span> <span class="pl-c1">DEBUG</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-kos">{</span>
    <span class="pl-c1">setters</span>:<span class="pl-kos">[</span>
            <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">core_1_1</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
                <span class="pl-s1">core_1</span> <span class="pl-c1">=</span> <span class="pl-s1">core_1_1</span><span class="pl-kos">;</span>
            <span class="pl-kos">}</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
        <span class="pl-en">execute</span>: <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-s1">exports_1</span><span class="pl-kos">(</span><span class="pl-s">"DEBUG"</span><span class="pl-kos">,</span> <span class="pl-c1">DEBUG</span> <span class="pl-c1">=</span> <span class="pl-c1">false</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">exports_1</span><span class="pl-kos">(</span><span class="pl-s">"DEBUG"</span><span class="pl-kos">,</span> <span class="pl-c1">!</span><span class="pl-c1">DEBUG</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
                <span class="pl-s1">core_1</span><span class="pl-kos">.</span><span class="pl-en">enableProdMode</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">And this one:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import { enableProdMode } from 'angular2/core';

export var DEBUG: boolean = false;

if (DEBUG == false) {
    enableProdMode();
}"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-s1">enableProdMode</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'angular2/core'</span><span class="pl-kos">;</span>

<span class="pl-k">export</span> <span class="pl-k">var</span> <span class="pl-smi">DEBUG</span>: <span class="pl-smi">boolean</span> <span class="pl-c1">=</span> <span class="pl-c1">false</span><span class="pl-kos">;</span>

<span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-smi">DEBUG</span> <span class="pl-c1">==</span> <span class="pl-c1">false</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-en">enableProdMode</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Transpiles to this one which is the correct one:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="System.register(['angular2/core'], function(exports_1) {
    var core_1;
    var DEBUG;
    return {
    setters:[
            function (core_1_1) {
                core_1 = core_1_1;
            }],
        execute: function() {
            exports_1(&quot;DEBUG&quot;, DEBUG = false);
            if (DEBUG == false) {
                core_1.enableProdMode();
            }
    }
    }
});"><pre class="notranslate"><span class="pl-v">System</span><span class="pl-kos">.</span><span class="pl-en">register</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-s">'angular2/core'</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">exports_1</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">var</span> <span class="pl-s1">core_1</span><span class="pl-kos">;</span>
    <span class="pl-k">var</span> <span class="pl-c1">DEBUG</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-kos">{</span>
    <span class="pl-c1">setters</span>:<span class="pl-kos">[</span>
            <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">core_1_1</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
                <span class="pl-s1">core_1</span> <span class="pl-c1">=</span> <span class="pl-s1">core_1_1</span><span class="pl-kos">;</span>
            <span class="pl-kos">}</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
        <span class="pl-en">execute</span>: <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-s1">exports_1</span><span class="pl-kos">(</span><span class="pl-s">"DEBUG"</span><span class="pl-kos">,</span> <span class="pl-c1">DEBUG</span> <span class="pl-c1">=</span> <span class="pl-c1">false</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">DEBUG</span> <span class="pl-c1">==</span> <span class="pl-c1">false</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
                <span class="pl-s1">core_1</span><span class="pl-kos">.</span><span class="pl-en">enableProdMode</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Here are my typescript options (gulp-typescript):</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var tsOptions = {
    outDir: PATHS.outDir,
    target: &quot;ES5&quot;,
    module: &quot;system&quot;,
    moduleResolution: &quot;node&quot;,
    sourceMap: false,
    emitDecoratorMetadata: true,
    experimentalDecorators: true,
    removeComments: true,
    noImplicitAny: false,
    noExternalResolve: true
};"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">tsOptions</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
    <span class="pl-c1">outDir</span>: <span class="pl-c1">PATHS</span><span class="pl-kos">.</span><span class="pl-c1">outDir</span><span class="pl-kos">,</span>
    <span class="pl-c1">target</span>: <span class="pl-s">"ES5"</span><span class="pl-kos">,</span>
    <span class="pl-c1">module</span>: <span class="pl-s">"system"</span><span class="pl-kos">,</span>
    <span class="pl-c1">moduleResolution</span>: <span class="pl-s">"node"</span><span class="pl-kos">,</span>
    <span class="pl-c1">sourceMap</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span>
    <span class="pl-c1">emitDecoratorMetadata</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
    <span class="pl-c1">experimentalDecorators</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
    <span class="pl-c1">removeComments</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
    <span class="pl-c1">noImplicitAny</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span>
    <span class="pl-c1">noExternalResolve</span>: <span class="pl-c1">true</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>