Fix special case to handle regexps that start with =

Closes #55
This commit is contained in:
Marijn Haverbeke 2013-08-28 10:35:21 +02:00
parent 2ace0fa8dc
commit 6659f7a033
3 changed files with 19 additions and 3 deletions

View File

@ -1099,7 +1099,7 @@
// does not help. // does not help.
function parseStatement() { function parseStatement() {
if (tokType === _slash) if (tokType === _slash || tokType === _assign && tokVal == "/=")
readToken(true); readToken(true);
var starttype = tokType, node = startNode(); var starttype = tokType, node = startNode();

View File

@ -776,7 +776,7 @@ to its body instead of creating a new node.</p> </td> <t
regular expression literal. This is to handle cases like regular expression literal. This is to handle cases like
<code>if (foo) /blah/.exec(foo);</code>, where looking at the previous token <code>if (foo) /blah/.exec(foo);</code>, where looking at the previous token
does not help.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseStatement</span><span class="p">()</span> <span class="p">{</span> does not help.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseStatement</span><span class="p">()</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_slash</span><span class="p">)</span> <span class="k">if</span> <span class="p">(</span><span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_slash</span> <span class="o">||</span> <span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_assign</span> <span class="o">&amp;&amp;</span> <span class="nx">tokVal</span> <span class="o">==</span> <span class="s2">&quot;/=&quot;</span><span class="p">)</span>
<span class="nx">readToken</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span> <span class="nx">readToken</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">starttype</span> <span class="o">=</span> <span class="nx">tokType</span><span class="p">,</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">();</span></pre></div> </td> </tr> <tr id="section-93"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-93">&#182;</a> </div> <p>Most types of statements are recognized by the keyword they <span class="kd">var</span> <span class="nx">starttype</span> <span class="o">=</span> <span class="nx">tokType</span><span class="p">,</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">();</span></pre></div> </td> </tr> <tr id="section-93"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-93">&#182;</a> </div> <p>Most types of statements are recognized by the keyword they

View File

@ -26266,6 +26266,23 @@ test("a.in / b", {
] ]
}); });
test("{}/=/", {
type: "Program",
body: [
{
type: "BlockStatement",
body: []
},
{
type: "ExpressionStatement",
expression: {
type: "Literal",
raw: "/=/"
}
}
]
});
// Failure tests // Failure tests
testFail("{", testFail("{",
@ -26874,4 +26891,3 @@ testFail("throw\n10;", "Illegal newline after throw (1:5)");
} }
); );
})(); })();