[Pkg-javascript-commits] [node-acorn-jsx] 431/484: Finalized destructuring support in loose parser; fixed startNodeAt.

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:21:06 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 e4a97ab87700c1f05d4effe15213cc60a5189b19
Author: Ingvar Stepanyan <me at rreverser.com>
Date:   Tue Jan 27 15:53:16 2015 +0200

    Finalized destructuring support in loose parser; fixed startNodeAt.
---
 acorn_loose.js        | 24 +++++++++++++++++++-----
 test/tests-harmony.js | 25 ++++++++-----------------
 2 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/acorn_loose.js b/acorn_loose.js
index ab0c6ea..035f223 100644
--- a/acorn_loose.js
+++ b/acorn_loose.js
@@ -235,13 +235,14 @@
     if (options.locations) {
       node = new Node(pos[0]);
       node.loc = new SourceLocation(pos[1]);
+      pos = pos[0];
     } else {
       node = new Node(pos);
     }
     if (options.directSourceFile)
       node.sourceFile = options.directSourceFile;
     if (options.ranges)
-      node.range = [pos[0], 0];
+      node.range = [pos, 0];
     return node;
   }
 
@@ -365,7 +366,7 @@
       }
       var init = parseExpression(true);
       if (token.type === tt._in || isContextual("of")) {
-        return parseForIn(node, checkLVal(init));
+        return parseForIn(node, toAssignable(init));
       }
       return parseFor(node, init);
 
@@ -432,7 +433,7 @@
         var clause = startNode();
         next();
         expect(tt.parenL);
-        clause.param = parseIdent();
+        clause.param = toAssignable(parseExprAtom());
         expect(tt.parenR);
         clause.guard = null;
         clause.body = parseBlock();
@@ -857,11 +858,12 @@
     if (curIndent + 1 < indent) { indent = curIndent; line = curLineStart; }
     while (!closes(tt.braceR, indent, line)) {
       if (isClass && semicolon()) continue;
-      var prop = startNode(), isGenerator;
+      var prop = startNode(), isGenerator, start;
       if (options.ecmaVersion >= 6) {
         if (isClass) {
           prop['static'] = false;
         } else {
+          start = storeCurrentPos();
           prop.method = false;
           prop.shorthand = false;
         }
@@ -901,7 +903,19 @@
         prop.value = parseMethod(isGenerator);
       } else {
         prop.kind = "init";
-        prop.value = options.ecmaVersion >= 6 ? prop.key : dummyIdent();
+        if (options.ecmaVersion >= 6) {
+          if (eat(tt.eq)) {
+            var assign = startNodeAt(start);
+            assign.operator = "=";
+            assign.left = prop.key;
+            assign.right = parseMaybeAssign();
+            prop.value = finishNode(assign, "AssignmentExpression");
+          } else {
+            prop.value = prop.key;
+          }
+        } else {
+          prop.value = dummyIdent();
+        }
         prop.shorthand = true;
       }
 
diff --git a/test/tests-harmony.js b/test/tests-harmony.js
index a1a9ffa..7ccb49a 100644
--- a/test/tests-harmony.js
+++ b/test/tests-harmony.js
@@ -14395,8 +14395,7 @@ test("var {propName: localVar = defaultValue} = obj", {
 }, {
   ecmaVersion: 6,
   ranges: true,
-  locations: true,
-  loose: false
+  locations: true
 });
 
 test("var {propName = defaultValue} = obj", {
@@ -14451,8 +14450,7 @@ test("var {propName = defaultValue} = obj", {
 }, {
   ecmaVersion: 6,
   ranges: true,
-  locations: true,
-  loose: false
+  locations: true
 });
 
 test("var [localVar = defaultValue] = obj", {
@@ -14494,8 +14492,7 @@ test("var [localVar = defaultValue] = obj", {
 }, {
   ecmaVersion: 6,
   ranges: true,
-  locations: true,
-  loose: false
+  locations: true
 });
 
 test("({x = 0} = obj)", {
@@ -14549,8 +14546,7 @@ test("({x = 0} = obj)", {
   }]
 }, {
   ecmaVersion: 6,
-  ranges: true,
-  loose: false
+  ranges: true
 });
 
 test("({x = 0}) => x", {
@@ -14606,8 +14602,7 @@ test("({x = 0}) => x", {
   }]
 }, {
   ecmaVersion: 6,
-  ranges: true,
-  loose: false
+  ranges: true
 });
 
 test("[a, {b: {c = 1}}] = arr", {
@@ -14689,8 +14684,7 @@ test("[a, {b: {c = 1}}] = arr", {
   }]
 }, {
   ecmaVersion: 6,
-  ranges: true,
-  loose: false
+  ranges: true
 });
 
 test("for ({x = 0} in arr);", {
@@ -14743,8 +14737,7 @@ test("for ({x = 0} in arr);", {
   }]
 }, {
   ecmaVersion: 6,
-  ranges: true,
-  loose: false
+  ranges: true
 });
 
 testFail("obj = {x = 0}", "Unexpected token (1:9)", {ecmaVersion: 6});
@@ -14796,14 +14789,12 @@ test("try {} catch ({message}) {}", {
         body: []
       }
     },
-    guardedHandlers: [],
     finalizer: null
   }]
 }, {
   ecmaVersion: 6,
   ranges: true,
-  locations: true,
-  loose: false
+  locations: true
 });
 
 // https://github.com/marijnh/acorn/issues/192

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