aboutsummaryrefslogtreecommitdiff
path: root/lib/output.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-02-25 02:14:33 +0800
committerGitHub <noreply@github.com>2018-02-25 02:14:33 +0800
commit52de64cf16a323797b11fb6fa286f0016be9a7a5 (patch)
tree3bad188b7e59aac90d38bfc9a843997e8a33f894 /lib/output.js
parent455790202a50e861573df118b9f9d536b6d23db4 (diff)
downloadtracifyjs-52de64cf16a323797b11fb6fa286f0016be9a7a5.tar.gz
tracifyjs-52de64cf16a323797b11fb6fa286f0016be9a7a5.zip
deduplicate parenthesis around object and function literals (#2953)
Diffstat (limited to 'lib/output.js')
-rw-r--r--lib/output.js7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/output.js b/lib/output.js
index bd1a70c2..cf0b41cd 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -576,6 +576,7 @@ function OutputStream(options) {
indentation : function() { return indentation },
current_width : function() { return current_col - indentation },
should_break : function() { return options.width && this.current_width() >= options.width },
+ has_parens : function() { return OUTPUT.slice(-1) == "(" },
newline : newline,
print : print,
space : space,
@@ -683,7 +684,7 @@ function OutputStream(options) {
// a function expression needs parens around it when it's provably
// the first token to appear in a statement.
PARENS(AST_Function, function(output){
- if (first_in_statement(output)) {
+ if (!output.has_parens() && first_in_statement(output)) {
return true;
}
@@ -704,7 +705,9 @@ function OutputStream(options) {
// same goes for an object literal, because otherwise it would be
// interpreted as a block of code.
- PARENS(AST_Object, first_in_statement);
+ PARENS(AST_Object, function(output){
+ return !output.has_parens() && first_in_statement(output);
+ });
PARENS(AST_Unary, function(output){
var p = output.parent();