Fix comment in destructuring patterns for Flow parser (#19902)
This commit is contained in:
1 parent
9f114788fd
commit
055dba4258
6 files changed
+200
-168
No files matched your search
@@ -0,0 +1,31 @@
|
||||
#### Fix comment in destructuring patterns (#19902 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```flow
|
||||
// Input
|
||||
const {
|
||||
foo,
|
||||
// bar
|
||||
// baz
|
||||
}: Foo = expr;
|
||||
|
||||
// Prettier stable (First format)
|
||||
const {
|
||||
foo1,
|
||||
} // bar
|
||||
// baz
|
||||
: Foo = expr;
|
||||
|
||||
// Prettier stable (Second format)
|
||||
const {
|
||||
foo1, // bar
|
||||
} // baz
|
||||
: Foo = expr;
|
||||
|
||||
// Prettier main
|
||||
const {
|
||||
foo1,
|
||||
// bar
|
||||
// baz
|
||||
}: Foo = expr;
|
||||
```
|
||||
@@ -989,7 +989,8 @@ function handleCommentsInDestructuringPattern({
|
||||
if (
|
||||
(enclosingNode?.type === "ObjectPattern" ||
|
||||
enclosingNode?.type === "ArrayPattern") &&
|
||||
followingNode?.type === "TSTypeAnnotation"
|
||||
(followingNode?.type === "TSTypeAnnotation" ||
|
||||
followingNode?.type === "TypeAnnotation")
|
||||
) {
|
||||
if (precedingNode) {
|
||||
addTrailingComment(precedingNode, comment);
|
||||
|
||||
@@ -69,46 +69,6 @@ type D2 =
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`11639.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
const foo = forwardRef<any>(({
|
||||
// foo
|
||||
size,
|
||||
// onClose,
|
||||
// onOpen,
|
||||
}: PopoverProps,
|
||||
) => {})
|
||||
|
||||
export function Component({
|
||||
prop,
|
||||
// comment
|
||||
}: Type) {
|
||||
return div;
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
const foo = forwardRef<any>(
|
||||
({
|
||||
// foo
|
||||
size,
|
||||
// onClose,
|
||||
// onOpen,
|
||||
}: PopoverProps) => {},
|
||||
);
|
||||
|
||||
export function Component({
|
||||
prop,
|
||||
// comment
|
||||
}: Type) {
|
||||
return div;
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`11662.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
@@ -136,127 +96,6 @@ foo<a>
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`15707.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
const {
|
||||
foo,
|
||||
// bar
|
||||
// baz
|
||||
}: Foo = expr;
|
||||
|
||||
const {
|
||||
foo1,
|
||||
// bar
|
||||
foo2,
|
||||
// baz
|
||||
}: Foo = expr;
|
||||
|
||||
const [
|
||||
foo,
|
||||
// bar
|
||||
// baz
|
||||
]: Foo = expr;
|
||||
|
||||
const [
|
||||
foo1,
|
||||
// bar
|
||||
foo2,
|
||||
// baz
|
||||
]: Foo = expr;
|
||||
|
||||
function method({
|
||||
foo,
|
||||
// bar = "bar",
|
||||
// bazz = "bazz",
|
||||
}: Foo) {}
|
||||
|
||||
function method({
|
||||
foo1,
|
||||
// bar = "bar",
|
||||
foo2
|
||||
// bazz = "bazz",
|
||||
}: Foo) {}
|
||||
|
||||
function method([
|
||||
foo,
|
||||
// bar = "bar",
|
||||
foo2
|
||||
// bazz = "bazz",
|
||||
]: Foo) {}
|
||||
|
||||
const {
|
||||
// bar
|
||||
// baz
|
||||
}: Foo = expr;
|
||||
|
||||
const [
|
||||
// bar
|
||||
// baz
|
||||
]: Foo = expr;
|
||||
|
||||
=====================================output=====================================
|
||||
const {
|
||||
foo,
|
||||
// bar
|
||||
// baz
|
||||
}: Foo = expr;
|
||||
|
||||
const {
|
||||
foo1,
|
||||
// bar
|
||||
foo2,
|
||||
// baz
|
||||
}: Foo = expr;
|
||||
|
||||
const [
|
||||
foo,
|
||||
// bar
|
||||
// baz
|
||||
]: Foo = expr;
|
||||
|
||||
const [
|
||||
foo1,
|
||||
// bar
|
||||
foo2,
|
||||
// baz
|
||||
]: Foo = expr;
|
||||
|
||||
function method({
|
||||
foo,
|
||||
// bar = "bar",
|
||||
// bazz = "bazz",
|
||||
}: Foo) {}
|
||||
|
||||
function method({
|
||||
foo1,
|
||||
// bar = "bar",
|
||||
foo2,
|
||||
// bazz = "bazz",
|
||||
}: Foo) {}
|
||||
|
||||
function method([
|
||||
foo,
|
||||
// bar = "bar",
|
||||
foo2,
|
||||
// bazz = "bazz",
|
||||
]: Foo) {}
|
||||
|
||||
const {
|
||||
// bar
|
||||
// baz
|
||||
}: Foo = expr;
|
||||
|
||||
const [
|
||||
// bar
|
||||
// baz
|
||||
]: Foo = expr;
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`16065.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
|
||||
File renamed without changes.
+6
-6
@@ -1,26 +1,26 @@
|
||||
const {
|
||||
foo,
|
||||
foo11,
|
||||
// bar
|
||||
// baz
|
||||
}: Foo = expr;
|
||||
|
||||
const {
|
||||
foo1,
|
||||
foo21,
|
||||
// bar
|
||||
foo2,
|
||||
foo22,
|
||||
// baz
|
||||
}: Foo = expr;
|
||||
|
||||
const [
|
||||
foo,
|
||||
foo31,
|
||||
// bar
|
||||
// baz
|
||||
]: Foo = expr;
|
||||
|
||||
const [
|
||||
foo1,
|
||||
foo41,
|
||||
// bar
|
||||
foo2,
|
||||
foo42,
|
||||
// baz
|
||||
]: Foo = expr;
|
||||
|
||||
+161
@@ -1,5 +1,166 @@
|
||||
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
||||
|
||||
exports[`11639.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript", "flow"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
const foo = forwardRef<any>(({
|
||||
// foo
|
||||
size,
|
||||
// onClose,
|
||||
// onOpen,
|
||||
}: PopoverProps,
|
||||
) => {})
|
||||
|
||||
export function Component({
|
||||
prop,
|
||||
// comment
|
||||
}: Type) {
|
||||
return div;
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
const foo = forwardRef<any>(
|
||||
({
|
||||
// foo
|
||||
size,
|
||||
// onClose,
|
||||
// onOpen,
|
||||
}: PopoverProps) => {},
|
||||
);
|
||||
|
||||
export function Component({
|
||||
prop,
|
||||
// comment
|
||||
}: Type) {
|
||||
return div;
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`15707.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript", "flow"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
const {
|
||||
foo11,
|
||||
// bar
|
||||
// baz
|
||||
}: Foo = expr;
|
||||
|
||||
const {
|
||||
foo21,
|
||||
// bar
|
||||
foo22,
|
||||
// baz
|
||||
}: Foo = expr;
|
||||
|
||||
const [
|
||||
foo31,
|
||||
// bar
|
||||
// baz
|
||||
]: Foo = expr;
|
||||
|
||||
const [
|
||||
foo41,
|
||||
// bar
|
||||
foo42,
|
||||
// baz
|
||||
]: Foo = expr;
|
||||
|
||||
function method({
|
||||
foo,
|
||||
// bar = "bar",
|
||||
// bazz = "bazz",
|
||||
}: Foo) {}
|
||||
|
||||
function method({
|
||||
foo1,
|
||||
// bar = "bar",
|
||||
foo2
|
||||
// bazz = "bazz",
|
||||
}: Foo) {}
|
||||
|
||||
function method([
|
||||
foo,
|
||||
// bar = "bar",
|
||||
foo2
|
||||
// bazz = "bazz",
|
||||
]: Foo) {}
|
||||
|
||||
const {
|
||||
// bar
|
||||
// baz
|
||||
}: Foo = expr;
|
||||
|
||||
const [
|
||||
// bar
|
||||
// baz
|
||||
]: Foo = expr;
|
||||
|
||||
=====================================output=====================================
|
||||
const {
|
||||
foo11,
|
||||
// bar
|
||||
// baz
|
||||
}: Foo = expr;
|
||||
|
||||
const {
|
||||
foo21,
|
||||
// bar
|
||||
foo22,
|
||||
// baz
|
||||
}: Foo = expr;
|
||||
|
||||
const [
|
||||
foo31,
|
||||
// bar
|
||||
// baz
|
||||
]: Foo = expr;
|
||||
|
||||
const [
|
||||
foo41,
|
||||
// bar
|
||||
foo42,
|
||||
// baz
|
||||
]: Foo = expr;
|
||||
|
||||
function method({
|
||||
foo,
|
||||
// bar = "bar",
|
||||
// bazz = "bazz",
|
||||
}: Foo) {}
|
||||
|
||||
function method({
|
||||
foo1,
|
||||
// bar = "bar",
|
||||
foo2,
|
||||
// bazz = "bazz",
|
||||
}: Foo) {}
|
||||
|
||||
function method([
|
||||
foo,
|
||||
// bar = "bar",
|
||||
foo2,
|
||||
// bazz = "bazz",
|
||||
]: Foo) {}
|
||||
|
||||
const {
|
||||
// bar
|
||||
// baz
|
||||
}: Foo = expr;
|
||||
|
||||
const [
|
||||
// bar
|
||||
// baz
|
||||
]: Foo = expr;
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`after-jsx-generic.tsx format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript", "flow"]
|
||||
|
||||
Reference in new issue
Block a user