[Pkg-javascript-commits] [node-acorn-jsx] 92/484: Improve options.locations performance by tracking newlines rather than finding them
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:09 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 0632b36c94b943b51362fca8b012cb39987271fd
Author: Alistair Braidwood <alistair_braidwood at yahoo.co.uk>
Date: Mon Jan 28 19:13:57 2013 +0000
Improve options.locations performance by tracking newlines rather than finding them
---
acorn.js | 81 ++++++++++++++++++++++++++++++++++++--------------------------
index.html | 79 +++++++++++++++++++++++++++++++++++-------------------------
2 files changed, 93 insertions(+), 67 deletions(-)
diff --git a/acorn.js b/acorn.js
index a2f4aa1..f7959ae 100644
--- a/acorn.js
+++ b/acorn.js
@@ -136,8 +136,12 @@
getToken.jumpTo = function(pos, reAllowed) {
tokPos = pos;
if (options.locations) {
- tokCurLine = tokLineStart = 0;
- tokLineStartNext = nextLineStart();
+ tokCurLine = tokLineStart = lineBreak.lastIndex = 0;
+ var match;
+ while ((match = lineBreak.exec(input)) && match.index < pos) {
+ ++tokCurLine;
+ tokLineStart = match.index + match[0].length;
+ }
}
var ch = input.charAt(pos - 1);
tokRegexpAllowed = reAllowed;
@@ -183,9 +187,9 @@
// When `options.locations` is true, these are used to keep
// track of the current line, and know when a new line has been
- // entered. See the `curLineLoc` function.
+ // entered.
- var tokCurLine, tokLineStart, tokLineStartNext;
+ var tokCurLine, tokLineStart;
// These store the position of the previous token, which is useful
// when finishing a node and assigning its `end` position.
@@ -429,36 +433,19 @@
// ## Tokenizer
- // These are used when `options.locations` is on, in order to track
- // the current line number and start of line offset, in order to set
- // `tokStartLoc` and `tokEndLoc`.
-
- function nextLineStart() {
- lineBreak.lastIndex = tokLineStart;
- var match = lineBreak.exec(input);
- return match ? match.index + match[0].length : input.length + 1;
- }
+ // These are used when `options.locations` is on, for the
+ // `tokStartLoc` and `tokEndLoc` properties.
function line_loc_t() {
this.line = tokCurLine;
this.column = tokPos - tokLineStart;
}
- function curLineLoc() {
- while (tokLineStartNext <= tokPos) {
- ++tokCurLine;
- tokLineStart = tokLineStartNext;
- tokLineStartNext = nextLineStart();
- }
- return new line_loc_t();
- }
-
// Reset the token state. Used at the start of a parse.
function initTokenState() {
tokCurLine = 1;
tokPos = tokLineStart = 0;
- tokLineStartNext = nextLineStart();
tokRegexpAllowed = true;
skipSpace();
}
@@ -469,7 +456,7 @@
function finishToken(type, val) {
tokEnd = tokPos;
- if (options.locations) tokEndLoc = curLineLoc();
+ if (options.locations) tokEndLoc = new line_loc_t;
tokType = type;
skipSpace();
tokVal = val;
@@ -477,20 +464,26 @@
}
function skipBlockComment() {
- if (options.onComment && options.locations)
- var startLoc = curLineLoc();
+ var startLoc = options.onComment && options.locations && new line_loc_t;
var start = tokPos, end = input.indexOf("*/", tokPos += 2);
if (end === -1) raise(tokPos - 2, "Unterminated comment");
tokPos = end + 2;
+ if (options.locations) {
+ lineBreak.lastIndex = start;
+ var match;
+ while ((match = lineBreak.exec(input)) && match.index < tokPos) {
+ ++tokCurLine;
+ tokLineStart = match.index + match[0].length;
+ }
+ }
if (options.onComment)
options.onComment(true, input.slice(start + 2, end), start, tokPos,
- startLoc, options.locations && curLineLoc());
+ startLoc, options.locations && new line_loc_t);
}
function skipLineComment() {
var start = tokPos;
- if (options.onComment && options.locations)
- var startLoc = curLineLoc();
+ var startLoc = options.onComment && options.locations && new line_loc_t;
var ch = input.charCodeAt(tokPos+=2);
while (tokPos < inputLen && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8329) {
++tokPos;
@@ -498,7 +491,7 @@
}
if (options.onComment)
options.onComment(false, input.slice(start + 2, tokPos), start, tokPos,
- startLoc, options.locations && curLineLoc());
+ startLoc, options.locations && new line_loc_t);
}
// Called at the start of the parse and after every token. Skips
@@ -507,7 +500,25 @@
function skipSpace() {
while (tokPos < inputLen) {
var ch = input.charCodeAt(tokPos);
- if (ch === 47) { // '/'
+ if (ch === 32) { // ' '
+ ++tokPos;
+ } else if(ch === 13) {
+ ++tokPos;
+ var next = input.charCodeAt(tokPos);
+ if(next === 10) {
+ ++tokPos;
+ }
+ if(options.locations) {
+ ++tokCurLine;
+ tokLineStart = tokPos;
+ }
+ } else if (ch === 10) {
+ ++tokPos;
+ ++tokCurLine;
+ tokLineStart = tokPos;
+ } else if(ch < 14 && ch > 8) {
+ ++tokPos;
+ } else if (ch === 47) { // '/'
var next = input.charCodeAt(tokPos+1);
if (next === 42) { // '*'
skipBlockComment();
@@ -662,7 +673,7 @@
function readToken(forceRegexp) {
tokStart = tokPos;
- if (options.locations) tokStartLoc = curLineLoc();
+ if (options.locations) tokStartLoc = new line_loc_t;
if (forceRegexp) return readRegexp();
if (tokPos >= inputLen) return finishToken(_eof);
@@ -809,7 +820,9 @@
case 102: rs_str.push(12); break; // 'f' -> '\f'
case 48: rs_str.push(0); break; // 0 -> '\0'
case 13: if (input.charCodeAt(tokPos) === 10) ++tokPos; // '\r\n'
- case 10: break; // ' \n'
+ case 10: // ' \n'
+ if (options.locations) { tokLineStart = tokPos; ++tokCurLine; }
+ break;
default: rs_str.push(ch); break;
}
}
@@ -1042,7 +1055,7 @@
function parseTopLevel(program) {
lastStart = lastEnd = tokPos;
- if (options.locations) lastEndLoc = curLineLoc();
+ if (options.locations) lastEndLoc = new line_loc_t;
inFunction = strict = null;
labels = [];
readToken();
diff --git a/index.html b/index.html
index 7b308ba..4e3d209 100644
--- a/index.html
+++ b/index.html
@@ -95,8 +95,12 @@ 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="mi">0</span><span class="p">;</span>
- <span class="nx">tokLineStartNext</span> <span class="o">=</span> <span class="nx">nextLineStart</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="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>
+ <span class="nx">tokLineStart</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">match</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">length</span><span class="p">;</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">charAt</span><span class="p">(</span><span class="nx">pos</span> <span class="o">-</span> <span class="mi">1</span><span class="p">);</span>
<span class="nx">tokRegexpAllowed</span> <span class="o">=</span> <span class="nx">reAllowed</span><span class="p">;</span>
@@ -118,7 +122,7 @@ token was one that is allowed to be followed by an expression.
division operator. See the <code>parseStatement</code> function for a
caveat.)</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">tokRegexpAllowed</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">¶</a> </div> <p>When <code>options.locations [...]
track of the current line, and know when a new line has been
-entered. See the <code>curLineLoc</code> function.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">tokCurLine</span><span class="p">,</span> <span class="nx">tokLineStart</span><span class="p">,</span> <span class="nx">tokLineStartNext</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> [...]
+entered.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">tokCurLine</span><span class="p">,</span> <span class="nx">tokLineStart</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">¶</a> [...]
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-23"> <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>
@@ -254,37 +258,20 @@ 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-50"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-50">¶</a> </div> <h2>Tokenizer</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section- [...]
-the current line number and start of line offset, in order to set
-<code>tokStartLoc</code> and <code>tokEndLoc</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">nextLineStart</span><span class="p">()</span> <span class="p">{</span>
- <span class="nx">lineBreak</span><span class="p">.</span><span class="nx">lastIndex</span> <span class="o">=</span> <span class="nx">tokLineStart</span><span class="p">;</span>
- <span class="kd">var</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="k">return</span> <span class="nx">match</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">match</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="nx">input</span><span class="p">.</span><span class="nx">length</span> <span class="o">+</span> <span class="mi">1</span><s [...]
- <span class="p">}</span>
-
- <span class="kd">function</span> <span class="nx">line_loc_t</span><span class="p">()</span> <span class="p">{</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-50"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-50">¶</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">line_loc_t</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>
-
- <span class="kd">function</span> <span class="nx">curLineLoc</span><span class="p">()</span> <span class="p">{</span>
- <span class="k">while</span> <span class="p">(</span><span class="nx">tokLineStartNext</span> <span class="o"><=</span> <span class="nx">tokPos</span><span class="p">)</span> <span class="p">{</span>
- <span class="o">++</span><span class="nx">tokCurLine</span><span class="p">;</span>
- <span class="nx">tokLineStart</span> <span class="o">=</span> <span class="nx">tokLineStartNext</span><span class="p">;</span>
- <span class="nx">tokLineStartNext</span> <span class="o">=</span> <span class="nx">nextLineStart</span><span class="p">();</span>
- <span class="p">}</span>
- <span class="k">return</span> <span class="k">new</span> <span class="nx">line_loc_t</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>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">tokLineStartNext</span> <span class="o">=</span> <span class="nx">nextLineStart</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">skipSpace</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 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>
- <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="nx">tokEndLoc</span> <span class="o">=</span> <span class="nx">curLineLoc</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="nx">tokEndLoc</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">line_loc_t</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">skipSpace</span><span class="p">();</span>
<span class="nx">tokVal</span> <span class="o">=</span> <span class="nx">val</span><span class="p">;</span>
@@ -292,20 +279,26 @@ the next one's <code>tokStart</code> will point at the right position.</p>
<span class="p">}</span>
<span class="kd">function</span> <span class="nx">skipBlockComment</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">onComment</span> <span class="o">&&</span> <span class="nx">options</span><span class="p">.</span><span class="nx">locations</span><span class="p">)</span>
- <span class="kd">var</span> <span class="nx">startLoc</span> <span class="o">=</span> <span class="nx">curLineLoc</span><span class="p">();</span>
+ <span class="kd">var</span> <span class="nx">startLoc</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">onComment</span> <span class="o">&&</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">line_loc_t</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">start</span> <span class="o">=</span> <span class="nx">tokPos</span><span class="p">,</span> <span class="nx">end</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s2">"*/"</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="k">if</span> <span class="p">(</span><span class="nx">end</span> <span class="o">===</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="nx">raise</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="s2">"Unterminated comment"</span><span class="p">);</span>
<span class="nx">tokPos</span> <span class="o">=</span> <span class="nx">end</span> <span class="o">+</span> <span class="mi">2</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">lineBreak</span><span class="p">.</span><span class="nx">lastIndex</span> <span class="o">=</span> <span class="nx">start</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">tokPos</span><span class="p">)</span> <span class=" [...]
+ <span class="o">++</span><span class="nx">tokCurLine</span><span class="p">;</span>
+ <span class="nx">tokLineStart</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">match</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">length</span><span class="p">;</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">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">true</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">end</span><span class="p">),</span> <span class="nx">start</span><span class="p">,</span> <sp [...]
- <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="nx">curLineLoc</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">line_loc_t</span><span class="p">);</span>
<span class="p">}</span>
<span class="kd">function</span> <span class="nx">skipLineComment</span><span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">start</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">options</span><span class="p">.</span><span class="nx">onComment</span> <span class="o">&&</span> <span class="nx">options</span><span class="p">.</span><span class="nx">locations</span><span class="p">)</span>
- <span class="kd">var</span> <span class="nx">startLoc</span> <span class="o">=</span> <span class="nx">curLineLoc</span><span class="p">();</span>
+ <span class="kd">var</span> <span class="nx">startLoc</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">onComment</span> <span class="o">&&</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">line_loc_t</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="o">+=</span><span class="mi">2</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="o">&&</span> <span class="nx">ch</span> <span class="o">!==</span> <span class="mi">10</span> <span class="o">&&</span> <span class="nx">ch</span> <span class="o">!==</span> <span class="mi">13</span> <span class="o">&&</span> <span class="nx">ch</span> <span class="o">!==</span> <span class="mi">8232</sp [...]
<span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span>
@@ -313,12 +306,30 @@ the next one's <code>tokStart</code> will point at the right position.</p>
<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">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="nx">curLineLoc</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">line_loc_t</span><span class="p">);</span>
<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> <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>
- <span class="k">if</span> <span class="p">(</span><span class="nx">ch</span> <span class="o">===</span> <span class="mi">47</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// '/'</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">ch</span> <span class="o">===</span> <span class="mi">32</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// ' '</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">13</span><span class="p">)</span> <span class="p">{</span>
+ <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</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="p">);</span>
+ <span class="k">if</span><span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">10</span><span class="p">)</span> <span class="p">{</span>
+ <span class="o">++</span><span class="nx">tokPos</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">locations</span><span class="p">)</span> <span class="p">{</span>
+ <span class="o">++</span><span class="nx">tokCurLine</span><span class="p">;</span>
+ <span class="nx">tokLineStart</span> <span class="o">=</span> <span class="nx">tokPos</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">ch</span> <span class="o">===</span> <span class="mi">10</span><span class="p">)</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">tokCurLine</span><span class="p">;</span>
+ <span class="nx">tokLineStart</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">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="p">{</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">47</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">42</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// '*'</span>
<span class="nx">skipBlockComment</span><span class="p">();</span>
@@ -450,7 +461,7 @@ of the type given by its first argument.</p> </td> <td c
<span class="kd">function</span> <span class="nx">readToken</span><span class="p">(</span><span class="nx">forceRegexp</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">tokStart</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">options</span><span class="p">.</span><span class="nx">locations</span><span class="p">)</span> <span class="nx">tokStartLoc</span> <span class="o">=</span> <span class="nx">curLineLoc</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="nx">tokStartLoc</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">line_loc_t</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">forceRegexp</span><span class="p">)</span> <span class="k">return</span> <span class="nx">readRegexp</span><span class="p">();</span>
<span class="k">if</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="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_eof</span><span class="p">);</span>
@@ -576,7 +587,9 @@ will return <code>null</code> unless the integer has exactly <code>len</code> di
<span class="k">case</span> <span class="mi">102</span><span class="o">:</span> <span class="nx">rs_str</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="mi">12</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// 'f' -> '\f'</span>
<span class="k">case</span> <span class="mi">48</span><span class="o">:</span> <span class="nx">rs_str</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// 0 -> '\0'</span>
<span class="k">case</span> <span class="mi">13</span><span class="o">:</span> <span class="k">if</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="o">===</span> <span class="mi">10</span><span class="p">)</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="c1">// '\r\n [...]
- <span class="k">case</span> <span class="mi">10</span><span class="o">:</span> <span class="k">break</span><span class="p">;</span> <span class="c1">// ' \n'</span>
+ <span class="k">case</span> <span class="mi">10</span><span class="o">:</span> <span class="c1">// ' \n'</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">tokLineStart</span> <span class="o">=</span> <span class="nx">tokPos</span><span class="p">;</span> <span class="o">++</span><span class="nx">tokCurLine</span><span class="p">;</span> <span class="p">}</span>
+ <span class="k">break</span><span class="p">;</span>
<span class="k">default</span><span class="o">:</span> <span class="nx">rs_str</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">ch</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
@@ -732,7 +745,7 @@ 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>
<span class="nx">lastStart</span> <span class="o">=</span> <span class="nx">lastEnd</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">options</span><span class="p">.</span><span class="nx">locations</span><span class="p">)</span> <span class="nx">lastEndLoc</span> <span class="o">=</span> <span class="nx">curLineLoc</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="nx">lastEndLoc</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">line_loc_t</span><span class="p">;</span>
<span class="nx">inFunction</span> <span class="o">=</span> <span class="nx">strict</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
<span class="nx">labels</span> <span class="o">=</span> <span class="p">[];</span>
<span class="nx">readToken</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