You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2019/12/18 17:57:32 UTC

[couchdb-escodegen] reference refs/pull/154/head created (now addff1a)

This is an automated email from the ASF dual-hosted git repository.

davisp pushed a change to reference refs/pull/154/head
in repository https://gitbox.apache.org/repos/asf/couchdb-escodegen.git.


      at addff1a  Fix MemberExpression issues

This reference includes the following new commits:

     new addff1a  Fix MemberExpression issues

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb-escodegen] 01/01: Fix MemberExpression issues

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to reference refs/pull/154/head
in repository https://gitbox.apache.org/repos/asf/couchdb-escodegen.git

commit addff1a84c8cb0ffb104e3903487c7f821e66966
Author: Dmitry Sorin <ds...@yandex-team.ru>
AuthorDate: Thu Dec 19 22:01:13 2013 +0400

    Fix MemberExpression issues
---
 escodegen.js | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/escodegen.js b/escodegen.js
index 5be8063..8c24994 100644
--- a/escodegen.js
+++ b/escodegen.js
@@ -216,6 +216,22 @@
         return result;
     }
 
+    function isValidIdentifier(str) {
+        if (!str.length) {
+            return false;
+        }
+
+        if (!/^[_|\$|a-z]/i.test(str)) {
+            return false;
+        }
+
+        if (!/^[_|\$|a-z|0-9]+$/i.test(str.substr(1))) {
+            return false;
+        }
+
+        return true;
+    }
+
     isArray = Array.isArray;
     if (!isArray) {
         isArray = function isArray(array) {
@@ -1038,6 +1054,8 @@
                     allowIn: true,
                     allowCall: allowCall
                 }), ']');
+            } else if (!isValidIdentifier(expr.property.name)) {
+                result.push('[', escapeString(expr.property.name), ']');
             } else {
                 if (expr.object.type === Syntax.Literal && typeof expr.object.value === 'number') {
                     fragment = toSourceNode(result).toString();