[Pkg-javascript-commits] [node-acorn-jsx] 427/484: Improve JSX braces context handling.

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 719ecbd2037c2446f960ab0affac07eb694e3386
Author: Ingvar Stepanyan <me at rreverser.com>
Date:   Sun Jan 25 00:33:03 2015 +0200

    Improve JSX braces context handling.
---
 acorn.js          | 12 +++++-------
 test/tests-jsx.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 7 deletions(-)

diff --git a/acorn.js b/acorn.js
index 9998818..3ae65e3 100644
--- a/acorn.js
+++ b/acorn.js
@@ -653,10 +653,6 @@
       return true;
     if (prevType == _braceL)
       return curTokContext() === b_stat;
-    if (prevType === _jsxTagEnd || prevType === _jsxText)
-      return true;
-    if (prevType === _jsxName)
-      return false;
     return !tokExprAllowed;
   }
 
@@ -676,8 +672,6 @@
     if (type === _parenR || type === _braceR) {
       var out = tokContext.pop();
       if (out === b_tmpl) {
-        preserveSpace = true;
-      } else if (curTokContext() === j_expr) {
         preserveSpace = tokExprAllowed = true;
       } else if (out === b_stat && curTokContext() === f_expr) {
         tokContext.pop();
@@ -686,7 +680,11 @@
         tokExprAllowed = !(out && out.isExpr);
       }
     } else if (type === _braceL) {
-      tokContext.push(braceIsBlock(prevType) ? b_stat : b_expr);
+      switch (curTokContext()) {
+        case j_oTag: tokContext.push(b_expr); break;
+        case j_expr: tokContext.push(b_tmpl); break;
+        default: tokContext.push(braceIsBlock(prevType) ? b_stat : b_expr);
+      }
       tokExprAllowed = true;
     } else if (type === _dollarBraceL) {
       tokContext.push(b_tmpl);
diff --git a/test/tests-jsx.js b/test/tests-jsx.js
index 6604c34..e5d2999 100644
--- a/test/tests-jsx.js
+++ b/test/tests-jsx.js
@@ -3541,6 +3541,52 @@ var fbTestFixture = {
           }
         ]
       }
+    },
+
+    '<div pre="leading" {...props} />': {
+      type: "ExpressionStatement",
+      range: [0, 32],
+      expression: {
+        type: "JSXElement",
+        range: [0, 32],
+        openingElement: {
+          type: "JSXOpeningElement",
+          range: [0, 32],
+          attributes: [
+            {
+              type: "JSXAttribute",
+              range: [5, 18],
+              name: {
+                type: "JSXIdentifier",
+                range: [5, 8],
+                name: "pre"
+              },
+              value: {
+                type: "Literal",
+                range: [9, 18],
+                value: "leading"
+              }
+            },
+            {
+              type: "JSXSpreadAttribute",
+              range: [19, 29],
+              argument: {
+                type: "Identifier",
+                range: [23, 28],
+                name: "props"
+              }
+            }
+          ],
+          name: {
+            type: "JSXIdentifier",
+            range: [1, 4],
+            name: "div"
+          },
+          selfClosing: true
+        },
+        closingElement: null,
+        children: []
+      }
     }
   }
 };

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