[Pkg-javascript-commits] [node-acorn-jsx] 235/484: Added `function *` support (part of generators feature).

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:36 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 b8a3300a2198032e4f0e947f3dcf54959fc8e680
Author: Ingvar Stepanyan <me at rreverser.com>
Date:   Sat Jul 26 05:43:48 2014 +0300

    Added `function *` support (part of generators feature).
---
 acorn.js              | 48 ++++++++++++++++++++++++++++++++++++++++--------
 test/tests-harmony.js |  4 ++--
 2 files changed, 42 insertions(+), 10 deletions(-)

diff --git a/acorn.js b/acorn.js
index b0206b4..aa61b15 100644
--- a/acorn.js
+++ b/acorn.js
@@ -1922,28 +1922,27 @@
         if (options.allowTrailingCommas && eat(_braceR)) break;
       } else first = false;
 
-      var prop = startNode(), kind;
+      var prop = startNode(), kind, isGenerator;
       if (options.ecmaVersion >= 6) {
         prop.method = false;
         prop.shorthand = false;
+        isGenerator = parseIsGenerator();
       }
       parsePropertyName(prop);
       if (eat(_colon)) {
         prop.value = parseExpression(true);
         kind = prop.kind = "init";
       } else if (options.ecmaVersion >= 6 && tokType === _parenL) {
-        var func = parseFunction(startNode(), false, true);
         kind = prop.kind = "init";
         prop.method = true;
-        prop.value = func;
+        prop.value = parseMethod(isGenerator);
       } else if (options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
                  (prop.key.name === "get" || prop.key.name === "set")) {
+        if (isGenerator) unexpected();
         sawGetSet = true;
         kind = prop.kind = prop.key.name;
         parsePropertyName(prop);
-        if (tokType !== _parenL) unexpected();
-        var func = parseFunction(startNode(), false, options.ecmaVersion >= 6);
-        prop.value = func;
+        prop.value = parseMethod(false);
       } else if (options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
         kind = prop.kind = "init";
         prop.value = prop.key;
@@ -2002,11 +2001,25 @@
     }
   }
 
+  // Checks if there's generator's sign ('*') and moves on.
+
+  function parseIsGenerator() {
+    if (tokVal === '*') {
+      next();
+      return true;
+    } else {
+      return false;
+    }
+  }
+
   // Parse a function declaration or literal (depending on the
   // `isStatement` parameter).
 
   function parseFunction(node, isStatement, allowExpressionBody) {
     initFunction(node);
+    if (options.ecmaVersion >= 6) {
+      node.generator = parseIsGenerator();
+    }
     if (isStatement || tokType === _name) {
       node.id = parseIdent();
     }
@@ -2015,6 +2028,23 @@
     return finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression");
   }
 
+  // Parse object or class method.
+
+  function parseMethod(isGenerator) {
+    var node = startNode();
+    initFunction(node);
+    parseFunctionParams(node);
+    var allowExpressionBody;
+    if (options.ecmaVersion >= 6) {
+      node.generator = isGenerator;
+      allowExpressionBody = true;
+    } else {
+      allowExpressionBody = false;
+    }
+    parseFunctionBody(node, allowExpressionBody);
+    return finishNode(node, "FunctionExpression");
+  }
+
   // Parse arrow function expression with given parameters.
 
   function parseArrowExpression(node, params) {
@@ -2148,15 +2178,17 @@
     while (!eat(_braceR)) {
       var method = startNode();
       method.static = !!eat(_static);
+      var isGenerator = parseIsGenerator();
       method.key = parseIdent(true);
-      if (method.key.type === "Identifier" && (method.key.name === "get" || method.key.name === "set") && tokType === _name) {
+      if ((method.key.name === "get" || method.key.name === "set") && tokType === _name) {
+        if (isGenerator) unexpected();
         method.kind = method.key.name;
         method.key = parseIdent(true);
         sawGetSet = true;
       } else {
         method.kind = "";
       }
-      method.value = parseFunction(startNode());
+      method.value = parseMethod(isGenerator);
       addProperty(classBody.body, finishNode(method, "MethodDefinition"), sawGetSet, "");
       eat(_semi);
     }
diff --git a/test/tests-harmony.js b/test/tests-harmony.js
index e3e9b01..ce1d941 100644
--- a/test/tests-harmony.js
+++ b/test/tests-harmony.js
@@ -14696,10 +14696,10 @@ test("(function () { yield* 10 })", {
               end: {line: 1, column: 24}
             }
           },
-          range: [15, 25],
+          range: [15, 24],
           loc: {
             start: {line: 1, column: 15},
-            end: {line: 1, column: 25}
+            end: {line: 1, column: 24}
           }
         }],
         range: [13, 26],

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