[Pkg-javascript-commits] [node-acorn-jsx] 33/484: Make 'this' a proper keyword
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:00 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 330084f9939f9492d57df69a9c4719946e6fe199
Author: Marijn Haverbeke <marijnh at gmail.com>
Date: Wed Oct 17 16:33:38 2012 +0200
Make 'this' a proper keyword
---
acorn.js | 17 ++++++++---------
index.html | 19 +++++++++----------
2 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/acorn.js b/acorn.js
index 3aea6da..0799736 100644
--- a/acorn.js
+++ b/acorn.js
@@ -212,6 +212,7 @@
var _if = {keyword: "if"}, _return = {keyword: "return", beforeExpr: true}, _switch = {keyword: "switch"};
var _throw = {keyword: "throw", beforeExpr: true}, _try = {keyword: "try"}, _var = {keyword: "var"};
var _while = {keyword: "while", isLoop: true}, _with = {keyword: "with"}, _new = {keyword: "new", beforeExpr: true};
+ var _this = {keyword: "this"};
// The keywords that denote values.
@@ -232,7 +233,7 @@
"function": _function, "if": _if, "return": _return, "switch": _switch,
"throw": _throw, "try": _try, "var": _var, "while": _while, "with": _with,
"null": _null, "true": _true, "false": _false, "new": _new, "in": _in,
- "instanceof": {keyword: "instanceof", binop: 7},
+ "instanceof": {keyword: "instanceof", binop: 7}, "this": _this,
"typeof": {keyword: "typeof", prefix: true},
"void": {keyword: "void", prefix: true},
"delete": {keyword: "delete", prefix: true}};
@@ -335,7 +336,7 @@
// And the keywords.
- var isKeyword = makePredicate("break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in");
+ var isKeyword = makePredicate("break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this");
// ## Character categories
@@ -563,7 +564,6 @@
return finishOp(code === 61 ? _eq : _prefix, 1);
case 126: // '~'
- if (next === 61) return finishOp(_assign, 2);
return finishOp(_prefix, 1);
}
@@ -1400,13 +1400,12 @@
function parseExprAtom() {
switch (tokType) {
+ case _this:
+ var node = startNode();
+ next();
+ return finishNode(node, "ThisExpression");
case _name:
- if (tokVal === "this") {
- var node = startNode();
- next();
- return finishNode(node, "ThisExpression");
- } else return parseIdent();
-
+ return parseIdent();
case _num: case _string: case _regexp:
var node = startNode();
node.value = tokVal;
diff --git a/index.html b/index.html
index bdb451f..7d30bcb 100644
--- a/index.html
+++ b/index.html
@@ -118,7 +118,8 @@ continue jumps to that label.</p> </td> <td class="code"
<span class="kd">var</span> <span class="nx">_finally</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"finally"</span><span class="p">},</span> <span class="nx">_for</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"for"</span><span class="p">,</span> <span class="nx">isLoop</span><span class="o">:</span> <s [...]
<span class="kd">var</span> <span class="nx">_if</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"if"</span><span class="p">},</span> <span class="nx">_return</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"return"</span><span class="p">,</span> <span class="nx">beforeExpr</span><span class="o">:</span> <s [...]
<span class="kd">var</span> <span class="nx">_throw</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"throw"</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">_try</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class=" [...]
- <span class="kd">var</span> <span class="nx">_while</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"while"</span><span class="p">,</span> <span class="nx">isLoop</span><span class="o">:</span> <span class="kc">true</span><span class="p">},</span> <span class="nx">_with</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2" [...]
+ <span class="kd">var</span> <span class="nx">_while</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"while"</span><span class="p">,</span> <span class="nx">isLoop</span><span class="o">:</span> <span class="kc">true</span><span class="p">},</span> <span class="nx">_with</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2" [...]
+ <span class="kd">var</span> <span class="nx">_this</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"this"</span><span class="p">};</span></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-30">¶</a> </div> [...]
<span class="kd">var</span> <span class="nx">_false</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"false"</span><span class="p">,</span> <span class="nx">atomValue</span><span class="o">:</span> <span class="kc">false</span><span class="p">};</span></pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div c [...]
(when parsing <code>for</code>) needs to be tested against specifically, so
we assign a variable name to it for quick comparing.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">_in</span> <span class="o">=</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"in"</span><span class="p">,</span> <span class="nx">binop</span><span class="o">:</span> <span class="mi">7</span><span class="p">,</span> <span class="nx [...]
@@ -127,7 +128,7 @@ we assign a variable name to it for quick comparing.</p> </td>
<span class="s2">"function"</span><span class="o">:</span> <span class="nx">_function</span><span class="p">,</span> <span class="s2">"if"</span><span class="o">:</span> <span class="nx">_if</span><span class="p">,</span> <span class="s2">"return"</span><span class="o">:</span> <span class="nx">_return</span><span class="p">,</span> <span class="s2">"switch"</span><span class="o">:</span> <span class="nx">_switch</span><span c [...]
<span class="s2">"throw"</span><span class="o">:</span> <span class="nx">_throw</span><span class="p">,</span> <span class="s2">"try"</span><span class="o">:</span> <span class="nx">_try</span><span class="p">,</span> <span class="s2">"var"</span><span class="o">:</span> <span class="nx">_var</span><span class="p">,</span> <span class="s2">"while"</span><span class="o">:</span> <span class="nx">_while</span><span class="p">,</ [...]
<span class="s2">"null"</span><span class="o">:</span> <span class="nx">_null</span><span class="p">,</span> <span class="s2">"true"</span><span class="o">:</span> <span class="nx">_true</span><span class="p">,</span> <span class="s2">"false"</span><span class="o">:</span> <span class="nx">_false</span><span class="p">,</span> <span class="s2">"new"</span><span class="o">:</span> <span class="nx">_new</span><span class="p">,</ [...]
- <span class="s2">"instanceof"</span><span class="o">:</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"instanceof"</span><span class="p">,</span> <span class="nx">binop</span><span class="o">:</span> <span class="mi">7</span><span class="p">},</span>
+ <span class="s2">"instanceof"</span><span class="o">:</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"instanceof"</span><span class="p">,</span> <span class="nx">binop</span><span class="o">:</span> <span class="mi">7</span><span class="p">},</span> <span class="s2">"this"</span><span class="o">:</span> <span class="nx">_this</span><span class="p">,</span>
<span class="s2">"typeof"</span><span class="o">:</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"typeof"</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="s2">"void"</span><span class="o">:</span> <span class="p">{</span><span class="nx">keyword</span><span class="o">:</span> <span class="s2">"void"</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="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></pre></div> </td> </tr> <tr id="section-33"> <td class="docs"> <div [...]
@@ -190,7 +191,7 @@ switch first dispatches on the lengths, to save on comparisons.</p>
<span class="nx">compareTo</span><span class="p">(</span><span class="nx">words</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="k">new</span> <span class="nb">Function</span><span class="p">(</span><span class="s2">"str"</span><span class="p">,</span> <span class="nx">f</span><span class="p">);</span>
- <span class="p">}</span></pre></div> </td> </tr> <tr id="section-38"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-38">¶</a> </div> <p>The ECMAScript 3 reserved word list.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">isReservedWord3</span [...]
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-38"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-38">¶</a> </div> <p>The ECMAScript 3 reserved word list.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">isReservedWord3</span [...]
whitespace, identifier, and identifier-start categories. These
are only applied when a character is found to actually have a
code point above 128.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">nonASCIIwhitespace</span> <span class="o">=</span> <span class="sr">/[\u1680\u180E\u2000-\u200A\u202F\u205F\u3000\uFEFF]/</span><span class="p">;</span>
@@ -353,7 +354,6 @@ of the type given by its first argument.</p> </td> <td c
<span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">code</span> <span class="o">===</span> <span class="mi">61</span> <span class="o">?</span> <span class="nx">_eq</span> <span class="o">:</span> <span class="nx">_prefix</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
<span class="k">case</span> <span class="mi">126</span><span class="o">:</span> <span class="c1">// '~'</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_assign</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_prefix</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</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>If we are here, we either found a non-ASCII identifier
character, or something that's entirely disallowed.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">ch</span> <span class="o">=</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>
@@ -1012,13 +1012,12 @@ expression, an expression started by a keyword like <code>function</code> or
<code>new</code>, or an expression wrapped in punctuation like <code>()</code>, <code>[]</code>,
or <code>{}</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">parseExprAtom</span><span class="p">()</span> <span class="p">{</span>
<span class="k">switch</span> <span class="p">(</span><span class="nx">tokType</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">case</span> <span class="nx">_this</span><span class="o">:</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">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">"ThisExpression"</span><span class="p">);</span>
<span class="k">case</span> <span class="nx">_name</span><span class="o">:</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">tokVal</span> <span class="o">===</span> <span class="s2">"this"</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">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">"ThisExpression"</span><span class="p">);</span>
- <span class="p">}</span> <span class="k">else</span> <span class="k">return</span> <span class="nx">parseIdent</span><span class="p">();</span>
-
+ <span class="k">return</span> <span class="nx">parseIdent</span><span class="p">();</span>
<span class="k">case</span> <span class="nx">_num</span><span class="o">:</span> <span class="k">case</span> <span class="nx">_string</span><span class="o">:</span> <span class="k">case</span> <span class="nx">_regexp</span><span class="o">:</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">value</span> <span class="o">=</span> <span class="nx">tokVal</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