<p dir="auto">tsc version 1.7.5<br>
target == es6</p>
<p dir="auto">Notice how the import of 'routes' changes to 'routes_1' in the compiled version (<em>var routes_1 = require('../common/routes');</em>), but the object literal for 'routes' (<em>react_router_1.match({ routes, location: req.url }</em>...) does not.</p>
<h1 dir="auto">INPUT</h1>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// server.tsx

const express = require('express');
const app = express();

import { renderToString } from 'react-dom/server';
import {
    Route,
    Router,
    match,
    RoutingContext } from 'react-router';
import React = require('react');
import invariant = require('invariant');

import {
    routes,
} from '../common/routes';

import {
    HttpMethods,
    RequestStates
} from '../common/utils/http';


app.get('*', (req: any, res: any) =&gt; {
  match({ routes, location: req.url }, (error: any, redirectLocation: any, renderProps: any) =&gt; {
    if (error) {
      res.status(500).send(error.message)
    } else if (redirectLocation) {
      res.redirect(302, redirectLocation.pathname + redirectLocation.search)
    } else if (renderProps) {
      console.log('renderProps', renderProps);
      res.status(200).send(renderToString(&lt;RoutingContext {...renderProps} /&gt;))
    } else {
      res.status(404).send('Not found')
    }
  })
});

const server = app.listen(3000, function () {
  const host = server.address().address;
  const port = server.address().port;

  console.log('Example app listening at http://%s:%s', host, port);
});"><pre class="notranslate"><span class="pl-c">// server.tsx</span>

<span class="pl-k">const</span> <span class="pl-s1">express</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'express'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-en">express</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-s1">renderToString</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'react-dom/server'</span><span class="pl-kos">;</span>
<span class="pl-k">import</span> <span class="pl-kos">{</span>
    <span class="pl-smi">Route</span><span class="pl-kos">,</span>
    <span class="pl-smi">Router</span><span class="pl-kos">,</span>
    <span class="pl-s1">match</span><span class="pl-kos">,</span>
    <span class="pl-smi">RoutingContext</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'react-router'</span><span class="pl-kos">;</span>
<span class="pl-k">import</span> <span class="pl-smi">React</span> <span class="pl-c1">=</span> require<span class="pl-kos">(</span><span class="pl-s">'react'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">import</span> <span class="pl-s1">invariant</span> <span class="pl-c1">=</span> require<span class="pl-kos">(</span><span class="pl-s">'invariant'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-k">import</span> <span class="pl-kos">{</span>
    <span class="pl-s1">routes</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'../common/routes'</span><span class="pl-kos">;</span>

<span class="pl-k">import</span> <span class="pl-kos">{</span>
    <span class="pl-smi">HttpMethods</span><span class="pl-kos">,</span>
    <span class="pl-smi">RequestStates</span>
<span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'../common/utils/http'</span><span class="pl-kos">;</span>


<span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s">'*'</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-s1">req</span>: <span class="pl-smi">any</span><span class="pl-kos">,</span> <span class="pl-s1">res</span>: <span class="pl-smi">any</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-en">match</span><span class="pl-kos">(</span><span class="pl-kos">{</span> routes<span class="pl-kos">,</span> <span class="pl-c1">location</span>: <span class="pl-s1">req</span><span class="pl-kos">.</span><span class="pl-c1">url</span> <span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-s1">error</span>: <span class="pl-smi">any</span><span class="pl-kos">,</span> <span class="pl-s1">redirectLocation</span>: <span class="pl-smi">any</span><span class="pl-kos">,</span> <span class="pl-s1">renderProps</span>: <span class="pl-smi">any</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">error</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-s1">res</span><span class="pl-kos">.</span><span class="pl-en">status</span><span class="pl-kos">(</span><span class="pl-c1">500</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">send</span><span class="pl-kos">(</span><span class="pl-s1">error</span><span class="pl-kos">.</span><span class="pl-c1">message</span><span class="pl-kos">)</span>
    <span class="pl-kos">}</span> <span class="pl-k">else</span> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">redirectLocation</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-s1">res</span><span class="pl-kos">.</span><span class="pl-en">redirect</span><span class="pl-kos">(</span><span class="pl-c1">302</span><span class="pl-kos">,</span> <span class="pl-s1">redirectLocation</span><span class="pl-kos">.</span><span class="pl-c1">pathname</span> <span class="pl-c1">+</span> <span class="pl-s1">redirectLocation</span><span class="pl-kos">.</span><span class="pl-c1">search</span><span class="pl-kos">)</span>
    <span class="pl-kos">}</span> <span class="pl-k">else</span> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">renderProps</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'renderProps'</span><span class="pl-kos">,</span> <span class="pl-s1">renderProps</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
      <span class="pl-s1">res</span><span class="pl-kos">.</span><span class="pl-en">status</span><span class="pl-kos">(</span><span class="pl-c1">200</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">send</span><span class="pl-kos">(</span><span class="pl-en">renderToString</span><span class="pl-kos">(</span><span class="pl-kos">&lt;</span><span class="pl-smi">RoutingContext</span><span class="pl-kos"></span> <span class="pl-kos">{</span>...<span class="pl-s1">renderProps</span><span class="pl-kos">}</span> <span class="pl-c1">/</span><span class="pl-c1">&gt;</span><span class="pl-kos">)</span><span class="pl-kos">)</span>
    <span class="pl-kos">}</span> <span class="pl-k">else</span> <span class="pl-kos">{</span>
      <span class="pl-s1">res</span><span class="pl-kos">.</span><span class="pl-en">status</span><span class="pl-kos">(</span><span class="pl-c1">404</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">send</span><span class="pl-kos">(</span><span class="pl-s">'Not found'</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-k">const</span> <span class="pl-s1">server</span> <span class="pl-c1">=</span> <span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">listen</span><span class="pl-kos">(</span><span class="pl-c1">3000</span><span class="pl-kos">,</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-k">const</span> <span class="pl-s1">host</span> <span class="pl-c1">=</span> <span class="pl-s1">server</span><span class="pl-kos">.</span><span class="pl-en">address</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">address</span><span class="pl-kos">;</span>
  <span class="pl-k">const</span> <span class="pl-s1">port</span> <span class="pl-c1">=</span> <span class="pl-s1">server</span><span class="pl-kos">.</span><span class="pl-en">address</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">port</span><span class="pl-kos">;</span>

  <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'Example app listening at http://%s:%s'</span><span class="pl-kos">,</span> <span class="pl-s1">host</span><span class="pl-kos">,</span> <span class="pl-s1">port</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>
<h1 dir="auto">OUTPUT</h1>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const express = require('express');
const app = express();
var server_1 = require('react-dom/server');
var react_router_1 = require('react-router');
var React = require('react');
var routes_1 = require('../common/routes');

app.get('*', (req, res) =&gt; {
    react_router_1.match({ routes, location: req.url }, (error, redirectLocation, renderProps) =&gt; {
        if (error) {
            res.status(500).send(error.message);
        }
        else if (redirectLocation) {
            res.redirect(302, redirectLocation.pathname + redirectLocation.search);
        }
        else if (renderProps) {
            console.log('renderProps', renderProps);
            res.status(200).send(server_1.renderToString(React.createElement(react_router_1.RoutingContext, React.__spread({}, renderProps))));
        }
        else {
            res.status(404).send('Not found');
        }
    });
});
const server = app.listen(3000, function () {
    const host = server.address().address;
    const port = server.address().port;
    console.log('Example app listening at http://%s:%s', host, port);
});```"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">express</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'express'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-s1">express</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">server_1</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'react-dom/server'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">react_router_1</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'react-router'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-v">React</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'react'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">routes_1</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'../common/routes'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s">'*'</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-s1">req</span><span class="pl-kos">,</span> <span class="pl-s1">res</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-s1">react_router_1</span><span class="pl-kos">.</span><span class="pl-en">match</span><span class="pl-kos">(</span><span class="pl-kos">{</span> routes<span class="pl-kos">,</span> <span class="pl-c1">location</span>: <span class="pl-s1">req</span><span class="pl-kos">.</span><span class="pl-c1">url</span> <span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-s1">error</span><span class="pl-kos">,</span> <span class="pl-s1">redirectLocation</span><span class="pl-kos">,</span> <span class="pl-s1">renderProps</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">error</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-s1">res</span><span class="pl-kos">.</span><span class="pl-en">status</span><span class="pl-kos">(</span><span class="pl-c1">500</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">send</span><span class="pl-kos">(</span><span class="pl-s1">error</span><span class="pl-kos">.</span><span class="pl-c1">message</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
        <span class="pl-k">else</span> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">redirectLocation</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-s1">res</span><span class="pl-kos">.</span><span class="pl-en">redirect</span><span class="pl-kos">(</span><span class="pl-c1">302</span><span class="pl-kos">,</span> <span class="pl-s1">redirectLocation</span><span class="pl-kos">.</span><span class="pl-c1">pathname</span> <span class="pl-c1">+</span> <span class="pl-s1">redirectLocation</span><span class="pl-kos">.</span><span class="pl-c1">search</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
        <span class="pl-k">else</span> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">renderProps</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'renderProps'</span><span class="pl-kos">,</span> <span class="pl-s1">renderProps</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-s1">res</span><span class="pl-kos">.</span><span class="pl-en">status</span><span class="pl-kos">(</span><span class="pl-c1">200</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">send</span><span class="pl-kos">(</span><span class="pl-s1">server_1</span><span class="pl-kos">.</span><span class="pl-en">renderToString</span><span class="pl-kos">(</span><span class="pl-v">React</span><span class="pl-kos">.</span><span class="pl-en">createElement</span><span class="pl-kos">(</span><span class="pl-s1">react_router_1</span><span class="pl-kos">.</span><span class="pl-c1">RoutingContext</span><span class="pl-kos">,</span> <span class="pl-v">React</span><span class="pl-kos">.</span><span class="pl-en">__spread</span><span class="pl-kos">(</span><span class="pl-kos">{</span><span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-s1">renderProps</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-k">else</span> <span class="pl-kos">{</span>
            <span class="pl-s1">res</span><span class="pl-kos">.</span><span class="pl-en">status</span><span class="pl-kos">(</span><span class="pl-c1">404</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">send</span><span class="pl-kos">(</span><span class="pl-s">'Not found'</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>
<span class="pl-k">const</span> <span class="pl-s1">server</span> <span class="pl-c1">=</span> <span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">listen</span><span class="pl-kos">(</span><span class="pl-c1">3000</span><span class="pl-kos">,</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-k">const</span> <span class="pl-s1">host</span> <span class="pl-c1">=</span> <span class="pl-s1">server</span><span class="pl-kos">.</span><span class="pl-en">address</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">address</span><span class="pl-kos">;</span>
    <span class="pl-k">const</span> <span class="pl-s1">port</span> <span class="pl-c1">=</span> <span class="pl-s1">server</span><span class="pl-kos">.</span><span class="pl-en">address</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">port</span><span class="pl-kos">;</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'Example app listening at http://%s:%s'</span><span class="pl-kos">,</span> <span class="pl-s1">host</span><span class="pl-kos">,</span> <span class="pl-s1">port</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-s">``</span>`</pre></div>
<p dir="auto">Using typescript@next (1.8.0-dev.20151109) and the following compilerOptions:</p>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;compilerOptions&quot;: {
    &quot;target&quot;: &quot;ES6&quot;,
    &quot;module&quot;: &quot;commonjs&quot;
}"><pre class="notranslate"><span class="pl-ent">"compilerOptions"</span>: {
    <span class="pl-ent">"target"</span>: <span class="pl-s"><span class="pl-pds">"</span>ES6<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"module"</span>: <span class="pl-s"><span class="pl-pds">"</span>commonjs<span class="pl-pds">"</span></span>
}</pre></div>
<p dir="auto">Any code using named import as a shorthand property will result in invalid code being generated.</p>
<p dir="auto">Example:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import {foo} from './foo';
const test = {
  foo
};"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span><span class="pl-s1">foo</span><span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'./foo'</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">test</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
  foo
<span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">generates</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var foo_1 = require('./foo');
const test = {
    foo
};"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">foo_1</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'./foo'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">test</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
    foo
<span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ReferenceError: foo is not defined"><pre class="notranslate"><code class="notranslate">ReferenceError: foo is not defined
</code></pre></div>