[Pkg-javascript-commits] [node-acorn-jsx] 334/484: Loose: arrow functions.

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:52 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 992fc0503d022b803ed2a69bc6a1f5268af03a00
Author: Ingvar Stepanyan <me at rreverser.com>
Date:   Mon Oct 27 02:01:31 2014 +0200

    Loose: arrow functions.
---
 acorn_loose.js | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/acorn_loose.js b/acorn_loose.js
index 25f7235..4f2dc7a 100644
--- a/acorn_loose.js
+++ b/acorn_loose.js
@@ -674,8 +674,12 @@
       var node = startNode();
       next();
       return finishNode(node, "ThisExpression");
+
     case tt.name:
-      return parseIdent();
+      var start = storeCurrentPos();
+      var id = parseIdent();
+      return eat(tt.arrow) ? parseArrowExpression(startNodeAt(start), [id]) : id;
+
     case tt.num: case tt.string: case tt.regexp:
       var node = startNode();
       node.value = token.value;
@@ -695,6 +699,9 @@
       next();
       var val = parseExpression();
       expect(tt.parenR);
+      if (eat(tt.arrow)) {
+        return parseArrowExpression(startNodeAt(start), val.expressions || (isDummy(val) ? [] : [val]));
+      }
       if (options.preserveParens) {
         var par = startNodeAt(start);
         par.expression = val;
@@ -880,11 +887,13 @@
     return checkLVal(node);
   }
 
-  function parseFunctionParams(node) {
+  function parseFunctionParams(node, params) {
     var defaults = [], hasDefaults = false;
 
-    pushCx();
-    var params = parseExprList(tt.parenR);
+    if (!params) {
+      pushCx();
+      params = parseExprList(tt.parenR);
+    }
     for (var i = 0; i < params.length; i++) {
       var param = params[i], defValue = null;
       if (param.type === "AssignmentExpression") {
@@ -923,12 +932,20 @@
     var node = startNode();
     initFunction(node);
     parseFunctionParams(node);
-    node.generator = isGenerator;
+    node.generator = isGenerator || false;
     node.expression = options.ecmaVersion >= 6 && token.type !== tt.braceL;
     node.body = node.expression ? parseExpression(true) : parseBlock();
     return finishNode(node, "FunctionExpression");
   }
 
+  function parseArrowExpression(node, params) {
+    initFunction(node);
+    parseFunctionParams(node, params);
+    node.expression = token.type !== tt.braceL;
+    node.body = node.expression ? parseExpression(true) : parseBlock();
+    return finishNode(node, "ArrowFunctionExpression");
+  }
+
   function parseExprList(close, allowEmpty) {
     var indent = curIndent, line = curLineStart, elts = [], continuedLine = nextLineStart;
     next(); // Opening bracket

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