Bugfix/ Don't inline pipeline operator with leading ownline comment (#5015)

* don't inline pipeline operator with leading ownline comment

* Add tests for comments surrounded with binary expressions

* Add babylon test for ownlinecomment with pipeline operator
master
Felix Wu 2018-09-02 00:38:19 +02:00 committed by Jed Fox
parent db2bc3636d
commit e86f08555a
6 changed files with 243 additions and 1 deletions

View File

@ -5204,7 +5204,9 @@ function printBinaryishExpressions(
}
const shouldInline = shouldInlineLogicalExpression(node);
const lineBeforeOperator = node.operator === "|>";
const lineBeforeOperator =
node.operator === "|>" &&
!hasLeadingOwnLineComment(options.originalText, node.right, options);
const right = shouldInline
? concat([node.operator, " ", path.call(print, "right")])

View File

@ -35,6 +35,153 @@ const foo = {
`;
exports[`binary-expressions.js - flow-verify 1`] = `
function addition() {
0
// Comment
+ x
}
function multiplication() {
0
// Comment
* x
}
function division() {
0
// Comment
/ x
}
function substraction() {
0
// Comment
- x
}
function remainder() {
0
// Comment
% x
}
function exponentiation() {
0
// Comment
** x
}
function leftShift() {
0
// Comment
<< x
}
function rightShift() {
0
// Comment
>> x
}
function unsignedRightShift() {
0
// Comment
>>> x
}
function bitwiseAnd() {
0
// Comment
& x
}
function bitwiseOr() {
0
// Comment
| x
}
function bitwiseXor() {
0
// Comment
^ x
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function addition() {
0 +
// Comment
x;
}
function multiplication() {
0 *
// Comment
x;
}
function division() {
0 /
// Comment
x;
}
function substraction() {
0 -
// Comment
x;
}
function remainder() {
0 %
// Comment
x;
}
function exponentiation() {
0 **
// Comment
x;
}
function leftShift() {
0 <<
// Comment
x;
}
function rightShift() {
0 >>
// Comment
x;
}
function unsignedRightShift() {
0 >>>
// Comment
x;
}
function bitwiseAnd() {
0 &
// Comment
x;
}
function bitwiseOr() {
0 |
// Comment
x;
}
function bitwiseXor() {
0 ^
// Comment
x;
}
`;
exports[`blank.js - flow-verify 1`] = `
// This file only
// has comments. This comment

View File

@ -0,0 +1,71 @@
function addition() {
0
// Comment
+ x
}
function multiplication() {
0
// Comment
* x
}
function division() {
0
// Comment
/ x
}
function substraction() {
0
// Comment
- x
}
function remainder() {
0
// Comment
% x
}
function exponentiation() {
0
// Comment
** x
}
function leftShift() {
0
// Comment
<< x
}
function rightShift() {
0
// Comment
>> x
}
function unsignedRightShift() {
0
// Comment
>>> x
}
function bitwiseAnd() {
0
// Comment
& x
}
function bitwiseOr() {
0
// Comment
| x
}
function bitwiseXor() {
0
// Comment
^ x
}

View File

@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`pipeline_own_line.js - babylon-verify 1`] = `
function pipeline() {
0
// Comment
|> x
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function pipeline() {
0 |>
// Comment
x;
}
`;

View File

@ -0,0 +1 @@
run_spec(__dirname, ["babylon"]);

View File

@ -0,0 +1,5 @@
function pipeline() {
0
// Comment
|> x
}