[Pkg-javascript-commits] [node-acorn-jsx] 218/484: Better parentheses check for arrow expression argument list.

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:32 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 f7fe322490cbb82320edecbc3dcfe4881808fbdd
Author: Ingvar Stepanyan <me at rreverser.com>
Date:   Thu Jul 24 23:08:49 2014 +0300

    Better parentheses check for arrow expression argument list.
---
 acorn.js              | 20 +++++++++++---------
 test/tests-harmony.js |  4 ++--
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/acorn.js b/acorn.js
index a879a93..5d622bb 100644
--- a/acorn.js
+++ b/acorn.js
@@ -226,6 +226,11 @@
 
   var inFunction, labels, strict;
 
+  // This counter is used for checking that arrow expressions did
+  // not contain nested parentheses in argument list.
+
+  var metParenL;
+
   // This function is used to raise exceptions on parse errors. It
   // takes an offset integer (into the current `input`) to indicate
   // the location of the error, attaches the position to the end
@@ -491,6 +496,7 @@
     tokCurLine = 1;
     tokPos = tokLineStart = 0;
     tokRegexpAllowed = true;
+    metParenL = 0;
     skipSpace();
   }
 
@@ -1689,20 +1695,16 @@
     case _parenL:
       var node = startNode(), tokStartLoc1 = tokStartLoc, tokStart1 = tokStart, val;
       next();
+      var oldParenL = ++metParenL;
       if (tokType !== _parenR) {
         val = parseExpression();
       }
       expect(_parenR);
-      if (eat(_arrow)) {
-        if (val) {
-          var innerParenL = input.slice(val.start, val.end).indexOf('(');
-          if (innerParenL >= 0) unexpected(val.start + innerParenL);
-        }
+      if (metParenL === oldParenL && eat(_arrow)) {
         val = parseArrowExpression(node, !val ? [] : val.type === "SequenceExpression" ? val.expressions : [val]);
-      } else
-      // disallow '()' before everything but error
-      if (!val) {
-        unexpected(tokPos - 1);
+      } else {
+        // disallow '()' before everything but error
+        if (!val) unexpected(lastStart);
       }
       val.start = tokStart1;
       val.end = lastEnd;
diff --git a/test/tests-harmony.js b/test/tests-harmony.js
index acd8056..4982dc8 100644
--- a/test/tests-harmony.js
+++ b/test/tests-harmony.js
@@ -15945,9 +15945,9 @@ testFail("import { foo, bar }", "Unexpected token (1:20)", {ecmaVersion: 6});
 
 testFail("import foo from bar", "Unexpected token (1:20)", {ecmaVersion: 6});
 
-testFail("((a)) => 42", "Unexpected token (1:1)", {ecmaVersion: 6});
+testFail("((a)) => 42", "Unexpected token (1:6)", {ecmaVersion: 6});
 
-testFail("(a, (b)) => 42", "Unexpected token (1:4)", {ecmaVersion: 6});
+testFail("(a, (b)) => 42", "Unexpected token (1:9)", {ecmaVersion: 6});
 
 testFail("\"use strict\"; (eval = 10) => 42", "Assigning to eval in strict mode (1:15)", {ecmaVersion: 6});
 

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