[Pkg-javascript-commits] [node-acorn-jsx] 126/484: Prefix keywords with underscore in tokTypes object

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:14 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 6fe123947be30cb565b4d575cbe3879c4ccd9672
Author: Marijn Haverbeke <marijnh at gmail.com>
Date:   Mon Jun 10 15:47:29 2013 +0200

    Prefix keywords with underscore in tokTypes object
---
 acorn.js       |  2 +-
 acorn_loose.js | 56 ++++++++++++++++++++++++++++----------------------------
 index.html     |  2 +-
 3 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/acorn.js b/acorn.js
index e7d8c44..00c4e47 100644
--- a/acorn.js
+++ b/acorn.js
@@ -328,7 +328,7 @@
                       parenL: _parenL, parenR: _parenR, comma: _comma, semi: _semi, colon: _colon,
                       dot: _dot, question: _question, slash: _slash, eq: _eq, name: _name, eof: _eof,
                       num: _num, regexp: _regexp, string: _string};
-  for (var kw in keywordTypes) exports.tokTypes[kw] = keywordTypes[kw];
+  for (var kw in keywordTypes) exports.tokTypes["_" + kw] = keywordTypes[kw];
 
   // This is a trick taken from Esprima. It turns out that, on
   // non-Chrome browsers, to check whether a string is in a set, a
diff --git a/acorn_loose.js b/acorn_loose.js
index de3b0e1..a1ee6d9 100644
--- a/acorn_loose.js
+++ b/acorn_loose.js
@@ -291,60 +291,60 @@
     var starttype = token.type, node = startNode();
 
     switch (starttype) {
-    case tt.break: case tt.continue:
+    case tt._break: case tt._continue:
       next();
-      var isBreak = starttype === tt.break;
+      var isBreak = starttype === tt._break;
       node.label = token.type === tt.name ? parseIdent() : null;
       semicolon();
       return finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
 
-    case tt.debugger:
+    case tt._debugger:
       next();
       semicolon();
       return finishNode(node, "DebuggerStatement");
 
-    case tt.do:
+    case tt._do:
       next();
       node.body = parseStatement();
-      node.test = eat(tt.while) ? parseParenExpression() : dummyIdent();
+      node.test = eat(tt._while) ? parseParenExpression() : dummyIdent();
       semicolon();
       return finishNode(node, "DoWhileStatement");
 
-    case tt.for:
+    case tt._for:
       next();
       pushCx();
       expect(tt.parenL);
       if (token.type === tt.semi) return parseFor(node, null);
-      if (token.type === tt.var) {
+      if (token.type === tt._var) {
         var init = startNode();
         next();
         parseVar(init, true);
-        if (init.declarations.length === 1 && eat(tt.in))
+        if (init.declarations.length === 1 && eat(tt._in))
           return parseForIn(node, init);
         return parseFor(node, init);
       }
       var init = parseExpression(false, true);
-      if (eat(tt.in)) {return parseForIn(node, checkLVal(init));}
+      if (eat(tt._in)) {return parseForIn(node, checkLVal(init));}
       return parseFor(node, init);
 
-    case tt.function:
+    case tt._function:
       next();
       return parseFunction(node, true);
 
-    case tt.if:
+    case tt._if:
       next();
       node.test = parseParenExpression();
       node.consequent = parseStatement();
-      node.alternate = eat(tt.else) ? parseStatement() : null;
+      node.alternate = eat(tt._else) ? parseStatement() : null;
       return finishNode(node, "IfStatement");
 
-    case tt.return:
+    case tt._return:
       next();
       if (eat(tt.semi) || canInsertSemicolon()) node.argument = null;
       else { node.argument = parseExpression(); semicolon(); }
       return finishNode(node, "ReturnStatement");
 
-    case tt.switch:
+    case tt._switch:
       var blockIndent = curIndent, line = curLineStart;
       next();
       node.discriminant = parseParenExpression();
@@ -353,8 +353,8 @@
       expect(tt.braceL);
 
       for (var cur; !closesBlock(tt.braceR, blockIndent, line);) {
-        if (token.type === tt.case || token.type === tt.default) {
-          var isCase = token.type === tt.case;
+        if (token.type === tt._case || token.type === tt._default) {
+          var isCase = token.type === tt._case;
           if (cur) finishNode(cur, "SwitchCase");
           node.cases.push(cur = startNode());
           cur.consequent = [];
@@ -376,17 +376,17 @@
       eat(tt.braceR);
       return finishNode(node, "SwitchStatement");
 
-    case tt.throw:
+    case tt._throw:
       next();
       node.argument = parseExpression();
       semicolon();
       return finishNode(node, "ThrowStatement");
 
-    case tt.try:
+    case tt._try:
       next();
       node.block = parseBlock();
       node.handler = null;
-      if (token.type === tt.catch) {
+      if (token.type === tt._catch) {
         var clause = startNode();
         next();
         expect(tt.parenL);
@@ -396,23 +396,23 @@
         clause.body = parseBlock();
         node.handler = finishNode(clause, "CatchClause");
       }
-      node.finalizer = eat(tt.finally) ? parseBlock() : null;
+      node.finalizer = eat(tt._finally) ? parseBlock() : null;
       if (!node.handler && !node.finalizer) return node.block;
       return finishNode(node, "TryStatement");
 
-    case tt.var:
+    case tt._var:
       next();
       node = parseVar(node);
       semicolon();
       return node;
 
-    case tt.while:
+    case tt._while:
       next();
       node.test = parseParenExpression();
       node.body = parseStatement();
       return finishNode(node, "WhileStatement");
 
-    case tt.with:
+    case tt._with:
       next();
       node.object = parseParenExpression();
       node.body = parseStatement();
@@ -542,7 +542,7 @@
   function parseExprOp(left, minPrec, noIn, indent, line) {
     if (curLineStart != line && curIndent < indent && tokenStartsLine()) return left;
     var prec = token.type.binop;
-    if (prec != null && (!noIn || token.type !== tt.in)) {
+    if (prec != null && (!noIn || token.type !== tt._in)) {
       if (prec > minPrec) {
         var node = startNodeFrom(left);
         node.left = left;
@@ -628,7 +628,7 @@
 
   function parseExprAtom() {
     switch (token.type) {
-    case tt.this:
+    case tt._this:
       var node = startNode();
       next();
       return finishNode(node, "ThisExpression");
@@ -641,7 +641,7 @@
       next();
       return finishNode(node, "Literal");
 
-    case tt.null: case tt.true: case tt.false:
+    case tt._null: case tt._true: case tt._false:
       var node = startNode();
       node.value = token.type.atomValue;
       node.raw = token.type.keyword
@@ -666,12 +666,12 @@
     case tt.braceL:
       return parseObj();
 
-    case tt.function:
+    case tt._function:
       var node = startNode();
       next();
       return parseFunction(node, false);
 
-    case tt.new:
+    case tt._new:
       return parseNew();
 
     default:
diff --git a/index.html b/index.html
index 045d0fb..27f8041 100644
--- a/index.html
+++ b/index.html
@@ -208,7 +208,7 @@ tokenizer.</p>             </td>             <td class="code">               <di
                       <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="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="nx">kw</span><span class="p">]</span> <span class="o">=</span> <span class="nx">keywordTypes</span><span class="p">[</span><span class="nx">kw</span><span class="p">];</span [...]
+  <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
 a regular expression, and on Chrome the two are about on par.

-- 
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