[Pkg-javascript-commits] [node-acorn-jsx] 328/484: Loose: Added support for shorthand properties.

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:50 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 dda90580df211f3d8275d0c28d37d26253ef5e88
Author: Ingvar Stepanyan <me at rreverser.com>
Date:   Mon Oct 27 00:07:40 2014 +0200

    Loose: Added support for shorthand properties.
---
 acorn_loose.js | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/acorn_loose.js b/acorn_loose.js
index 4159309..9bc5320 100644
--- a/acorn_loose.js
+++ b/acorn_loose.js
@@ -287,6 +287,7 @@
   }
 
   function checkLVal(expr) {
+    if (!expr) return expr;
     switch (expr.type) {
       case "Identifier":
       case "MemberExpression":
@@ -742,10 +743,14 @@
     next();
     if (curIndent + 1 < indent) { indent = curIndent; line = curLineStart; }
     while (!closes(tt.braceR, indent, line)) {
-      var name = parsePropertyName();
-      if (!name) { if (isDummy(parseExpression(true))) next(); eat(tt.comma); continue; }
-      var prop = startNode();
-      prop.key = name;
+      var prop = startNode(), isGenerator;
+      if (options.ecmaVersion >= 6) {
+        prop.method = false;
+        prop.shorthand = false;
+        isGenerator = eat(tt.star);
+      }
+      parsePropertyName(prop);
+      if (!prop.key) { if (isDummy(parseExpression(true))) next(); eat(tt.comma); continue; }
       if (eat(tt.colon)) {
         prop.value = parseExpression(true);
         prop.kind = "init";
@@ -755,7 +760,9 @@
         prop.key = parsePropertyName() || dummyIdent();
         prop.value = parseFunction(startNode(), false);
       } else {
-        prop.value = dummyIdent();
+        prop.value = options.ecmaVersion >= 6 ? prop.key : dummyIdent();
+        prop.kind = "init";
+        prop.shorthand = true;
       }
 
       node.properties.push(finishNode(prop, "Property"));
@@ -766,9 +773,18 @@
     return finishNode(node, "ObjectExpression");
   }
 
-  function parsePropertyName() {
-    if (token.type === tt.num || token.type === tt.string) return parseExprAtom();
-    if (token.type === tt.name || token.type.keyword) return parseIdent();
+  function parsePropertyName(prop) {
+    if (options.ecmaVersion >= 6) {
+      if (eat(tt.bracketL)) {
+        prop.computed = true;
+        prop.key = parseExpression();
+        expect(tt.bracketR);
+        return;
+      } else {
+        prop.computed = false;
+      }
+    }
+    prop.key = (token.type === tt.num || token.type === tt.string) ? parseExprAtom() : parseIdent();
   }
 
   function parsePropertyAccessor() {

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