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:58:39 UTC
[couchdb-escodegen] 01/01: Fix parentheses combined with call
expressions
This is an automated email from the ASF dual-hosted git repository.
davisp pushed a commit to reference refs/pull/24/head
in repository https://gitbox.apache.org/repos/asf/couchdb-escodegen.git
commit c6b790787e58edb070cc4449249f666e7da44031
Author: Robert Gust-Bardon <do...@robert.gust-bardon.org>
AuthorDate: Thu Jul 19 18:48:34 2012 +0200
Fix parentheses combined with call expressions
---
escodegen.js | 2 +-
test/options.js | 18 ++++++++++++++++--
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/escodegen.js b/escodegen.js
index 98edef0..e202f5e 100644
--- a/escodegen.js
+++ b/escodegen.js
@@ -705,7 +705,7 @@
);
len = expr['arguments'].length;
- if (parentheses || len > 0) {
+ if (parentheses || len > 0 || precedence === Precedence.Call) {
result += '(';
for (i = 0; i < len; i += 1) {
result += generateExpression(expr['arguments'][i], {
diff --git a/test/options.js b/test/options.js
index 7922951..e6df8e0 100644
--- a/test/options.js
+++ b/test/options.js
@@ -663,8 +663,15 @@ var data = [{
}
},
items: {
+ 'new Foo()': 'new Foo();',
'new Foo(42)': 'new Foo(42);',
- 'new Foo() in bar': 'new Foo() in bar;'
+ 'new Foo() in bar': 'new Foo() in bar;',
+ 'new Date.constructor()': 'new Date.constructor();',
+ 'new Date().constructor': 'new Date().constructor;',
+ 'new Date.setUTCMilliseconds(0)': 'new Date.setUTCMilliseconds(0);',
+ 'new Date().setUTCMilliseconds(0)': 'new Date().setUTCMilliseconds(0);',
+ 'new new Foo()()': 'new new Foo()();',
+ 'new new (Foo()())()()': 'new new (Foo()())()();'
}
}, {
options: {
@@ -673,8 +680,15 @@ var data = [{
}
},
items: {
+ 'new Foo()': 'new Foo;',
'new Foo(42)': 'new Foo(42);',
- 'new Foo() in bar': 'new Foo in bar;'
+ 'new Foo() in bar': 'new Foo in bar;',
+ 'new Date.constructor()': 'new Date.constructor;',
+ 'new Date().constructor': 'new Date().constructor;',
+ 'new Date.setUTCMilliseconds(0)': 'new Date.setUTCMilliseconds(0);',
+ 'new Date().setUTCMilliseconds(0)': 'new Date().setUTCMilliseconds(0);',
+ 'new new Foo()': 'new new Foo;',
+ 'new new (Foo()())()()': 'new new (Foo()());'
}
}];