From f602be5a478a5bcdca870b31936dc873ecae1120 Mon Sep 17 00:00:00 2001 From: Riad Krim <752000+rkrim@users.noreply.github.com> Date: Tue, 31 Jan 2023 01:16:17 +0100 Subject: [PATCH 1/9] Update `embeddedLanguageFormatting` option documentation (#14048) --- docs/options.md | 6 +++--- website/versioned_docs/version-stable/options.md | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/options.md b/docs/options.md index 0e26e7d9e..58e4ee696 100644 --- a/docs/options.md +++ b/docs/options.md @@ -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"` | --embedded-language-formatting= | embeddedLanguageFormatting: "" | ## Single Attribute Per Line diff --git a/website/versioned_docs/version-stable/options.md b/website/versioned_docs/version-stable/options.md index 71112ffbd..f7d9ea5b3 100644 --- a/website/versioned_docs/version-stable/options.md +++ b/website/versioned_docs/version-stable/options.md @@ -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"` | --embedded-language-formatting= | embeddedLanguageFormatting: "" | ## Single Attribute Per Line From bc18fa439708fd16a359f83d903bffae6ff8b5aa Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 6 Feb 2023 11:17:48 +0800 Subject: [PATCH 2/9] Fix incorrect removal of parentheses when using an `infer` with a constraint in a function predicate (#14279) --- changelog_unreleased/typescript/14279.md | 16 +++++ src/language-js/needs-parens.js | 24 ++++--- .../__snapshots__/jsfmt.spec.js.snap | 68 +++++++++++++++---- .../conditional-types/issue-13275.ts | 1 - .../conditional-types/parentheses.ts | 20 ++++++ 5 files changed, 106 insertions(+), 23 deletions(-) create mode 100644 changelog_unreleased/typescript/14279.md delete mode 100644 tests/format/typescript/conditional-types/issue-13275.ts create mode 100644 tests/format/typescript/conditional-types/parentheses.ts diff --git a/changelog_unreleased/typescript/14279.md b/changelog_unreleased/typescript/14279.md new file mode 100644 index 000000000..b15c9c37e --- /dev/null +++ b/changelog_unreleased/typescript/14279.md @@ -0,0 +1,16 @@ +#### Fix parens in inferred function return types with `extends` (#14279 by @fisker) + + +```ts +// Input +type Foo = T extends ((a) => a is infer R extends string) ? R : never; + +// Prettier stable (First format) +type Foo = T extends (a) => a is infer R extends string ? R : never; + +// Prettier stable (Second format) +SyntaxError: '?' expected. + +// Prettier main +type Foo = T extends ((a) => a is infer R extends string) ? R : never; +``` diff --git a/src/language-js/needs-parens.js b/src/language-js/needs-parens.js index 0fd0207db..6155f0a79 100644 --- a/src/language-js/needs-parens.js +++ b/src/language-js/needs-parens.js @@ -466,22 +466,30 @@ function needsParens(path, options) { } case "TSConditionalType": - if (name === "extendsType" && parent.type === "TSConditionalType") { - return true; - } - // fallthrough case "TSFunctionType": case "TSConstructorType": if (name === "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 (name === "checkType" && parent.type === "TSConditionalType") { return true; } diff --git a/tests/format/typescript/conditional-types/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/conditional-types/__snapshots__/jsfmt.spec.js.snap index e598947c2..14c69d952 100644 --- a/tests/format/typescript/conditional-types/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/conditional-types/__snapshots__/jsfmt.spec.js.snap @@ -278,20 +278,6 @@ type Unpacked = T extends (infer U)[] ================================================================================ `; -exports[`issue-13275.ts format 1`] = ` -====================================options===================================== -parsers: ["typescript"] -printWidth: 80 - | printWidth -=====================================input====================================== -type Foo = T extends ((...a: any[]) => infer R extends string) ? R : never; - -=====================================output===================================== -type Foo = 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 extends (infer U)[] ================================================================================ `; + +exports[`parentheses.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +// #13275 +type Foo = T extends ((...a: any[]) => infer R extends string) ? R : never; +type Foo = T extends (new (...a: any[]) => infer R extends string) ? R : never; + +// #14275 +type Test = T extends (( + token: TSESTree.Token +) => token is infer U extends TSESTree.Token) + ? U + : TSESTree.Token; +type Test = T extends (( + token: TSESTree.Token +) => asserts token is infer U extends TSESTree.Token) + ? U + : TSESTree.Token; +type Test = T extends (new ( + token: TSESTree.Token +) => token is infer U extends TSESTree.Token) + ? U + : TSESTree.Token; + +=====================================output===================================== +// #13275 +type Foo = T extends ((...a: any[]) => infer R extends string) ? R : never; +type Foo = T extends (new (...a: any[]) => infer R extends string) + ? R + : never; + +// #14275 +type Test = T extends (( + token: TSESTree.Token +) => token is infer U extends TSESTree.Token) + ? U + : TSESTree.Token; +type Test = T extends (( + token: TSESTree.Token +) => asserts token is infer U extends TSESTree.Token) + ? U + : TSESTree.Token; +type Test = T extends (new ( + token: TSESTree.Token +) => token is infer U extends TSESTree.Token) + ? U + : TSESTree.Token; + +================================================================================ +`; diff --git a/tests/format/typescript/conditional-types/issue-13275.ts b/tests/format/typescript/conditional-types/issue-13275.ts deleted file mode 100644 index de1ccb285..000000000 --- a/tests/format/typescript/conditional-types/issue-13275.ts +++ /dev/null @@ -1 +0,0 @@ -type Foo = T extends ((...a: any[]) => infer R extends string) ? R : never; diff --git a/tests/format/typescript/conditional-types/parentheses.ts b/tests/format/typescript/conditional-types/parentheses.ts new file mode 100644 index 000000000..ea27b6710 --- /dev/null +++ b/tests/format/typescript/conditional-types/parentheses.ts @@ -0,0 +1,20 @@ +// #13275 +type Foo = T extends ((...a: any[]) => infer R extends string) ? R : never; +type Foo = T extends (new (...a: any[]) => infer R extends string) ? R : never; + +// #14275 +type Test = T extends (( + token: TSESTree.Token +) => token is infer U extends TSESTree.Token) + ? U + : TSESTree.Token; +type Test = T extends (( + token: TSESTree.Token +) => asserts token is infer U extends TSESTree.Token) + ? U + : TSESTree.Token; +type Test = T extends (new ( + token: TSESTree.Token +) => token is infer U extends TSESTree.Token) + ? U + : TSESTree.Token; From 9842b29ca3d9f9f6d27403d939f6d878e3228164 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 7 Feb 2023 15:19:09 +0800 Subject: [PATCH 3/9] Recognize `@satisfies` in Closure-style type casts (#14262) --- changelog_unreleased/javascript/14262.md | 16 ++++++++++++++++ src/language-js/comments.js | 17 +---------------- src/language-js/utils/is-type-cast-comment.js | 4 ++-- .../__snapshots__/jsfmt.spec.js.snap | 18 ++++++++++++++++++ .../js/comments-closure-typecast/satisfies.js | 3 +++ 5 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 changelog_unreleased/javascript/14262.md create mode 100644 tests/format/js/comments-closure-typecast/satisfies.js diff --git a/changelog_unreleased/javascript/14262.md b/changelog_unreleased/javascript/14262.md new file mode 100644 index 000000000..bbce6e74a --- /dev/null +++ b/changelog_unreleased/javascript/14262.md @@ -0,0 +1,16 @@ +#### Recognize `@satisfies` in Closure-style type casts (#14262 by @fisker) + + +```jsx +// Input +const a = /** @satisfies {Record} */ ({hello: 1337}); +const b = /** @type {Record} */ ({hello: 1337}); + +// Prettier stable +const a = /** @satisfies {Record} */ { hello: 1337 }; +const b = /** @type {Record} */ ({ hello: 1337 }); + +// Prettier main +const a = /** @satisfies {Record} */ ({hello: 1337}); +const b = /** @type {Record} */ ({hello: 1337}); +``` diff --git a/src/language-js/comments.js b/src/language-js/comments.js index cb6e151eb..a9b7f75d3 100644 --- a/src/language-js/comments.js +++ b/src/language-js/comments.js @@ -31,6 +31,7 @@ const { } = require("./utils/index.js"); const { locStart, locEnd } = require("./loc.js"); const isBlockComment = require("./utils/is-block-comment.js"); +const isTypeCastComment = require("./utils/is-type-cast-comment.js"); /** * @typedef {import("./types/estree").Node} Node @@ -955,21 +956,6 @@ function getCommentChildNodes(node, options) { } } -/** - * @param {Comment} comment - * @returns {boolean} - */ -function isTypeCastComment(comment) { - return ( - isBlockComment(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) - ); -} - /** * @param {AstPath} path * @returns {boolean} @@ -1005,7 +991,6 @@ module.exports = { handleOwnLineComment, handleEndOfLineComment, handleRemainingComment, - isTypeCastComment, getCommentChildNodes, willPrintOwnComments, }; diff --git a/src/language-js/utils/is-type-cast-comment.js b/src/language-js/utils/is-type-cast-comment.js index 4f0ad4dcf..c3d259089 100644 --- a/src/language-js/utils/is-type-cast-comment.js +++ b/src/language-js/utils/is-type-cast-comment.js @@ -16,8 +16,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) ); } diff --git a/tests/format/js/comments-closure-typecast/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/comments-closure-typecast/__snapshots__/jsfmt.spec.js.snap index 722445bec..7fc196e42 100644 --- a/tests/format/js/comments-closure-typecast/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/comments-closure-typecast/__snapshots__/jsfmt.spec.js.snap @@ -571,6 +571,24 @@ const objectWithComment2 = /** @type MyType */ ( ================================================================================ `; +exports[`satisfies.js format 1`] = ` +====================================options===================================== +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +module.exports = /** @satisfies {Record} */ ({ + hello: 1337, +}); + +=====================================output===================================== +module.exports = /** @satisfies {Record} */ ({ + hello: 1337, +}); + +================================================================================ +`; + exports[`styled-components.js format 1`] = ` ====================================options===================================== parsers: ["babel"] diff --git a/tests/format/js/comments-closure-typecast/satisfies.js b/tests/format/js/comments-closure-typecast/satisfies.js new file mode 100644 index 000000000..791fc7e47 --- /dev/null +++ b/tests/format/js/comments-closure-typecast/satisfies.js @@ -0,0 +1,3 @@ +module.exports = /** @satisfies {Record} */ ({ + hello: 1337, +}); From 399f2fae4037168adf5aa34ee1e32312758b4a68 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 8 Feb 2023 09:40:23 +0800 Subject: [PATCH 4/9] Add changelog for #14206 (#14311) --- changelog_unreleased/misc/14206.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog_unreleased/misc/14206.md diff --git a/changelog_unreleased/misc/14206.md b/changelog_unreleased/misc/14206.md new file mode 100644 index 000000000..ee77842c2 --- /dev/null +++ b/changelog_unreleased/misc/14206.md @@ -0,0 +1,3 @@ +#### Ignore files in `.sl/` (#14206 by @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. From 6bb24b2c5a0d6a4b511c1499705257bed60ffb35 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 8 Feb 2023 09:40:59 +0800 Subject: [PATCH 5/9] Fix leading comments in mapped types with `readonly` (Cherry-pick #13427) (#14310) --- changelog_unreleased/typescript/13427.md | 22 ++++ src/language-js/print/type-parameters.js | 7 ++ src/language-js/print/typescript.js | 7 -- .../__snapshots__/jsfmt.spec.js.snap | 113 ++++++++++++++++++ .../typescript/mapped-type/issue-11098.ts | 51 ++++++++ 5 files changed, 193 insertions(+), 7 deletions(-) create mode 100644 changelog_unreleased/typescript/13427.md create mode 100644 tests/format/typescript/mapped-type/issue-11098.ts diff --git a/changelog_unreleased/typescript/13427.md b/changelog_unreleased/typescript/13427.md new file mode 100644 index 000000000..96f9b91da --- /dev/null +++ b/changelog_unreleased/typescript/13427.md @@ -0,0 +1,22 @@ +#### Fix leading comments in mapped types with `readonly` (#13427 by @thorn0, @sosukesuzuki) + + +```tsx +// Input +type Type = { + // comment + readonly [key in Foo]; +}; + +// Prettier stable +type Type = { + readonly // comment + [key in Foo]; +}; + +// Prettier main +type Type = { + // comment + readonly [key in Foo]; +}; +``` diff --git a/src/language-js/print/type-parameters.js b/src/language-js/print/type-parameters.js index 154ffb161..7154b97de 100644 --- a/src/language-js/print/type-parameters.js +++ b/src/language-js/print/type-parameters.js @@ -12,6 +12,7 @@ const { shouldPrintComma, getFunctionParameters, isObjectType, + getTypeScriptMappedTypeModifier, } = require("../utils/index.js"); const { createGroupIdMapper } = require("../../common/util.js"); const { shouldHugType } = require("./type-annotation.js"); @@ -109,6 +110,12 @@ function printTypeParameter(path, options, print) { const parts = []; const parent = path.getParentNode(); if (parent.type === "TSMappedType") { + if (parent.readonly) { + parts.push( + getTypeScriptMappedTypeModifier(parent.readonly, "readonly"), + " " + ); + } parts.push("[", print("name")); if (node.constraint) { parts.push(" in ", print("constraint")); diff --git a/src/language-js/print/typescript.js b/src/language-js/print/typescript.js index 68defeffe..f03ad7b2a 100644 --- a/src/language-js/print/typescript.js +++ b/src/language-js/print/typescript.js @@ -307,13 +307,6 @@ function printTypescript(path, options, print) { "{", indent([ options.bracketSpacing ? line : softline, - node.readonly - ? [ - getTypeScriptMappedTypeModifier(node.readonly, "readonly"), - " ", - ] - : "", - printTypeScriptModifiers(path, options, print), print("typeParameter"), node.optional ? getTypeScriptMappedTypeModifier(node.optional, "?") diff --git a/tests/format/typescript/mapped-type/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/mapped-type/__snapshots__/jsfmt.spec.js.snap index 18ffc4528..fe565652c 100644 --- a/tests/format/typescript/mapped-type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/mapped-type/__snapshots__/jsfmt.spec.js.snap @@ -22,6 +22,119 @@ type Example = { ================================================================================ `; +exports[`issue-11098.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +type Type = { + // comment + readonly [T in number]; +}; + +type Type = { + // comment1 + // comment2 + readonly [T in number]; +}; + +type Type = { + // comment + +readonly [T in number]; +}; + +type Type = { + // comment + -readonly [T in number]; +}; + +type Type = { + // comment + + readonly [T in number]; +}; + +type Type = { + // comment + +readonly [T in number]; +}; + +type Type = { + // comment + readonly [T in number]; +}; + +type Type = { + // comment + [T in number]; +}; + +type Type = { + readonly + // comment + [T in number]; +}; + +type Type = { + readonly // foo + /* bar */ [T in number]; +}; + +=====================================output===================================== +type Type = { + // comment + readonly [T in number]; +}; + +type Type = { + // comment1 + // comment2 + readonly [T in number]; +}; + +type Type = { + // comment + +readonly [T in number]; +}; + +type Type = { + // comment + -readonly [T in number]; +}; + +type Type = { + // comment + +readonly [T in number]; +}; + +type Type = { + // comment + +readonly [T in number]; +}; + +type Type = { + // comment + readonly [T in number]; +}; + +type Type = { + // comment + [T in number]; +}; + +type Type = { + // comment + readonly [T in number]; +}; + +type Type = { + // foo + /* bar */ readonly [T in number]; +}; + +================================================================================ +`; + exports[`mapped-type.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/format/typescript/mapped-type/issue-11098.ts b/tests/format/typescript/mapped-type/issue-11098.ts new file mode 100644 index 000000000..2024b8eaf --- /dev/null +++ b/tests/format/typescript/mapped-type/issue-11098.ts @@ -0,0 +1,51 @@ +type Type = { + // comment + readonly [T in number]; +}; + +type Type = { + // comment1 + // comment2 + readonly [T in number]; +}; + +type Type = { + // comment + +readonly [T in number]; +}; + +type Type = { + // comment + -readonly [T in number]; +}; + +type Type = { + // comment + + readonly [T in number]; +}; + +type Type = { + // comment + +readonly [T in number]; +}; + +type Type = { + // comment + readonly [T in number]; +}; + +type Type = { + // comment + [T in number]; +}; + +type Type = { + readonly + // comment + [T in number]; +}; + +type Type = { + readonly // foo + /* bar */ [T in number]; +}; From e681edb67c2435812af6d753fce43f8a9ca4b819 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 8 Feb 2023 11:04:32 +0800 Subject: [PATCH 6/9] Release 2.8.4 --- .github/ISSUE_TEMPLATE/formatting.md | 2 +- .github/ISSUE_TEMPLATE/integration.md | 2 +- CHANGELOG.md | 123 ++++++++++++++++++ docs/browser.md | 30 ++--- package.json | 2 +- .../versioned_docs/version-stable/browser.md | 30 ++--- 6 files changed, 156 insertions(+), 33 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/formatting.md b/.github/ISSUE_TEMPLATE/formatting.md index 8e49b6b6f..f2a21f21f 100644 --- a/.github/ISSUE_TEMPLATE/formatting.md +++ b/.github/ISSUE_TEMPLATE/formatting.md @@ -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 diff --git a/.github/ISSUE_TEMPLATE/integration.md b/.github/ISSUE_TEMPLATE/integration.md index 239aba6e9..58f004f6c 100644 --- a/.github/ISSUE_TEMPLATE/integration.md +++ b/.github/ISSUE_TEMPLATE/integration.md @@ -20,7 +20,7 @@ BEFORE SUBMITTING AN ISSUE: **Environments:** -- Prettier Version: 2.8.3 +- Prettier Version: 2.8.4 - Running Prettier via: - Runtime: - Operating System: diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a47b3eff..92259f95c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) + + +```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. + + +```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)) + + +```jsx +// Input +const a = /** @satisfies {Record} */ ({hello: 1337}); +const b = /** @type {Record} */ ({hello: 1337}); + +// Prettier 2.8.3 +const a = /** @satisfies {Record} */ { hello: 1337 }; +const b = /** @type {Record} */ ({ hello: 1337 }); + +// Prettier 2.8.4 +const a = /** @satisfies {Record} */ ({hello: 1337}); +const b = /** @type {Record} */ ({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)) + + +```ts +// Input +type Foo = T extends ((a) => a is infer R extends string) ? R : never; + +// Prettier 2.8.3 (First format) +type Foo = 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 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) diff --git a/docs/browser.md b/docs/browser.md index f55a8a773..da1e69b7d 100644 --- a/docs/browser.md +++ b/docs/browser.md @@ -20,8 +20,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 and - - `parser-*.mjs` in + - `parser-*.js` in and + - `parser-*.mjs` in You need to load the ones that you’re going to use and pass them to `prettier.format` using the `plugins` option. @@ -32,8 +32,8 @@ See below for examples. ### Global ```html - - + + - + +