preserve parentheses for JSDoc type casting with extra spaces a… (#7011)
This commit is contained in:
1 parent
c9892675b3
commit
90eed411d4
4 files changed
+55
-1
No files matched your search
@@ -0,0 +1,18 @@
|
||||
#### Preserve parentheses for JSDoc type casting with extra spaces and asterisk at end ([#7011](https://github.com/prettier/prettier/pull/7011) by [@evilebottnawi](https://github.com/evilebottnawi))
|
||||
|
||||
Formatting of comments in labeled statements was not stable
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```javascript
|
||||
// Input
|
||||
const foo = /** @type {!Foo} **/ (baz);
|
||||
const bar = /** @type {!Foo} * * */(baz);
|
||||
|
||||
// Prettier stable
|
||||
const foo = /** @type {!Foo} **/ baz;
|
||||
const bar = /** @type {!Foo} * * */ baz;
|
||||
|
||||
// Prettier master
|
||||
const foo = /** @type {!Foo} **/ (baz);
|
||||
const bar = /** @type {!Foo} * * */ (baz);
|
||||
```
|
||||
@@ -53,7 +53,7 @@ function hasClosureCompilerTypeCastComment(text, path) {
|
||||
const cleaned = comment
|
||||
.trim()
|
||||
.split("\n")
|
||||
.map(line => line.replace(/^[\s*]+/, ""))
|
||||
.map(line => line.replace(/^[\s*]+/, "").replace(/[\s*]+$/, ""))
|
||||
.join(" ")
|
||||
.trim();
|
||||
if (!/^@type\s*\{[^]+\}$/.test(cleaned)) {
|
||||
|
||||
@@ -156,3 +156,31 @@ const v8 = /**@type{string} */ (value);
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`extra-spaces-and-asterisks.js 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
const foo1 = /** @type {!Foo} */(bar);
|
||||
const foo2 = /** @type {!Foo} **/(bar);
|
||||
const foo3 = /** @type {!Foo} * */(bar);
|
||||
const foo4 = /** @type {!Foo} ***/(bar);
|
||||
const foo5 = /** @type {!Foo} * * */(bar);
|
||||
const foo6 = /** @type {!Foo} *****/(bar);
|
||||
const foo7 = /** @type {!Foo} * * * * */(bar);
|
||||
const foo8 = /** @type {!Foo} ** * * */(bar);
|
||||
|
||||
=====================================output=====================================
|
||||
const foo1 = /** @type {!Foo} */ (bar);
|
||||
const foo2 = /** @type {!Foo} **/ (bar);
|
||||
const foo3 = /** @type {!Foo} * */ (bar);
|
||||
const foo4 = /** @type {!Foo} ***/ (bar);
|
||||
const foo5 = /** @type {!Foo} * * */ (bar);
|
||||
const foo6 = /** @type {!Foo} *****/ (bar);
|
||||
const foo7 = /** @type {!Foo} * * * * */ (bar);
|
||||
const foo8 = /** @type {!Foo} ** * * */ (bar);
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -0,0 +1,8 @@
|
||||
const foo1 = /** @type {!Foo} */(bar);
|
||||
const foo2 = /** @type {!Foo} **/(bar);
|
||||
const foo3 = /** @type {!Foo} * */(bar);
|
||||
const foo4 = /** @type {!Foo} ***/(bar);
|
||||
const foo5 = /** @type {!Foo} * * */(bar);
|
||||
const foo6 = /** @type {!Foo} *****/(bar);
|
||||
const foo7 = /** @type {!Foo} * * * * */(bar);
|
||||
const foo8 = /** @type {!Foo} ** * * */(bar);
|
||||
Reference in new issue
Block a user