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:33 UTC
[couchdb-escodegen] 01/01: Fix MemberExpression issues
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();