<p dir="auto">Choose one: is this a bug report or feature request? Bug report.</p>
<h3 dir="auto">Input Code</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="callee(castee: CastTo)"><pre class="notranslate"><span class="pl-en">callee</span><span class="pl-kos">(</span><span class="pl-s1">castee</span>: <span class="pl-v">CastTo</span><span class="pl-kos">)</span></pre></div>
<h3 dir="auto">Babel Configuration (.babelrc, package.json, cli command)</h3>
<p dir="auto">Babylon with <code class="notranslate">flow</code> plugin enabled. Appears to affect both Babylon 6 and 7.</p>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">Both the Flow docs (<a href="https://flow.org/en/docs/types/casting/" rel="nofollow">https://flow.org/en/docs/types/casting/</a>) and the Flow parser flag this as a parse error.<br>
The Flow parser says <code class="notranslate">Unexpected token :</code> at line 1, column 13</p>
<p dir="auto">It should be necessary to wrap type casts in explicit <code class="notranslate">( )</code>, so e.g. <code class="notranslate">callee((castee: CastTo))</code>.</p>
<h3 dir="auto">Current Behavior</h3>
<p dir="auto">Parses successfully leaving an AST like</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ExprStmt( CallExpression( callee, TypeCastExpression( castee, CastTo ) ) )"><pre class="notranslate"><code class="notranslate">ExprStmt( CallExpression( callee, TypeCastExpression( castee, CastTo ) ) )
</code></pre></div>
<h3 dir="auto">Possible Solution</h3>
<p dir="auto">I am working on a patch here: <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/wcjohnson/babylon-lightscript/commit/322842abe7b9fd0ece731eaa2238edeaaa315876/hovercard" href="https://github.com/wcjohnson/babylon-lightscript/commit/322842abe7b9fd0ece731eaa2238edeaaa315876">wcjohnson/babylon-lightscript@<tt>322842a</tt></a></p>
<p dir="auto">The patch is against a heavily modified Babylon but may be useful nonetheless.</p>
<p dir="auto">The basic idea is to parse as <code class="notranslate">TypeCastish</code> and then convert back to <code class="notranslate">TypeCastExpression</code> only during <code class="notranslate">parseParenAndDistinguishExpression</code>. Any time a <code class="notranslate">TypeCastish</code> is seen outside of there, throw an unexpected type cast error.</p>
<h3 dir="auto">Context</h3>
<p dir="auto">I work on the LightScript language, which uses a fork of Babylon as its parser. The LightScript issue that led to this issue is here: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="254408615" data-permission-text="Title is private" data-url="https://github.com/wcjohnson/lightscript/issues/22" data-hovercard-type="issue" data-hovercard-url="/wcjohnson/lightscript/issues/22/hovercard" href="https://github.com/wcjohnson/lightscript/issues/22">wcjohnson/lightscript#22</a></p>
<h3 dir="auto">Your Environment</h3>
<table role="table">
<thead>
<tr>
<th>software</th>
<th>version(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Babylon</td>
<td>approximately 6.16.0</td>
</tr>
<tr>
<td>node</td>
<td>6</td>
</tr>
<tr>
<td>npm</td>
<td>5</td>
</tr>
<tr>
<td>Operating System</td>
<td>OS X</td>
</tr>
</tbody>
</table>
<h3 dir="auto">Input Code</h3>

<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="state.set('foo': bar)"><pre class="notranslate"><span class="pl-s1">state</span><span class="pl-kos">.</span><span class="pl-en">set</span><span class="pl-kos">(</span><span class="pl-s">'foo'</span>: <span class="pl-s1">bar</span><span class="pl-kos">)</span></pre></div>
<h3 dir="auto">Babylon/Babel Configuration</h3>

<p dir="auto">Flow syntax plugin enabled</p>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">Should be a syntax error</p>
<h3 dir="auto">Current Behavior</h3>
<p dir="auto">We're currently parsing <code class="notranslate">bar</code> as a TypeCastExpression w/ a value of <code class="notranslate">foo</code>. Flow requires that you wrap a TypeCastExpression in parens, and we're allowing the parens for the CallExpression to be used right now, which the Flow parser does <em>not</em> allow.</p>
<p dir="auto">Context: <a href="https://twitter.com/schep_/status/841741581589860355" rel="nofollow">https://twitter.com/schep_/status/841741581589860355</a></p>