Fix formatting of ternary (#15679)
This commit is contained in:
1 parent
3728294246
commit
ddf223a3ff
6 files changed
+70
No files matched your search
@@ -0,0 +1,19 @@
|
||||
#### Fix formatting of ternary in function call (#15677 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```jsx
|
||||
// Input
|
||||
stopDirectory = await (useCache
|
||||
? memoizedFindProjectRoot
|
||||
: findProjectRootWithoutCache)(path.dirname(path.resolve(filePath)));
|
||||
|
||||
// Prettier stable
|
||||
stopDirectory = await (useCache
|
||||
? memoizedFindProjectRoot
|
||||
: findProjectRootWithoutCache)(path.dirname(path.resolve(filePath)));
|
||||
|
||||
// Prettier main
|
||||
stopDirectory = await (
|
||||
useCache ? memoizedFindProjectRoot : findProjectRootWithoutCache
|
||||
)(path.dirname(path.resolve(filePath)));
|
||||
```
|
||||
@@ -137,6 +137,7 @@ const ancestorNameMap = new Map([
|
||||
["ThrowStatement", "argument"],
|
||||
["UnaryExpression", "argument"],
|
||||
["YieldExpression", "argument"],
|
||||
["AwaitExpression", "argument"],
|
||||
]);
|
||||
function shouldExtraIndentForConditionalExpression(path) {
|
||||
const { node } = path;
|
||||
|
||||
@@ -76,6 +76,7 @@ const ancestorNameMap = new Map([
|
||||
["ThrowStatement", "argument"],
|
||||
["UnaryExpression", "argument"],
|
||||
["YieldExpression", "argument"],
|
||||
["AwaitExpression", "argument"],
|
||||
]);
|
||||
/**
|
||||
* Do we want to wrap the entire ternary in its own indent?
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`await-expression.js - {"experimentalTernaries":true} format 1`] = `
|
||||
====================================options=====================================
|
||||
experimentalTernaries: true
|
||||
parsers: ["babel"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
stopDirectory = await (useCache
|
||||
? memoizedFindProjectRoot
|
||||
: findProjectRootWithoutCache)(path.dirname(path.resolve(filePath)));
|
||||
|
||||
=====================================output=====================================
|
||||
stopDirectory = await (
|
||||
useCache ?
|
||||
memoizedFindProjectRoot
|
||||
: findProjectRootWithoutCache)(path.dirname(path.resolve(filePath)));
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`await-expression.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
stopDirectory = await (useCache
|
||||
? memoizedFindProjectRoot
|
||||
: findProjectRootWithoutCache)(path.dirname(path.resolve(filePath)));
|
||||
|
||||
=====================================output=====================================
|
||||
stopDirectory = await (
|
||||
useCache ? memoizedFindProjectRoot : findProjectRootWithoutCache
|
||||
)(path.dirname(path.resolve(filePath)));
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -0,0 +1,3 @@
|
||||
stopDirectory = await (useCache
|
||||
? memoizedFindProjectRoot
|
||||
: findProjectRootWithoutCache)(path.dirname(path.resolve(filePath)));
|
||||
@@ -0,0 +1,7 @@
|
||||
const parsers = [
|
||||
// Didn't test flow and typescript since they can't parse `await (a ? b : c)` correctly
|
||||
"babel", // "flow", "typescript"
|
||||
];
|
||||
|
||||
run_spec(import.meta, parsers);
|
||||
run_spec(import.meta, parsers, { experimentalTernaries: true });
|
||||
Reference in new issue
Block a user