[Pkg-javascript-commits] [node-acorn-jsx] 49/484: Stop accumulating line comments when trackComments is off
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:03 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 043386067a099ad5ef38b9211b8bc190304cc3c1
Author: Marijn Haverbeke <marijnh at gmail.com>
Date: Mon Nov 5 22:39:22 2012 +0100
Stop accumulating line comments when trackComments is off
---
acorn.js | 6 ++++--
index.html | 6 ++++--
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/acorn.js b/acorn.js
index 6323b1f..81abc2d 100644
--- a/acorn.js
+++ b/acorn.js
@@ -444,7 +444,8 @@
++tokPos;
ch = input.charCodeAt(tokPos);
}
- (tokComments || (tokComments = [])).push(input.slice(start, tokPos));
+ if (options.trackComments)
+ (tokComments || (tokComments = [])).push(input.slice(start, tokPos));
}
// Called at the start of the parse and after every token. Skips
@@ -878,7 +879,8 @@
if (tokCommentsAfter) {
node.commentsAfter = tokCommentsAfter;
tokCommentsAfter = null;
- } else if (lastFinishedNode && lastFinishedNode.end === lastEnd) {
+ } else if (lastFinishedNode && lastFinishedNode.end === lastEnd &&
+ lastFinishedNode.commentsAfter) {
node.commentsAfter = lastFinishedNode.commentsAfter;
lastFinishedNode.commentsAfter = null;
}
diff --git a/index.html b/index.html
index 216adce..0336051 100644
--- a/index.html
+++ b/index.html
@@ -263,7 +263,8 @@ the right position.</p> </td> <td class="code">
<span class="o">++</span><span class="nx">tokPos</span><span class="p">;</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="p">}</span>
- <span class="p">(</span><span class="nx">tokComments</span> <span class="o">||</span> <span class="p">(</span><span class="nx">tokComments</span> <span class="o">=</span> <span class="p">[])).</span><span class="nx">push</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="p">,</span> <span class="nx">tokPos</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">trackComments</span><span class="p">)</span>
+ <span class="p">(</span><span class="nx">tokComments</span> <span class="o">||</span> <span class="p">(</span><span class="nx">tokComments</span> <span class="o">=</span> <span class="p">[])).</span><span class="nx">push</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="p">,</span> <span class="nx">tokPos</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> <p>Called at the start of the parse and after every token. Skips
whitespace and comments, and, if <code>options.trackComments</code> is on,
will store all skipped comments in <code>tokComments</code>.</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>
@@ -605,7 +606,8 @@ operator node, not the second literal node.</p> </td> <t
<span class="k">if</span> <span class="p">(</span><span class="nx">tokCommentsAfter</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">commentsAfter</span> <span class="o">=</span> <span class="nx">tokCommentsAfter</span><span class="p">;</span>
<span class="nx">tokCommentsAfter</span> <span class="o">=</span> <span class="kc">null</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">lastFinishedNode</span> <span class="o">&&</span> <span class="nx">lastFinishedNode</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="p">{</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">lastFinishedNode</span> <span class="o">&&</span> <span class="nx">lastFinishedNode</span><span class="p">.</span><span class="nx">end</span> <span class="o">===</span> <span class="nx">lastEnd</span> <span class="o">&&</span>
+ <span class="nx">lastFinishedNode</span><span class="p">.</span><span class="nx">commentsAfter</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">commentsAfter</span> <span class="o">=</span> <span class="nx">lastFinishedNode</span><span class="p">.</span><span class="nx">commentsAfter</span><span class="p">;</span>
<span class="nx">lastFinishedNode</span><span class="p">.</span><span class="nx">commentsAfter</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
<span class="p">}</span>
--
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