[Pkg-javascript-commits] [node-acorn-jsx] 183/484: Add option: `--`
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:23 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 31e77b975ed0bf14f68f9b0f6608bbe78d694bf0
Author: impinball <impinball at gmail.com>
Date: Tue May 13 12:41:31 2014 -0400
Add option: `--`
Had a few bugs in the initial patch request (#98) as well...
Also, fixed the help() command to print to stderr on nonzero exit statuses given.
---
bin/acorn | 28 +++++++++++++++++++++-------
index.html | 37 +++++++++++++++++++++++++++----------
2 files changed, 48 insertions(+), 17 deletions(-)
diff --git a/bin/acorn b/bin/acorn
index 506cdc4..f70fe21 100755
--- a/bin/acorn
+++ b/bin/acorn
@@ -4,28 +4,42 @@ var path = require("path");
var fs = require("fs");
var acorn = require("../acorn.js");
-var infile, parsed, options = {}, silent = false, compact = false;
+var infile, infilecount = 0;
+var options = {}, silent = false, compact = false;
+var parsed;
function help(status) {
- console.log("usage: " + path.basename(process.argv[1]) + " infile [--ecma3|--ecma5] [--strictSemicolons]");
- console.log(" [--locations] [--compact] [--silent] [--help]");
+ // we want to print to stderr, not stdout, on errors.
+ var print = (status == 0) ? console.out : console.err;
+ print("usage: " + path.basename(process.argv[1]) + " [--ecma3|--ecma5] [--strictSemicolons]");
+ print(" [--locations] [--compact] [--silent] [--help] [--] infile");
process.exit(status);
}
for (var i = 2; i < process.argv.length; ++i) {
var arg = process.argv[i];
- if (arg == "--ecma3") options.ecmaVersion = 3;
+ if (arg[0] != "-") {
+ infile = arg;
+ ++infilecount;
+ continue;
+ } else if (arg == "--") {
+ if (i < process.argv.length - 2) help(1); // we have too many remaining `infile`s
+ infile = process.argv[i + 1]; // we want the *next* argument, not the current one
+ ++infilecount;
+ break;
+ }
+ else if (arg == "--ecma3") options.ecmaVersion = 3;
else if (arg == "--ecma5") options.ecmaVersion = 5;
else if (arg == "--strictSemicolons") options.strictSemicolons = true;
else if (arg == "--locations") options.locations = true;
else if (arg == "--silent") silent = true;
else if (arg == "--compact") compact = true;
else if (arg == "--help") help(0);
- else if (arg[0] == "-") help(1);
- else infile = arg;
+ else help(1); // we already took care of all arguments without a starting dash
}
-if (!infile) help(1);
+// test against counter: we want exactly 1 file. Any more or less should error.
+if (infilecount !== 1) help(1);
try {
var code = fs.readFileSync(infile, "utf8");
diff --git a/index.html b/index.html
index 0e2d6e6..f336e3c 100644
--- a/index.html
+++ b/index.html
@@ -188,7 +188,7 @@ we assign a variable name to it for quick comparing.</p> </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></pre></div> </td> [...]
<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">" [...]
parser use them properly (the presence of these properties is
what categorizes them as operators).</p>
@@ -217,8 +217,8 @@ in AssignmentExpression nodes.</p> </td> <td class="code
<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 [...]
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">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="o">:</span> <span class="nx">_eq</span><span class="p">,</span> <span class="nx">name</span><span clas [...]
- <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="o">:</span> <span class="nx">_string</span><span class="p">};</span>
+ <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 [...]
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
@@ -376,8 +376,14 @@ into it.</p>
<code>tokRegexpAllowed</code> trick does not work. See <code>parseStatement</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">readToken_dot</span><span class="p">()</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="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">48</span> <span class="o">&&</span> <span class="nx">next</span> <span class="o"><=</span> <span class="mi">57</span><span class="p">)</span> <span class="k">return</span> <span class="nx">readNumber</span><span class="p">(</span><span class="kc">true</span><span class="p">);</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">_dot</span><span class="p">);</span>
+ <span class="kd">var</span> <span class="nx">next2</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">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">next</span> <span class="o">===</span> <span class="mi">46</span> <span class="o">&&</span> <span class="nx">next2</span> <span class="o">===</span> <span class="mi">46</span><span class="p">)</span> <span class="p">{</span> <span cl [...]
+ <span class="nx">tokPos</span> <span class="o">+=</span> <span class="mi">3</span><span class="p">;</span>
+ <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_ellipsis</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</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">_dot</span><span class="p">);</span>
+ <span class="p">}</span>
<span class="p">}</span>
<span class="kd">function</span> <span class="nx">readToken_slash</span><span class="p">()</span> <span class="p">{</span> <span class="c1">// '/'</span>
@@ -448,7 +454,7 @@ into it.</p>
<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
-by a digit.</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>
+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">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>
@@ -1280,11 +1286,22 @@ init properties are also not allowed to be repeated.</p> </td>
<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="nx">node</span><span class="p">.</span><span class="nx">params</span> <span class="o">=</span> <span class="p">[];</span>
- <span class="kd">var</span> <span class="nx">first</span> <span class="o">=</span> <span class="kc">true</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">expect</span><span class="p">(</span><span class="nx">_parenL</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">_parenR</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">first</span><span class="p">)</span> <span class="nx">expect</span><span class="p">(</span><span class="nx">_comma</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="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="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">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="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>
--
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