Merge branch 'main' into next

# Conflicts:
#	docs/browser.md
#	package.json
#	src/language-js/comments/handle-comments.js
#	src/language-js/needs-parens.js
#	src/language-js/print/type-parameters.js
#	yarn.lock
This commit is contained in:
fisker Cheung committed 2023-02-08 12:37:23 +08:00
commit b1ef30dd17
18 files changed
+288 -123

No files matched your search

+2
View File
@@ -5,6 +5,8 @@
# See https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revs-fileltfilegt
# Prettier bump after release
# 2.8.4
f3b23ab63c9387329dc1993e1d0aa71583d67a0b
# 2.8.3
9e9f8ec13f0420a4825fdba85d79ddeaaef1e00c
# 2.8.2
+1 -1
View File
@@ -26,7 +26,7 @@ Don't fill the form below manually! Let a program create a report for you:
-->
**Prettier 2.8.3**
**Prettier 2.8.4**
[Playground link](https://prettier.io/playground/#.....)
```sh
+1 -1
View File
@@ -20,7 +20,7 @@ BEFORE SUBMITTING AN ISSUE:
**Environments:**
- Prettier Version: 2.8.3
- Prettier Version: 2.8.4
- Running Prettier via: <!-- CLI, Node.js API, Browser API, etc. -->
- Runtime: <!-- Node.js v14, Chrome v83, etc. -->
- Operating System: <!-- Windows, Linux, macOS, etc. -->
+123
View File
@@ -1,3 +1,126 @@
# 2.8.4
[diff](https://github.com/prettier/prettier/compare/2.8.3...2.8.4)
#### Fix leading comments in mapped types with `readonly` ([#13427](https://github.com/prettier/prettier/pull/13427) by [@thorn0](https://github.com/thorn0), [@sosukesuzuki](https://github.com/sosukesuzuki))
<!-- prettier-ignore -->
```tsx
// Input
type Type = {
// comment
readonly [key in Foo];
};
// Prettier 2.8.3
type Type = {
readonly // comment
[key in Foo];
};
// Prettier 2.8.4
type Type = {
// comment
readonly [key in Foo];
};
```
#### Group params in opening block statements ([#14067](https://github.com/prettier/prettier/pull/14067) by [@jamescdavis](https://github.com/jamescdavis))
This is a follow-up to #13930 to establish wrapping consistency between opening block statements and else blocks by
grouping params in opening blocks. This causes params to break to a new line together and not be split across lines
unless the length of params exceeds the print width. This also updates the else block wrapping to behave exactly the
same as opening blocks.
<!-- prettier-ignore -->
```hbs
{{! Input }}
{{#block param param param param param param param param param param as |blockParam|}}
Hello
{{else block param param param param param param param param param param as |blockParam|}}
There
{{/block}}
{{! Prettier 2.8.3 }}
{{#block
param
param
param
param
param
param
param
param
param
param
as |blockParam|
}}
Hello
{{else block param
param
param
param
param
param
param
param
param
param}}
There
{{/block}}
{{! Prettier 2.8.4 }}
{{#block
param param param param param param param param param param
as |blockParam|
}}
Hello
{{else block
param param param param param param param param param param
as |blockParam|
}}
There
{{/block}}
```
#### Ignore files in `.sl/` ([#14206](https://github.com/prettier/prettier/pull/14206) by [@bolinfest](https://github.com/bolinfest))
In [Sapling SCM](https://sapling-scm.com/), `.sl/` is the folder where it stores its state, analogous to `.git/` in Git. It should be ignored in Prettier like the other SCM folders.
#### Recognize `@satisfies` in Closure-style type casts ([#14262](https://github.com/prettier/prettier/pull/14262) by [@fisker](https://github.com/fisker))
<!-- prettier-ignore -->
```jsx
// Input
const a = /** @satisfies {Record<string, string>} */ ({hello: 1337});
const b = /** @type {Record<string, string>} */ ({hello: 1337});
// Prettier 2.8.3
const a = /** @satisfies {Record<string, string>} */ { hello: 1337 };
const b = /** @type {Record<string, string>} */ ({ hello: 1337 });
// Prettier 2.8.4
const a = /** @satisfies {Record<string, string>} */ ({hello: 1337});
const b = /** @type {Record<string, string>} */ ({hello: 1337});
```
#### Fix parens in inferred function return types with `extends` ([#14279](https://github.com/prettier/prettier/pull/14279) by [@fisker](https://github.com/fisker))
<!-- prettier-ignore -->
```ts
// Input
type Foo<T> = T extends ((a) => a is infer R extends string) ? R : never;
// Prettier 2.8.3 (First format)
type Foo<T> = T extends (a) => a is infer R extends string ? R : never;
// Prettier 2.8.3 (Second format)
SyntaxError: '?' expected.
// Prettier 2.8.4
type Foo<T> = T extends ((a) => a is infer R extends string) ? R : never;
```
# 2.8.3
[diff](https://github.com/prettier/prettier/compare/2.8.2...2.8.3)
-57
View File
@@ -1,57 +0,0 @@
#### Group params in opening block statements (#14067 by @jamescdavis)
This is a follow-up to #13930 to establish wrapping consistency between opening block statements and else blocks by
grouping params in opening blocks. This causes params to break to a new line together and not be split across lines
unless the length of params exceeds the print width. This also updates the else block wrapping to behave exactly the
same as opening blocks.
<!-- prettier-ignore -->
```hbs
{{! Input }}
{{#block param param param param param param param param param param as |blockParam|}}
Hello
{{else block param param param param param param param param param param as |blockParam|}}
There
{{/block}}
{{! Prettier stable }}
{{#block
param
param
param
param
param
param
param
param
param
param
as |blockParam|
}}
Hello
{{else block param
param
param
param
param
param
param
param
param
param}}
There
{{/block}}
{{! Prettier main }}
{{#block
param param param param param param param param param param
as |blockParam|
}}
Hello
{{else block
param param param param param param param param param param
as |blockParam|
}}
There
{{/block}}
```
+14 -14
View File
@@ -18,7 +18,7 @@ Required options:
- **[`parser`](options.md#parser) (or [`filepath`](options.md#file-path))**: One of these options has to be specified for Prettier to know which parser to use.
- **`plugins`**: Unlike the `format` function from the [Node.js-based API](api.md#prettierformatsource--options), this function doesn’t load plugins automatically. The `plugins` option is required because all the parsers included in the Prettier package come as plugins (for reasons of file size). These plugins are files in <https://unpkg.com/browse/prettier@2.8.0/plugins/>
- **`plugins`**: Unlike the `format` function from the [Node.js-based API](api.md#prettierformatsource--options), this function doesn’t load plugins automatically. The `plugins` option is required because all the parsers included in the Prettier package come as plugins (for reasons of file size). These plugins are files in <https://unpkg.com/browse/prettier@2.8.4/plugins/>
You need to load the ones that you’re going to use and pass them to `prettier.format` using the `plugins` option.
@@ -29,8 +29,8 @@ See below for examples.
### Global
```html
<script src="https://unpkg.com/prettier@2.8.3/standalone.js"></script>
<script src="https://unpkg.com/prettier@2.8.3/plugins/graphql.js"></script>
<script src="https://unpkg.com/prettier@2.8.4/standalone.js"></script>
<script src="https://unpkg.com/prettier@2.8.4/plugins/graphql.js"></script>
<script>
(async () => {
const formatted = await prettier.format("type Query { hello: String }", {
@@ -47,8 +47,8 @@ Note that the [`unpkg` field](https://unpkg.com/#examples) in Prettier’s `pack
```html
<script type="module">
import * as prettier from "https://unpkg.com/prettier@2.8.3/standalone.mjs";
import pluginGraphql from "https://unpkg.com/prettier@2.8.3/plugins/graphql.mjs";
import * as prettier from "https://unpkg.com/prettier@2.8.4/standalone.mjs";
import pluginGraphql from "https://unpkg.com/prettier@2.8.4/plugins/graphql.mjs";
const formatted = await prettier.format("type Query { hello: String }", {
parser: "graphql",
@@ -61,8 +61,8 @@ Note that the [`unpkg` field](https://unpkg.com/#examples) in Prettier’s `pack
```js
define([
"https://unpkg.com/prettier@2.8.3/standalone.js",
"https://unpkg.com/prettier@2.8.3/plugins/graphql.js",
"https://unpkg.com/prettier@2.8.4/standalone.js",
"https://unpkg.com/prettier@2.8.4/plugins/graphql.js",
], async (prettier, ...plugins) => {
const formatted = await prettier.format("type Query { hello: String }", {
parser: "graphql",
@@ -89,8 +89,8 @@ This syntax doesn’t necessarily work in the browser, but it can be used when b
### Worker
```js
importScripts("https://unpkg.com/prettier@2.8.3/standalone.js");
importScripts("https://unpkg.com/prettier@2.8.3/plugins/graphql.js");
importScripts("https://unpkg.com/prettier@2.8.4/standalone.js");
importScripts("https://unpkg.com/prettier@2.8.4/plugins/graphql.js");
(async () => {
const formatted = await prettier.format("type Query { hello: String }", {
parser: "graphql",
@@ -105,8 +105,8 @@ If you want to format [embedded code](options.md#embedded-language-formatting),
```html
<script type="module">
import * as prettier from "https://unpkg.com/prettier@2.8.3/standalone.mjs";
import pluginBabel from "https://unpkg.com/prettier@2.8.3/plugins/babel.mjs";
import * as prettier from "https://unpkg.com/prettier@2.8.4/standalone.mjs";
import pluginBabel from "https://unpkg.com/prettier@2.8.4/plugins/babel.mjs";
console.log(
await prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
@@ -122,9 +122,9 @@ The HTML code embedded in JavaScript stays unformatted because the `html` parser
```html
<script type="module">
import * as prettier from "https://unpkg.com/prettier@2.8.3/standalone.mjs";
import pluginBabel from "https://unpkg.com/prettier@2.8.3/plugins/babel.mjs";
import pluginHtml from "https://unpkg.com/prettier@2.8.3/plugins/html.mjs";
import * as prettier from "https://unpkg.com/prettier@2.8.4/standalone.mjs";
import pluginBabel from "https://unpkg.com/prettier@2.8.4/plugins/babel.mjs";
import pluginHtml from "https://unpkg.com/prettier@2.8.4/plugins/html.mjs";
console.log(
await prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
+3 -3
View File
@@ -449,9 +449,9 @@ Valid options:
- `"auto"` – Format embedded code if Prettier can automatically identify it.
- `"off"` - Never automatically format embedded code.
| Default | CLI Override | API Override |
| -------- | ------------------------------------ | ----------------------------------- |
| `"auto"` | `--embedded-language-formatting=off` | `embeddedLanguageFormatting: "off"` |
| Default | CLI Override | API Override |
| -------- | ----------------------------------------------------------- | ---------------------------------------------------------- |
| `"auto"` | <code>--embedded-language-formatting=<off&#124;auto></code> | <code>embeddedLanguageFormatting: "<off&#124;auto>"</code> |
## Single Attribute Per Line
+1 -1
View File
@@ -141,7 +141,7 @@
"magic-string": "0.27.0",
"npm-run-all": "4.1.5",
"path-browserify": "1.0.1",
"prettier": "2.8.3",
"prettier": "2.8.4",
"pretty-bytes": "6.1.0",
"rollup-plugin-license": "3.0.1",
"semver": "7.3.8",
+17 -9
View File
@@ -460,11 +460,6 @@ function needsParens(path, options) {
return false;
}
case "TSConditionalType":
if (key === "extendsType" && parent.type === "TSConditionalType") {
return true;
}
// fallthrough
case "TSFunctionType":
if (
path.match(
@@ -478,17 +473,30 @@ function needsParens(path, options) {
return true;
}
// fallthrough
case "TSConditionalType":
case "TSConstructorType":
if (key === "extendsType" && parent.type === "TSConditionalType") {
const returnTypeAnnotation = (node.returnType || node.typeAnnotation)
.typeAnnotation;
if (node.type === "TSConditionalType") {
return true;
}
let { typeAnnotation } = node.returnType || node.typeAnnotation;
if (
returnTypeAnnotation.type === "TSInferType" &&
returnTypeAnnotation.typeParameter.constraint
typeAnnotation.type === "TSTypePredicate" &&
typeAnnotation.typeAnnotation
) {
typeAnnotation = typeAnnotation.typeAnnotation.typeAnnotation;
}
if (
typeAnnotation.type === "TSInferType" &&
typeAnnotation.typeParameter.constraint
) {
return true;
}
}
if (key === "checkType" && parent.type === "TSConditionalType") {
return true;
}
@@ -14,8 +14,8 @@ function isTypeCastComment(comment) {
comment.value[0] === "*" &&
// TypeScript expects the type to be enclosed in curly brackets, however
// Closure Compiler accepts types in parens and even without any delimiters at all.
// That's why we just search for "@type".
/@type\b/.test(comment.value)
// That's why we just search for "@type" and "@satisfies".
/@(?:type|satisfies)\b/.test(comment.value)
);
}
@@ -571,6 +571,24 @@ const objectWithComment2 = /** @type MyType */ (
================================================================================
`;
exports[`satisfies.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
| printWidth
=====================================input======================================
module.exports = /** @satisfies {Record<string, string>} */ ({
hello: 1337,
});
=====================================output=====================================
module.exports = /** @satisfies {Record<string, string>} */ ({
hello: 1337,
});
================================================================================
`;
exports[`styled-components.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
@@ -0,0 +1,3 @@
module.exports = /** @satisfies {Record<string, string>} */ ({
hello: 1337,
});
@@ -278,20 +278,6 @@ type Unpacked<T> = T extends (infer U)[]
================================================================================
`;
exports[`issue-13275.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
type Foo<T> = T extends ((...a: any[]) => infer R extends string) ? R : never;
=====================================output=====================================
type Foo<T> = T extends ((...a: any[]) => infer R extends string) ? R : never;
================================================================================
`;
exports[`nested-in-condition.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
@@ -431,3 +417,57 @@ type Unpacked<T> = T extends (infer U)[]
================================================================================
`;
exports[`parentheses.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
// #13275
type Foo<T> = T extends ((...a: any[]) => infer R extends string) ? R : never;
type Foo<T> = T extends (new (...a: any[]) => infer R extends string) ? R : never;
// #14275
type Test<T> = T extends ((
token: TSESTree.Token
) => token is infer U extends TSESTree.Token)
? U
: TSESTree.Token;
type Test<T> = T extends ((
token: TSESTree.Token
) => asserts token is infer U extends TSESTree.Token)
? U
: TSESTree.Token;
type Test<T> = T extends (new (
token: TSESTree.Token
) => token is infer U extends TSESTree.Token)
? U
: TSESTree.Token;
=====================================output=====================================
// #13275
type Foo<T> = T extends ((...a: any[]) => infer R extends string) ? R : never;
type Foo<T> = T extends (new (...a: any[]) => infer R extends string)
? R
: never;
// #14275
type Test<T> = T extends ((
token: TSESTree.Token,
) => token is infer U extends TSESTree.Token)
? U
: TSESTree.Token;
type Test<T> = T extends ((
token: TSESTree.Token,
) => asserts token is infer U extends TSESTree.Token)
? U
: TSESTree.Token;
type Test<T> = T extends (new (
token: TSESTree.Token,
) => token is infer U extends TSESTree.Token)
? U
: TSESTree.Token;
================================================================================
`;
@@ -1 +0,0 @@
type Foo<T> = T extends ((...a: any[]) => infer R extends string) ? R : never;
@@ -0,0 +1,20 @@
// #13275
type Foo<T> = T extends ((...a: any[]) => infer R extends string) ? R : never;
type Foo<T> = T extends (new (...a: any[]) => infer R extends string) ? R : never;
// #14275
type Test<T> = T extends ((
token: TSESTree.Token
) => token is infer U extends TSESTree.Token)
? U
: TSESTree.Token;
type Test<T> = T extends ((
token: TSESTree.Token
) => asserts token is infer U extends TSESTree.Token)
? U
: TSESTree.Token;
type Test<T> = T extends (new (
token: TSESTree.Token
) => token is infer U extends TSESTree.Token)
? U
: TSESTree.Token;
@@ -21,8 +21,8 @@ Required options:
- **`plugins`**: Unlike the `format` function from the [Node.js-based API](api.md#prettierformatsource--options), this function doesn’t load plugins automatically. The `plugins` option is required because all the parsers included in the Prettier package come as plugins (for reasons of file size). These plugins are files named
- `parser-*.js` in <https://unpkg.com/browse/prettier@2.8.3/> and
- `parser-*.mjs` in <https://unpkg.com/browse/prettier@2.8.3/esm/>
- `parser-*.js` in <https://unpkg.com/browse/prettier@2.8.4/> and
- `parser-*.mjs` in <https://unpkg.com/browse/prettier@2.8.4/esm/>
You need to load the ones that you’re going to use and pass them to `prettier.format` using the `plugins` option.
@@ -33,8 +33,8 @@ See below for examples.
### Global
```html
<script src="https://unpkg.com/prettier@2.8.3/standalone.js"></script>
<script src="https://unpkg.com/prettier@2.8.3/parser-graphql.js"></script>
<script src="https://unpkg.com/prettier@2.8.4/standalone.js"></script>
<script src="https://unpkg.com/prettier@2.8.4/parser-graphql.js"></script>
<script>
prettier.format("type Query { hello: String }", {
parser: "graphql",
@@ -49,8 +49,8 @@ Note that the [`unpkg` field](https://unpkg.com/#examples) in Prettier’s `pack
```html
<script type="module">
import prettier from "https://unpkg.com/prettier@2.8.3/esm/standalone.mjs";
import parserGraphql from "https://unpkg.com/prettier@2.8.3/esm/parser-graphql.mjs";
import prettier from "https://unpkg.com/prettier@2.8.4/esm/standalone.mjs";
import parserGraphql from "https://unpkg.com/prettier@2.8.4/esm/parser-graphql.mjs";
prettier.format("type Query { hello: String }", {
parser: "graphql",
@@ -63,8 +63,8 @@ Note that the [`unpkg` field](https://unpkg.com/#examples) in Prettier’s `pack
```js
define([
"https://unpkg.com/prettier@2.8.3/standalone.js",
"https://unpkg.com/prettier@2.8.3/parser-graphql.js",
"https://unpkg.com/prettier@2.8.4/standalone.js",
"https://unpkg.com/prettier@2.8.4/parser-graphql.js",
], (prettier, ...plugins) => {
prettier.format("type Query { hello: String }", {
parser: "graphql",
@@ -89,8 +89,8 @@ This syntax doesn’t necessarily work in the browser, but it can be used when b
### Worker
```js
importScripts("https://unpkg.com/prettier@2.8.3/standalone.js");
importScripts("https://unpkg.com/prettier@2.8.3/parser-graphql.js");
importScripts("https://unpkg.com/prettier@2.8.4/standalone.js");
importScripts("https://unpkg.com/prettier@2.8.4/parser-graphql.js");
prettier.format("type Query { hello: String }", {
parser: "graphql",
plugins: prettierPlugins,
@@ -103,8 +103,8 @@ If you want to format [embedded code](options.md#embedded-language-formatting),
```html
<script type="module">
import prettier from "https://unpkg.com/prettier@2.8.3/esm/standalone.mjs";
import parserBabel from "https://unpkg.com/prettier@2.8.3/esm/parser-babel.mjs";
import prettier from "https://unpkg.com/prettier@2.8.4/esm/standalone.mjs";
import parserBabel from "https://unpkg.com/prettier@2.8.4/esm/parser-babel.mjs";
console.log(
prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
@@ -120,9 +120,9 @@ The HTML code embedded in JavaScript stays unformatted because the `html` parser
```html
<script type="module">
import prettier from "https://unpkg.com/prettier@2.8.3/esm/standalone.mjs";
import parserBabel from "https://unpkg.com/prettier@2.8.3/esm/parser-babel.mjs";
import parserHtml from "https://unpkg.com/prettier@2.8.3/esm/parser-html.mjs";
import prettier from "https://unpkg.com/prettier@2.8.4/esm/standalone.mjs";
import parserBabel from "https://unpkg.com/prettier@2.8.4/esm/parser-babel.mjs";
import parserHtml from "https://unpkg.com/prettier@2.8.4/esm/parser-html.mjs";
console.log(
prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
@@ -450,9 +450,9 @@ Valid options:
- `"auto"` – Format embedded code if Prettier can automatically identify it.
- `"off"` - Never automatically format embedded code.
| Default | CLI Override | API Override |
| -------- | ------------------------------------ | ----------------------------------- |
| `"auto"` | `--embedded-language-formatting=off` | `embeddedLanguageFormatting: "off"` |
| Default | CLI Override | API Override |
| -------- | ----------------------------------------------------------- | ---------------------------------------------------------- |
| `"auto"` | <code>--embedded-language-formatting=<off&#124;auto></code> | <code>embeddedLanguageFormatting: "<off&#124;auto>"</code> |
## Single Attribute Per Line
+11 -2
View File
@@ -7103,7 +7103,16 @@ __metadata:
languageName: node
linkType: hard
"prettier@npm:2.8.3, prettier@npm:^2.8.3":
"prettier@npm:2.8.4":
version: 2.8.4
resolution: "prettier@npm:2.8.4"
bin:
prettier: bin-prettier.js
checksum: c173064bf3df57b6d93d19aa98753b9b9dd7657212e33b41ada8e2e9f9884066bb9ca0b4005b89b3ab137efffdf8fbe0b462785aba20364798ff4303aadda57e
languageName: node
linkType: hard
"prettier@npm:^2.8.3":
version: 2.8.3
resolution: "prettier@npm:2.8.3"
bin:
@@ -7212,7 +7221,7 @@ __metadata:
postcss-scss: 4.0.6
postcss-selector-parser: 2.2.3
postcss-values-parser: 2.0.1
prettier: 2.8.3
prettier: 2.8.4
pretty-bytes: 6.1.0
regexp-util: 1.2.2
remark-footnotes: 2.0.0