[Pkg-javascript-commits] [node-acorn-jsx] 150/484: Fix wrong end position for VariableDeclaration nodes
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:18 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 22c3161b6ebf4c87d56a1babce68d8252d9b3bd4
Author: Marijn Haverbeke <marijnh at gmail.com>
Date: Wed Oct 2 20:39:51 2013 +0200
Fix wrong end position for VariableDeclaration nodes
It should include the semicolon.
Closes #67
---
acorn.js | 7 ++++---
index.html | 11 ++++++-----
test/tests.js | 18 +++++++++---------
3 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/acorn.js b/acorn.js
index 30f8918..826378a 100644
--- a/acorn.js
+++ b/acorn.js
@@ -1180,6 +1180,7 @@
var init = startNode();
next();
parseVar(init, true);
+ finishNode(init, "VariableDeclaration");
if (init.declarations.length === 1 && eat(_in))
return parseForIn(node, init);
return parseFor(node, init);
@@ -1277,9 +1278,9 @@
case _var:
next();
- node = parseVar(node);
+ parseVar(node);
semicolon();
- return node;
+ return finishNode(node, "VariableDeclaration");
case _while:
next();
@@ -1400,7 +1401,7 @@
node.declarations.push(finishNode(decl, "VariableDeclarator"));
if (!eat(_comma)) break;
}
- return finishNode(node, "VariableDeclaration");
+ return node;
}
// ### Expression parsing
diff --git a/index.html b/index.html
index a32801b..67f043a 100644
--- a/index.html
+++ b/index.html
@@ -842,6 +842,7 @@ a regular <code>for</code> loop.</p> </td> <td class="co
<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">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">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">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>
@@ -931,9 +932,9 @@ adding statements to.</p> </td> <td class="code">
<span class="k">case</span> <span class="nx">_var</span><span class="o">:</span>
<span class="nx">next</span><span class="p">();</span>
- <span class="nx">node</span> <span class="o">=</span> <span class="nx">parseVar</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
+ <span class="nx">parseVar</span><span class="p">(</span><span class="nx">node</span><span class="p">);</span>
<span class="nx">semicolon</span><span class="p">();</span>
- <span class="k">return</span> <span class="nx">node</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">"VariableDeclaration"</span><span class="p">);</span>
<span class="k">case</span> <span class="nx">_while</span><span class="o">:</span>
<span class="nx">next</span><span class="p">();</span>
@@ -1030,7 +1031,7 @@ expression.</p> </td> <td class="code"> <d
<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">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"VariableDeclaration"</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-106"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-106">¶</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,
@@ -1085,8 +1086,8 @@ 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">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">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="kd">var</span> <span class="nx">exprNode</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">"LogicalExpres [...]
+ <span class="k">return</span> <span class="nx">parseExprOp</span><span class="p">(</span><span class="nx">exprNode</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>
diff --git a/test/tests.js b/test/tests.js
index 25c06a4..c9a080e 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -16215,7 +16215,7 @@ test("var x, y;", {
},
end: {
line: 1,
- column: 8
+ column: 9
}
}
}
@@ -17307,7 +17307,7 @@ test("if (morning) var x = 0;", {
},
end: {
line: 1,
- column: 22
+ column: 23
}
}
},
@@ -23685,7 +23685,7 @@ test("var hi = function() { sayHi() };", {
},
end: {
line: 1,
- column: 31
+ column: 32
}
}
}
@@ -23786,7 +23786,7 @@ test("var hi = function eval() { };", {
},
end: {
line: 1,
- column: 28
+ column: 29
}
}
}
@@ -23887,7 +23887,7 @@ test("var hi = function arguments() { };", {
},
end: {
line: 1,
- column: 33
+ column: 34
}
}
}
@@ -24030,7 +24030,7 @@ test("var hello = function hi() { sayHi() };", {
},
end: {
line: 1,
- column: 37
+ column: 38
}
}
}
@@ -24348,7 +24348,7 @@ test("var x /* comment */;", {
},
end: {
line: 1,
- column: 5
+ column: 20
}
}
}
@@ -26164,7 +26164,7 @@ test("var a = 1;", {
{
type: "VariableDeclaration",
start: 0,
- end: 9,
+ end: 10,
loc: {
start: {
line: 1,
@@ -26172,7 +26172,7 @@ test("var a = 1;", {
},
end: {
line: 1,
- column: 9
+ column: 10
},
source: "test.js"
},
--
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