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 operatormaster
parent
db2bc3636d
commit
e86f08555a
|
@ -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")])
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
`;
|
|
@ -0,0 +1 @@
|
|||
run_spec(__dirname, ["babylon"]);
|
|
@ -0,0 +1,5 @@
|
|||
function pipeline() {
|
||||
0
|
||||
// Comment
|
||||
|> x
|
||||
}
|
Loading…
Reference in New Issue