Consistent formatting for "new expression" with type cast (#18507)
This commit is contained in:
1 parent
d4ed917542
commit
9bf7f1b971
5 files changed
+114
-8
No files matched your search
@@ -0,0 +1,45 @@
|
||||
#### Fix formatting for new expression with type cast (#18507 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```tsx
|
||||
// Input
|
||||
new (require("./webpack/plugins/next-trace-entrypoints-plugin")
|
||||
.TraceEntryPointsPlugin as P)({
|
||||
rootDir: dir,
|
||||
});
|
||||
|
||||
(
|
||||
require("./webpack/plugins/next-trace-entrypoints-plugin")
|
||||
.TraceEntryPointsPlugin as P
|
||||
)({
|
||||
rootDir: dir,
|
||||
});
|
||||
|
||||
// Prettier stable
|
||||
new (require("./webpack/plugins/next-trace-entrypoints-plugin")
|
||||
.TraceEntryPointsPlugin as P)({
|
||||
rootDir: dir,
|
||||
});
|
||||
|
||||
(
|
||||
require("./webpack/plugins/next-trace-entrypoints-plugin")
|
||||
.TraceEntryPointsPlugin as P
|
||||
)({
|
||||
rootDir: dir,
|
||||
});
|
||||
|
||||
// Prettier main
|
||||
new (
|
||||
require("./webpack/plugins/next-trace-entrypoints-plugin")
|
||||
.TraceEntryPointsPlugin as P
|
||||
)({
|
||||
rootDir: dir,
|
||||
});
|
||||
|
||||
(
|
||||
require("./webpack/plugins/next-trace-entrypoints-plugin")
|
||||
.TraceEntryPointsPlugin as P
|
||||
)({
|
||||
rootDir: dir,
|
||||
});
|
||||
```
|
||||
@@ -26,7 +26,8 @@ function printBinaryCastExpression(path, options, print) {
|
||||
];
|
||||
|
||||
if (
|
||||
(key === "callee" && isCallExpression(parent)) ||
|
||||
(key === "callee" &&
|
||||
(isCallExpression(parent) || parent.type === "NewExpression")) ||
|
||||
(key === "object" && isMemberExpression(parent))
|
||||
) {
|
||||
return group([indent([softline, ...parts]), softline]);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
new (require("./webpack/plugins/next-trace-entrypoints-plugin")
|
||||
.TraceEntryPointsPlugin as P)({
|
||||
rootDir: dir,
|
||||
});
|
||||
|
||||
(require("./webpack/plugins/next-trace-entrypoints-plugin")
|
||||
.TraceEntryPointsPlugin as P)({
|
||||
rootDir: dir,
|
||||
});
|
||||
|
||||
(require("./webpack/plugins/next-trace-entrypoints-plugin")
|
||||
?.TraceEntryPointsPlugin as P)?.({
|
||||
rootDir: dir,
|
||||
});
|
||||
@@ -1,8 +1,54 @@
|
||||
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
||||
|
||||
exports[`18406.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
new (require("./webpack/plugins/next-trace-entrypoints-plugin")
|
||||
.TraceEntryPointsPlugin as P)({
|
||||
rootDir: dir,
|
||||
});
|
||||
|
||||
(require("./webpack/plugins/next-trace-entrypoints-plugin")
|
||||
.TraceEntryPointsPlugin as P)({
|
||||
rootDir: dir,
|
||||
});
|
||||
|
||||
(require("./webpack/plugins/next-trace-entrypoints-plugin")
|
||||
?.TraceEntryPointsPlugin as P)?.({
|
||||
rootDir: dir,
|
||||
});
|
||||
|
||||
=====================================output=====================================
|
||||
new (
|
||||
require("./webpack/plugins/next-trace-entrypoints-plugin")
|
||||
.TraceEntryPointsPlugin as P
|
||||
)({
|
||||
rootDir: dir,
|
||||
});
|
||||
|
||||
(
|
||||
require("./webpack/plugins/next-trace-entrypoints-plugin")
|
||||
.TraceEntryPointsPlugin as P
|
||||
)({
|
||||
rootDir: dir,
|
||||
});
|
||||
|
||||
(
|
||||
require("./webpack/plugins/next-trace-entrypoints-plugin")
|
||||
?.TraceEntryPointsPlugin as P
|
||||
)?.({
|
||||
rootDir: dir,
|
||||
});
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`array-and-object.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel-ts", "typescript"]
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
@@ -22,7 +68,7 @@ testObjLiteral = <PermissionsChecker<any> | undefined>{ prop1: "myPropVal" };
|
||||
|
||||
exports[`as-const.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel-ts", "typescript"]
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
@@ -44,7 +90,7 @@ let x = "123" as const;
|
||||
|
||||
exports[`assert-and-assign.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel-ts", "typescript"]
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
@@ -59,7 +105,7 @@ printWidth: 80
|
||||
|
||||
exports[`generic-cast.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel-ts", "typescript"]
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
@@ -312,7 +358,7 @@ function x() {
|
||||
|
||||
exports[`hug-args.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel-ts", "typescript"]
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
@@ -362,7 +408,7 @@ postMessages(<IActionMessage[]>[
|
||||
|
||||
exports[`parenthesis.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel-ts", "typescript"]
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
|
||||
@@ -1 +1 @@
|
||||
runFormatTest(import.meta, ["babel-ts", "typescript"]);
|
||||
runFormatTest(import.meta, ["typescript"]);
|
||||
Reference in new issue
Block a user