diff --git a/src/babel/generation/index.js b/src/babel/generation/index.js index 11d8fdc458..49faa50453 100644 --- a/src/babel/generation/index.js +++ b/src/babel/generation/index.js @@ -149,11 +149,12 @@ class CodeGenerator { return print; } - catchUp(node, parent) { + catchUp(node, parent, leftParenPrinted) { // catch up to this nodes newline if we're behind if (node.loc && this.format.retainLines && this.buffer.buf) { var needsParens = false; - if (parent && this.position.line < node.loc.start.line && t.isTerminatorless(parent)) { + if (!leftParenPrinted && parent && + this.position.line < node.loc.start.line && t.isTerminatorless(parent)) { needsParens = true; this._push("("); } @@ -216,7 +217,7 @@ class CodeGenerator { this.printLeadingComments(node, parent); - var needsParensFromCatchup = this.catchUp(node, parent); + var needsParensFromCatchup = this.catchUp(node, parent, needsParens); newline(true); diff --git a/test/core/fixtures/generation/edgecase/return-with-retainlines-and-compact-option/actual.js b/test/core/fixtures/generation/edgecase/return-with-retainlines-and-compact-option/actual.js new file mode 100644 index 0000000000..2a0e91f010 --- /dev/null +++ b/test/core/fixtures/generation/edgecase/return-with-retainlines-and-compact-option/actual.js @@ -0,0 +1,6 @@ +function foo(l) { + return ( + // hi + l + ); +} diff --git a/test/core/fixtures/generation/edgecase/return-with-retainlines-and-compact-option/expected.js b/test/core/fixtures/generation/edgecase/return-with-retainlines-and-compact-option/expected.js new file mode 100644 index 0000000000..042f71356d --- /dev/null +++ b/test/core/fixtures/generation/edgecase/return-with-retainlines-and-compact-option/expected.js @@ -0,0 +1,4 @@ +function foo(l){ +return ( + +l);} diff --git a/test/core/fixtures/generation/edgecase/return-with-retainlines-and-compact-option/options.json b/test/core/fixtures/generation/edgecase/return-with-retainlines-and-compact-option/options.json new file mode 100644 index 0000000000..87138b0d7e --- /dev/null +++ b/test/core/fixtures/generation/edgecase/return-with-retainlines-and-compact-option/options.json @@ -0,0 +1,4 @@ +{ + "retainLines": true, + "compact": true +}