[Pkg-javascript-commits] [node-acorn-jsx] 138/484: Fix bug with parsing slash after operator-keyword property
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:15 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 6113324cd2f6facf5abcb8717e9c7053513aaba0
Author: Marijn Haverbeke <marijnh at gmail.com>
Date: Sun Aug 25 15:01:20 2013 +0200
Fix bug with parsing slash after operator-keyword property
Closes #53
---
acorn.js | 1 +
index.html | 20 +++++++++++---------
test/tests.js | 31 ++++++++++++++++++++++++++++++-
3 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/acorn.js b/acorn.js
index 9808f43..e0e8b63 100644
--- a/acorn.js
+++ b/acorn.js
@@ -1717,6 +1717,7 @@
function parseIdent(liberal) {
var node = startNode();
node.name = tokType === _name ? tokVal : (liberal && !options.forbidReserved && tokType.keyword) || unexpected();
+ tokRegexpAllowed = false;
next();
return finishNode(node, "Identifier");
}
diff --git a/index.html b/index.html
index fac2e03..2c52cf1 100644
--- a/index.html
+++ b/index.html
@@ -14,11 +14,11 @@ https://github.com/marijnh/acorn.git
<p>This file defines the main parser interface. The library also comes
with a <a href="acorn_loose.js">error-tolerant parser</a> and an
-<a href="util/walk.js">abstract syntax tree walker</a>, defined in other files.</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">mod</span><span class="p">)</span> <span class="p">{</span>
+<a href="util/walk.js">abstract syntax tree walker</a>, defined in other files.</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">root</span><span class="p">,</span> <span class="nx">mod</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">exports</span> <span class="o">==</span> <span class="s2">"object"</span> <span class="o">&&</span> <span class="k">typeof</span> <span class="nx">module</span> <span class="o">==</span> <span class="s2">"object"</span><span class="p">)</span> <span class="k">return</span> <span class="nx">mod</span><span class="p">(</span><span class="nx">exports</span><span cla [...]
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">define</span> <span class="o">==</span> <span class="s2">"function"</span> <span class="o">&&</span> <span class="nx">define</span><span class="p">.</span><span class="nx">amd</span><span class="p">)</span> <span class="k">return</span> <span class="nx">define</span><span class="p">([</span><span class="s2">"exports"</span><span class="p">],</span> <span class="n [...]
- <span class="nx">mod</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">acorn</span> <span class="o">||</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">acorn</span> <span class="o">=</span> <span class="p">{}));</span> <span class="c1">// Plain browser env</span>
-<span class="p">})(</span><span class="kd">function</span><span class="p">(</span><span class="nx">exports</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">mod</span><span class="p">(</span><span class="nx">root</span><span class="p">.</span><span class="nx">acorn</span> <span class="o">||</span> <span class="p">(</span><span class="nx">root</span><span class="p">.</span><span class="nx">acorn</span> <span class="o">=</span> <span class="p">{}));</span> <span class="c1">// Plain browser env</span>
+<span class="p">})(</span><span class="k">this</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">exports</span><span class="p">)</span> <span class="p">{</span>
<span class="s2">"use strict"</span><span class="p">;</span>
<span class="nx">exports</span><span class="p">.</span><span class="nx">version</span> <span class="o">=</span> <span class="s2">"0.3.2"</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">¶</a> </div> <p>The main exported interface (under <code>self.ac [...]
@@ -103,7 +103,8 @@ reset the internal state, and invalidate existing tokenizers.</p> </
<span class="nx">getToken</span><span class="p">.</span><span class="nx">jumpTo</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">pos</span><span class="p">,</span> <span class="nx">reAllowed</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">tokPos</span> <span class="o">=</span> <span class="nx">pos</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">tokCurLine</span> <span class="o">=</span> <span class="nx">tokLineStart</span> <span class="o">=</span> <span class="nx">lineBreak</span><span class="p">.</span><span class="nx">lastIndex</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="nx">tokCurLine</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="nx">tokLineStart</span> <span class="o">=</span> <span class="nx">lineBreak</span><span class="p">.</span><span class="nx">lastIndex</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">match</span><span class="p">;</span>
<span class="k">while</span> <span class="p">((</span><span class="nx">match</span> <span class="o">=</span> <span class="nx">lineBreak</span><span class="p">.</span><span class="nx">exec</span><span class="p">(</span><span class="nx">input</span><span class="p">))</span> <span class="o">&&</span> <span class="nx">match</span><span class="p">.</span><span class="nx">index</span> <span class="o"><</span> <span class="nx">pos</span><span class="p">)</span> <span class="p [...]
<span class="o">++</span><span class="nx">tokCurLine</span><span class="p">;</span>
@@ -343,7 +344,7 @@ whitespace and comments, and.</p> </td> <td class="code"
<span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">47</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// '/'</span>
<span class="nx">skipLineComment</span><span class="p">();</span>
<span class="p">}</span> <span class="k">else</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">ch</span> <span class="o"><</span> <span class="mi">14</span> <span class="o">&&</span> <span class="nx">ch</span> <span class="o">></span> <span class="mi">8</span><span class="p">)</span> <span class="o">||</span> <span class="nx">ch</span> <span class="o">===</span> <span class="mi">32</span> <span class="o">||</span> <span class="nx">ch</span> < [...]
+ <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">ch</span> <span class="o">===</span> <span class="mi">160</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// '\xa0'</span>
<span class="o">++</span><span class="nx">tokPos</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">ch</span> <span class="o">>=</span> <span class="mi">5760</span> <span class="o">&&</span> <span class="nx">nonASCIIwhitespace</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">ch</span><span [...]
<span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span>
@@ -1057,7 +1058,7 @@ operators like <code>+=</code>.</p> </td> <td class="cod
<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-109"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-109">¶</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="nx">noIn</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="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-110"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-110">¶</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
@@ -1070,19 +1071,19 @@ 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">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">operator</span> <span class="o">=</span> <span class="nx">tokVal</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">parseExprOp</span><span class="p">(</span><span class="nx">parseMaybeUnary</span><span class="p">(</span><span class="nx">noIn</span><span class="p">),</span> <span class="nx">prec</span><span class="p">,</span> <span class="nx">noIn</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">parseExprOp</span><span class="p">(</span><span class="nx">parseMaybeUnary</span><span class="p">(),</span> <span class="nx">prec</span><span class="p">,</span> <span class="nx">noIn</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">node</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="sr">/&&|\|\|/</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">operator</span><span class="p">)</span> <span class="o">?</span> <span class="s2">"LogicalExpression [...]
<span class="k">return</span> <span class="nx">parseExprOp</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">minPrec</span><span class="p">,</span> <span class="nx">noIn</span><span class="p">);</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-111"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-111">¶</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-111"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-111">¶</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>
<span class="nx">node</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">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">parseMaybeUnary</span><span class="p">(</span><span class="nx">noIn</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">parseMaybeUnary</span><span class="p">();</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">update</span><span class="p">)</span> <span class="nx">checkLVal</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">else</span> <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">operator</span> <span class="o">===</span> <span class="s2">"delete"</span> <span class="o">&&</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">argument</span><span class="p">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s2">"Identifier"</span><span class="p">)</span>
@@ -1284,6 +1285,7 @@ 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>
<span class="nx">node</span><span class="p">.</span><span class="nx">name</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">tokVal</span> <span class="o">:</span> <span class="p">(</span><span class="nx">liberal</span> <span class="o">&&</span> <span class="o">!</span><span class="nx">options</span><span class="p">.</span><span class="nx">forbidReserved</span> <spa [...]
+ <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>
diff --git a/test/tests.js b/test/tests.js
index 87a6707..8c42786 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -26235,7 +26235,36 @@ test("var a = 1;", {
}, {
locations: true,
sourceFile: "test.js"
-})
+});
+
+test("a.in / b", {
+ type: "Program",
+ body: [
+ {
+ type: "ExpressionStatement",
+ expression: {
+ type: "BinaryExpression",
+ left: {
+ type: "MemberExpression",
+ object: {
+ type: "Identifier",
+ name: "a"
+ },
+ property: {
+ type: "Identifier",
+ name: "in"
+ },
+ computed: false
+ },
+ operator: "/",
+ right: {
+ type: "Identifier",
+ name: "b"
+ }
+ }
+ }
+ ]
+});
// Failure tests
--
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