[Pkg-javascript-commits] [node-acorn-jsx] 228/484: Added backward-compatible test that object properties have type of "Property".
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:34 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-acorn-jsx.
commit dd37866fdb09a32a21da1ce1ec55643f80db80f0
Author: Ingvar Stepanyan <me at rreverser.com>
Date: Fri Jul 25 16:38:34 2014 +0300
Added backward-compatible test that object properties have type of "Property".
(Better fix for Constellation/estraverse#4, Constellation/escodegen#80 and similar bugs)
---
index.html | 570 ++++++++++++++++++++++++++++++++++++++++++----------------
test/tests.js | 26 +++
2 files changed, 439 insertions(+), 157 deletions(-)
diff --git a/index.html b/index.html
index aed3cb6..ff59372 100644
--- a/index.html
+++ b/index.html
@@ -142,7 +142,8 @@ entered.</p> </td> <td class="code"> <div
when finishing a node and assigning its <code>end</code> position.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">lastStart</span><span class="p">,</span> <span class="nx">lastEnd</span><span class="p">,</span> <span class="nx">lastEndLoc</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> [...]
<code>return</code> statements outside of functions, <code>labels</code> to verify that
<code>break</code> and <code>continue</code> have somewhere to jump to, and <code>strict</code>
-indicates whether strict mode is on.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">inFunction</span><span class="p">,</span> <span class="nx">labels</span><span class="p">,</span> <span class="nx">strict</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="pilwrap"> [...]
+indicates whether strict mode is on.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">inFunction</span><span class="p">,</span> <span class="nx">labels</span><span class="p">,</span> <span class="nx">strict</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="pilwrap"> [...]
+not contain nested parentheses in argument list.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">metParenL</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-27">¶</a> </div> [...]
takes an offset integer (into the current <code>input</code>) to indicate
the location of the error, attaches the position to the end
of the error message, and then raises a <code>SyntaxError</code> with that
@@ -152,12 +153,12 @@ message.</p> </td> <td class="code"> <div
<span class="kd">var</span> <span class="nx">err</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">SyntaxError</span><span class="p">(</span><span class="nx">message</span><span class="p">);</span>
<span class="nx">err</span><span class="p">.</span><span class="nx">pos</span> <span class="o">=</span> <span class="nx">pos</span><span class="p">;</span> <span class="nx">err</span><span class="p">.</span><span class="nx">loc</span> <span class="o">=</span> <span class="nx">loc</span><span class="p">;</span> <span class="nx">err</span><span class="p">.</span><span class="nx">raisedAt</span> <span class="o">=</span> <span class="nx">tokPos</span><span class="p">;</span>
<span class="k">throw</span> <span class="nx">err</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-27">¶</a> </div> <p>Reused empty array added for node fields that are always empty.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-28">¶</a> </div> <p>Reused empty array added for node fields that are always empty.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class [...]
allows the tokenizer to store the information it has about a
-token in a way that is very cheap for the parser to look up.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-30">¶</a> </div> <p>All token type variables start with an underscore, to make them
-easy to recognize.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-31">¶</a> </div> <p>These are the general types. The <code>type</code> property is only used to
+token in a way that is very cheap for the parser to look up.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-31">¶</a> </div> <p>All token type variables start with an underscore, to make them
+easy to recognize.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-32"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-32">¶</a> </div> <p>These are the general types. The <code>type</code> property is only used to
make them recognizeable when debugging.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">_num</span> <span class="o">=</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s2">"num"</span><span class="p">},</span> <span class="nx">_regexp</span> <span class="o">=</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span [...]
- <span class="kd">var</span> <span class="nx">_name</span> <span class="o">=</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s2">"name"</span><span class="p">},</span> <span class="nx">_eof</span> <span class="o">=</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s2">"eof"</span><span class="p">};</span></pre></div> </td> </tr> [...]
+ <span class="kd">var</span> <span class="nx">_name</span> <span class="o">=</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s2">"name"</span><span class="p">},</span> <span class="nx">_eof</span> <span class="o">=</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s2">"eof"</span><span class="p">};</span></pre></div> </td> </tr> [...]
operators) indicates that the token originated from an
identifier-like word, which is used when parsing property names.</p>
@@ -176,10 +177,12 @@ continue jumps to that label.</p> </td> <td class="code"
<span class="kd">var</span> <span class="nx">_throw</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"throw"</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <span class="kc">true</span><span class="p">},</span> <span class="nx">_try</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class=" [...]
<span class="kd">var</span> <span class="nx">_let</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"let"</span><span class="p">},</span> <span class="nx">_const</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"const"</span><span class="p">};</span>
<span class="kd">var</span> <span class="nx">_while</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"while"</span><span class="p">,</span> <span class="nx">isLoop</span><span class="o">:</span> <span class="kc">true</span><span class="p">},</span> <span class="nx">_with</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2" [...]
- <span class="kd">var</span> <span class="nx">_this</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"this"</span><span class="p">};</span></pre></div> </td> </tr> <tr id="section-33"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-33">¶</a> </div> [...]
- <span class="kd">var</span> <span class="nx">_false</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"false"</span><span class="p">,</span> <span class="nx">atomValue</span><span class="o">:</span> <span class="kc">false</span><span class="p">};</span></pre></div> </td> </tr> <tr id="section-34"> <td class="docs"> <div c [...]
+ <span class="kd">var</span> <span class="nx">_this</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"this"</span><span class="p">};</span>
+ <span class="kd">var</span> <span class="nx">_class</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"class"</span><span class="p">},</span> <span class="nx">_extends</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"extends"</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</ [...]
+ <span class="kd">var</span> <span class="nx">_false</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"false"</span><span class="p">,</span> <span class="nx">atomValue</span><span class="o">:</span> <span class="kc">false</span><span class="p">};</span></pre></div> </td> </tr> <tr id="section-35"> <td class="docs"> <div c [...]
(when parsing <code>for</code>) needs to be tested against specifically, so
-we assign a variable name to it for quick comparing.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">_in</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"in"</span><span class="p">,</span> <span class="nx">binop</span><span class="o">:</span> <span class="mi">7</span><span class="p">,</span> <span class="nx [...]
+we assign a variable name to it for quick comparing.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">_in</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"in"</span><span class="p">,</span> <span class="nx">binop</span><span class="o">:</span> <span class="mi">7</span><span class="p">,</span> <span class="nx [...]
+ <span class="kd">var</span> <span class="nx">_of</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"of"</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <span class="kc">true</span><span class="p">};</span></pre></div> </td> </tr> <tr id="section-36"> <td class="docs"> <div class=" [...]
<span class="s2">"continue"</span><span class="o">:</span> <span class="nx">_continue</span><span class="p">,</span> <span class="s2">"debugger"</span><span class="o">:</span> <span class="nx">_debugger</span><span class="p">,</span> <span class="s2">"default"</span><span class="o">:</span> <span class="nx">_default</span><span class="p">,</span>
<span class="s2">"do"</span><span class="o">:</span> <span class="nx">_do</span><span class="p">,</span> <span class="s2">"else"</span><span class="o">:</span> <span class="nx">_else</span><span class="p">,</span> <span class="s2">"finally"</span><span class="o">:</span> <span class="nx">_finally</span><span class="p">,</span> <span class="s2">"for"</span><span class="o">:</span> <span class="nx">_for</span><span class="p">,</span>
<span class="s2">"function"</span><span class="o">:</span> <span class="nx">_function</span><span class="p">,</span> <span class="s2">"if"</span><span class="o">:</span> <span class="nx">_if</span><span class="p">,</span> <span class="s2">"return"</span><span class="o">:</span> <span class="nx">_return</span><span class="p">,</span> <span class="s2">"switch"</span><span class="o">:</span> <span class="nx">_switch</span><span c [...]
@@ -189,10 +192,12 @@ we assign a variable name to it for quick comparing.</p> </td>
<span class="s2">"instanceof"</span><span class="o">:</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"instanceof"</span><span class="p">,</span> <span class="nx">binop</span><span class="o">:</span> <span class="mi">7</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <span class="kc">true</span><span class="p">},</span> <span class="s2">"this&quo [...]
<span class="s2">"typeof"</span><span class="o">:</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"typeof"</span><span class="p">,</span> <span class="nx">prefix</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <span class="kc">true</span><span class="p">},</span>
<span class="s2">"void"</span><span class="o">:</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"void"</span><span class="p">,</span> <span class="nx">prefix</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <span class="kc">true</span><span class="p">},</span>
- <span class="s2">"delete"</span><span class="o">:</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"delete"</span><span class="p">,</span> <span class="nx">prefix</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <span class="kc">true</span><span class="p">}};</span></pre></div> </td> [...]
+ <span class="s2">"delete"</span><span class="o">:</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"delete"</span><span class="p">,</span> <span class="nx">prefix</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <span class="kc">true</span><span class="p">},</span>
+ <span class="s2">"class"</span><span class="o">:</span> <span class="nx">_class</span><span class="p">,</span> <span class="s2">"extends"</span><span class="o">:</span> <span class="nx">_extends</span><span class="p">,</span> <span class="s2">"static"</span><span class="o">:</span> <span class="nx">_static</span><span class="p">,</span> <span class="s2">"of"</span><span class="o">:</span> <span class="nx">_of</span><span class [...]
<span class="kd">var</span> <span class="nx">_braceR</span> <span class="o">=</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s2">"}"</span><span class="p">},</span> <span class="nx">_parenL</span> <span class="o">=</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s2">"("</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <span clas [...]
<span class="kd">var</span> <span class="nx">_comma</span> <span class="o">=</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s2">","</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <span class="kc">true</span><span class="p">},</span> <span class="nx">_semi</span> <span class="o">=</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s2">" [...]
- <span class="kd">var</span> <span class="nx">_colon</span> <span class="o">=</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s2">":"</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <span class="kc">true</span><span class="p">},</span> <span class="nx">_dot</span> <span class="o">=</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s2">" [...]
+ <span class="kd">var</span> <span class="nx">_colon</span> <span class="o">=</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s2">":"</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <span class="kc">true</span><span class="p">},</span> <span class="nx">_dot</span> <span class="o">=</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s2">" [...]
+ <span class="kd">var</span> <span class="nx">_arrow</span> <span class="o">=</span> <span class="p">{</span><span class="nx">type</span><span class="o">:</span> <span class="s2">"=>"</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <span class="kc">true</span><span class="p">};</span></pre></div> </td> </tr> <tr id="section-38"> <td class="docs"> <div clas [...]
parser use them properly (the presence of these properties is
what categorizes them as operators).</p>
@@ -218,12 +223,12 @@ in AssignmentExpression nodes.</p> </td> <td class="code
<span class="kd">var</span> <span class="nx">_relational</span> <span class="o">=</span> <span class="p">{</span><span class="nx">binop</span><span class="o">:</span> <span class="mi">7</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <span class="kc">true</span><span class="p">};</span>
<span class="kd">var</span> <span class="nx">_bitShift</span> <span class="o">=</span> <span class="p">{</span><span class="nx">binop</span><span class="o">:</span> <span class="mi">8</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <span class="kc">true</span><span class="p">};</span>
<span class="kd">var</span> <span class="nx">_plusMin</span> <span class="o">=</span> <span class="p">{</span><span class="nx">binop</span><span class="o">:</span> <span class="mi">9</span><span class="p">,</span> <span class="nx">prefix</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <span class="kc">true</span><span class="p">};</span>
- <span class="kd">var</span> <span class="nx">_multiplyModulo</span> <span class="o">=</span> <span class="p">{</span><span class="nx">binop</span><span class="o">:</span> <span class="mi">10</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <span class="kc">true</span><span class="p">};</span></pre></div> </td> </tr> <tr id="section-38"> <td class="docs"> <div class="pi [...]
+ <span class="kd">var</span> <span class="nx">_multiplyModulo</span> <span class="o">=</span> <span class="p">{</span><span class="nx">binop</span><span class="o">:</span> <span class="mi">10</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <span class="kc">true</span><span class="p">};</span></pre></div> </td> </tr> <tr id="section-39"> <td class="docs"> <div class="pi [...]
tokenizer.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">exports</span><span class="p">.</span><span class="nx">tokTypes</span> <span class="o">=</span> <span class="p">{</span><span class="nx">bracketL</span><span class="o">:</span> <span class="nx">_bracketL</span><span class="p">,</span> <span class="nx">bracketR</span><span class="o">:</span> <span class="nx">_bracketR</span><span class="p">,</span> <span class="nx">b [...]
<span class="nx">parenL</span><span class="o">:</span> <span class="nx">_parenL</span><span class="p">,</span> <span class="nx">parenR</span><span class="o">:</span> <span class="nx">_parenR</span><span class="p">,</span> <span class="nx">comma</span><span class="o">:</span> <span class="nx">_comma</span><span class="p">,</span> <span class="nx">semi</span><span class="o">:</span> <span class="nx">_semi</span><span class="p">,</span> <span class="nx">colon</span><sp [...]
<span class="nx">dot</span><span class="o">:</span> <span class="nx">_dot</span><span class="p">,</span> <span class="nx">ellipsis</span><span class="o">:</span> <span class="nx">_ellipsis</span><span class="p">,</span> <span class="nx">question</span><span class="o">:</span> <span class="nx">_question</span><span class="p">,</span> <span class="nx">slash</span><span class="o">:</span> <span class="nx">_slash</span><span class="p">,</span> <span class="nx">eq</span> [...]
<span class="nx">name</span><span class="o">:</span> <span class="nx">_name</span><span class="p">,</span> <span class="nx">eof</span><span class="o">:</span> <span class="nx">_eof</span><span class="p">,</span> <span class="nx">num</span><span class="o">:</span> <span class="nx">_num</span><span class="p">,</span> <span class="nx">regexp</span><span class="o">:</span> <span class="nx">_regexp</span><span class="p">,</span> <span class="nx">string</span><span class= [...]
- <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">kw</span> <span class="k">in</span> <span class="nx">keywordTypes</span><span class="p">)</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">tokTypes</span><span class="p">[</span><span class="s2">"_"</span> <span class="o">+</span> <span class="nx">kw</span><span class="p">]</span> <span class="o">=</span> <span class="nx">keywordTypes</span><span class [...]
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">kw</span> <span class="k">in</span> <span class="nx">keywordTypes</span><span class="p">)</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">tokTypes</span><span class="p">[</span><span class="s2">"_"</span> <span class="o">+</span> <span class="nx">kw</span><span class="p">]</span> <span class="o">=</span> <span class="nx">keywordTypes</span><span class [...]
non-Chrome browsers, to check whether a string is in a set, a
predicate containing a big ugly <code>switch</code> statement is faster than
a regular expression, and on Chrome the two are about on par.
@@ -246,7 +251,7 @@ predicate from a space-separated string of words.</p>
<span class="nx">f</span> <span class="o">+=</span> <span class="s2">"switch(str){"</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">arr</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="o">++</span><span class="nx">i</span><span class="p">)</span> <span class="nx">f</span> <span class="o">+=</span> <span class="s2">&q [...]
<span class="nx">f</span> <span class="o">+=</span> <span class="s2">"return true}return false;"</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-40"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-40">¶</a> </div> <p>When there are more than three length categories, an outer
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-41"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-41">¶</a> </div> <p>When there are more than three length categories, an outer
switch first dispatches on the lengths, to save on comparisons.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">cats</span><span class="p">.</span><span class="nx">length</span> <span class="o">></span> <span class="mi">3</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">cats</span><span class="p">.</span><span class="nx">sort</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">a</span><span class="p">,</span> <span class="nx">b</span><span class="p">)</span> <span class="p">{</span><span class="k">return</span> <span class="nx">b</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="nx">a</span><span class="p">.</span><span class="nx">l [...]
<span class="nx">f</span> <span class="o">+=</span> <span class="s2">"switch(str.length){"</span><span class="p">;</span>
@@ -255,17 +260,17 @@ switch first dispatches on the lengths, to save on comparisons.</p>
<span class="nx">f</span> <span class="o">+=</span> <span class="s2">"case "</span> <span class="o">+</span> <span class="nx">cat</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">length</span> <span class="o">+</span> <span class="s2">":"</span><span class="p">;</span>
<span class="nx">compareTo</span><span class="p">(</span><span class="nx">cat</span><span class="p">);</span>
<span class="p">}</span>
- <span class="nx">f</span> <span class="o">+=</span> <span class="s2">"}"</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-41"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-41">¶</a> </div> <p>Otherwise, simply generate a flat <code>switch</code> statement.</p> </td> <td cla [...]
+ <span class="nx">f</span> <span class="o">+=</span> <span class="s2">"}"</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-42"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-42">¶</a> </div> <p>Otherwise, simply generate a flat <code>switch</code> statement.</p> </td> <td cla [...]
<span class="nx">compareTo</span><span class="p">(</span><span class="nx">words</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="k">new</span> <span class="nb">Function</span><span class="p">(</span><span class="s2">"str"</span><span class="p">,</span> <span class="nx">f</span><span class="p">);</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-42"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-42">¶</a> </div> <p>The ECMAScript 3 reserved word list.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">isReservedWord3</span [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-43"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-43">¶</a> </div> <p>The ECMAScript 3 reserved word list.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">isReservedWord3</span [...]
<span class="kd">var</span> <span class="nx">isEcma5AndLessKeyword</span> <span class="o">=</span> <span class="nx">makePredicate</span><span class="p">(</span><span class="nx">ecma5AndLessKeywords</span><span class="p">);</span>
- <span class="kd">var</span> <span class="nx">isEcma6Keyword</span> <span class="o">=</span> <span class="nx">makePredicate</span><span class="p">(</span><span class="nx">ecma5AndLessKeywords</span> <span class="o">+</span> <span class="s2">" let const"</span><span class="p">);</span>
+ <span class="kd">var</span> <span class="nx">isEcma6Keyword</span> <span class="o">=</span> <span class="nx">makePredicate</span><span class="p">(</span><span class="nx">ecma5AndLessKeywords</span> <span class="o">+</span> <span class="s2">" let const class extends static of"</span><span class="p">);</span>
- <span class="kd">var</span> <span class="nx">isKeyword</span> <span class="o">=</span> <span class="nx">isEcma5AndLessKeyword</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-47"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-47">¶</a> </div> <h2>Character categories</h2> </td> <td class= [...]
+ <span class="kd">var</span> <span class="nx">isKeyword</span> <span class="o">=</span> <span class="nx">isEcma5AndLessKeyword</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-48"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-48">¶</a> </div> <h2>Character categories</h2> </td> <td class= [...]
whitespace, identifier, and identifier-start categories. These
are only applied when a character is found to actually have a
code point above 128.
@@ -273,14 +278,14 @@ Generated by <code>tools/generate-identifier-regex.js</code>.</p> </
<span class="kd">var</span> <span class="nx">nonASCIIidentifierStartChars</span> <span class="o">=</span> <span class="s2">"\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u0 [...]
<span class="kd">var</span> <span class="nx">nonASCIIidentifierChars</span> <span class="o">=</span> <span class="s2">"\u0300-\u036F\u0483-\u0487\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u0669\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u06F0-\u06F9\u0711\u0730-\u074A\u07A6-\u07B0\u07C0-\u07C9\u07EB-\u07F3\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08E4-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0966-\ [...]
<span class="kd">var</span> <span class="nx">nonASCIIidentifierStart</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="s2">"["</span> <span class="o">+</span> <span class="nx">nonASCIIidentifierStartChars</span> <span class="o">+</span> <span class="s2">"]"</span><span class="p">);</span>
- <span class="kd">var</span> <span class="nx">nonASCIIidentifier</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="s2">"["</span> <span class="o">+</span> <span class="nx">nonASCIIidentifierStartChars</span> <span class="o">+</span> <span class="nx">nonASCIIidentifierChars</span> <span class="o">+</span> <span class="s2">"]"</span><span class="p">);</span></pre></div> </td> [...]
-line break). Used to count lines.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">lineBreak</span> <span class="o">=</span> <span class="sr">/\r\n|[\n\r\u2028\u2029]/g</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-51"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" hr [...]
+ <span class="kd">var</span> <span class="nx">nonASCIIidentifier</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="s2">"["</span> <span class="o">+</span> <span class="nx">nonASCIIidentifierStartChars</span> <span class="o">+</span> <span class="nx">nonASCIIidentifierChars</span> <span class="o">+</span> <span class="s2">"]"</span><span class="p">);</span></pre></div> </td> [...]
+line break). Used to count lines.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">lineBreak</span> <span class="o">=</span> <span class="sr">/\r\n|[\n\r\u2028\u2029]/g</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-52"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" hr [...]
<span class="k">if</span> <span class="p">(</span><span class="nx">code</span> <span class="o"><</span> <span class="mi">65</span><span class="p">)</span> <span class="k">return</span> <span class="nx">code</span> <span class="o">===</span> <span class="mi">36</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">code</span> <span class="o"><</span> <span class="mi">91</span><span class="p">)</span> <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">code</span> <span class="o"><</span> <span class="mi">97</span><span class="p">)</span> <span class="k">return</span> <span class="nx">code</span> <span class="o">===</span> <span class="mi">95</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">code</span> <span class="o"><</span> <span class="mi">123</span><span class="p">)</span><span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
<span class="k">return</span> <span class="nx">code</span> <span class="o">>=</span> <span class="mh">0xaa</span> <span class="o">&&</span> <span class="nx">nonASCIIidentifierStart</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span class="nx">code</span><span class="p">));</span>
- <span class="p">};</span></pre></div> </td> </tr> <tr id="section-52"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-52">¶</a> </div> <p>Test whether a given character is part of an identifier.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx"> [...]
+ <span class="p">};</span></pre></div> </td> </tr> <tr id="section-53"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-53">¶</a> </div> <p>Test whether a given character is part of an identifier.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx"> [...]
<span class="k">if</span> <span class="p">(</span><span class="nx">code</span> <span class="o"><</span> <span class="mi">48</span><span class="p">)</span> <span class="k">return</span> <span class="nx">code</span> <span class="o">===</span> <span class="mi">36</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">code</span> <span class="o"><</span> <span class="mi">58</span><span class="p">)</span> <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">code</span> <span class="o"><</span> <span class="mi">65</span><span class="p">)</span> <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
@@ -288,16 +293,17 @@ line break). Used to count lines.</p> </td> <td class="c
<span class="k">if</span> <span class="p">(</span><span class="nx">code</span> <span class="o"><</span> <span class="mi">97</span><span class="p">)</span> <span class="k">return</span> <span class="nx">code</span> <span class="o">===</span> <span class="mi">95</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">code</span> <span class="o"><</span> <span class="mi">123</span><span class="p">)</span><span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
<span class="k">return</span> <span class="nx">code</span> <span class="o">>=</span> <span class="mh">0xaa</span> <span class="o">&&</span> <span class="nx">nonASCIIidentifier</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span class="nx">code</span><span class="p">));</span>
- <span class="p">};</span></pre></div> </td> </tr> <tr id="section-53"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-53">¶</a> </div> <h2>Tokenizer</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section [...]
+ <span class="p">};</span></pre></div> </td> </tr> <tr id="section-54"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-54">¶</a> </div> <h2>Tokenizer</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section [...]
<code>tokStartLoc</code> and <code>tokEndLoc</code> properties.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">Position</span><span class="p">()</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">line</span> <span class="o">=</span> <span class="nx">tokCurLine</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">column</span> <span class="o">=</span> <span class="nx">tokPos</span> <span class="o">-</span> <span class="nx">tokLineStart</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-55"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-55">¶</a> </div> <p>Reset the token state. Used at the start of a parse.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx"> [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-56"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-56">¶</a> </div> <p>Reset the token state. Used at the start of a parse.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx"> [...]
<span class="nx">tokCurLine</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="nx">tokPos</span> <span class="o">=</span> <span class="nx">tokLineStart</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="nx">tokRegexpAllowed</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="nx">metParenL</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="nx">skipSpace</span><span class="p">();</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-56"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-56">¶</a> </div> <p>Called at the end of every token. Sets <code>tokEnd</code>, <code>tokVal</code>, and
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-57"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-57">¶</a> </div> <p>Called at the end of every token. Sets <code>tokEnd</code>, <code>tokVal</code>, and
<code>tokRegexpAllowed</code>, and skips the space after the token, so that
the next one's <code>tokStart</code> will point at the right position.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">type</span><span class="p">,</span> <span class="nx">val</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">tokEnd</span> <span class="o">=</span> <span class="nx">tokPos</span><span class="p">;</span>
@@ -337,7 +343,7 @@ the next one's <code>tokStart</code> will point at the right position.</p>
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">onComment</span><span class="p">)</span>
<span class="nx">options</span><span class="p">.</span><span class="nx">onComment</span><span class="p">(</span><span class="kc">false</span><span class="p">,</span> <span class="nx">input</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="nx">start</span> <span class="o">+</span> <span class="mi">2</span><span class="p">,</span> <span class="nx">tokPos</span><span class="p">),</span> <span class="nx">start</span><span class="p">,</span> [...]
<span class="nx">startLoc</span><span class="p">,</span> <span class="nx">options</span><span class="p">.</span><span class="nx">locations</span> <span class="o">&&</span> <span class="k">new</span> <span class="nx">Position</span><span class="p">);</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-57"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-57">¶</a> </div> <p>Called at the start of the parse and after every token. Skips
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-58"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-58">¶</a> </div> <p>Called at the start of the parse and after every token. Skips
whitespace and comments, and.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">skipSpace</span><span class="p">()</span> <span class="p">{</span>
<span class="k">while</span> <span class="p">(</span><span class="nx">tokPos</span> <span class="o"><</span> <span class="nx">inputLen</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">ch</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="p">);</span>
@@ -376,7 +382,7 @@ whitespace and comments, and.</p> </td> <td class="code"
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-58"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-58">¶</a> </div> <h3>Token reading</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="sect [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-59"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-59">¶</a> </div> <h3>Token reading</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="sect [...]
is somewhat obscure, because it works in character codes rather
than characters, and because operator parsing has been inlined
into it.</p>
@@ -427,7 +433,7 @@ into it.</p>
<span class="kd">var</span> <span class="nx">next</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="nx">code</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">==</span> <span class="mi">45</span> <span class="o">&&</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span> <span class="o">+</span> <span class="mi">2</span><span class="p">)</span> <span class="o">==</span> <span class="mi">62</span> <span class="o">&&</span>
- <span class="nx">newline</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">input</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="nx">lastEnd</span><span class="p">,</span> <span class="nx">tokPos</span><span class="p">)))</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-60"> <td class="docs"> [...]
+ <span class="nx">newline</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">input</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="nx">lastEnd</span><span class="p">,</span> <span class="nx">tokPos</span><span class="p">)))</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-61"> <td class="docs"> [...]
<span class="nx">skipLineComment</span><span class="p">();</span>
<span class="nx">skipSpace</span><span class="p">();</span>
<span class="k">return</span> <span class="nx">readToken</span><span class="p">();</span>
@@ -447,7 +453,7 @@ into it.</p>
<span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_bitShift</span><span class="p">,</span> <span class="nx">size</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">==</span> <span class="mi">33</span> <span class="o">&&</span> <span class="nx">code</span> <span class="o">==</span> <span class="mi">60</span> <span class="o">&&</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span> <span class="o">+</span> <span class="mi">2</span><span class="p [...]
- <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span> <span class="o">+</span> <span class="mi">3</span><span class="p">)</span> <span class="o">==</span> <span class="mi">45</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-61"> <td class="docs"> <div class="pilwrap"> [...]
+ <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span> <span class="o">+</span> <span class="mi">3</span><span class="p">)</span> <span class="o">==</span> <span class="mi">45</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-62"> <td class="docs"> <div class="pilwrap"> [...]
<span class="nx">skipLineComment</span><span class="p">();</span>
<span class="nx">skipSpace</span><span class="p">();</span>
<span class="k">return</span> <span class="nx">readToken</span><span class="p">();</span>
@@ -457,16 +463,20 @@ into it.</p>
<span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_relational</span><span class="p">,</span> <span class="nx">size</span><span class="p">);</span>
<span class="p">}</span>
- <span class="kd">function</span> <span class="nx">readToken_eq_excl</span><span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// '=!'</span>
+ <span class="kd">function</span> <span class="nx">readToken_eq_excl</span><span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// '=!', '=>'</span>
<span class="kd">var</span> <span class="nx">next</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_equality</span><span class="p">,</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span> <span class="o">+</span> <span class="mi">2</ [...]
+ <span class="k">if</span> <span class="p">(</span><span class="nx">code</span> <span class="o">===</span> <span class="mi">61</span> <span class="o">&&</span> <span class="nx">next</span> <span class="o">===</span> <span class="mi">62</span> <span class="o">&&</span> <span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">6</span><span class="p">)</span> <span class="p">{</span> <span cla [...]
+ <span class="nx">tokPos</span> <span class="o">+=</span> <span class="mi">2</span><span class="p">;</span>
+ <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_arrow</span><span class="p">);</span>
+ <span class="p">}</span>
<span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">code</span> <span class="o">===</span> <span class="mi">61</span> <span class="o">?</span> <span class="nx">_eq</span> <span class="o">:</span> <span class="nx">_prefix</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="kd">function</span> <span class="nx">getTokenFromCode</span><span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="p">{</span>
- <span class="k">switch</span><span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-62"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-62">¶</a> </div> <p>The interpretation of a dot depends on whether it is followed
+ <span class="k">switch</span><span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-63"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-63">¶</a> </div> <p>The interpretation of a dot depends on whether it is followed
by a digit or another two dots.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">case</span> <span class="mi">46</span><span class="o">:</span> <span class="c1">// '.'</span>
- <span class="k">return</span> <span class="nx">readToken_dot</span><span class="p">();</span></pre></div> </td> </tr> <tr id="section-63"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-63">¶</a> </div> <p>Punctuation tokens.</p> </td> <td class="code"> <div class="highlight"><pre> <span cl [...]
+ <span class="k">return</span> <span class="nx">readToken_dot</span><span class="p">();</span></pre></div> </td> </tr> <tr id="section-64"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-64">¶</a> </div> <p>Punctuation tokens.</p> </td> <td class="code"> <div class="highlight"><pre> <span cl [...]
<span class="k">case</span> <span class="mi">41</span><span class="o">:</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_parenR</span><span class="p">);</span>
<span class="k">case</span> <span class="mi">59</span><span class="o">:</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_semi</span><span class="p">);</span>
<span class="k">case</span> <span class="mi">44</span><span class="o">:</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_comma</span><span class="p">);</span>
@@ -475,9 +485,15 @@ by a digit or another two dots.</p> </td> <td class="cod
<span class="k">case</span> <span class="mi">123</span><span class="o">:</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_braceL</span><span class="p">);</span>
<span class="k">case</span> <span class="mi">125</span><span class="o">:</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_braceR</span><span class="p">);</span>
<span class="k">case</span> <span class="mi">58</span><span class="o">:</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_colon</span><span class="p">);</span>
- <span class="k">case</span> <span class="mi">63</span><span class="o">:</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_question</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-64"> <td class="docs"> <div class="pilwrap"> <a [...]
+ <span class="k">case</span> <span class="mi">63</span><span class="o">:</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_question</span><span class="p">);</span>
+
+ <span class="k">case</span> <span class="mi">48</span><span class="o">:</span> <span class="c1">// '0'</span>
<span class="kd">var</span> <span class="nx">next</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">120</span> <span class="o">||</span> <span class="nx">next</span> <span class="o">===</span> <span class="mi">88</span><span class="p">)</span> <span class="k">return</span> <span class="nx">readHexNumber</span><span class="p">();</span></pre></div> </td> </tr> <tr id="section-65"> <td class="docs" [...]
+ <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">120</span> <span class="o">||</span> <span class="nx">next</span> <span class="o">===</span> <span class="mi">88</span><span class="p">)</span> <span class="k">return</span> <span class="nx">readRadixNumber</span><span class="p">(</span><span class="mi">16</span><span class="p">);</span> <span class="c1">// '0x', '0X' - hex number</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">6</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">111</span> <span class="o">||</span> <span class="nx">next</span> <span class="o">===</span> <span class="mi">79</span><span class="p">)</span> <span class="k">return</span> <span class="nx">readRadixNumber</span><span class="p">(</span><span class="mi">8</span><span class="p">);</span> <span class="c1">// '0o', '0O' - octal number</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">98</span> <span class="o">||</span> <span class="nx">next</span> <span class="o">===</span> <span class="mi">66</span><span class="p">)</span> <span class="k">return</span> <span class="nx">readRadixNumber</span><span class="p">(</span><span class="mi">2</span><span class="p">);</span> <span class="c1">// '0b', '0B' - binary number</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-65"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-65">¶</a> </div> <p>Anything else beginning with a digit is an integer, octal
number, or float.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">case</span> <span class="mi">49</span><span class="o">:</span> <span class="k">case</span> <span class="mi">50</span><span class="o">:</span> <span class="k">case</span> <span class="mi">51</span><span class="o">:</span> <span class="k">case</span> <span class="mi">52</span><span class="o">:</span> <span class="k">case</span> <span class="mi">53</span><span [...]
<span class="k">return</span> <span class="nx">readNumber</span><span class="p">(</span><span class="kc">false</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-66"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-66">¶</a> </div> <p>Quotes produce strings.</p> </td> <td class="code"> [...]
<span class="k">return</span> <span class="nx">readString</span><span class="p">(</span><span class="nx">code</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-67"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-67">¶</a> </div> <p>Operators are parsed inline in tiny state machines. '=' (61) is
@@ -580,10 +596,10 @@ will return <code>null</code> unless the integer has exactly <code>len</code> di
<span class="k">return</span> <span class="nx">total</span><span class="p">;</span>
<span class="p">}</span>
- <span class="kd">function</span> <span class="nx">readHexNumber</span><span class="p">()</span> <span class="p">{</span>
+ <span class="kd">function</span> <span class="nx">readRadixNumber</span><span class="p">(</span><span class="nx">radix</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">tokPos</span> <span class="o">+=</span> <span class="mi">2</span><span class="p">;</span> <span class="c1">// 0x</span>
- <span class="kd">var</span> <span class="nx">val</span> <span class="o">=</span> <span class="nx">readInt</span><span class="p">(</span><span class="mi">16</span><span class="p">);</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">val</span> <span class="o">==</span> <span class="kc">null</span><span class="p">)</span> <span class="nx">raise</span><span class="p">(</span><span class="nx">tokStart</span> <span class="o">+</span> <span class="mi">2</span><span class="p">,</span> <span class="s2">"Expected hexadecimal number"</span><span class="p">);</span>
+ <span class="kd">var</span> <span class="nx">val</span> <span class="o">=</span> <span class="nx">readInt</span><span class="p">(</span><span class="nx">radix</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">val</span> <span class="o">==</span> <span class="kc">null</span><span class="p">)</span> <span class="nx">raise</span><span class="p">(</span><span class="nx">tokStart</span> <span class="o">+</span> <span class="mi">2</span><span class="p">,</span> <span class="s2">"Expected number in radix "</span> <span class="o">+</span> <span class="nx">radix</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">isIdentifierStart</span><span class="p">(</span><span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="p">)))</span> <span class="nx">raise</span><span class="p">(</span><span class="nx">tokPos</span><span class="p">,</span> <span class="s2">"Identifier directly after number"</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_num</span><span class="p">,</span> <span class="nx">val</span><span class="p">);</span>
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-73"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-73">¶</a> </div> <p>Read an integer, octal integer, or floating-point number.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class= [...]
@@ -609,7 +625,26 @@ will return <code>null</code> unless the integer has exactly <code>len</code> di
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="sr">/[89]/</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">str</span><span class="p">)</span> <span class="o">||</span> <span class="nx">strict</span><span class="p">)</span> <span class="nx">raise</span><span class="p">(</span><span class="nx">start</span><span class="p">,</span> <span class="s2">"Invalid number"</span><span class="p [...]
<span class="k">else</span> <span class="nx">val</span> <span class="o">=</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nx">str</span><span class="p">,</span> <span class="mi">8</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_num</span><span class="p">,</span> <span class="nx">val</span><span class="p">);</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-74"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-74">¶</a> </div> <p>Read a string value, interpreting backslash-escapes.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx"> [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-74"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-74">¶</a> </div> <p>Read a string value, interpreting backslash-escapes.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx"> [...]
+ <span class="kd">var</span> <span class="nx">ch</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="p">),</span> <span class="nx">code</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="nx">ch</span> <span class="o">===</span> <span class="mi">123</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o"><</span> <span class="mi">6</span><span class="p">)</span> <span class="nx">unexpected</span><span class="p">();</span>
+ <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span>
+ <span class="nx">code</span> <span class="o">=</span> <span class="nx">readHexChar</span><span class="p">(</span><span class="nx">input</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">'}'</span><span class="p">,</span> <span class="nx">tokPos</span><span class="p">)</span> <span class="o">-</span> <span class="nx">tokPos</span><span class="p">);</span>
+ <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">code</span> <span class="o">></span> <span class="mh">0x10FFFF</span><span class="p">)</span> <span class="nx">unexpected</span><span class="p">();</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="nx">code</span> <span class="o">=</span> <span class="nx">readHexChar</span><span class="p">(</span><span class="mi">4</span><span class="p">);</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-75"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-75">¶</a> </div> <p>UTF-16 Encoding</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">code</span> <spa [...]
+ <span class="k">return</span> <span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span class="nx">code</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="kd">var</span> <span class="nx">cu1</span> <span class="o">=</span> <span class="p">((</span><span class="nx">code</span> <span class="o">-</span> <span class="mh">0x10000</span><span class="p">)</span> <span class="o">>></span> <span class="mi">10</span><span class="p">)</span> <span class="o">+</span> <span class="mh">0xD800</span><span class="p">;</span>
+ <span class="kd">var</span> <span class="nx">cu2</span> <span class="o">=</span> <span class="p">((</span><span class="nx">code</span> <span class="o">-</span> <span class="mh">0x10000</span><span class="p">)</span> <span class="o">&</span> <span class="mi">1023</span><span class="p">)</span> <span class="o">+</span> <span class="mh">0xDC00</span><span class="p">;</span>
+ <span class="k">return</span> <span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span class="nx">cu1</span><span class="p">,</span> <span class="nx">cu2</span><span class="p">);</span>
+ <span class="p">}</span>
+
+ <span class="kd">function</span> <span class="nx">readString</span><span class="p">(</span><span class="nx">quote</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">tokPos</span><span class="o">++</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">out</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(;;)</span> <span class="p">{</span>
@@ -635,7 +670,7 @@ will return <code>null</code> unless the integer has exactly <code>len</code> di
<span class="k">case</span> <span class="mi">110</span><span class="o">:</span> <span class="nx">out</span> <span class="o">+=</span> <span class="s2">"\n"</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// 'n' -> '\n'</span>
<span class="k">case</span> <span class="mi">114</span><span class="o">:</span> <span class="nx">out</span> <span class="o">+=</span> <span class="s2">"\r"</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// 'r' -> '\r'</span>
<span class="k">case</span> <span class="mi">120</span><span class="o">:</span> <span class="nx">out</span> <span class="o">+=</span> <span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span class="nx">readHexChar</span><span class="p">(</span><span class="mi">2</span><span class="p">));</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// 'x'</span>
- <span class="k">case</span> <span class="mi">117</span><span class="o">:</span> <span class="nx">out</span> <span class="o">+=</span> <span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span class="nx">readHexChar</span><span class="p">(</span><span class="mi">4</span><span class="p">));</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// 'u'</span>
+ <span class="k">case</span> <span class="mi">117</span><span class="o">:</span> <span class="nx">out</span> <span class="o">+=</span> <span class="nx">readCodePoint</span><span class="p">();</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// 'u'</span>
<span class="k">case</span> <span class="mi">85</span><span class="o">:</span> <span class="nx">out</span> <span class="o">+=</span> <span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span class="nx">readHexChar</span><span class="p">(</span><span class="mi">8</span><span class="p">));</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// 'U'</span>
<span class="k">case</span> <span class="mi">116</span><span class="o">:</span> <span class="nx">out</span> <span class="o">+=</span> <span class="s2">"\t"</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// 't' -> '\t'</span>
<span class="k">case</span> <span class="mi">98</span><span class="o">:</span> <span class="nx">out</span> <span class="o">+=</span> <span class="s2">"\b"</span><span class="p">;</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// 'b' -> '\b'</span>
@@ -655,13 +690,13 @@ will return <code>null</code> unless the integer has exactly <code>len</code> di
<span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-75"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-75">¶</a> </div> <p>Used to read character escape sequences ('\x', '\u', '\U').</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span clas [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-76"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-76">¶</a> </div> <p>Used to read character escape sequences ('\x', '\u', '\U').</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span clas [...]
<span class="kd">var</span> <span class="nx">n</span> <span class="o">=</span> <span class="nx">readInt</span><span class="p">(</span><span class="mi">16</span><span class="p">,</span> <span class="nx">len</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">n</span> <span class="o">===</span> <span class="kc">null</span><span class="p">)</span> <span class="nx">raise</span><span class="p">(</span><span class="nx">tokStart</span><span class="p">,</span> <span class="s2">"Bad character escape sequence"</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">n</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-76"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-76">¶</a> </div> <p>Used to signal to callers of <code>readWord1</code> whether the word
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-77"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-77">¶</a> </div> <p>Used to signal to callers of <code>readWord1</code> whether the word
contained any escape sequences. This is needed because words with
-escape sequences must not be interpreted as keywords.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">containsEsc</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-77"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-77">¶</a> </div> [...]
+escape sequences must not be interpreted as keywords.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">containsEsc</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-78"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-78">¶</a> </div> [...]
to whether the word contained a '\u' escape.</p>
<p>Only builds up the word character-by-character when it actually
@@ -691,14 +726,14 @@ containeds an escape, as a micro-optimization.</p> </td>
<span class="nx">first</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">containsEsc</span> <span class="o">?</span> <span class="nx">word</span> <span class="o">:</span> <span class="nx">input</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="nx">start</span><span class="p">,</span> <span class="nx">tokPos</span><span class="p">);</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-78"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-78">¶</a> </div> <p>Read an identifier or keyword token. Will check for reserved
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-79"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-79">¶</a> </div> <p>Read an identifier or keyword token. Will check for reserved
words when necessary.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">readWord</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">word</span> <span class="o">=</span> <span class="nx">readWord1</span><span class="p">();</span>
<span class="kd">var</span> <span class="nx">type</span> <span class="o">=</span> <span class="nx">_name</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">containsEsc</span> <span class="o">&&</span> <span class="nx">isKeyword</span><span class="p">(</span><span class="nx">word</span><span class="p">))</span>
<span class="nx">type</span> <span class="o">=</span> <span class="nx">keywordTypes</span><span class="p">[</span><span class="nx">word</span><span class="p">];</span>
<span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">type</span><span class="p">,</span> <span class="nx">word</span><span class="p">);</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-79"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-79">¶</a> </div> <h2>Parser</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-80" [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-80"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-80">¶</a> </div> <h2>Parser</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-81" [...]
syntactic elements, and recursively calling those, each function
advancing the input stream and returning an AST node. Precedence
of constructs (for example, the fact that <code>!x[1]</code> means <code>!(x[1])</code>
@@ -712,12 +747,12 @@ way, it'll receive the node for <code>x[1]</code> already parsed, and wraps
operator precedence, because it is much more compact than using
the technique outlined above, which uses different, nesting
functions to specify precedence, for all of the ten binary
-precedence levels that JavaScript defines.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-81"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-81">¶</a> </div> <h3>Parser utilities</h3> </td> <td class="code"> <di [...]
+precedence levels that JavaScript defines.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-82"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-82">¶</a> </div> <h3>Parser utilities</h3> </td> <td class="code"> <di [...]
<span class="nx">lastStart</span> <span class="o">=</span> <span class="nx">tokStart</span><span class="p">;</span>
<span class="nx">lastEnd</span> <span class="o">=</span> <span class="nx">tokEnd</span><span class="p">;</span>
<span class="nx">lastEndLoc</span> <span class="o">=</span> <span class="nx">tokEndLoc</span><span class="p">;</span>
<span class="nx">readToken</span><span class="p">();</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-83"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-83">¶</a> </div> <p>Enter strict mode. Re-reads the next token to please pedantic
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-84"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-84">¶</a> </div> <p>Enter strict mode. Re-reads the next token to please pedantic
tests ("use strict"; 010; -- should fail).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">setStrict</span><span class="p">(</span><span class="nx">strct</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">strict</span> <span class="o">=</span> <span class="nx">strct</span><span class="p">;</span>
<span class="nx">tokPos</span> <span class="o">=</span> <span class="nx">tokStart</span><span class="p">;</span>
@@ -729,7 +764,7 @@ tests ("use strict"; 010; -- should fail).</p> </td> <td
<span class="p">}</span>
<span class="nx">skipSpace</span><span class="p">();</span>
<span class="nx">readToken</span><span class="p">();</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-84"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-84">¶</a> </div> <p>Start an AST node, attaching a start offset.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">Node</sp [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-85"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-85">¶</a> </div> <p>Start an AST node, attaching a start offset.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">Node</sp [...]
<span class="k">this</span><span class="p">.</span><span class="nx">type</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">start</span> <span class="o">=</span> <span class="nx">tokStart</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">end</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
@@ -752,7 +787,7 @@ tests ("use strict"; 010; -- should fail).</p> </td> <td
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ranges</span><span class="p">)</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">range</span> <span class="o">=</span> <span class="p">[</span><span class="nx">tokStart</span><span class="p">,</span> <span class="mi">0</span><span class="p">];</span>
<span class="k">return</span> <span class="nx">node</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-85"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-85">¶</a> </div> <p>Start a node whose start offset information should be based on
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-86"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-86">¶</a> </div> <p>Start a node whose start offset information should be based on
the start of another node. For example, a binary operator node is
only started after its left-hand side has already been parsed.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">startNodeFrom</span><span class="p">(</span><span class="nx">other</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Node</span><span class="p">();</span>
@@ -765,7 +800,7 @@ only started after its left-hand side has already been parsed.</p> <
<span class="nx">node</span><span class="p">.</span><span class="nx">range</span> <span class="o">=</span> <span class="p">[</span><span class="nx">other</span><span class="p">.</span><span class="nx">range</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mi">0</span><span class="p">];</span>
<span class="k">return</span> <span class="nx">node</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-86"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-86">¶</a> </div> <p>Finish an AST node, adding <code>type</code> and <code>end</code> properties.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-87"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-87">¶</a> </div> <p>Finish an AST node, adding <code>type</code> and <code>end</code> properties.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function [...]
<span class="nx">node</span><span class="p">.</span><span class="nx">type</span> <span class="o">=</span> <span class="nx">type</span><span class="p">;</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">end</span> <span class="o">=</span> <span class="nx">lastEnd</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">locations</span><span class="p">)</span>
@@ -773,34 +808,58 @@ only started after its left-hand side has already been parsed.</p> <
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ranges</span><span class="p">)</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">range</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="nx">lastEnd</span><span class="p">;</span>
<span class="k">return</span> <span class="nx">node</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-87"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-87">¶</a> </div> <p>Test whether a statement node is the string literal <code>"use strict"</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">functio [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-88"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-88">¶</a> </div> <p>Test whether a statement node is the string literal <code>"use strict"</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">functio [...]
<span class="k">return</span> <span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">5</span> <span class="o">&&</span> <span class="nx">stmt</span><span class="p">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s2">"ExpressionStatement"</span> <span class="o">&&</span>
<span class="nx">stmt</span><span class="p">.</span><span class="nx">expression</span><span class="p">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s2">"Literal"</span> <span class="o">&&</span> <span class="nx">stmt</span><span class="p">.</span><span class="nx">expression</span><span class="p">.</span><span class="nx">value</span> <span class="o">===</span> <span class="s2">"use strict"</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-88"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-88">¶</a> </div> <p>Predicate that tests whether the next token is of the given
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-89"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-89">¶</a> </div> <p>Predicate that tests whether the next token is of the given
type, and if yes, consumes it as a side effect.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">eat</span><span class="p">(</span><span class="nx">type</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">type</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">next</span><span class="p">();</span>
<span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
<span class="p">}</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-89"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-89">¶</a> </div> <p>Test whether a semicolon can be inserted at the current position.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <spa [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-90"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-90">¶</a> </div> <p>Test whether a semicolon can be inserted at the current position.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <spa [...]
<span class="k">return</span> <span class="o">!</span><span class="nx">options</span><span class="p">.</span><span class="nx">strictSemicolons</span> <span class="o">&&</span>
<span class="p">(</span><span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_eof</span> <span class="o">||</span> <span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_braceR</span> <span class="o">||</span> <span class="nx">newline</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">input</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="nx">l [...]
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-90"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-90">¶</a> </div> <p>Consume a semicolon, or, failing that, see if we are allowed to
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-91"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-91">¶</a> </div> <p>Consume a semicolon, or, failing that, see if we are allowed to
pretend that there is a semicolon at this position.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">semicolon</span><span class="p">()</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">eat</span><span class="p">(</span><span class="nx">_semi</span><span class="p">)</span> <span class="o">&&</span> <span class="o">!</span><span class="nx">canInsertSemicolon</span><span class="p">())</span> <span class="nx">unexpected</span><span class="p">();</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-91"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-91">¶</a> </div> <p>Expect a token of a given type. If found, consume it, otherwise,
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-92"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-92">¶</a> </div> <p>Expect a token of a given type. If found, consume it, otherwise,
raise an unexpected token error.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">expect</span><span class="p">(</span><span class="nx">type</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">type</span><span class="p">)</span> <span class="nx">next</span><span class="p">();</span>
<span class="k">else</span> <span class="nx">unexpected</span><span class="p">();</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-92"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-92">¶</a> </div> <p>Raise an unexpected token error.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">unexpected</span><sp [...]
- <span class="nx">raise</span><span class="p">(</span><span class="nx">tokStart</span><span class="p">,</span> <span class="s2">"Unexpected token"</span><span class="p">);</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">¶</a> </div> <p>Verify that a node is an lval — something that can be assigned
-to.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">checkLVal</span><span class="p">(</span><span class="nx">expr</span><span class="p">)</span> <span class="p">{</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">expr</span><span class="p">.</span><span class="nx">type</span> <span class="o">!==</span> <span class="s2">"Identifier"</span> <span class="o">&&</span> <span class="nx">expr</span><span class="p">.</span><span class="nx">type</span> <span class="o">!==</span> <span class="s2">"MemberExpression"</span><span class="p">)</span>
- <span class="nx">raise</span><span class="p">(</span><span class="nx">expr</span><span class="p">.</span><span class="nx">start</span><span class="p">,</span> <span class="s2">"Assigning to rvalue"</span><span class="p">);</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">strict</span> <span class="o">&&</span> <span class="nx">expr</span><span class="p">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s2">"Identifier"</span> <span class="o">&&</span> <span class="nx">isStrictBadIdWord</span><span class="p">(</span><span class="nx">expr</span><span class="p">.</span><span class="nx">name</span><span class="p">))</span>
- <span class="nx">raise</span><span class="p">(</span><span class="nx">expr</span><span class="p">.</span><span class="nx">start</span><span class="p">,</span> <span class="s2">"Assigning to "</span> <span class="o">+</span> <span class="nx">expr</span><span class="p">.</span><span class="nx">name</span> <span class="o">+</span> <span class="s2">" in strict mode"</span><span class="p">);</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-94"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-94">¶</a> </div> <h3>Statement parsing</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id=" [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-93"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-93">¶</a> </div> <p>Raise an unexpected token error.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">unexpected</span><sp [...]
+ <span class="nx">raise</span><span class="p">(</span><span class="nx">pos</span> <span class="o">!=</span> <span class="kc">null</span> <span class="o">?</span> <span class="nx">pos</span> <span class="o">:</span> <span class="nx">tokStart</span><span class="p">,</span> <span class="s2">"Unexpected token"</span><span class="p">);</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-94"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-94">¶</a> </div> <p>Verify that a node is an lval — something that can be assigned
+to.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">checkLVal</span><span class="p">(</span><span class="nx">expr</span><span class="p">,</span> <span class="nx">isBinding</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">switch</span> <span class="p">(</span><span class="nx">expr</span><span class="p">.</span><span class="nx">type</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">case</span> <span class="s2">"Identifier"</span><span class="o">:</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">strict</span> <span class="o">&&</span> <span class="nx">isStrictBadIdWord</span><span class="p">(</span><span class="nx">expr</span><span class="p">.</span><span class="nx">name</span><span class="p">))</span>
+ <span class="nx">raise</span><span class="p">(</span><span class="nx">expr</span><span class="p">.</span><span class="nx">start</span><span class="p">,</span> <span class="nx">isBinding</span>
+ <span class="o">?</span> <span class="s2">"Binding "</span> <span class="o">+</span> <span class="nx">expr</span><span class="p">.</span><span class="nx">name</span> <span class="o">+</span> <span class="s2">" in strict mode"</span>
+ <span class="o">:</span> <span class="s2">"Assigning to "</span> <span class="o">+</span> <span class="nx">expr</span><span class="p">.</span><span class="nx">name</span> <span class="o">+</span> <span class="s2">" in strict mode"</span>
+ <span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+
+ <span class="k">case</span> <span class="s2">"MemberExpression"</span><span class="o">:</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">isBinding</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
+
+ <span class="k">case</span> <span class="s2">"ObjectPattern"</span><span class="o">:</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">expr</span><span class="p">.</span><span class="nx">properties</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span>
+ <span class="nx">checkLVal</span><span class="p">(</span><span class="nx">expr</span><span class="p">.</span><span class="nx">properties</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">value</span><span class="p">,</span> <span class="nx">isBinding</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+
+ <span class="k">case</span> <span class="s2">"ArrayPattern"</span><span class="o">:</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">expr</span><span class="p">.</span><span class="nx">elements</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span>
+ <span class="nx">checkLVal</span><span class="p">(</span><span class="nx">expr</span><span class="p">.</span><span class="nx">elements</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span> <span class="nx">isBinding</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+
+ <span class="k">case</span> <span class="s2">"SpreadElement"</span><span class="o">:</span>
+ <span class="k">break</span><span class="p">;</span>
+
+ <span class="k">default</span><span class="o">:</span>
+ <span class="nx">raise</span><span class="p">(</span><span class="nx">expr</span><span class="p">.</span><span class="nx">start</span><span class="p">,</span> <span class="s2">"Assigning to rvalue"</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-95"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-95">¶</a> </div> <h3>Statement parsing</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id=" [...]
statements, and wraps them in a Program node. Optionally takes a
<code>program</code> argument. If present, the statements will be appended
to its body instead of creating a new node.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseTopLevel</span><span class="p">(</span><span class="nx">program</span><span class="p">)</span> <span class="p">{</span>
@@ -821,7 +880,7 @@ to its body instead of creating a new node.</p> </td> <t
<span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"Program"</span><span class="p">);</span>
<span class="p">}</span>
- <span class="kd">var</span> <span class="nx">loopLabel</span> <span class="o">=</span> <span class="p">{</span><span class="nx">kind</span><span class="o">:</span> <span class="s2">"loop"</span><span class="p">},</span> <span class="nx">switchLabel</span> <span class="o">=</span> <span class="p">{</span><span class="nx">kind</span><span class="o">:</span> <span class="s2">"switch"</span><span class="p">};</span></pre></div> </td> </tr> [...]
+ <span class="kd">var</span> <span class="nx">loopLabel</span> <span class="o">=</span> <span class="p">{</span><span class="nx">kind</span><span class="o">:</span> <span class="s2">"loop"</span><span class="p">},</span> <span class="nx">switchLabel</span> <span class="o">=</span> <span class="p">{</span><span class="nx">kind</span><span class="o">:</span> <span class="s2">"switch"</span><span class="p">};</span></pre></div> </td> </tr> [...]
<p>If expecting a statement and finding a slash operator, parse a
regular expression literal. This is to handle cases like
@@ -830,7 +889,7 @@ does not help.</p> </td> <td class="code">
<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">&&</span> <span class="nx">tokVal</span> <span class="o">==</span> <span class="s2">"/="</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-97"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-97">¶</a> [...]
+ <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-98"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-98">¶</a> [...]
start with. Many are trivial to parse, some require a bit of
complexity.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">switch</span> <span class="p">(</span><span class="nx">starttype</span><span class="p">)</span> <span class="p">{</span>
<span class="k">case</span> <span class="nx">_break</span><span class="o">:</span> <span class="k">case</span> <span class="nx">_continue</span><span class="o">:</span> <span class="k">return</span> <span class="nx">parseBreakContinueStatement</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">starttype</span><span class="p">.</span><span class="nx">keyword</span><span class="p">);</span>
@@ -838,6 +897,7 @@ complexity.</p> </td> <td class="code"> <d
<span class="k">case</span> <span class="nx">_do</span><span class="o">:</span> <span class="k">return</span> <span class="nx">parseDoStatement</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
<span class="k">case</span> <span class="nx">_for</span><span class="o">:</span> <span class="k">return</span> <span class="nx">parseForStatement</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
<span class="k">case</span> <span class="nx">_function</span><span class="o">:</span> <span class="k">return</span> <span class="nx">parseFunctionStatement</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
+ <span class="k">case</span> <span class="nx">_class</span><span class="o">:</span> <span class="k">return</span> <span class="nx">parseClass</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
<span class="k">case</span> <span class="nx">_if</span><span class="o">:</span> <span class="k">return</span> <span class="nx">parseIfStatement</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
<span class="k">case</span> <span class="nx">_return</span><span class="o">:</span> <span class="k">return</span> <span class="nx">parseReturnStatement</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
<span class="k">case</span> <span class="nx">_switch</span><span class="o">:</span> <span class="k">return</span> <span class="nx">parseSwitchStatement</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
@@ -847,7 +907,7 @@ complexity.</p> </td> <td class="code"> <d
<span class="k">case</span> <span class="nx">_while</span><span class="o">:</span> <span class="k">return</span> <span class="nx">parseWhileStatement</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
<span class="k">case</span> <span class="nx">_with</span><span class="o">:</span> <span class="k">return</span> <span class="nx">parseWithStatement</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
<span class="k">case</span> <span class="nx">_braceL</span><span class="o">:</span> <span class="k">return</span> <span class="nx">parseBlock</span><span class="p">();</span> <span class="c1">// no point creating a function for this</span>
- <span class="k">case</span> <span class="nx">_semi</span><span class="o">:</span> <span class="k">return</span> <span class="nx">parseEmptyStatement</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-98"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-98">¶</a> </div> [...]
+ <span class="k">case</span> <span class="nx">_semi</span><span class="o">:</span> <span class="k">return</span> <span class="nx">parseEmptyStatement</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-99"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-99">¶</a> </div> [...]
brace, it's an ExpressionStatement or LabeledStatement. We
simply start parsing an expression, and afterwards, if the
next token is a colon and the expression was a simple
@@ -867,7 +927,7 @@ Identifier node, we switch to interpreting it as a label.</p> </td>
<span class="k">else</span> <span class="p">{</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">label</span> <span class="o">=</span> <span class="nx">parseIdent</span><span class="p">();</span>
<span class="nx">semicolon</span><span class="p">();</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-99"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-99">¶</a> </div> <p>Verify that there is an actual destination to break or
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-100"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-100">¶</a> </div> <p>Verify that there is an actual destination to break or
continue to.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">labels</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="o">++</span><span class=" [...]
<span class="kd">var</span> <span class="nx">lab</span> <span class="o">=</span> <span class="nx">labels</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">label</span> <span class="o">==</span> <span class="kc">null</span> <span class="o">||</span> <span class="nx">lab</span><span class="p">.</span><span class="nx">name</span> <span class="o">===</span> <span class="nx">node</span><span class="p">.</span><span class="nx">label</span><span class="p">.</span><span class="nx">name</span><span class="p">)</span> <span cl [...]
@@ -895,29 +955,33 @@ continue to.</p> </td> <td class="code"> <
<span class="nx">semicolon</span><span class="p">();</span>
<span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"DoWhileStatement"</span><span class="p">);</span>
<span class="p">}</span>
- </pre></div> </td> </tr> <tr id="section-100"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-100">¶</a> </div> <p>Disambiguating between a <code>for</code> and a <code>for</code>/<code>in</code> loop is
-non-trivial. Basically, we have to parse the init <code>var</code>
+ </pre></div> </td> </tr> <tr id="section-101"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-101">¶</a> </div> <p>Disambiguating between a <code>for</code> and a <code>for</code>/<code>in</code> or <code>for</code>/<code>of</code>
+loop is non-trivial. Basically, we have to parse the init <code>var</code>
statement or expression, disallowing the <code>in</code> operator (see
the second parameter to <code>parseExpression</code>), and then check
-whether the next token is <code>in</code>. When there is no init part
-(semicolon immediately after the opening parenthesis), it is
-a regular <code>for</code> loop.</p> </td> <td class="code"> <div class="highlight"><pre>
+whether the next token is <code>in</code> or <code>of</code>. When there is no init
+part (semicolon immediately after the opening parenthesis), it
+is a regular <code>for</code> loop.</p> </td> <td class="code"> <div class="highlight"><pre>
<span class="kd">function</span> <span class="nx">parseForStatement</span><span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">next</span><span class="p">();</span>
<span class="nx">labels</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">loopLabel</span><span class="p">);</span>
<span class="nx">expect</span><span class="p">(</span><span class="nx">_parenL</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">_semi</span><span class="p">)</span> <span class="k">return</span> <span class="nx">parseFor</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="kc">null</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">_var</span> <span class="o">||</span> <span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_let</span><span class="p">)</span> <span class="p">{</span>
- <span class="kd">var</span> <span class="nx">init</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">(),</span> <span class="nx">varKind</span> <span class="o">=</span> <span class="nx">tokType</span><span class="p">.</span><span class="nx">keyword</span><span class="p">;</span>
+ <span class="kd">var</span> <span class="nx">init</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">(),</span> <span class="nx">varKind</span> <span class="o">=</span> <span class="nx">tokType</span><span class="p">.</span><span class="nx">keyword</span><span class="p">,</span> <span class="nx">isLet</span> <span class="o">=</span> <span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_let</span><span class="p">;</span>
<span class="nx">next</span><span class="p">();</span>
<span class="nx">parseVar</span><span class="p">(</span><span class="nx">init</span><span class="p">,</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">varKind</span><span class="p">);</span>
<span class="nx">finishNode</span><span class="p">(</span><span class="nx">init</span><span class="p">,</span> <span class="s2">"VariableDeclaration"</span><span class="p">);</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">init</span><span class="p">.</span><span class="nx">declarations</span><span class="p">.</span><span class="nx">length</span> <span class="o">===</span> <span class="mi">1</span> <span class="o">&&</span> <span class="nx">eat</span><span class="p">(</span><span class="nx">_in</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">_in</span> <span class="o">||</span> <span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_of</span><span class="p">)</span> <span class="o">&&</span> <span class="nx">init</span><span class="p">.</span><span class="nx">declarations</span><span class="p">.</span><span class="nx">length</span> <span class="o">===</span> <span c [...]
+ <span class="o">!</span><span class="p">(</span><span class="nx">isLet</span> <span class="o">&&</span> <span class="nx">init</span><span class="p">.</span><span class="nx">declarations</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">init</span><span class="p">))</span>
<span class="k">return</span> <span class="nx">parseForIn</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">init</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">parseFor</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">init</span><span class="p">);</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">init</span> <span class="o">=</span> <span class="nx">parseExpression</span><span class="p">(</span><span class="kc">false</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">eat</span><span class="p">(</span><span class="nx">_in</span><span class="p">))</span> <span class="p">{</span><span class="nx">checkLVal</span><span class="p">(</span><span class="nx">init</span><span class="p">);</span> <span class="k">return</span> <span class="nx">parseForIn</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">init</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">_in</span> <span class="o">||</span> <span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_of</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">checkLVal</span><span class="p">(</span><span class="nx">init</span><span class="p">);</span>
+ <span class="k">return</span> <span class="nx">parseForIn</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">init</span><span class="p">);</span>
+ <span class="p">}</span>
<span class="k">return</span> <span class="nx">parseFor</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">init</span><span class="p">);</span>
<span class="p">}</span>
@@ -937,7 +1001,7 @@ a regular <code>for</code> loop.</p> </td> <td class="co
<span class="kd">function</span> <span class="nx">parseReturnStatement</span><span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">inFunction</span> <span class="o">&&</span> <span class="o">!</span><span class="nx">options</span><span class="p">.</span><span class="nx">allowReturnOutsideFunction</span><span class="p">)</span>
<span class="nx">raise</span><span class="p">(</span><span class="nx">tokStart</span><span class="p">,</span> <span class="s2">"'return' outside of function"</span><span class="p">);</span>
- <span class="nx">next</span><span class="p">();</span></pre></div> </td> </tr> <tr id="section-101"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-101">¶</a> </div> <p>In <code>return</code> (and <code>break</code>/<code>continue</code>), the keywords with
+ <span class="nx">next</span><span class="p">();</span></pre></div> </td> </tr> <tr id="section-102"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-102">¶</a> </div> <p>In <code>return</code> (and <code>break</code>/<code>continue</code>), the keywords with
optional arguments, we eagerly look for a semicolon or the
possibility to insert one.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">eat</span><span class="p">(</span><span class="nx">_semi</span><span class="p">)</span> <span class="o">||</span> <span class="nx">canInsertSemicolon</span><span class="p">())</span> <span class="nx">node</span><span class="p">.</span><span class="nx">argument</span> <span class="o">=</span> <span c [...]
<span class="k">else</span> <span class="p">{</span> <span class="nx">node</span><span class="p">.</span><span class="nx">argument</span> <span class="o">=</span> <span class="nx">parseExpression</span><span class="p">();</span> <span class="nx">semicolon</span><span class="p">();</span> <span class="p">}</span>
@@ -949,7 +1013,7 @@ possibility to insert one.</p> </td> <td class="code">
<span class="nx">node</span><span class="p">.</span><span class="nx">discriminant</span> <span class="o">=</span> <span class="nx">parseParenExpression</span><span class="p">();</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">cases</span> <span class="o">=</span> <span class="p">[];</span>
<span class="nx">expect</span><span class="p">(</span><span class="nx">_braceL</span><span class="p">);</span>
- <span class="nx">labels</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">switchLabel</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-102"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-102">¶</a> </div> <p>Statements under must be grouped (by label) in SwitchCase
+ <span class="nx">labels</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">switchLabel</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-103"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-103">¶</a> </div> <p>Statements under must be grouped (by label) in SwitchCase
nodes. <code>cur</code> is used to keep the node that we are currently
adding statements to.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">cur</span><span class="p">,</span> <span class="nx">sawDefault</span><span class="p">;</span> <span class="nx">tokType</span> <span class="o">!=</span> <span class="nx">_braceR</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">_case</span> <span class="o">||</span> <span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_default</span><span class="p">)</span> <span class="p">{</span>
@@ -1051,13 +1115,13 @@ adding statements to.</p> </td> <td class="code">
<span class="nx">node</span><span class="p">.</span><span class="nx">expression</span> <span class="o">=</span> <span class="nx">expr</span><span class="p">;</span>
<span class="nx">semicolon</span><span class="p">();</span>
<span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"ExpressionStatement"</span><span class="p">);</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-103"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-103">¶</a> </div> <p>Used for constructs like <code>switch</code> and <code>if</code> that insist on
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-104"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-104">¶</a> </div> <p>Used for constructs like <code>switch</code> and <code>if</code> that insist on
parentheses around their expression.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseParenExpression</span><span class="p">()</span> <span class="p">{</span>
<span class="nx">expect</span><span class="p">(</span><span class="nx">_parenL</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">val</span> <span class="o">=</span> <span class="nx">parseExpression</span><span class="p">();</span>
<span class="nx">expect</span><span class="p">(</span><span class="nx">_parenR</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">val</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-104"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-104">¶</a> </div> <p>Parse a semicolon-enclosed block of statements, handling <code>"use
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-105"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-105">¶</a> </div> <p>Parse a semicolon-enclosed block of statements, handling <code>"use
strict"</code> declarations when <code>allowStrict</code> is true (used for
function bodies).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseBlock</span><span class="p">(</span><span class="nx">allowStrict</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">(),</span> <span class="nx">first</span> <span class="o">=</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">strict</span> <span class="o">=</span> <span class="kc">false</span><span class="p">,</span> <span class="nx">oldStrict</span><span class="p">;</span>
@@ -1074,7 +1138,7 @@ function bodies).</p> </td> <td class="code">
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">strict</span> <span class="o">&&</span> <span class="o">!</span><span class="nx">oldStrict</span><span class="p">)</span> <span class="nx">setStrict</span><span class="p">(</span><span class="kc">false</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"BlockStatement"</span><span class="p">);</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-105"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-105">¶</a> </div> <p>Parse a regular <code>for</code> loop. The disambiguation code in
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-106"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-106">¶</a> </div> <p>Parse a regular <code>for</code> loop. The disambiguation code in
<code>parseStatement</code> will already have parsed the init statement or
expression.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseFor</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">init</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">init</span> <span class="o">=</span> <span class="nx">init</span><span class="p">;</span>
@@ -1086,31 +1150,33 @@ expression.</p> </td> <td class="code"> <d
<span class="nx">node</span><span class="p">.</span><span class="nx">body</span> <span class="o">=</span> <span class="nx">parseStatement</span><span class="p">();</span>
<span class="nx">labels</span><span class="p">.</span><span class="nx">pop</span><span class="p">();</span>
<span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"ForStatement"</span><span class="p">);</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-106"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-106">¶</a> </div> <p>Parse a <code>for</code>/<code>in</code> loop.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">pars [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-107"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-107">¶</a> </div> <p>Parse a <code>for</code>/<code>in</code> and <code>for</code>/<code>of</code> loop, which are almost
+same from parser's perspective.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseForIn</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">init</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">type</span> <span class="o">=</span> <span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_in</span> <span class="o">?</span> <span class="s2">"ForInStatement"</span> <span class="o">:</span> <span class="s2">"ForOfStatement"</span><span class="p">;</span>
+ <span class="nx">next</span><span class="p">();</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">left</span> <span class="o">=</span> <span class="nx">init</span><span class="p">;</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">right</span> <span class="o">=</span> <span class="nx">parseExpression</span><span class="p">();</span>
<span class="nx">expect</span><span class="p">(</span><span class="nx">_parenR</span><span class="p">);</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">body</span> <span class="o">=</span> <span class="nx">parseStatement</span><span class="p">();</span>
<span class="nx">labels</span><span class="p">.</span><span class="nx">pop</span><span class="p">();</span>
- <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"ForInStatement"</span><span class="p">);</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-107"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-107">¶</a> </div> <p>Parse a list of variable declarations.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseVar</sp [...]
+ <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">type</span><span class="p">);</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-108"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-108">¶</a> </div> <p>Parse a list of variable declarations.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseVar</sp [...]
<span class="nx">node</span><span class="p">.</span><span class="nx">declarations</span> <span class="o">=</span> <span class="p">[];</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">kind</span> <span class="o">=</span> <span class="nx">kind</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(;;)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">decl</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">();</span>
- <span class="nx">decl</span><span class="p">.</span><span class="nx">id</span> <span class="o">=</span> <span class="nx">parseIdent</span><span class="p">();</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">strict</span> <span class="o">&&</span> <span class="nx">isStrictBadIdWord</span><span class="p">(</span><span class="nx">decl</span><span class="p">.</span><span class="nx">id</span><span class="p">.</span><span class="nx">name</span><span class="p">))</span>
- <span class="nx">raise</span><span class="p">(</span><span class="nx">decl</span><span class="p">.</span><span class="nx">id</span><span class="p">.</span><span class="nx">start</span><span class="p">,</span> <span class="s2">"Binding "</span> <span class="o">+</span> <span class="nx">decl</span><span class="p">.</span><span class="nx">id</span><span class="p">.</span><span class="nx">name</span> <span class="o">+</span> <span class="s2">" in strict mode"</spa [...]
+ <span class="nx">decl</span><span class="p">.</span><span class="nx">id</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">6</span> <span class="o">?</span> <span class="nx">toAssignable</span><span class="p">(</span><span class="nx">parseExprAtom</span><span class="p">())</span> <span class="o">:</span> <span class="nx">parseIdent</span><span class="p">();</span>
+ <span class="nx">checkLVal</span><span class="p">(</span><span class="nx">decl</span><span class="p">.</span><span class="nx">id</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
<span class="nx">decl</span><span class="p">.</span><span class="nx">init</span> <span class="o">=</span> <span class="nx">eat</span><span class="p">(</span><span class="nx">_eq</span><span class="p">)</span> <span class="o">?</span> <span class="nx">parseExpression</span><span class="p">(</span><span class="kc">true</span><span class="p">,</span> <span class="nx">noIn</span><span class="p">)</span> <span class="o">:</span> <span class="p">(</span><span class="nx">kind</span> <span [...]
<span class="nx">node</span><span class="p">.</span><span class="nx">declarations</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">finishNode</span><span class="p">(</span><span class="nx">decl</span><span class="p">,</span> <span class="s2">"VariableDeclarator"</span><span class="p">));</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">eat</span><span class="p">(</span><span class="nx">_comma</span><span class="p">))</span> <span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">node</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-108"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-108">¶</a> </div> <h3>Expression parsing</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr i [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-109"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-109">¶</a> </div> <h3>Expression parsing</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr i [...]
'atomic', nondivisible expression types at the bottom. Most of
the functions will simply let the function(s) below them parse,
and, <em>if</em> the syntactic construct they handle is present, wrap
-the AST node that the inner parser gave them in another node.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-110"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-110">¶</a> </div> <p>Parse a full expression. The arguments are used to forbid comma
+the AST node that the inner parser gave them in another node.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-111"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-111">¶</a> </div> <p>Parse a full expression. The arguments are used to forbid comma
sequences (in argument lists, array literals, or object literals)
or the <code>in</code> operator (in for loops initalization expressions).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseExpression</span><span class="p">(</span><span class="nx">noComma</span><span class="p">,</span> <span class="nx">noIn</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">expr</span> <span class="o">=</span> <span class="nx">parseMaybeAssign</span><span class="p">(</span><span class="nx">noIn</span><span class="p">);</span>
@@ -1121,20 +1187,20 @@ or the <code>in</code> operator (in for loops initalization expressions).</p>
<span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"SequenceExpression"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">expr</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-111"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-111">¶</a> </div> <p>Parse an assignment expression. This includes applications of
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-112"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-112">¶</a> </div> <p>Parse an assignment expression. This includes applications of
operators like <code>+=</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseMaybeAssign</span><span class="p">(</span><span class="nx">noIn</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">left</span> <span class="o">=</span> <span class="nx">parseMaybeConditional</span><span class="p">(</span><span class="nx">noIn</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">tokType</span><span class="p">.</span><span class="nx">isAssign</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNodeFrom</span><span class="p">(</span><span class="nx">left</span><span class="p">);</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">operator</span> <span class="o">=</span> <span class="nx">tokVal</span><span class="p">;</span>
- <span class="nx">node</span><span class="p">.</span><span class="nx">left</span> <span class="o">=</span> <span class="nx">left</span><span class="p">;</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">left</span> <span class="o">=</span> <span class="nx">tokVal</span> <span class="o">===</span> <span class="s1">'='</span> <span class="o">?</span> <span class="nx">toAssignable</span><span class="p">(</span><span class="nx">left</span><span class="p">)</span> <span class="o">:</span> <span class="nx">left</span><span class="p">;</span>
+ <span class="nx">checkLVal</span><span class="p">(</span><span class="nx">left</span><span class="p">);</span>
<span class="nx">next</span><span class="p">();</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">right</span> <span class="o">=</span> <span class="nx">parseMaybeAssign</span><span class="p">(</span><span class="nx">noIn</span><span class="p">);</span>
- <span class="nx">checkLVal</span><span class="p">(</span><span class="nx">left</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"AssignmentExpression"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">left</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-112"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-112">¶</a> </div> <p>Parse a ternary conditional (<code>?:</code>) operator.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class= [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-113"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-113">¶</a> </div> <p>Parse a ternary conditional (<code>?:</code>) operator.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class= [...]
<span class="kd">var</span> <span class="nx">expr</span> <span class="o">=</span> <span class="nx">parseExprOps</span><span class="p">(</span><span class="nx">noIn</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">eat</span><span class="p">(</span><span class="nx">_question</span><span class="p">))</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNodeFrom</span><span class="p">(</span><span class="nx">expr</span><span class="p">);</span>
@@ -1145,9 +1211,9 @@ operators like <code>+=</code>.</p> </td> <td class="cod
<span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"ConditionalExpression"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">expr</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-113"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-113">¶</a> </div> <p>Start the precedence parser.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseExprOps</span><sp [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-114"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-114">¶</a> </div> <p>Start the precedence parser.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseExprOps</span><sp [...]
<span class="k">return</span> <span class="nx">parseExprOp</span><span class="p">(</span><span class="nx">parseMaybeUnary</span><span class="p">(),</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="nx">noIn</span><span class="p">);</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-114"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-114">¶</a> </div> <p>Parse binary operators with the operator precedence parsing
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-115"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-115">¶</a> </div> <p>Parse binary operators with the operator precedence parsing
algorithm. <code>left</code> is the left-hand side of the operator.
<code>minPrec</code> provides context that allows the function to stop and
defer further parser to one of its callers when it encounters an
@@ -1166,7 +1232,7 @@ operator that has a lower precedence than the set it is parsing.</p>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">left</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-115"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-115">¶</a> </div> <p>Parse unary operators, both prefix and postfix.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">par [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-116"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-116">¶</a> </div> <p>Parse unary operators, both prefix and postfix.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">par [...]
<span class="k">if</span> <span class="p">(</span><span class="nx">tokType</span><span class="p">.</span><span class="nx">prefix</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">(),</span> <span class="nx">update</span> <span class="o">=</span> <span class="nx">tokType</span><span class="p">.</span><span class="nx">isUpdate</span><span class="p">;</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">operator</span> <span class="o">=</span> <span class="nx">tokVal</span><span class="p">;</span>
@@ -1191,7 +1257,7 @@ operator that has a lower precedence than the set it is parsing.</p>
<span class="nx">expr</span> <span class="o">=</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"UpdateExpression"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">expr</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-116"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-116">¶</a> </div> <p>Parse call, dot, and <code>[]</code>-subscript expressions.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span cl [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-117"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-117">¶</a> </div> <p>Parse call, dot, and <code>[]</code>-subscript expressions.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span cl [...]
<span class="k">return</span> <span class="nx">parseSubscripts</span><span class="p">(</span><span class="nx">parseExprAtom</span><span class="p">());</span>
<span class="p">}</span>
@@ -1215,7 +1281,7 @@ operator that has a lower precedence than the set it is parsing.</p>
<span class="nx">node</span><span class="p">.</span><span class="nx">arguments</span> <span class="o">=</span> <span class="nx">parseExprList</span><span class="p">(</span><span class="nx">_parenR</span><span class="p">,</span> <span class="kc">false</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">parseSubscripts</span><span class="p">(</span><span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"CallExpression"</span><span class="p">),</span> <span class="nx">noCalls</span><span class="p">);</span>
<span class="p">}</span> <span class="k">else</span> <span class="k">return</span> <span class="nx">base</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-117"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-117">¶</a> </div> <p>Parse an atomic expression — either a single token that is an
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-118"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-118">¶</a> </div> <p>Parse an atomic expression — either a single token that is an
expression, an expression started by a keyword like <code>function</code> or
<code>new</code>, or an expression wrapped in punctuation like <code>()</code>, <code>[]</code>,
or <code>{}</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseExprAtom</span><span class="p">()</span> <span class="p">{</span>
@@ -1224,8 +1290,14 @@ or <code>{}</code>.</p> </td> <td class="code">
<span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">();</span>
<span class="nx">next</span><span class="p">();</span>
<span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"ThisExpression"</span><span class="p">);</span>
+
<span class="k">case</span> <span class="nx">_name</span><span class="o">:</span>
- <span class="k">return</span> <span class="nx">parseIdent</span><span class="p">();</span>
+ <span class="kd">var</span> <span class="nx">id</span> <span class="o">=</span> <span class="nx">parseIdent</span><span class="p">();</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">eat</span><span class="p">(</span><span class="nx">_arrow</span><span class="p">))</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">parseArrowExpression</span><span class="p">(</span><span class="nx">startNodeFrom</span><span class="p">(</span><span class="nx">id</span><span class="p">),</span> <span class="p">[</span><span class="nx">id</span><span class="p">]);</span>
+ <span class="p">}</span>
+ <span class="k">return</span> <span class="nx">id</span><span class="p">;</span>
+
<span class="k">case</span> <span class="nx">_num</span><span class="o">:</span> <span class="k">case</span> <span class="nx">_string</span><span class="o">:</span> <span class="k">case</span> <span class="nx">_regexp</span><span class="o">:</span>
<span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">();</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">value</span> <span class="o">=</span> <span class="nx">tokVal</span><span class="p">;</span>
@@ -1241,18 +1313,26 @@ or <code>{}</code>.</p> </td> <td class="code">
<span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"Literal"</span><span class="p">);</span>
<span class="k">case</span> <span class="nx">_parenL</span><span class="o">:</span>
- <span class="kd">var</span> <span class="nx">tokStartLoc1</span> <span class="o">=</span> <span class="nx">tokStartLoc</span><span class="p">,</span> <span class="nx">tokStart1</span> <span class="o">=</span> <span class="nx">tokStart</span><span class="p">;</span>
+ <span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">(),</span> <span class="nx">tokStartLoc1</span> <span class="o">=</span> <span class="nx">tokStartLoc</span><span class="p">,</span> <span class="nx">tokStart1</span> <span class="o">=</span> <span class="nx">tokStart</span><span class="p">,</span> <span class="nx">val</span><span class="p">;</span>
<span class="nx">next</span><span class="p">();</span>
- <span class="kd">var</span> <span class="nx">val</span> <span class="o">=</span> <span class="nx">parseExpression</span><span class="p">();</span>
+ <span class="kd">var</span> <span class="nx">oldParenL</span> <span class="o">=</span> <span class="o">++</span><span class="nx">metParenL</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">_parenR</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">val</span> <span class="o">=</span> <span class="nx">parseExpression</span><span class="p">();</span>
+ <span class="p">}</span>
+ <span class="nx">expect</span><span class="p">(</span><span class="nx">_parenR</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">metParenL</span> <span class="o">===</span> <span class="nx">oldParenL</span> <span class="o">&&</span> <span class="nx">eat</span><span class="p">(</span><span class="nx">_arrow</span><span class="p">))</span> <span class="p">{</span>
+ <span class="nx">val</span> <span class="o">=</span> <span class="nx">parseArrowExpression</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="o">!</span><span class="nx">val</span> <span class="o">?</span> <span class="p">[]</span> <span class="o">:</span> <span class="nx">val</span><span class="p">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s2">"SequenceExpression"</span> <span class="o">?</s [...]
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-119"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-119">¶</a> </div> <p>disallow '()' before everything but error</p> </td> <td class="code"> <div class="highlight"><pre> [...]
+ <span class="p">}</span>
<span class="nx">val</span><span class="p">.</span><span class="nx">start</span> <span class="o">=</span> <span class="nx">tokStart1</span><span class="p">;</span>
- <span class="nx">val</span><span class="p">.</span><span class="nx">end</span> <span class="o">=</span> <span class="nx">tokEnd</span><span class="p">;</span>
+ <span class="nx">val</span><span class="p">.</span><span class="nx">end</span> <span class="o">=</span> <span class="nx">lastEnd</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">locations</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">val</span><span class="p">.</span><span class="nx">loc</span><span class="p">.</span><span class="nx">start</span> <span class="o">=</span> <span class="nx">tokStartLoc1</span><span class="p">;</span>
- <span class="nx">val</span><span class="p">.</span><span class="nx">loc</span><span class="p">.</span><span class="nx">end</span> <span class="o">=</span> <span class="nx">tokEndLoc</span><span class="p">;</span>
+ <span class="nx">val</span><span class="p">.</span><span class="nx">loc</span><span class="p">.</span><span class="nx">end</span> <span class="o">=</span> <span class="nx">lastEndLoc</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ranges</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">val</span><span class="p">.</span><span class="nx">range</span> <span class="o">=</span> <span class="p">[</span><span class="nx">tokStart1</span><span class="p">,</span> <span class="nx">lastEnd</span><span class="p">];</span>
<span class="p">}</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ranges</span><span class="p">)</span>
- <span class="nx">val</span><span class="p">.</span><span class="nx">range</span> <span class="o">=</span> <span class="p">[</span><span class="nx">tokStart1</span><span class="p">,</span> <span class="nx">tokEnd</span><span class="p">];</span>
- <span class="nx">expect</span><span class="p">(</span><span class="nx">_parenR</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">val</span><span class="p">;</span>
<span class="k">case</span> <span class="nx">_bracketL</span><span class="o">:</span>
@@ -1269,13 +1349,19 @@ or <code>{}</code>.</p> </td> <td class="code">
<span class="nx">next</span><span class="p">();</span>
<span class="k">return</span> <span class="nx">parseFunction</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="kc">false</span><span class="p">);</span>
+ <span class="k">case</span> <span class="nx">_class</span><span class="o">:</span>
+ <span class="k">return</span> <span class="nx">parseClass</span><span class="p">(</span><span class="nx">startNode</span><span class="p">(),</span> <span class="kc">false</span><span class="p">);</span>
+
<span class="k">case</span> <span class="nx">_new</span><span class="o">:</span>
<span class="k">return</span> <span class="nx">parseNew</span><span class="p">();</span>
+ <span class="k">case</span> <span class="nx">_ellipsis</span><span class="o">:</span>
+ <span class="k">return</span> <span class="nx">parseSpread</span><span class="p">();</span>
+
<span class="k">default</span><span class="o">:</span>
<span class="nx">unexpected</span><span class="p">();</span>
<span class="p">}</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-118"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-118">¶</a> </div> <p>New's precedence is slightly tricky. It must allow its argument
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-120"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-120">¶</a> </div> <p>New's precedence is slightly tricky. It must allow its argument
to be a <code>[]</code> or dot subscript expression, but not a call — at
least, not without wrapping it in parentheses. Thus, it uses the</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseNew</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">();</span>
@@ -1284,7 +1370,12 @@ least, not without wrapping it in parentheses. Thus, it uses the</p>
<span class="k">if</span> <span class="p">(</span><span class="nx">eat</span><span class="p">(</span><span class="nx">_parenL</span><span class="p">))</span> <span class="nx">node</span><span class="p">.</span><span class="nx">arguments</span> <span class="o">=</span> <span class="nx">parseExprList</span><span class="p">(</span><span class="nx">_parenR</span><span class="p">,</span> <span class="kc">false</span><span class="p">);</span>
<span class="k">else</span> <span class="nx">node</span><span class="p">.</span><span class="nx">arguments</span> <span class="o">=</span> <span class="nx">empty</span><span class="p">;</span>
<span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"NewExpression"</span><span class="p">);</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-119"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-119">¶</a> </div> <p>Parse an object literal.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseObj</span><span class [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-121"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-121">¶</a> </div> <p>Parse spread element '...expr'</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseSpread</span><s [...]
+ <span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">();</span>
+ <span class="nx">next</span><span class="p">();</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">argument</span> <span class="o">=</span> <span class="nx">parseExpression</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
+ <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"SpreadElement"</span><span class="p">);</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-122"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-122">¶</a> </div> <p>Parse an object literal.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseObj</span><span class [...]
<span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">(),</span> <span class="nx">first</span> <span class="o">=</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">sawGetSet</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">properties</span> <span class="o">=</span> <span class="p">[];</span>
<span class="nx">next</span><span class="p">();</span>
@@ -1294,85 +1385,211 @@ least, not without wrapping it in parentheses. Thus, it uses the</p>
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">allowTrailingCommas</span> <span class="o">&&</span> <span class="nx">eat</span><span class="p">(</span><span class="nx">_braceR</span><span class="p">))</span> <span class="k">break</span><span class="p">;</span>
<span class="p">}</span> <span class="k">else</span> <span class="nx">first</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
- <span class="kd">var</span> <span class="nx">prop</span> <span class="o">=</span> <span class="p">{</span><span class="nx">key</span><span class="o">:</span> <span class="nx">parsePropertyName</span><span class="p">()},</span> <span class="nx">isGetSet</span> <span class="o">=</span> <span class="kc">false</span><span class="p">,</span> <span class="nx">kind</span><span class="p">;</span>
+ <span class="kd">var</span> <span class="nx">prop</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">(),</span> <span class="nx">kind</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">6</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">prop</span><span class="p">.</span><span class="nx">method</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
+ <span class="nx">prop</span><span class="p">.</span><span class="nx">shorthand</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="nx">parsePropertyName</span><span class="p">(</span><span class="nx">prop</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">eat</span><span class="p">(</span><span class="nx">_colon</span><span class="p">))</span> <span class="p">{</span>
<span class="nx">prop</span><span class="p">.</span><span class="nx">value</span> <span class="o">=</span> <span class="nx">parseExpression</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
<span class="nx">kind</span> <span class="o">=</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">kind</span> <span class="o">=</span> <span class="s2">"init"</span><span class="p">;</span>
- <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">5</span> <span class="o">&&</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s2">"Identifier"</spa [...]
+ <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">6</span> <span class="o">&&</span> <span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_parenL</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">func</span> <span class="o">=</span> <span class="nx">parseFunction</span><span class="p">(</span><span class="nx">startNode</span><span class="p">(),</span> <span class="kc">false</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
+ <span class="nx">kind</span> <span class="o">=</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">kind</span> <span class="o">=</span> <span class="s2">"init"</span><span class="p">;</span>
+ <span class="nx">prop</span><span class="p">.</span><span class="nx">method</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="nx">prop</span><span class="p">.</span><span class="nx">value</span> <span class="o">=</span> <span class="nx">func</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">5</span> <span class="o">&&</span> <span class="o">!</span><span class="nx">prop</span><span class="p">.</span><span class="nx">computed</span> <span class="o">&&</span> <span class="nx">prop</span><span class="p">.</span><span cl [...]
<span class="p">(</span><span class="nx">prop</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">name</span> <span class="o">===</span> <span class="s2">"get"</span> <span class="o">||</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">name</span> <span class="o">===</span> <span class="s2">"set"</span><span class="p">))</span> <s [...]
- <span class="nx">isGetSet</span> <span class="o">=</span> <span class="nx">sawGetSet</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="nx">sawGetSet</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
<span class="nx">kind</span> <span class="o">=</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">kind</span> <span class="o">=</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">name</span><span class="p">;</span>
- <span class="nx">prop</span><span class="p">.</span><span class="nx">key</span> <span class="o">=</span> <span class="nx">parsePropertyName</span><span class="p">();</span>
+ <span class="nx">parsePropertyName</span><span class="p">(</span><span class="nx">prop</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">_parenL</span><span class="p">)</span> <span class="nx">unexpected</span><span class="p">();</span>
- <span class="nx">prop</span><span class="p">.</span><span class="nx">value</span> <span class="o">=</span> <span class="nx">parseFunction</span><span class="p">(</span><span class="nx">startNode</span><span class="p">(),</span> <span class="kc">false</span><span class="p">);</span>
- <span class="p">}</span> <span class="k">else</span> <span class="nx">unexpected</span><span class="p">();</span></pre></div> </td> </tr> <tr id="section-120"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-120">¶</a> </div> <p>getters and setters are not allowed to clash — either with
-each other or with an init property — and in strict mode,
-init properties are also not allowed to be repeated.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">prop</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s2">"Identifier"</span> <span class="o">&&</span> <span class="p">(</span><span class="nx">strict</ [...]
- <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">node</span><span class="p">.</span><span class="nx">properties</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="o">++</span><span class="nx">i</span><span class="p">)</span> <span clas [...]
- <span class="kd">var</span> <span class="nx">other</span> <span class="o">=</span> <span class="nx">node</span><span class="p">.</span><span class="nx">properties</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">other</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">name</span> <span class="o">===</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">name</span><span class="p">)</span> <span class="p">{</span>
- <span class="kd">var</span> <span class="nx">conflict</span> <span class="o">=</span> <span class="nx">kind</span> <span class="o">==</span> <span class="nx">other</span><span class="p">.</span><span class="nx">kind</span> <span class="o">||</span> <span class="nx">isGetSet</span> <span class="o">&&</span> <span class="nx">other</span><span class="p">.</span><span class="nx">kind</span> <span class="o">===</span> <span class="s2">"init"</span> <span class="o [...]
- <span class="nx">kind</span> <span class="o">===</span> <span class="s2">"init"</span> <span class="o">&&</span> <span class="p">(</span><span class="nx">other</span><span class="p">.</span><span class="nx">kind</span> <span class="o">===</span> <span class="s2">"get"</span> <span class="o">||</span> <span class="nx">other</span><span class="p">.</span><span class="nx">kind</span> <span class="o">===</span> <span class="s2">"set"</span> [...]
- <span class="k">if</span> <span class="p">(</span><span class="nx">conflict</span> <span class="o">&&</span> <span class="o">!</span><span class="nx">strict</span> <span class="o">&&</span> <span class="nx">kind</span> <span class="o">===</span> <span class="s2">"init"</span> <span class="o">&&</span> <span class="nx">other</span><span class="p">.</span><span class="nx">kind</span> <span class="o">===</span> <span class="s2">"init"< [...]
- <span class="k">if</span> <span class="p">(</span><span class="nx">conflict</span><span class="p">)</span> <span class="nx">raise</span><span class="p">(</span><span class="nx">prop</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">start</span><span class="p">,</span> <span class="s2">"Redefinition of property"</span><span class="p">);</span>
- <span class="p">}</span>
+ <span class="kd">var</span> <span class="nx">func</span> <span class="o">=</span> <span class="nx">parseFunction</span><span class="p">(</span><span class="nx">startNode</span><span class="p">(),</span> <span class="kc">false</span><span class="p">,</span> <span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">6</span><span class="p">);</span>
+ <span class="nx">prop</span><span class="p">.</span><span class="nx">value</span> <span class="o">=</span> <span class="nx">func</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">6</span> <span class="o">&&</span> <span class="o">!</span><span class="nx">prop</span><span class="p">.</span><span class="nx">computed</span> <span class="o">&&</span> <span class="nx">prop</span><span class="p">.</span><span cl [...]
+ <span class="nx">kind</span> <span class="o">=</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">kind</span> <span class="o">=</span> <span class="s2">"init"</span><span class="p">;</span>
+ <span class="nx">prop</span><span class="p">.</span><span class="nx">value</span> <span class="o">=</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">key</span><span class="p">;</span>
+ <span class="nx">prop</span><span class="p">.</span><span class="nx">shorthand</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="nx">unexpected</span><span class="p">();</span>
+
+ <span class="nx">addProperty</span><span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">properties</span><span class="p">,</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">prop</span><span class="p">,</span> <span class="s2">"Property"</span><span class="p">),</span> <span class="nx">sawGetSet</span><span class="p">,</span> <span class="s2">"init"</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"ObjectExpression"</span><span class="p">);</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-123"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-123">¶</a> </div> <p>Add property to list with keeping in mind and checking that
+object/class getters and setters are not allowed to clash —
+either with each other or with an init property — and in
+strict mode, init properties are also not allowed to be repeated.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">addProperty</span><span class="p">(</span><span class="nx">props</span><span class="p">,</span> <span class="nx">current</span><span class="p">,</span> <span class="nx">sawGetSet</span><span class="p">,</span> <span class="nx">defaultKind</span><span class="p">)</span> <span clas [...]
+ <span class="k">if</span> <span class="p">(</span><span class="nx">current</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s2">"Identifier"</span> <span class="o">&&</span> <span class="p">(</span><span class="nx">strict</span> <span class="o">||</span> <span class="nx">sawGetSet</span><span class="p">))</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">kind</span> <span class="o">=</span> <span class="nx">current</span><span class="p">.</span><span class="nx">kind</span><span class="p">,</span> <span class="nx">isGetSet</span> <span class="o">=</span> <span class="nx">kind</span> <span class="o">!==</span> <span class="nx">defaultKind</span><span class="p">;</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">props</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="o">++</span><span class="nx">i</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">other</span> <span class="o">=</span> <span class="nx">props</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">other</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">name</span> <span class="o">===</span> <span class="nx">current</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">name</span> <span class="o">&&</span> <span class="nx">other</span><span class="p">.</span><span class="kr">static</span> <span class="o">===</ [...]
+ <span class="kd">var</span> <span class="nx">conflict</span> <span class="o">=</span> <span class="nx">kind</span> <span class="o">==</span> <span class="nx">other</span><span class="p">.</span><span class="nx">kind</span> <span class="o">||</span> <span class="nx">isGetSet</span> <span class="o">&&</span> <span class="nx">other</span><span class="p">.</span><span class="nx">kind</span> <span class="o">===</span> <span class="nx">defaultKind</span> <span class="o">||</span>
+ <span class="nx">kind</span> <span class="o">===</span> <span class="nx">defaultKind</span> <span class="o">&&</span> <span class="p">(</span><span class="nx">other</span><span class="p">.</span><span class="nx">kind</span> <span class="o">!==</span> <span class="nx">defaultKind</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">conflict</span> <span class="o">&&</span> <span class="o">!</span><span class="nx">strict</span> <span class="o">&&</span> <span class="nx">kind</span> <span class="o">===</span> <span class="nx">defaultKind</span> <span class="o">&&</span> <span class="nx">other</span><span class="p">.</span><span class="nx">kind</span> <span class="o">===</span> <span class="nx">defaultKind</span><span [...]
+ <span class="k">if</span> <span class="p">(</span><span class="nx">conflict</span><span class="p">)</span> <span class="nx">raise</span><span class="p">(</span><span class="nx">current</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">start</span><span class="p">,</span> <span class="s2">"Redefinition of property"</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
- <span class="nx">node</span><span class="p">.</span><span class="nx">properties</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">prop</span><span class="p">);</span>
<span class="p">}</span>
- <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"ObjectExpression"</span><span class="p">);</span>
+ <span class="nx">props</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">current</span><span class="p">);</span>
<span class="p">}</span>
- <span class="kd">function</span> <span class="nx">parsePropertyName</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">_num</span> <span class="o">||</span> <span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_string</span><span class="p">)</span> <span class="k">return</span> <span class="nx">parseExprAtom</span><span class="p">();</span>
- <span class="k">return</span> <span class="nx">parseIdent</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-121"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-121">¶</a> </div> <p>Parse a function declaration or literal (depending on the
-<code>isStatement</code> parameter).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseFunction</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">isStatement</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">_name</span><span class="p">)</span> <span class="nx">node</span><span class="p">.</span><span class="nx">id</span> <span class="o">=</span> <span class="nx">parseIdent</span><span class="p">();</span>
- <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">isStatement</span><span class="p">)</span> <span class="nx">unexpected</span><span class="p">();</span>
- <span class="k">else</span> <span class="nx">node</span><span class="p">.</span><span class="nx">id</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
+ <span class="kd">function</span> <span class="nx">parsePropertyName</span><span class="p">(</span><span class="nx">prop</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">6</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">eat</span><span class="p">(</span><span class="nx">_bracketL</span><span class="p">))</span> <span class="p">{</span>
+ <span class="nx">prop</span><span class="p">.</span><span class="nx">computed</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="nx">prop</span><span class="p">.</span><span class="nx">key</span> <span class="o">=</span> <span class="nx">parseExpression</span><span class="p">();</span>
+ <span class="nx">expect</span><span class="p">(</span><span class="nx">_bracketR</span><span class="p">);</span>
+ <span class="k">return</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="nx">prop</span><span class="p">.</span><span class="nx">computed</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="nx">prop</span><span class="p">.</span><span class="nx">key</span> <span class="o">=</span> <span class="p">(</span><span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_num</span> <span class="o">||</span> <span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_string</span><span class="p">)</span> <span class="o">?</span> <span class="nx">parseExprAtom</span><span class="p">()</span> <span class="o">:</span> <span class="nx"> [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-124"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-124">¶</a> </div> <p>Initialize empty function node.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">initFunction</span> [...]
+ <span class="nx">node</span><span class="p">.</span><span class="nx">id</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">params</span> <span class="o">=</span> <span class="p">[];</span>
- <span class="nx">node</span><span class="p">.</span><span class="nx">rest</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">6</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">defaults</span> <span class="o">=</span> <span class="p">[];</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">rest</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">generator</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-125"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-125">¶</a> </div> <p>Parse a function declaration or literal (depending on the
+<code>isStatement</code> parameter).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseFunction</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">isStatement</span><span class="p">,</span> <span class="nx">allowExpressionBody</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">initFunction</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">isStatement</span> <span class="o">||</span> <span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_name</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">id</span> <span class="o">=</span> <span class="nx">parseIdent</span><span class="p">();</span>
+ <span class="p">}</span>
+ <span class="nx">parseFunctionParams</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
+ <span class="nx">parseFunctionBody</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">allowExpressionBody</span><span class="p">);</span>
+ <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">isStatement</span> <span class="o">?</span> <span class="s2">"FunctionDeclaration"</span> <span class="o">:</span> <span class="s2">"FunctionExpression"</span><span class="p">);</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-126"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-126">¶</a> </div> <p>Parse arrow function expression with given parameters.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class=" [...]
+ <span class="nx">initFunction</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
+
+ <span class="kd">var</span> <span class="nx">defaults</span> <span class="o">=</span> <span class="nx">node</span><span class="p">.</span><span class="nx">defaults</span><span class="p">,</span> <span class="nx">hasDefaults</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
+
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">lastI</span> <span class="o">=</span> <span class="nx">params</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><=</span> <span class="nx">lastI</span><span cla [...]
+ <span class="kd">var</span> <span class="nx">param</span> <span class="o">=</span> <span class="nx">params</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="nx">param</span><span class="p">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s2">"AssignmentExpression"</span> <span class="o">&&</span> <span class="nx">param</span><span class="p">.</span><span class="nx">operator</span> <span class="o">===</span> <span class="s2">"="</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">hasDefaults</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="nx">params</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">=</span> <span class="nx">param</span><span class="p">.</span><span class="nx">left</span><span class="p">;</span>
+ <span class="nx">defaults</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">param</span><span class="p">.</span><span class="nx">right</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="nx">toAssignable</span><span class="p">(</span><span class="nx">param</span><span class="p">,</span> <span class="nx">i</span> <span class="o">===</span> <span class="nx">lastI</span><span class="p">);</span>
+ <span class="nx">defaults</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="kc">null</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">param</span><span class="p">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s2">"SpreadElement"</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">params</span><span class="p">.</span><span class="nx">length</span><span class="o">--</span><span class="p">;</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">rest</span> <span class="o">=</span> <span class="nx">param</span><span class="p">.</span><span class="nx">argument</span><span class="p">;</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+
+ <span class="nx">node</span><span class="p">.</span><span class="nx">params</span> <span class="o">=</span> <span class="nx">params</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">hasDefaults</span><span class="p">)</span> <span class="nx">node</span><span class="p">.</span><span class="nx">defaults</span> <span class="o">=</span> <span class="p">[];</span>
+
+ <span class="nx">parseFunctionBody</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
+ <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"ArrowFunctionExpression"</span><span class="p">);</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-127"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-127">¶</a> </div> <p>Parse function parameters.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseFunctionParams</spa [...]
+ <span class="kd">var</span> <span class="nx">defaults</span> <span class="o">=</span> <span class="p">[],</span> <span class="nx">hasDefaults</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
+
<span class="nx">expect</span><span class="p">(</span><span class="nx">_parenL</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(;;)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">eat</span><span class="p">(</span><span class="nx">_parenR</span><span class="p">))</span> <span class="p">{</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">6</span> <span class="o">&&</span> <span class="nx">eat</span><span class="p">(</span><span class="nx">_ellipsis</span><span class="p">))</span> <span class="p">{</span>
- <span class="nx">node</span><span class="p">.</span><span class="nx">rest</span> <span class="o">=</span> <span class="nx">parseIdent</span><span class="p">();</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">rest</span> <span class="o">=</span> <span class="nx">toAssignable</span><span class="p">(</span><span class="nx">parseExprAtom</span><span class="p">());</span>
+ <span class="nx">checkSpreadAssign</span><span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">rest</span><span class="p">);</span>
<span class="nx">expect</span><span class="p">(</span><span class="nx">_parenR</span><span class="p">);</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
- <span class="nx">node</span><span class="p">.</span><span class="nx">params</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">parseIdent</span><span class="p">());</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">params</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">6</span> <span class="o">?</span> <span class="nx">toAssignable</span><span class="p">(</span><span class="nx">parseExprAtom</span><span class="p">())</span> <span class="o">:</span> <span [...]
+ <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">6</span> <span class="o">&&</span> <span class="nx">tokVal</span> <span class="o">===</span> <span class="s1">'='</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">next</span><span class="p">();</span>
+ <span class="nx">hasDefaults</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="nx">defaults</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">parseExpression</span><span class="p">(</span><span class="kc">true</span><span class="p">));</span>
+ <span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">eat</span><span class="p">(</span><span class="nx">_comma</span><span class="p">))</span> <span class="p">{</span>
<span class="nx">expect</span><span class="p">(</span><span class="nx">_parenR</span><span class="p">);</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-122"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-122">¶</a> </div> <p>Start a new scope with regard to labels and the <code>inFunction</code>
-flag (restore them to their old value afterwards).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">oldInFunc</span> <span class="o">=</span> <span class="nx">inFunction</span><span class="p">,</span> <span class="nx">oldLabels</span> <span class="o">=</span> <span class="nx">labels</span><span class="p">;</span>
- <span class="nx">inFunction</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span> <span class="nx">labels</span> <span class="o">=</span> <span class="p">[];</span>
- <span class="nx">node</span><span class="p">.</span><span class="nx">body</span> <span class="o">=</span> <span class="nx">parseBlock</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
- <span class="nx">inFunction</span> <span class="o">=</span> <span class="nx">oldInFunc</span><span class="p">;</span> <span class="nx">labels</span> <span class="o">=</span> <span class="nx">oldLabels</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-123"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-123">¶</a> </div> [...]
+ <span class="p">}</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="nx">hasDefaults</span><span class="p">)</span> <span class="nx">node</span><span class="p">.</span><span class="nx">defaults</span> <span class="o">=</span> <span class="nx">defaults</span><span class="p">;</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-128"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-128">¶</a> </div> <p>Parse function body and check parameters.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseFunc [...]
+ <span class="kd">var</span> <span class="nx">isExpression</span> <span class="o">=</span> <span class="nx">allowExpression</span> <span class="o">&&</span> <span class="nx">tokType</span> <span class="o">!==</span> <span class="nx">_braceL</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="nx">isExpression</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">body</span> <span class="o">=</span> <span class="nx">parseExpression</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">expression</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-129"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-129">¶</a> </div> <p>Start a new scope with regard to labels and the <code>inFunction</code>
+flag (restore them to their old value afterwards).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">oldInFunc</span> <span class="o">=</span> <span class="nx">inFunction</span><span class="p">,</span> <span class="nx">oldLabels</span> <span class="o">=</span> <span class="nx">labels</span><span class="p">;</span>
+ <span class="nx">inFunction</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span> <span class="nx">labels</span> <span class="o">=</span> <span class="p">[];</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">body</span> <span class="o">=</span> <span class="nx">parseBlock</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">expression</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
+ <span class="nx">inFunction</span> <span class="o">=</span> <span class="nx">oldInFunc</span><span class="p">;</span> <span class="nx">labels</span> <span class="o">=</span> <span class="nx">oldLabels</span><span class="p">;</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-130"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-130">¶</a> </div> <p>If this is a strict mode function, verify that argument names
are not repeated, and it does not try to bind the words <code>eval</code>
-or <code>arguments</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">strict</span> <span class="o">||</span> <span class="nx">node</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">length</span> <span class="o">&&</span> <span class="nx">isUseStrict</span><spa [...]
- <span class="k">if</span> <span class="p">(</span><span class="nx">i</span> <span class="o">>=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
- <span class="nx">id</span> <span class="o">=</span> <span class="nx">node</span><span class="p">.</span><span class="nx">params</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
- <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">i</span> <span class="o">==</span> <span class="o">-</span><span class="mi">2</span><span class="p">)</span> <span class="p">{</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">rest</span><span class="p">)</span> <span class="nx">id</span> <span class="o">=</span> <span class="nx">node</span><span class="p">.</span><span class="nx">rest</span><span class="p">;</span>
- <span class="k">else</span> <span class="k">continue</span><span class="p">;</span>
- <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">id</span><span class="p">)</span> <span class="nx">id</span> <span class="o">=</span> <span class="nx">node</span><span class="p">.</span><span class="nx">id</span><span class="p">;</span>
- <span class="k">else</span> <span class="k">continue</span><span class="p">;</span>
- <span class="p">}</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">isStrictReservedWord</span><span class="p">(</span><span class="nx">id</span><span class="p">.</span><span class="nx">name</span><span class="p">)</span> <span class="o">||</span> <span class="nx">isStrictBadIdWord</span><span class="p">(</span><span class="nx">id</span><span class="p">.</span><span class="nx">name</span><span class="p">))</span>
- <span class="nx">raise</span><span class="p">(</span><span class="nx">id</span><span class="p">.</span><span class="nx">start</span><span class="p">,</span> <span class="s2">"Defining '"</span> <span class="o">+</span> <span class="nx">id</span><span class="p">.</span><span class="nx">name</span> <span class="o">+</span> <span class="s2">"' in strict mode"</span><span class="p">);</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">i</span> <span class="o">>=</span> <span class="mi">0</span><span class="p">)</span> <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">j</span> <span class="o"><</span> <span class="nx">i</span><span class="p">;</span> <span class="o">++</span><span class="nx">j</ [...]
- <span class="nx">raise</span><span class="p">(</span><span class="nx">id</span><span class="p">.</span><span class="nx">start</span><span class="p">,</span> <span class="s2">"Argument name clash in strict mode"</span><span class="p">);</span>
- <span class="p">}</span>
+or <code>arguments</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">strict</span> <span class="o">||</span> <span class="o">!</span><span class="nx">isExpression</span> <span class="o">&&</span> <span class="nx">node</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span cla [...]
+ <span class="kd">var</span> <span class="nx">nameHash</span> <span class="o">=</span> <span class="p">{};</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">id</span><span class="p">)</span>
+ <span class="nx">checkFunctionParam</span><span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">id</span><span class="p">,</span> <span class="nx">nameHash</span><span class="p">);</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">node</span><span class="p">.</span><span class="nx">params</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span>
+ <span class="nx">checkFunctionParam</span><span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">params</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span> <span class="nx">nameHash</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">rest</span><span class="p">)</span>
+ <span class="nx">checkFunctionParam</span><span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">rest</span><span class="p">,</span> <span class="nx">nameHash</span><span class="p">);</span>
<span class="p">}</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-131"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-131">¶</a> </div> <p>Verify that argument names are not repeated, and it does not
+try to bind the words <code>eval</code> or <code>arguments</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">checkFunctionParam</span><span class="p">(</span><span class="nx">param</span><span class="p">,</span> <span class="nx">nameHash</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">switch</span> <span class="p">(</span><span class="nx">param</span><span class="p">.</span><span class="nx">type</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">case</span> <span class="s2">"Identifier"</span><span class="o">:</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">isStrictReservedWord</span><span class="p">(</span><span class="nx">param</span><span class="p">.</span><span class="nx">name</span><span class="p">)</span> <span class="o">||</span> <span class="nx">isStrictBadIdWord</span><span class="p">(</span><span class="nx">param</span><span class="p">.</span><span class="nx">name</span><span class="p">))</span>
+ <span class="nx">raise</span><span class="p">(</span><span class="nx">param</span><span class="p">.</span><span class="nx">start</span><span class="p">,</span> <span class="s2">"Defining '"</span> <span class="o">+</span> <span class="nx">param</span><span class="p">.</span><span class="nx">name</span> <span class="o">+</span> <span class="s2">"' in strict mode"</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">param</span><span class="p">.</span><span class="nx">name</span> <span class="k">in</span> <span class="nx">nameHash</span><span class="p">)</span>
+ <span class="nx">raise</span><span class="p">(</span><span class="nx">param</span><span class="p">.</span><span class="nx">start</span><span class="p">,</span> <span class="s2">"Argument name clash in strict mode"</span><span class="p">);</span>
+ <span class="nx">nameHash</span><span class="p">[</span><span class="nx">param</span><span class="p">.</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="k">break</span><span class="p">;</span>
- <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">isStatement</span> <span class="o">?</span> <span class="s2">"FunctionDeclaration"</span> <span class="o">:</span> <span class="s2">"FunctionExpression"</span><span class="p">);</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-125"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-125">¶</a> </div> <p>Parses a comma-separated list of expressions, and returns them as
+ <span class="k">case</span> <span class="s2">"ObjectPattern"</span><span class="o">:</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">param</span><span class="p">.</span><span class="nx">properties</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span>
+ <span class="nx">checkFunctionParam</span><span class="p">(</span><span class="nx">param</span><span class="p">.</span><span class="nx">properties</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">value</span><span class="p">,</span> <span class="nx">nameHash</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+
+ <span class="k">case</span> <span class="s2">"ArrayPattern"</span><span class="o">:</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">param</span><span class="p">.</span><span class="nx">elements</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span>
+ <span class="nx">checkFunctionParam</span><span class="p">(</span><span class="nx">param</span><span class="p">.</span><span class="nx">elements</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span> <span class="nx">nameHash</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-132"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-132">¶</a> </div> <p>Parse a class declaration or literal (depending on the
+<code>isStatement</code> parameter).</p> </td> <td class="code"> <div class="highlight"><pre>
+ <span class="kd">function</span> <span class="nx">parseClass</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">isStatement</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">next</span><span class="p">();</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">id</span> <span class="o">=</span> <span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_name</span> <span class="o">?</span> <span class="nx">parseIdent</span><span class="p">()</span> <span class="o">:</span> <span class="nx">isStatement</span> <span class="o">?</span> <span class="nx">unexpected</span><span class="p">()</span> <span class="o">:</span> <span class="kc">null</span><span class [...]
+ <span class="nx">node</span><span class="p">.</span><span class="nx">superClass</span> <span class="o">=</span> <span class="nx">eat</span><span class="p">(</span><span class="nx">_extends</span><span class="p">)</span> <span class="o">?</span> <span class="nx">parseExpression</span><span class="p">()</span> <span class="o">:</span> <span class="kc">null</span><span class="p">;</span>
+ <span class="kd">var</span> <span class="nx">classBody</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">(),</span> <span class="nx">sawGetSet</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
+ <span class="nx">classBody</span><span class="p">.</span><span class="nx">body</span> <span class="o">=</span> <span class="p">[];</span>
+ <span class="nx">expect</span><span class="p">(</span><span class="nx">_braceL</span><span class="p">);</span>
+ <span class="k">while</span> <span class="p">(</span><span class="o">!</span><span class="nx">eat</span><span class="p">(</span><span class="nx">_braceR</span><span class="p">))</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">method</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">();</span>
+ <span class="nx">method</span><span class="p">.</span><span class="kr">static</span> <span class="o">=</span> <span class="o">!!</span><span class="nx">eat</span><span class="p">(</span><span class="nx">_static</span><span class="p">);</span>
+ <span class="nx">method</span><span class="p">.</span><span class="nx">key</span> <span class="o">=</span> <span class="nx">parseIdent</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">method</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s2">"Identifier"</span> <span class="o">&&</span> <span class="p">(</span><span class="nx">method</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">name</span> <span class="o">===</span> <span cla [...]
+ <span class="nx">method</span><span class="p">.</span><span class="nx">kind</span> <span class="o">=</span> <span class="nx">method</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">name</span><span class="p">;</span>
+ <span class="nx">method</span><span class="p">.</span><span class="nx">key</span> <span class="o">=</span> <span class="nx">parseIdent</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
+ <span class="nx">sawGetSet</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="nx">method</span><span class="p">.</span><span class="nx">kind</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="nx">method</span><span class="p">.</span><span class="nx">value</span> <span class="o">=</span> <span class="nx">parseFunction</span><span class="p">(</span><span class="nx">startNode</span><span class="p">());</span>
+ <span class="nx">addProperty</span><span class="p">(</span><span class="nx">classBody</span><span class="p">.</span><span class="nx">body</span><span class="p">,</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">method</span><span class="p">,</span> <span class="s2">"MethodDefinition"</span><span class="p">),</span> <span class="nx">sawGetSet</span><span class="p">,</span> <span class="s2">""</span><span class="p">);</span>
+ <span class="nx">eat</span><span class="p">(</span><span class="nx">_semi</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">body</span> <span class="o">=</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">classBody</span><span class="p">,</span> <span class="s2">"ClassBody"</span><span class="p">);</span>
+ <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">isStatement</span> <span class="o">?</span> <span class="s2">"ClassDeclaration"</span> <span class="o">:</span> <span class="s2">"ClassExpression"</span><span class="p">);</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-133"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-133">¶</a> </div> <p>Parses a comma-separated list of expressions, and returns them as
an array. <code>close</code> is the token type that ends the list, and
<code>allowEmpty</code> can be turned on to allow subsequent commas with
nothing in between them to be parsed as <code>null</code> (which is needed
@@ -1388,7 +1605,7 @@ for array literals).</p> </td> <td class="code">
<span class="k">else</span> <span class="nx">elts</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">parseExpression</span><span class="p">(</span><span class="kc">true</span><span class="p">));</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">elts</span><span class="p">;</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-126"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-126">¶</a> </div> <p>Parse the next token as an identifier. If <code>liberal</code> is true (used
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-134"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-134">¶</a> </div> <p>Parse the next token as an identifier. If <code>liberal</code> is true (used
when parsing properties), it will also convert keywords into
identifiers.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseIdent</span><span class="p">(</span><span class="nx">liberal</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">();</span>
@@ -1409,6 +1626,45 @@ identifiers.</p> </td> <td class="code"> <
<span class="nx">tokRegexpAllowed</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
<span class="nx">next</span><span class="p">();</span>
<span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"Identifier"</span><span class="p">);</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-135"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-135">¶</a> </div> <p>Convert existing expression atom to assignable pattern
+if possible.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">toAssignable</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">allowSpread</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ecmaVersion</span> <span class="o">>=</span> <span class="mi">6</span> <span class="o">&&</span> <span class="nx">node</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">switch</span> <span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">type</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">case</span> <span class="s2">"Identifier"</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s2">"MemberExpression"</span><span class="o">:</span>
+ <span class="k">break</span><span class="p">;</span>
+
+ <span class="k">case</span> <span class="s2">"ObjectExpression"</span><span class="o">:</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">type</span> <span class="o">=</span> <span class="s2">"ObjectPattern"</span><span class="p">;</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">node</span><span class="p">.</span><span class="nx">properties</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span cl [...]
+ <span class="kd">var</span> <span class="nx">prop</span> <span class="o">=</span> <span class="nx">node</span><span class="p">.</span><span class="nx">properties</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">prop</span><span class="p">.</span><span class="nx">kind</span> <span class="o">!==</span> <span class="s2">"init"</span><span class="p">)</span> <span class="nx">unexpected</span><span class="p">(</span><span class="nx">prop</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">start</span><span class="p">);</span>
+ <span class="nx">toAssignable</span><span class="p">(</span><span class="nx">prop</span><span class="p">.</span><span class="nx">value</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="k">break</span><span class="p">;</span>
+
+ <span class="k">case</span> <span class="s2">"ArrayExpression"</span><span class="o">:</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">type</span> <span class="o">=</span> <span class="s2">"ArrayPattern"</span><span class="p">;</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">lastI</span> <span class="o">=</span> <span class="nx">node</span><span class="p">.</span><span class="nx">elements</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span> <span class="nx">i</span> <span c [...]
+ <span class="nx">toAssignable</span><span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">elements</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span> <span class="nx">i</span> <span class="o">===</span> <span class="nx">lastI</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="k">break</span><span class="p">;</span>
+
+ <span class="k">case</span> <span class="s2">"SpreadElement"</span><span class="o">:</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">allowSpread</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">toAssignable</span><span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">argument</span><span class="p">);</span>
+ <span class="nx">checkSpreadAssign</span><span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">argument</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="k">default</span><span class="o">:</span>
+ <span class="nx">unexpected</span><span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">start</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="k">return</span> <span class="nx">node</span><span class="p">;</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-136"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-136">¶</a> </div> <p>Checks if node can be assignable spread argument.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">c [...]
+ <span class="k">if</span> <span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">type</span> <span class="o">!==</span> <span class="s2">"Identifier"</span> <span class="o">&&</span> <span class="nx">node</span><span class="p">.</span><span class="nx">type</span> <span class="o">!==</span> <span class="s2">"ArrayPattern"</span><span class="p">)</span>
+ <span class="nx">unexpected</span><span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">start</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">});</span>
diff --git a/test/tests.js b/test/tests.js
index f7d9e04..2a0cda4 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -1459,6 +1459,7 @@ test("x = { answer: 42 }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "answer",
@@ -1562,6 +1563,7 @@ test("x = { if: 42 }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "if",
@@ -1665,6 +1667,7 @@ test("x = { true: 42 }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "true",
@@ -1768,6 +1771,7 @@ test("x = { false: 42 }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "false",
@@ -1871,6 +1875,7 @@ test("x = { null: 42 }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "null",
@@ -1974,6 +1979,7 @@ test("x = { \"answer\": 42 }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Literal",
value: "answer",
@@ -2077,6 +2083,7 @@ test("x = { x: 1, x: 2 }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "x",
@@ -2108,6 +2115,7 @@ test("x = { x: 1, x: 2 }", {
kind: "init"
},
{
+ type: "Property",
key: {
type: "Identifier",
name: "x",
@@ -2211,6 +2219,7 @@ test("x = { get width() { return m_width } }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "width",
@@ -2357,6 +2366,7 @@ test("x = { get undef() {} }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "undef",
@@ -2475,6 +2485,7 @@ test("x = { get if() {} }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "if",
@@ -2593,6 +2604,7 @@ test("x = { get true() {} }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "true",
@@ -2711,6 +2723,7 @@ test("x = { get false() {} }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "false",
@@ -2829,6 +2842,7 @@ test("x = { get null() {} }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "null",
@@ -2947,6 +2961,7 @@ test("x = { get \"undef\"() {} }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Literal",
value: "undef",
@@ -3065,6 +3080,7 @@ test("x = { get 10() {} }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Literal",
value: 10,
@@ -3183,6 +3199,7 @@ test("x = { set width(w) { m_width = w } }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "width",
@@ -3372,6 +3389,7 @@ test("x = { set if(w) { m_if = w } }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "if",
@@ -3561,6 +3579,7 @@ test("x = { set true(w) { m_true = w } }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "true",
@@ -3750,6 +3769,7 @@ test("x = { set false(w) { m_false = w } }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "false",
@@ -3939,6 +3959,7 @@ test("x = { set null(w) { m_null = w } }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "null",
@@ -4128,6 +4149,7 @@ test("x = { set \"null\"(w) { m_null = w } }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Literal",
value: "null",
@@ -4317,6 +4339,7 @@ test("x = { set 10(w) { m_null = w } }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Literal",
value: 10,
@@ -4506,6 +4529,7 @@ test("x = { get: 42 }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "get",
@@ -4609,6 +4633,7 @@ test("x = { set: 43 }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "set",
@@ -21734,6 +21759,7 @@ test("throw { message: \"Error\" }", {
type: "ObjectExpression",
properties: [
{
+ type: "Property",
key: {
type: "Identifier",
name: "message",
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git
More information about the Pkg-javascript-commits
mailing list