Improve formatting for do expression (#10693)

This commit is contained in:
Sosuke Suzuki authored and GitHub committed 2021-04-12 04:22:44 +03:00
1 parent 07ae0134e5
commit 0cdc62e405
4 files changed
+175 -1

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
#### Improve formatting for do expression (#10693 by @sosukesuzuki)
<!-- prettier-ignore -->
```js
// Input
expect(do {
var bar = "foo";
bar;
}).toBe("foo");
// Prettier stable
expect(
do {
var bar = "foo";
bar;
}
).toBe("foo");
// Prettier main
expect(do {
var bar = "foo";
bar;
}).toBe("foo");
```
+2 -1
View File
@@ -247,7 +247,8 @@ function couldGroupArg(arg, arrowChainRecursion = false) {
(!arrowChainRecursion &&
(isCallExpression(arg.body) ||
arg.body.type === "ConditionalExpression")) ||
isJsxNode(arg.body)))
isJsxNode(arg.body))) ||
arg.type === "DoExpression"
);
}
@@ -1,5 +1,113 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`call-arguments.js [espree] format 1`] = `
"Unexpected token do (3:3)
1 | // from https://github.com/babel/babel/pull/13122/
2 | expect(
> 3 | do {
| ^
4 | var bar = \\"foo\\";
5 | if (!bar) throw new Error(
6 | \\"unreachable\\""
`;
exports[`call-arguments.js [meriyah] format 1`] = `
"[3:4]: Unexpected token: 'do' (3:4)
1 | // from https://github.com/babel/babel/pull/13122/
2 | expect(
> 3 | do {
| ^
4 | var bar = \\"foo\\";
5 | if (!bar) throw new Error(
6 | \\"unreachable\\""
`;
exports[`call-arguments.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
| printWidth
=====================================input======================================
// from https://github.com/babel/babel/pull/13122/
expect(
do {
var bar = "foo";
if (!bar) throw new Error(
"unreachable"
)
bar;
}
).toBe("foo");
expect(bar).toBe("foo");
var x = do {
var bar = "foo";
if (!bar) throw new Error(
"unreachable"
)
bar;
};
expect(
do {
var bar = "foo";
bar;
}
).toBe("foo");
expect(bar).toBe("foo");
var x = do {
var bar = "foo";
bar;
};
expect(
() => do {
() => {
var bar = "foo";
};
bar;
}
).toThrow(ReferenceError);
=====================================output=====================================
// from https://github.com/babel/babel/pull/13122/
expect(do {
var bar = "foo";
if (!bar) throw new Error("unreachable");
bar;
}).toBe("foo");
expect(bar).toBe("foo");
var x = do {
var bar = "foo";
if (!bar) throw new Error("unreachable");
bar;
};
expect(do {
var bar = "foo";
bar;
}).toBe("foo");
expect(bar).toBe("foo");
var x = do {
var bar = "foo";
bar;
};
expect(
() => do {
() => {
var bar = "foo";
};
bar;
}
).toThrow(ReferenceError);
================================================================================
`;
exports[`do.js [espree] format 1`] = `
"Unexpected token do (3:5)
1 | const envSpecific = {
+41
View File
@@ -0,0 +1,41 @@
// from https://github.com/babel/babel/pull/13122/
expect(
do {
var bar = "foo";
if (!bar) throw new Error(
"unreachable"
)
bar;
}
).toBe("foo");
expect(bar).toBe("foo");
var x = do {
var bar = "foo";
if (!bar) throw new Error(
"unreachable"
)
bar;
};
expect(
do {
var bar = "foo";
bar;
}
).toBe("foo");
expect(bar).toBe("foo");
var x = do {
var bar = "foo";
bar;
};
expect(
() => do {
() => {
var bar = "foo";
};
bar;
}
).toThrow(ReferenceError);