From 0f19075f5f0bc3ecca0c583a0be699eca157ff06 Mon Sep 17 00:00:00 2001 From: Caleb Jasik Date: Fri, 12 Aug 2022 03:18:55 -0500 Subject: [PATCH 001/136] Add prettier-plugin-astro to list of plugins (#13269) * Add prettier-plugin-astro to list of plugins * Order the plugin correctly alphabetically * Update creator text/link * Update cspell dictionary --- cspell.json | 2 ++ docs/plugins.md | 1 + 2 files changed, 3 insertions(+) diff --git a/cspell.json b/cspell.json index 4475099a8a8a..c35113b9ef73 100644 --- a/cspell.json +++ b/cspell.json @@ -14,6 +14,7 @@ "arrayify", "Artem", "Ascher", + "astro", "atrule", "atrules", "atword", @@ -369,6 +370,7 @@ "webstorm", "Weixin", "whitespaces", + "withastro", "wxss", "xdescribe", "xtest", diff --git a/docs/plugins.md b/docs/plugins.md index 59c603ab2626..c77b1126c83c 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -58,6 +58,7 @@ To turn off plugin autoloading, use `--no-plugin-search` when using Prettier CLI ## Community Plugins - [`prettier-plugin-apex`](https://github.com/dangmai/prettier-plugin-apex) by [**@dangmai**](https://github.com/dangmai) +- [`prettier-plugin-astro`](https://github.com/withastro/prettier-plugin-astro) by [**@withastro contributors**](https://github.com/withastro/prettier-plugin-astro/graphs/contributors) - [`prettier-plugin-elm`](https://github.com/gicentre/prettier-plugin-elm) by [**@giCentre**](https://github.com/gicentre) - [`prettier-plugin-erb`](https://github.com/adamzapasnik/prettier-plugin-erb) by [**@adamzapasnik**](https://github.com/adamzapasnik) - [`prettier-plugin-glsl`](https://github.com/NaridaL/glsl-language-toolkit/tree/main/packages/prettier-plugin-glsl) by [**@NaridaL**](https://github.com/NaridaL) From 5910eb9204497b656594ceaaeae057a318a9fede Mon Sep 17 00:00:00 2001 From: Nikolas Date: Mon, 15 Aug 2022 12:18:37 +0200 Subject: [PATCH 002/136] Add `prettier-plugin-prisma` to list of community plugins (#13272) --- docs/plugins.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/plugins.md b/docs/plugins.md index c77b1126c83c..0065dbce2ffe 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -66,6 +66,7 @@ To turn off plugin autoloading, use `--no-plugin-search` when using Prettier CLI - [`prettier-plugin-java`](https://github.com/jhipster/prettier-java) by [**@JHipster**](https://github.com/jhipster) - [`prettier-plugin-jsonata`](https://github.com/Stedi/prettier-plugin-jsonata) by [**@Stedi**](https://github.com/Stedi) - [`prettier-plugin-kotlin`](https://github.com/Angry-Potato/prettier-plugin-kotlin) by [**@Angry-Potato**](https://github.com/Angry-Potato) +- [`prettier-plugin-prisma`](https://github.com/umidbekk/prettier-plugin-prisma) by [**@umidbekk**](https://github.com/umidbekk) - [`prettier-plugin-properties`](https://github.com/eemeli/prettier-plugin-properties) by [**@eemeli**](https://github.com/eemeli) - [`prettier-plugin-sh`](https://github.com/un-ts/prettier/tree/master/packages/sh) by [**@JounQin**](https://github.com/JounQin) - [`prettier-plugin-sql`](https://github.com/un-ts/prettier/tree/master/packages/sql) by [**@JounQin**](https://github.com/JounQin) From 2d3a2748471bf03d4bf59e3dc47f689cc984fadf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pereira?= <43006560+jspereiramoura@users.noreply.github.com> Date: Wed, 17 Aug 2022 11:32:29 -0300 Subject: [PATCH 003/136] fix: extra space between '#' and '{' (#13286) * fix: extra space between '#' and '{' * Update src/language-css/printer-postcss.js Co-authored-by: fisker Cheung * adding changelog * Update 13286.md Co-authored-by: fisker Cheung --- changelog_unreleased/scss/13286.md | 13 +++++++++++++ src/language-css/printer-postcss.js | 8 ++++++++ .../scss/variables/__snapshots__/jsfmt.spec.js.snap | 2 ++ tests/format/scss/variables/variables.scss | 1 + 4 files changed, 24 insertions(+) create mode 100644 changelog_unreleased/scss/13286.md diff --git a/changelog_unreleased/scss/13286.md b/changelog_unreleased/scss/13286.md new file mode 100644 index 000000000000..d64d731952d5 --- /dev/null +++ b/changelog_unreleased/scss/13286.md @@ -0,0 +1,13 @@ +#### fix: extra space between '#' and '{' (#13286 by @jspereiramoura) + + +```scss +// Input +padding: var(--spacer#{(1) + 2}); + +// Prettier stable +padding: var(--spacer# {(1) + 2}); + +// Prettier main +padding: var(--spacer#{(1) + 2}); +``` diff --git a/src/language-css/printer-postcss.js b/src/language-css/printer-postcss.js index 825961ff2a23..744646020238 100644 --- a/src/language-css/printer-postcss.js +++ b/src/language-css/printer-postcss.js @@ -825,6 +825,14 @@ function genericPrint(path, options, print) { continue; } + if ( + iNode.value?.endsWith("#") && + iNextNode.value === "{" && + isParenGroupNode(iNextNode.group) + ) { + continue; + } + // Be default all values go through `line` parts.push(line); } diff --git a/tests/format/scss/variables/__snapshots__/jsfmt.spec.js.snap b/tests/format/scss/variables/__snapshots__/jsfmt.spec.js.snap index 6f19d50c0783..4312c1b47702 100644 --- a/tests/format/scss/variables/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/scss/variables/__snapshots__/jsfmt.spec.js.snap @@ -12,6 +12,7 @@ printWidth: 80 prop1: var(--#{$var}); prop2: var(#{$var}, --my-#{$var}, pink); prop3: calc(var(--#{$var}) * 1px); + prop4: var(--spacer#{(1) + 2}); } @supports (--#{$prop}: green) { @@ -27,6 +28,7 @@ printWidth: 80 prop1: var(--#{$var}); prop2: var(#{$var}, --my-#{$var}, pink); prop3: calc(var(--#{$var}) * 1px); + prop4: var(--spacer#{(1) + 2}); } @supports (--#{$prop}: green) { diff --git a/tests/format/scss/variables/variables.scss b/tests/format/scss/variables/variables.scss index 35e7c6e9b359..577714686417 100644 --- a/tests/format/scss/variables/variables.scss +++ b/tests/format/scss/variables/variables.scss @@ -4,6 +4,7 @@ prop1: var(--#{$var}); prop2: var(#{$var}, --my-#{$var}, pink); prop3: calc(var(--#{$var}) * 1px); + prop4: var(--spacer#{(1) + 2}); } @supports (--#{$prop}: green) { From f2244bdc8621c0a001e3717f595bc8fd8653cce7 Mon Sep 17 00:00:00 2001 From: Gleb Dolzhikov Date: Wed, 17 Aug 2022 18:36:25 +0300 Subject: [PATCH 004/136] Fix parens in inferred function return types with `extends` (#13289) Co-authored-by: Gleb Dolzhikov <9276677@gmail.com> --- changelog_unreleased/typescript/13289.md | 13 +++++++++++++ src/language-js/needs-parens.js | 10 ++++++++++ .../__snapshots__/jsfmt.spec.js.snap | 14 ++++++++++++++ .../typescript/conditional-types/issue-13275.ts | 1 + 4 files changed, 38 insertions(+) create mode 100644 changelog_unreleased/typescript/13289.md create mode 100644 tests/format/typescript/conditional-types/issue-13275.ts diff --git a/changelog_unreleased/typescript/13289.md b/changelog_unreleased/typescript/13289.md new file mode 100644 index 000000000000..7a4183c1969a --- /dev/null +++ b/changelog_unreleased/typescript/13289.md @@ -0,0 +1,13 @@ +#### Fix parens in inferred function return types with `extends` (#13289 by @GlebDolzhikov) + + +```ts +// Input +type Foo = T extends (...a: any[]) => (infer R extends string) ? R : never; + +// Prettier stable +type Foo = T extends (...a: any[]) => infer R extends string ? R : never; + +// Prettier main +type Foo = T extends ((...a: any[]) => infer R extends string) ? R : never; +``` diff --git a/src/language-js/needs-parens.js b/src/language-js/needs-parens.js index 0695e9731cd4..1a71011ecdca 100644 --- a/src/language-js/needs-parens.js +++ b/src/language-js/needs-parens.js @@ -412,6 +412,16 @@ function needsParens(path, options) { // fallthrough case "TSFunctionType": case "TSConstructorType": + if (name === "extendsType" && parent.type === "TSConditionalType") { + const returnTypeAnnotation = (node.returnType || node.typeAnnotation) + .typeAnnotation; + if ( + returnTypeAnnotation.type === "TSInferType" && + returnTypeAnnotation.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 d109f4511d53..7231c3da425e 100644 --- a/tests/format/typescript/conditional-types/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/conditional-types/__snapshots__/jsfmt.spec.js.snap @@ -278,6 +278,20 @@ 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"] diff --git a/tests/format/typescript/conditional-types/issue-13275.ts b/tests/format/typescript/conditional-types/issue-13275.ts new file mode 100644 index 000000000000..de1ccb2859aa --- /dev/null +++ b/tests/format/typescript/conditional-types/issue-13275.ts @@ -0,0 +1 @@ +type Foo = T extends ((...a: any[]) => infer R extends string) ? R : never; From a2a3849c430b31871db5e89ff1542b4d14f80f68 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 21 Aug 2022 09:48:37 +0200 Subject: [PATCH 005/136] Added `prettier-plugin-nginx` to Community Plugins list (#13320) Added [`prettier-plugin-nginx`](https://github.com/joedeandev/prettier-plugin-nginx) to Community Plugins list. --- cspell.json | 1 + docs/plugins.md | 1 + 2 files changed, 2 insertions(+) diff --git a/cspell.json b/cspell.json index c35113b9ef73..ed51d0e903e3 100644 --- a/cspell.json +++ b/cspell.json @@ -224,6 +224,7 @@ "neoclide", "neoformat", "neovim", + "nginx", "nnoremap", "nocheck", "nonenumerable", diff --git a/docs/plugins.md b/docs/plugins.md index 0065dbce2ffe..d599cf544e45 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -66,6 +66,7 @@ To turn off plugin autoloading, use `--no-plugin-search` when using Prettier CLI - [`prettier-plugin-java`](https://github.com/jhipster/prettier-java) by [**@JHipster**](https://github.com/jhipster) - [`prettier-plugin-jsonata`](https://github.com/Stedi/prettier-plugin-jsonata) by [**@Stedi**](https://github.com/Stedi) - [`prettier-plugin-kotlin`](https://github.com/Angry-Potato/prettier-plugin-kotlin) by [**@Angry-Potato**](https://github.com/Angry-Potato) +- [`prettier-plugin-nginx`](https://github.com/joedeandev/prettier-plugin-nginx) by [**@joedeandev**](https://github.com/joedeandev) - [`prettier-plugin-prisma`](https://github.com/umidbekk/prettier-plugin-prisma) by [**@umidbekk**](https://github.com/umidbekk) - [`prettier-plugin-properties`](https://github.com/eemeli/prettier-plugin-properties) by [**@eemeli**](https://github.com/eemeli) - [`prettier-plugin-sh`](https://github.com/un-ts/prettier/tree/master/packages/sh) by [**@JounQin**](https://github.com/JounQin) From 5a627651ff648edd38bd0b5e667210a8a1f4e4a1 Mon Sep 17 00:00:00 2001 From: Gleb Dolzhikov Date: Tue, 23 Aug 2022 15:56:52 +0300 Subject: [PATCH 006/136] fix: line breaks in multiline strings, issue 13157 (#13274) Co-authored-by: Georgii Dolzhykov Co-authored-by: Gleb Dolzhikov Co-authored-by: fisker Cheung --- changelog_unreleased/javascript/13274.md | 34 ++++++++++ src/language-js/print/flow.js | 3 +- src/language-js/print/literal.js | 5 +- .../literal/__snapshots__/jsfmt.spec.js.snap | 27 ++++++++ tests/format/flow/literal/jsfmt.spec.js | 1 + tests/format/flow/literal/multiline.js | 6 ++ .../strings/__snapshots__/jsfmt.spec.js.snap | 65 +++++++++++++++++++ tests/format/js/strings/multiline-literal.js | 9 +++ .../literal/__snapshots__/jsfmt.spec.js.snap | 25 +++++++ tests/format/typescript/literal/jsfmt.spec.js | 1 + tests/format/typescript/literal/multiline.ts | 6 ++ 11 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 changelog_unreleased/javascript/13274.md create mode 100644 tests/format/flow/literal/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/flow/literal/jsfmt.spec.js create mode 100644 tests/format/flow/literal/multiline.js create mode 100644 tests/format/js/strings/multiline-literal.js create mode 100644 tests/format/typescript/literal/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/typescript/literal/jsfmt.spec.js create mode 100644 tests/format/typescript/literal/multiline.ts diff --git a/changelog_unreleased/javascript/13274.md b/changelog_unreleased/javascript/13274.md new file mode 100644 index 000000000000..26466f984015 --- /dev/null +++ b/changelog_unreleased/javascript/13274.md @@ -0,0 +1,34 @@ +#### Fix inconsistent formatting for multiline strings (#13274 by @GlebDolzhikov) + + +```jsx +// Input +const loremIpsumFooBazBar1 = 'Multiline string\ + Multiline string\ +' + +const loremIpsumFooBazBar2 = 'Multiline string\ + Multiline string\ + Multiline string' + +// Prettier stable +const loremIpsumFooBazBar1 = "Multiline string\ + Multiline string\ +"; + +const loremIpsumFooBazBar2 = + "Multiline string\ + Multiline string\ + Multiline string"; + +// Prettier main +const loremIpsumFooBazBar1 = + "Multiline string\ + Multiline string\ +"; + +const loremIpsumFooBazBar2 = + "Multiline string\ + Multiline string\ + Multiline string"; +``` diff --git a/src/language-js/print/flow.js b/src/language-js/print/flow.js index 47ffce034fd3..22bf76583b76 100644 --- a/src/language-js/print/flow.js +++ b/src/language-js/print/flow.js @@ -16,6 +16,7 @@ const { shouldPrintComma, } = require("../utils/index.js"); const { locStart, locEnd } = require("../loc.js"); +const { replaceTextEndOfLine } = require("../../document/doc-utils.js"); const { printClass } = require("./class.js"); const { printOpaqueType, @@ -278,7 +279,7 @@ function printFlow(path, options, print) { case "QualifiedTypeIdentifier": return [print("qualification"), ".", print("id")]; case "StringLiteralTypeAnnotation": - return printString(rawText(node), options); + return replaceTextEndOfLine(printString(rawText(node), options)); case "NumberLiteralTypeAnnotation": assert.strictEqual(typeof node.value, "number"); // fall through diff --git a/src/language-js/print/literal.js b/src/language-js/print/literal.js index a61a65eb3ddf..a614bd5f4ba1 100644 --- a/src/language-js/print/literal.js +++ b/src/language-js/print/literal.js @@ -1,5 +1,6 @@ "use strict"; const { printString, printNumber } = require("../../common/util.js"); +const { replaceTextEndOfLine } = require("../../document/doc-utils.js"); function printLiteral(path, options /*, print*/) { const node = path.getNode(); @@ -13,7 +14,7 @@ function printLiteral(path, options /*, print*/) { case "NumericLiteral": // Babel 6 Literal split return printNumber(node.extra.raw); case "StringLiteral": // Babel 6 Literal split - return printString(node.extra.raw, options); + return replaceTextEndOfLine(printString(node.extra.raw, options)); case "NullLiteral": // Babel 6 Literal split return "null"; case "BooleanLiteral": // Babel 6 Literal split @@ -40,7 +41,7 @@ function printLiteral(path, options /*, print*/) { } if (typeof value === "string") { - return printString(node.raw, options); + return replaceTextEndOfLine(printString(node.raw, options)); } return String(value); diff --git a/tests/format/flow/literal/__snapshots__/jsfmt.spec.js.snap b/tests/format/flow/literal/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..bafcf8a566e5 --- /dev/null +++ b/tests/format/flow/literal/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,27 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`multiline.js format 1`] = ` +====================================options===================================== +parsers: ["flow", "babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +type loremIpsumFooBazBar1 = 'Multiline string\\ + Multiline string' + +type loremIpsumFooBazBar2 = 'Multiline string\\ + Multiline string\\ + Multiline string' + +=====================================output===================================== +type loremIpsumFooBazBar1 = + "Multiline string\\ + Multiline string"; + +type loremIpsumFooBazBar2 = + "Multiline string\\ + Multiline string\\ + Multiline string"; + +================================================================================ +`; diff --git a/tests/format/flow/literal/jsfmt.spec.js b/tests/format/flow/literal/jsfmt.spec.js new file mode 100644 index 000000000000..fbfa6501a049 --- /dev/null +++ b/tests/format/flow/literal/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["flow", "babel"]); diff --git a/tests/format/flow/literal/multiline.js b/tests/format/flow/literal/multiline.js new file mode 100644 index 000000000000..22648828e01c --- /dev/null +++ b/tests/format/flow/literal/multiline.js @@ -0,0 +1,6 @@ +type loremIpsumFooBazBar1 = 'Multiline string\ + Multiline string' + +type loremIpsumFooBazBar2 = 'Multiline string\ + Multiline string\ + Multiline string' diff --git a/tests/format/js/strings/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/strings/__snapshots__/jsfmt.spec.js.snap index dc97633deb10..9dead44561d5 100644 --- a/tests/format/js/strings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/strings/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,70 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`multiline-literal.js - {"trailingComma":"all"} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow"] +printWidth: 80 +trailingComma: "all" + | printWidth +=====================================input====================================== +// https://github.com/prettier/prettier/pull/13274 + +const loremIpsumFooBazBar1 = 'Multiline string\\ + Multiline string\\ +' + +const loremIpsumFooBazBar2 = 'Multiline string\\ + Multiline string\\ + Multiline string' + +=====================================output===================================== +// https://github.com/prettier/prettier/pull/13274 + +const loremIpsumFooBazBar1 = + "Multiline string\\ + Multiline string\\ +"; + +const loremIpsumFooBazBar2 = + "Multiline string\\ + Multiline string\\ + Multiline string"; + +================================================================================ +`; + +exports[`multiline-literal.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow"] +printWidth: 80 + | printWidth +=====================================input====================================== +// https://github.com/prettier/prettier/pull/13274 + +const loremIpsumFooBazBar1 = 'Multiline string\\ + Multiline string\\ +' + +const loremIpsumFooBazBar2 = 'Multiline string\\ + Multiline string\\ + Multiline string' + +=====================================output===================================== +// https://github.com/prettier/prettier/pull/13274 + +const loremIpsumFooBazBar1 = + "Multiline string\\ + Multiline string\\ +"; + +const loremIpsumFooBazBar2 = + "Multiline string\\ + Multiline string\\ + Multiline string"; + +================================================================================ +`; + exports[`non-octal-eight-and-nine.js [acorn] format 1`] = ` "Invalid escape sequence (3:3) 1 | // https://github.com/babel/babel/pull/11852 diff --git a/tests/format/js/strings/multiline-literal.js b/tests/format/js/strings/multiline-literal.js new file mode 100644 index 000000000000..fcecf64f399e --- /dev/null +++ b/tests/format/js/strings/multiline-literal.js @@ -0,0 +1,9 @@ +// https://github.com/prettier/prettier/pull/13274 + +const loremIpsumFooBazBar1 = 'Multiline string\ + Multiline string\ +' + +const loremIpsumFooBazBar2 = 'Multiline string\ + Multiline string\ + Multiline string' diff --git a/tests/format/typescript/literal/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/literal/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..cb42c67fc013 --- /dev/null +++ b/tests/format/typescript/literal/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,25 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`multiline.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +type loremIpsumFooBazBar1 = 'Multiline string\\ + Multiline string' + +type loremIpsumFooBazBar2 = 'Multiline string\\ + Multiline string\\ + Multiline string' + +=====================================output===================================== +type loremIpsumFooBazBar1 = "Multiline string\\ + Multiline string"; + +type loremIpsumFooBazBar2 = "Multiline string\\ + Multiline string\\ + Multiline string"; + +================================================================================ +`; diff --git a/tests/format/typescript/literal/jsfmt.spec.js b/tests/format/typescript/literal/jsfmt.spec.js new file mode 100644 index 000000000000..2ea3bb6eb2e4 --- /dev/null +++ b/tests/format/typescript/literal/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["typescript"]); diff --git a/tests/format/typescript/literal/multiline.ts b/tests/format/typescript/literal/multiline.ts new file mode 100644 index 000000000000..22648828e01c --- /dev/null +++ b/tests/format/typescript/literal/multiline.ts @@ -0,0 +1,6 @@ +type loremIpsumFooBazBar1 = 'Multiline string\ + Multiline string' + +type loremIpsumFooBazBar2 = 'Multiline string\ + Multiline string\ + Multiline string' From e4af667e03c27d79ddc7c387c7428aa3b52eb16e Mon Sep 17 00:00:00 2001 From: Adrian Leonhard Date: Mon, 29 Aug 2022 14:06:41 +0200 Subject: [PATCH 007/136] docs: plugins.md: add getCommentChildNodes (#12502) --- docs/plugins.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/plugins.md b/docs/plugins.md index d599cf544e45..5c1d754e4b70 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -163,6 +163,7 @@ export const printers = { canAttachComment, isBlockComment, printComment, + getCommentChildNodes, handleComments: { ownLine, endOfLine, @@ -297,6 +298,21 @@ Comments are often not part of a language's AST and present a challenge for pret By default, if the AST has a top-level `comments` property, Prettier assumes that `comments` stores an array of comment nodes. Prettier will then use the provided `parsers[].locStart`/`locEnd` functions to search for the AST node that each comment "belongs" to. Comments are then attached to these nodes **mutating the AST in the process**, and the `comments` property is deleted from the AST root. The `*Comment` functions are used to adjust Prettier's algorithm. Once the comments are attached to the AST, Prettier will automatically call the `printComment(path, options): Doc` function and insert the returned doc into the (hopefully) correct place. +#### (optional) `getCommentChildNodes` + +By default, Prettier searches all object properties (except for a few predefined ones) of each node recursively. This function can be provided to override that behavior. It has the signature: + +```ts +function getCommentChildNodes( + // The node whose children should be returned. + node: AST, + // Current options + options: object +): AST[] | undefined; +``` + +Return `[]` if the node has no children or `undefined` to fall back on the default behavior. + #### (optional) `printComment` Called whenever a comment node needs to be printed. It has the signature: From f48f514deb932ff11a6d22dde4dbd6ee837be5cf Mon Sep 17 00:00:00 2001 From: Dinika Date: Mon, 29 Aug 2022 15:21:18 +0200 Subject: [PATCH 008/136] Update integrating-with-linters.md (#12363) --- docs/integrating-with-linters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/integrating-with-linters.md b/docs/integrating-with-linters.md index bd6c125d018e..0c4a7e339228 100644 --- a/docs/integrating-with-linters.md +++ b/docs/integrating-with-linters.md @@ -29,7 +29,7 @@ The downsides of those plugins are: - They are slower than running Prettier directly. - They’re yet one layer of indirection where things may break. -Finally, we have tools that run `prettier` and then immediately for example `eslint --fix` on files. +Finally, we have tools that run `prettier` and then immediately lint files by running, for example, `eslint --fix` on them. - [prettier-eslint](https://github.com/prettier/prettier-eslint) - [prettier-stylelint](https://github.com/hugomrdias/prettier-stylelint) From 9850bc6af3c50b2079eabfe6eadc5ec531aeec5a Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Mon, 29 Aug 2022 15:24:02 +0200 Subject: [PATCH 009/136] docs(configuration): linkfix (#12005) * docs(configuration): linkfix * Link to the `overrides` section in new ESLint website * Update stable version docs too Co-authored-by: fisker Cheung --- docs/configuration.md | 2 +- website/versioned_docs/version-stable/configuration.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 3d8c4092035f..12f6c712f4f3 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -66,7 +66,7 @@ singleQuote = true Overrides let you have different configuration for certain file extensions, folders and specific files. -Prettier borrows ESLint’s [override format](https://eslint.org/docs/user-guide/configuring#example-configuration). +Prettier borrows ESLint’s [override format](https://eslint.org/docs/latest/user-guide/configuring/configuration-files#how-do-overrides-work). JSON: diff --git a/website/versioned_docs/version-stable/configuration.md b/website/versioned_docs/version-stable/configuration.md index 148d900f2c17..547c8bef8308 100644 --- a/website/versioned_docs/version-stable/configuration.md +++ b/website/versioned_docs/version-stable/configuration.md @@ -67,7 +67,7 @@ singleQuote = true Overrides let you have different configuration for certain file extensions, folders and specific files. -Prettier borrows ESLint’s [override format](https://eslint.org/docs/user-guide/configuring#example-configuration). +Prettier borrows ESLint’s [override format](https://eslint.org/docs/latest/user-guide/configuring/configuration-files#how-do-overrides-work). JSON: From 68bd87b24ba00049ac74870de75596639fd967bb Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Wed, 31 Aug 2022 00:59:20 +0900 Subject: [PATCH 010/136] Fix generated changelog comment for css like syntax (#13403) Fix generated comment for css like syntax --- scripts/generate-changelog.mjs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/generate-changelog.mjs b/scripts/generate-changelog.mjs index 8578dfd6d82b..f3d9e7ffc2cd 100644 --- a/scripts/generate-changelog.mjs +++ b/scripts/generate-changelog.mjs @@ -154,6 +154,10 @@ function getSyntaxFromCategory(category) { return "jsx"; case "typescript": return "tsx"; + case "css": + case "scss": + case "less": + return "css"; default: return category; } @@ -175,6 +179,8 @@ function getCommentForSyntax(syntax, comment) { return `# ${comment}`; case "hbs": return `{{! ${comment} }}`; + case "css": + return `/* ${comment} */`; default: return `// ${comment}`; } From 98b93cfb038fbb49cf29f8fcb6a717b88c957f3f Mon Sep 17 00:00:00 2001 From: Ryan Vandersmith Date: Thu, 1 Sep 2022 19:03:52 -0600 Subject: [PATCH 011/136] Add `prettier-plugin-motoko` to community plugin list (#13406) --- cspell.json | 1 + docs/plugins.md | 1 + 2 files changed, 2 insertions(+) diff --git a/cspell.json b/cspell.json index ed51d0e903e3..d2cb167bf4b4 100644 --- a/cspell.json +++ b/cspell.json @@ -214,6 +214,7 @@ "Monteiro", "Morrell", "motiz", + "Motoko", "mousedown", "mouseup", "mprettier", diff --git a/docs/plugins.md b/docs/plugins.md index 5c1d754e4b70..3cb936e3bf09 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -66,6 +66,7 @@ To turn off plugin autoloading, use `--no-plugin-search` when using Prettier CLI - [`prettier-plugin-java`](https://github.com/jhipster/prettier-java) by [**@JHipster**](https://github.com/jhipster) - [`prettier-plugin-jsonata`](https://github.com/Stedi/prettier-plugin-jsonata) by [**@Stedi**](https://github.com/Stedi) - [`prettier-plugin-kotlin`](https://github.com/Angry-Potato/prettier-plugin-kotlin) by [**@Angry-Potato**](https://github.com/Angry-Potato) +- [`prettier-plugin-motoko`](https://github.com/dfinity/prettier-plugin-motoko) by [**@dfinity**](https://github.com/dfinity) - [`prettier-plugin-nginx`](https://github.com/joedeandev/prettier-plugin-nginx) by [**@joedeandev**](https://github.com/joedeandev) - [`prettier-plugin-prisma`](https://github.com/umidbekk/prettier-plugin-prisma) by [**@umidbekk**](https://github.com/umidbekk) - [`prettier-plugin-properties`](https://github.com/eemeli/prettier-plugin-properties) by [**@eemeli**](https://github.com/eemeli) From ed4c3c19eb91bd8a0ea51c709c707443b2a3b064 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 3 Sep 2022 17:16:12 +0800 Subject: [PATCH 012/136] Build(deps-dev): Bump node-fetch from 3.2.3 to 3.2.10 (#13408) Bumps [node-fetch](https://github.com/node-fetch/node-fetch) from 3.2.3 to 3.2.10. - [Release notes](https://github.com/node-fetch/node-fetch/releases) - [Commits](https://github.com/node-fetch/node-fetch/compare/v3.2.3...v3.2.10) --- updated-dependencies: - dependency-name: node-fetch dependency-type: direct:development ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 2a8261c4795d..60d0095613a2 100644 --- a/package.json +++ b/package.json @@ -129,7 +129,7 @@ "jest-snapshot-serializer-raw": "1.2.0", "jest-watch-typeahead": "1.0.0", "node-actionlint": "1.2.2", - "node-fetch": "3.2.3", + "node-fetch": "3.2.10", "npm-run-all": "4.1.5", "path-browserify": "1.0.1", "prettier": "2.7.1", diff --git a/yarn.lock b/yarn.lock index e3c427e3ddf9..0be6db91d6bb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5052,10 +5052,10 @@ node-domexception@^1.0.0: resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5" integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ== -node-fetch@3.2.3: - version "3.2.3" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.2.3.tgz#a03c9cc2044d21d1a021566bd52f080f333719a6" - integrity sha512-AXP18u4pidSZ1xYXRDPY/8jdv3RAozIt/WLNR/MBGZAz+xjtlr90RvCnsvHQRiXyWliZF/CpytExp32UU67/SA== +node-fetch@3.2.10: + version "3.2.10" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.2.10.tgz#e8347f94b54ae18b57c9c049ef641cef398a85c8" + integrity sha512-MhuzNwdURnZ1Cp4XTazr69K0BTizsBroX7Zx3UgDSVcZYKF/6p0CBe4EUb/hLqmzVhl0UpYfgRljQ4yxE+iCxA== dependencies: data-uri-to-buffer "^4.0.0" fetch-blob "^3.1.4" From c51d509560b713fdef9590fc60a55329c8660671 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 3 Sep 2022 17:18:01 +0800 Subject: [PATCH 013/136] Build(deps): Bump node-fetch from 3.2.3 to 3.2.10 in /scripts/release (#13411) Bumps [node-fetch](https://github.com/node-fetch/node-fetch) from 3.2.3 to 3.2.10. - [Release notes](https://github.com/node-fetch/node-fetch/releases) - [Commits](https://github.com/node-fetch/node-fetch/compare/v3.2.3...v3.2.10) --- updated-dependencies: - dependency-name: node-fetch dependency-type: direct:production ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- scripts/release/package.json | 2 +- scripts/release/yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/release/package.json b/scripts/release/package.json index a1bd2cdfccbe..ec336a3f0ff3 100644 --- a/scripts/release/package.json +++ b/scripts/release/package.json @@ -9,7 +9,7 @@ "enquirer": "2.3.6", "execa": "6.1.0", "minimist": "1.2.6", - "node-fetch": "3.2.3", + "node-fetch": "3.2.10", "outdent": "0.8.0", "semver": "7.3.7", "string-width": "5.1.2" diff --git a/scripts/release/yarn.lock b/scripts/release/yarn.lock index a1fc05b1c883..3b490ac31518 100644 --- a/scripts/release/yarn.lock +++ b/scripts/release/yarn.lock @@ -2013,10 +2013,10 @@ node-domexception@^1.0.0: resolved "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz" integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ== -node-fetch@3.2.3: - version "3.2.3" - resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-3.2.3.tgz" - integrity sha512-AXP18u4pidSZ1xYXRDPY/8jdv3RAozIt/WLNR/MBGZAz+xjtlr90RvCnsvHQRiXyWliZF/CpytExp32UU67/SA== +node-fetch@3.2.10: + version "3.2.10" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.2.10.tgz#e8347f94b54ae18b57c9c049ef641cef398a85c8" + integrity sha512-MhuzNwdURnZ1Cp4XTazr69K0BTizsBroX7Zx3UgDSVcZYKF/6p0CBe4EUb/hLqmzVhl0UpYfgRljQ4yxE+iCxA== dependencies: data-uri-to-buffer "^4.0.0" fetch-blob "^3.1.4" From 371c7093d0fe1c0ef244ac009c7b7573948c7f09 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 6 Sep 2022 14:40:59 +0800 Subject: [PATCH 014/136] Group `@typescript-eslint/*` dependencies in renovate config (#13430) --- .github/renovate.json5 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/renovate.json5 b/.github/renovate.json5 index f3dd88ef60b6..74f9dfb2f5c8 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -14,6 +14,10 @@ excludePackageNames: ["@babel/parser"], groupName: "babel", }, + { + matchPackagePrefixes: ["@typescript-eslint/"], + groupName: "typescript-eslint", + }, { branchPrefix: "renovate/website/", matchPaths: ["website/package.json"], From cd3e530c2e51fb8296c0fb7738a9afdd3a3a4410 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 6 Sep 2022 20:38:50 +0800 Subject: [PATCH 015/136] Reduce size of `parser-typescript.js` (#13431) --- scripts/build/config.mjs | 57 +-- scripts/build/modify-typescript-module.mjs | 484 +++++++++++++++++++++ 2 files changed, 486 insertions(+), 55 deletions(-) create mode 100644 scripts/build/modify-typescript-module.mjs diff --git a/scripts/build/config.mjs b/scripts/build/config.mjs index 4c55bd896bef..e06d5bbbc48a 100644 --- a/scripts/build/config.mjs +++ b/scripts/build/config.mjs @@ -2,6 +2,7 @@ import path from "node:path"; import { createRequire } from "node:module"; import createEsmUtils from "esm-utils"; import { PROJECT_ROOT } from "../utils/index.mjs"; +import modifyTypescriptModule from "./modify-typescript-module.mjs"; const { require } = createEsmUtils(import.meta); @@ -101,62 +102,8 @@ const parsers = [ }, { module: require.resolve("typescript"), - process(text) { - return text.replace( - /(?<=\n)(?\s+)function tryGetNodePerformanceHooks\(\) {.*?\n\k}(?=\n)/s, - "function tryGetNodePerformanceHooks() {}" - ); - }, + process: modifyTypescriptModule, }, - - ...Object.entries({ - // `typescript/lib/typescript.js` expose extra global objects - // `TypeScript`, `toolsVersion`, `globalThis` - 'typeof process === "undefined" || process.browser': "false", - 'typeof globalThis === "object"': "true", - - "_fs.realpathSync.native": - "_fs.realpathSync && _fs.realpathSync.native", - // Remove useless `ts.sys` - "ts.sys = ": "ts.sys = undefined && ", - - // Remove useless language service - "ts.realizeDiagnostics = ": "ts.realizeDiagnostics = undefined && ", - "ts.TypeScriptServicesFactory = ": - "ts.TypeScriptServicesFactory = undefined && ", - "var ShimBase = ": "var ShimBase = undefined && ", - "var TypeScriptServicesFactory = ": - "var TypeScriptServicesFactory = undefined && ", - "var LanguageServiceShimObject = ": - "var LanguageServiceShimObject = undefined && ", - "var CoreServicesShimHostAdapter = ": - "var CoreServicesShimHostAdapter = undefined && ", - "var LanguageServiceShimHostAdapter = ": - "var LanguageServiceShimHostAdapter = undefined && ", - "var ScriptSnapshotShimAdapter = ": - "var ScriptSnapshotShimAdapter = undefined && ", - "var ClassifierShimObject = ": - "var ClassifierShimObject = undefined && ", - "var CoreServicesShimObject = ": - "var CoreServicesShimObject = undefined && ", - "function simpleForwardCall(": "0 && function simpleForwardCall(", - "function forwardJSONCall(": "0 && function forwardJSONCall(", - "function forwardCall(": "0 && function forwardCall(", - "function realizeDiagnostics(": "0 && function realizeDiagnostics(", - "function realizeDiagnostic(": "0 && function realizeDiagnostic(", - "function convertClassifications(": - "0 && function convertClassifications(", - - // Dynamic `require()`s - "ts.sys && ts.sys.require": "false", - "require(etwModulePath)": "undefined", - 'require("source-map-support").install()': "", - "require(modulePath)": "undefined", - }).map(([find, replacement]) => ({ - module: require.resolve("typescript"), - find, - replacement, - })), { module: require.resolve("debug/src/browser.js"), path: require.resolve("./shims/debug.cjs"), diff --git a/scripts/build/modify-typescript-module.mjs b/scripts/build/modify-typescript-module.mjs new file mode 100644 index 000000000000..da1b4760729c --- /dev/null +++ b/scripts/build/modify-typescript-module.mjs @@ -0,0 +1,484 @@ +import path from "node:path"; +import escapeStringRegexp from "escape-string-regexp"; +import { outdent } from "outdent"; +import { writeFile, PROJECT_ROOT } from "../utils/index.mjs"; + +/* +Root submodule in `typescript.js` are bundled like + +```js +var ts; +(function (ts) { + // Submodule +})(ts || (ts = {})); +``` +*/ + +const SUBMODULE_START = escapeStringRegexp("var ts;\n(function (ts) {"); +const SUBMODULE_END = escapeStringRegexp("})(ts || (ts = {}));"); + +function getSubmodules(text, testFunction) { + const regexp = new RegExp( + [ + "(?<=\n)", + `(?${SUBMODULE_START})`, + "(?=\n)", + "(?.*?)", + "(?<=\n)", + `(?${SUBMODULE_END})`, + "(?=\n)", + ].join(""), + "gsu" + ); + + return [...text.matchAll(regexp)] + .filter((match) => testFunction(match.groups.text)) + .map((match) => ({ + start: match.index, + end: match.index + match[0].length, + ...match.groups, + })); +} + +function removeSubmodule(text, testFunction) { + return replaceSubmodule(text, testFunction, ""); +} + +function replaceSubmodule(text, testFunction, replacement) { + const modules = getSubmodules(text, testFunction); + if (modules.length !== 1) { + return text; + // TODO: Enable this check when merge to `next` branch + // throw Object.assign( + // new Error( + // `Expect exactly one submodule to be found, got ${modules.length} submodules.` + // ), + // { modules } + // ); + } + + const [{ start, end, before, after }] = modules; + if (replacement) { + replacement = before + "\n" + replacement + "\n" + after; + } + + return text.slice(0, start) + replacement + text.slice(end); +} + +function removeMultipleSubmodules(text, testFunction) { + let modules = getSubmodules(text, testFunction); + + if (modules.length < 2) { + throw new Error("Expect more than one submodules to be found"); + } + + for (; modules.length > 0; modules = getSubmodules(text, testFunction)) { + const [{ start, end }] = modules; + text = text.slice(0, start) + text.slice(end); + } + + return text; +} + +function replaceAlignedCode(text, { start, end, replacement = "" }) { + const regexp = new RegExp( + [ + "(?<=\n)", + "(?\\s*)", + escapeStringRegexp(start), + ".*?", + "(?<=\n)", + "\\k", + escapeStringRegexp(end), + "(?=\n)", + ].join(""), + "gsu" + ); + + return text.replaceAll(regexp, replacement); +} + +function modifyTypescriptModule(text) { + // Code after `globalThis` shim are useless + const positionOfGlobalThisShim = text.indexOf( + "// We polyfill `globalThis` here so re can reliably patch the global scope" + ); + if (positionOfGlobalThisShim === -1) { + throw new Error("Unexpected source."); + } + text = text.slice(0, positionOfGlobalThisShim) + "module.exports = ts;"; + + // File system + text = removeSubmodule(text, (text) => + text.includes("ts.generateDjb2Hash = generateDjb2Hash;") + ); + + // Language service + text = removeSubmodule(text, (text) => + text.includes("ts.TypeScriptServicesFactory = TypeScriptServicesFactory;") + ); + + // `ts.Version` + text = removeSubmodule(text, (text) => + text.includes("ts.Version = Version;") + ); + + // `ts.transform` + text = removeSubmodule(text, (text) => + text.includes("ts.transform = transform;") + ); + + // `ts.BreakpointResolver` + text = removeSubmodule(text, (text) => + text.trimStart().startsWith("var BreakpointResolver;") + ); + + // `ts.textChanges` + text = removeSubmodule(text, (text) => + text.trimStart().startsWith("var textChanges;") + ); + + // `ts.preProcessFile` + text = removeSubmodule(text, (text) => + text.includes("ts.preProcessFile = preProcessFile;") + ); + + // `ts.Rename` + text = removeSubmodule(text, (text) => + text.trimStart().startsWith("var Rename;") + ); + + // `ts.SmartSelectionRange` + text = removeSubmodule(text, (text) => + text.trimStart().startsWith("var SmartSelectionRange;") + ); + + // `ts.SignatureHelp` + text = removeSubmodule(text, (text) => + text.trimStart().startsWith("var SignatureHelp;") + ); + + // `ts.InlayHints` + text = removeSubmodule(text, (text) => + text.trimStart().startsWith("var InlayHints;") + ); + + // Sourcemap + text = removeSubmodule(text, (text) => + text.includes("ts.getSourceMapper = getSourceMapper;") + ); + text = removeSubmodule(text, (text) => + text.includes("ts.createSourceMapGenerator = createSourceMapGenerator;") + ); + + // Suggestion + text = removeSubmodule(text, (text) => + text.includes( + "ts.computeSuggestionDiagnostics = computeSuggestionDiagnostics;" + ) + ); + + // Tracing + text = removeSubmodule(text, (text) => + text.includes("ts.startTracing = tracingEnabled.startTracing;") + ); + + // Diagnostics + text = removeSubmodule(text, (text) => + text.includes("ts.createProgramHost = createProgramHost;") + ); + + // `ts.transformTypeScript` + text = removeSubmodule(text, (text) => + text.includes("ts.transformTypeScript = transformTypeScript;") + ); + + // `ts.createRuntimeTypeSerializer` + text = removeSubmodule(text, (text) => + text.includes( + "ts.createRuntimeTypeSerializer = createRuntimeTypeSerializer;" + ) + ); + + // Transform + // `ts.transformLegacyDecorators` + text = removeSubmodule(text, (text) => + text.includes("ts.transformLegacyDecorators = transformLegacyDecorators;") + ); + // `ts.transformES5` + text = removeSubmodule(text, (text) => + text.includes("ts.transformES5 = transformES5;") + ); + // `ts.transformES2015` + text = removeSubmodule(text, (text) => + text.includes("ts.transformES2015 = transformES2015;") + ); + // `ts.transformES2016` + text = removeSubmodule(text, (text) => + text.includes("ts.transformES2016 = transformES2016;") + ); + // `ts.transformES2017` & `ts.createSuperAccessVariableStatement` + text = removeSubmodule( + text, + (text) => + text.includes("ts.transformES2017 = transformES2017;") && + text.includes( + "ts.createSuperAccessVariableStatement = createSuperAccessVariableStatement;" + ) + ); + // `ts.transformES2018` + text = removeSubmodule(text, (text) => + text.includes("ts.transformES2018 = transformES2018;") + ); + // `ts.transformES2019` + text = removeSubmodule(text, (text) => + text.includes("ts.transformES2019 = transformES2019;") + ); + // `ts.transformES2020` + text = removeSubmodule(text, (text) => + text.includes("ts.transformES2020 = transformES2020;") + ); + // `ts.transformES2021` + text = removeSubmodule(text, (text) => + text.includes("ts.transformES2021 = transformES2021;") + ); + // `ts.transformESNext` + text = removeSubmodule(text, (text) => + text.includes("ts.transformESNext = transformESNext;") + ); + // `ts.transformJsx` + text = removeSubmodule(text, (text) => + text.includes("ts.transformJsx = transformJsx;") + ); + // `ts.transformGenerators` + text = removeSubmodule(text, (text) => + text.includes("ts.transformGenerators = transformGenerators;") + ); + // `ts.transformModule` + text = removeSubmodule(text, (text) => + text.includes("ts.transformModule = transformModule;") + ); + // `ts.transformSystemModule` + text = removeSubmodule(text, (text) => + text.includes("ts.transformSystemModule = transformSystemModule;") + ); + // `ts.transformECMAScriptModule` + text = removeSubmodule(text, (text) => + text.includes("ts.transformECMAScriptModule = transformECMAScriptModule;") + ); + // `ts.transformNodeModule` + text = removeSubmodule(text, (text) => + text.includes("ts.transformNodeModule = transformNodeModule;") + ); + // `ts.transformClassFields` + text = removeSubmodule(text, (text) => + text.includes("ts.transformClassFields = transformClassFields;") + ); + // `ts.transformDeclarations` + text = removeSubmodule(text, (text) => + text.includes("ts.transformDeclarations = transformDeclarations;") + ); + // `ts.transformNodes` and more + text = removeSubmodule(text, (text) => + text.includes("ts.transformNodes = transformNodes;") + ); + + // `ts.server` + text = removeSubmodule(text, (text) => text.includes("(ts.server = {})")); + + // `ts.JsTyping` + text = removeSubmodule(text, (text) => text.includes("(ts.JsTyping = {})")); + + // `ts.ClassificationType` + text = removeSubmodule(text, (text) => + text.includes("(ts.ClassificationType = {})") + ); + + // Build + text = removeSubmodule(text, (text) => + text.includes("ts.createSolutionBuilder = createSolutionBuilder;") + ); + text = removeSubmodule(text, (text) => + text.includes("ts.parseBuildCommand = parseBuildCommand;") + ); + text = removeSubmodule(text, (text) => + text.includes("ts.createBuilderProgram = createBuilderProgram;") + ); + text = removeSubmodule(text, (text) => + text.includes( + "ts.createSemanticDiagnosticsBuilderProgram = createSemanticDiagnosticsBuilderProgram;" + ) + ); + text = removeSubmodule(text, (text) => + text.includes("ts.createResolutionCache = createResolutionCache;") + ); + text = removeSubmodule(text, (text) => + text.includes("ts.createWatchCompilerHost = createWatchCompilerHost;") + ); + text = removeSubmodule(text, (text) => + text.includes( + "ts.resolveConfigFileProjectName = resolveConfigFileProjectName;" + ) + ); + text = removeSubmodule(text, (text) => + text.includes("ts.getBuildInfo = getBuildInfo;") + ); + + // Compile + text = removeSubmodule(text, (text) => + text.includes("ts.createCompilerHost = createCompilerHost;") + ); + text = removeSubmodule(text, (text) => + text.includes("(ts.BuilderState = {})") + ); + text = removeSubmodule(text, (text) => + text.includes("ts.transpile = transpile;") + ); + + // Watch + text = removeSubmodule(text, (text) => + text.includes("ts.getWatchFactory = getWatchFactory;") + ); + + // `ts.canProduceDiagnostics`, `ts.createGetSymbolAccessibilityDiagnosticForNode`, and `ts.createGetSymbolAccessibilityDiagnosticForNode` + text = removeSubmodule(text, (text) => + text.includes("ts.canProduceDiagnostics = canProduceDiagnostics;") + ); + + // `ts.moduleSpecifiers` + text = removeSubmodule(text, (text) => + text.includes("(ts.moduleSpecifiers = {})") + ); + + // `ts.trace` + text = removeSubmodule(text, (text) => text.includes("ts.trace = trace;")); + + // `ts.createTypeChecker` + text = removeSubmodule(text, (text) => + text.includes("ts.createTypeChecker = createTypeChecker;") + ); + + // `ts.DocumentHighlights` + text = removeSubmodule(text, (text) => + text.includes("(ts.DocumentHighlights = {})") + ); + + // `ts.createDocumentRegistry` + text = removeSubmodule(text, (text) => + text.includes("ts.createDocumentRegistry = createDocumentRegistry;") + ); + + // `ts.CallHierarchy` + text = removeSubmodule(text, (text) => + text.includes("(ts.CallHierarchy = {})") + ); + + // `ts.flattenDestructuringAssignment` and `ts.flattenDestructuringBinding` + text = removeSubmodule( + text, + (text) => + text.includes( + "ts.flattenDestructuringAssignment = flattenDestructuringAssignment" + ) && + text.includes( + "ts.flattenDestructuringBinding = flattenDestructuringBinding" + ) + ); + + // `ts.processTaggedTemplateExpression` + text = removeSubmodule(text, (text) => + text.includes( + "ts.processTaggedTemplateExpression = processTaggedTemplateExpression" + ) + ); + + // Editor + text = removeSubmodule(text, (text) => + text.includes("ts.getEditsForFileRename = getEditsForFileRename;") + ); + text = removeSubmodule(text, (text) => + text.includes("(ts.GoToDefinition = {})") + ); + text = removeSubmodule(text, (text) => text.includes("(ts.JsDoc = {})")); + text = removeSubmodule(text, (text) => text.includes("(ts.NavigateTo = {})")); + text = removeSubmodule(text, (text) => + text.includes("(ts.NavigationBar = {})") + ); + text = removeSubmodule(text, (text) => + text.includes("(ts.OrganizeImports = {})") + ); + text = removeSubmodule(text, (text) => + text.includes("(ts.OutliningElementsCollector = {})") + ); + text = removeSubmodule(text, (text) => + text.includes("ts.createPatternMatcher = createPatternMatcher;") + ); + text = removeSubmodule(text, (text) => + text.includes("(ts.SymbolDisplay = {})") + ); + + // `ts.refactor` (multiple) + text = removeMultipleSubmodules(text, (text) => + text.trimStart().startsWith("var refactor;") + ); + + // `ts.codefix` (multiple) + text = removeMultipleSubmodules(text, (text) => + text.trimStart().startsWith("var codefix;") + ); + + // `ts.formatting` (multiple) + text = removeMultipleSubmodules(text, (text) => + text.trimStart().startsWith("var formatting;") + ); + + // `ts.Completions` (multiple) + text = removeMultipleSubmodules(text, (text) => + text.trimStart().startsWith("var Completions;") + ); + + // `ts.FindAllReferences` (multiple) + text = removeMultipleSubmodules(text, (text) => + text.trimStart().startsWith("var FindAllReferences;") + ); + + // Performance + text = replaceSubmodule( + text, + (text) => + text.includes( + "ts.tryGetNativePerformanceHooks = tryGetNativePerformanceHooks;" + ), + outdent` + ts.tryGetNativePerformanceHooks = () => {}; + ts.timestamp = Date.now; + ` + ); + + for (const [find, replacement] of Object.entries({ + // yarn pnp + "process.versions.pnp": "undefined", + + // Dynamic `require()`s + "ts.sys && ts.sys.require": "false", + "require(etwModulePath)": "undefined", + })) { + text = text.replaceAll(find, replacement); + } + + text = replaceAlignedCode(text, { + start: "var debugObjectHost = (function () {", + end: "})();", + }); + + return text; +} + +// Save modified code to `{PROJECT_ROOT}/.tmp/modified-typescript.js` for debug +const saveOutputToDisk = (process) => (text) => { + const result = process(text); + writeFile(path.join(PROJECT_ROOT, ".tmp/modified-typescript.js"), result); + return result; +}; + +export default saveOutputToDisk(modifyTypescriptModule); From b0d9387b95cdd4e9d50f5999d3be53b0b5d03a97 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Sat, 17 Sep 2022 20:32:03 +0800 Subject: [PATCH 016/136] Fix unpkg link (#13484) --- docs/browser.md | 4 ++-- scripts/release/steps/update-version.js | 5 ++++- website/versioned_docs/version-stable/browser.md | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/browser.md b/docs/browser.md index cab603285900..b0f5403627ed 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. diff --git a/scripts/release/steps/update-version.js b/scripts/release/steps/update-version.js index b97cbe7da1aa..56ab17054afd 100644 --- a/scripts/release/steps/update-version.js +++ b/scripts/release/steps/update-version.js @@ -24,7 +24,10 @@ async function bump({ version }) { // Update unpkg link in docs processFile("docs/browser.md", (content) => - content.replace(/(\/\/unpkg\.com\/prettier@).*?\//g, `$1${version}/`) + content.replace( + /(\/\/unpkg\.com\/(?:browse\/)?prettier@).*?\//g, + `$1${version}/` + ) ); await runYarn(["update-stable-docs"], { diff --git a/website/versioned_docs/version-stable/browser.md b/website/versioned_docs/version-stable/browser.md index 969e51d63414..6bd05b7e709d 100644 --- a/website/versioned_docs/version-stable/browser.md +++ b/website/versioned_docs/version-stable/browser.md @@ -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 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. From 8764a3d3784e085a21d5475b67a9b70d4a287495 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 22 Sep 2022 19:11:19 +0800 Subject: [PATCH 017/136] Improve typescript bundle speed (#13433) --- package.json | 1 + scripts/build/modify-typescript-module.mjs | 501 +++++++++++---------- yarn.lock | 7 + 3 files changed, 265 insertions(+), 244 deletions(-) diff --git a/package.json b/package.json index 60d0095613a2..c8b85a22ca6d 100644 --- a/package.json +++ b/package.json @@ -128,6 +128,7 @@ "jest-snapshot-serializer-ansi": "1.0.0", "jest-snapshot-serializer-raw": "1.2.0", "jest-watch-typeahead": "1.0.0", + "magic-string": "0.26.4", "node-actionlint": "1.2.2", "node-fetch": "3.2.10", "npm-run-all": "4.1.5", diff --git a/scripts/build/modify-typescript-module.mjs b/scripts/build/modify-typescript-module.mjs index da1b4760729c..634abd5fbf1e 100644 --- a/scripts/build/modify-typescript-module.mjs +++ b/scripts/build/modify-typescript-module.mjs @@ -1,6 +1,7 @@ import path from "node:path"; import escapeStringRegexp from "escape-string-regexp"; import { outdent } from "outdent"; +import MagicString from "magic-string"; import { writeFile, PROJECT_ROOT } from "../utils/index.mjs"; /* @@ -17,7 +18,7 @@ var ts; const SUBMODULE_START = escapeStringRegexp("var ts;\n(function (ts) {"); const SUBMODULE_END = escapeStringRegexp("})(ts || (ts = {}));"); -function getSubmodules(text, testFunction) { +function getSubmodules(text) { const regexp = new RegExp( [ "(?<=\n)", @@ -31,74 +32,108 @@ function getSubmodules(text, testFunction) { "gsu" ); - return [...text.matchAll(regexp)] - .filter((match) => testFunction(match.groups.text)) - .map((match) => ({ - start: match.index, - end: match.index + match[0].length, - ...match.groups, - })); + return [...text.matchAll(regexp)].map((match) => ({ + start: match.index, + end: match.index + match[0].length, + ...match.groups, + })); } -function removeSubmodule(text, testFunction) { - return replaceSubmodule(text, testFunction, ""); -} +class TypeScriptModuleSource { + #source; + #modules; -function replaceSubmodule(text, testFunction, replacement) { - const modules = getSubmodules(text, testFunction); - if (modules.length !== 1) { - return text; - // TODO: Enable this check when merge to `next` branch - // throw Object.assign( - // new Error( - // `Expect exactly one submodule to be found, got ${modules.length} submodules.` - // ), - // { modules } - // ); + constructor(text) { + this.#source = new MagicString(text); + this.#modules = getSubmodules(text); } - const [{ start, end, before, after }] = modules; - if (replacement) { - replacement = before + "\n" + replacement + "\n" + after; + removeSubmodule(testFunction) { + return this.replaceSubmodule(testFunction, ""); } - return text.slice(0, start) + replacement + text.slice(end); -} + replaceSubmodule(testFunction, replacement) { + const modules = this.#modules.filter(({ text }) => testFunction(text)); + if (modules.length !== 1) { + return this; + + // TODO: Enable this check when merge to `next` branch + // throw Object.assign( + // new Error( + // `Expect exactly one submodule to be found, got ${modules.length} submodules.` + // ), + // { modules } + // ); + } + + const [{ start, end, before, after }] = modules; + if (!replacement) { + this.#source.remove(start, end); + } else { + this.#source.overwrite( + start, + end, + before + "\n" + replacement + "\n" + after + ); + } + return this; + } + + removeMultipleSubmodules(testFunction) { + const modules = this.#modules.filter(({ text }) => testFunction(text)); -function removeMultipleSubmodules(text, testFunction) { - let modules = getSubmodules(text, testFunction); + if (modules.length < 2) { + throw new Error("Expect more than one submodules to be found"); + } - if (modules.length < 2) { - throw new Error("Expect more than one submodules to be found"); + for (const { start, end } of modules) { + this.#source.remove(start, end); + } + return this; } - for (; modules.length > 0; modules = getSubmodules(text, testFunction)) { - const [{ start, end }] = modules; - text = text.slice(0, start) + text.slice(end); + replaceAlignedCode({ start, end, replacement = "" }) { + const regexp = new RegExp( + [ + "(?<=\n)", + "(?\\s*)", + escapeStringRegexp(start), + ".*?", + "(?<=\n)", + "\\k", + escapeStringRegexp(end), + "(?=\n)", + ].join(""), + "gsu" + ); + + this.#source.replaceAll(regexp, replacement); + return this; } - return text; -} + remove(...args) { + this.#source.remove(...args); + return this; + } -function replaceAlignedCode(text, { start, end, replacement = "" }) { - const regexp = new RegExp( - [ - "(?<=\n)", - "(?\\s*)", - escapeStringRegexp(start), - ".*?", - "(?<=\n)", - "\\k", - escapeStringRegexp(end), - "(?=\n)", - ].join(""), - "gsu" - ); + append(...args) { + this.#source.append(...args); + return this; + } + + replaceAll(...args) { + this.#source.replaceAll(...args); + return this; + } - return text.replaceAll(regexp, replacement); + toString() { + return this.#source.toString(); + } } function modifyTypescriptModule(text) { + const source = new TypeScriptModuleSource(text); + // Code after `globalThis` shim are useless const positionOfGlobalThisShim = text.indexOf( "// We polyfill `globalThis` here so re can reliably patch the global scope" @@ -106,276 +141,262 @@ function modifyTypescriptModule(text) { if (positionOfGlobalThisShim === -1) { throw new Error("Unexpected source."); } - text = text.slice(0, positionOfGlobalThisShim) + "module.exports = ts;"; + source.remove(positionOfGlobalThisShim, text.length); + source.append("module.exports = ts;"); // File system - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.includes("ts.generateDjb2Hash = generateDjb2Hash;") ); // Language service - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.includes("ts.TypeScriptServicesFactory = TypeScriptServicesFactory;") ); // `ts.Version` - text = removeSubmodule(text, (text) => - text.includes("ts.Version = Version;") - ); + source.removeSubmodule((text) => text.includes("ts.Version = Version;")); // `ts.transform` - text = removeSubmodule(text, (text) => - text.includes("ts.transform = transform;") - ); + source.removeSubmodule((text) => text.includes("ts.transform = transform;")); // `ts.BreakpointResolver` - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.trimStart().startsWith("var BreakpointResolver;") ); // `ts.textChanges` - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.trimStart().startsWith("var textChanges;") ); // `ts.preProcessFile` - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.includes("ts.preProcessFile = preProcessFile;") ); // `ts.Rename` - text = removeSubmodule(text, (text) => - text.trimStart().startsWith("var Rename;") - ); + source.removeSubmodule((text) => text.trimStart().startsWith("var Rename;")); // `ts.SmartSelectionRange` - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.trimStart().startsWith("var SmartSelectionRange;") ); // `ts.SignatureHelp` - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.trimStart().startsWith("var SignatureHelp;") ); // `ts.InlayHints` - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.trimStart().startsWith("var InlayHints;") ); // Sourcemap - text = removeSubmodule(text, (text) => - text.includes("ts.getSourceMapper = getSourceMapper;") - ); - text = removeSubmodule(text, (text) => - text.includes("ts.createSourceMapGenerator = createSourceMapGenerator;") - ); + source + .removeSubmodule((text) => + text.includes("ts.getSourceMapper = getSourceMapper;") + ) + .removeSubmodule((text) => + text.includes("ts.createSourceMapGenerator = createSourceMapGenerator;") + ); // Suggestion - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.includes( "ts.computeSuggestionDiagnostics = computeSuggestionDiagnostics;" ) ); // Tracing - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.includes("ts.startTracing = tracingEnabled.startTracing;") ); // Diagnostics - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.includes("ts.createProgramHost = createProgramHost;") ); // `ts.transformTypeScript` - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.includes("ts.transformTypeScript = transformTypeScript;") ); // `ts.createRuntimeTypeSerializer` - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.includes( "ts.createRuntimeTypeSerializer = createRuntimeTypeSerializer;" ) ); // Transform - // `ts.transformLegacyDecorators` - text = removeSubmodule(text, (text) => - text.includes("ts.transformLegacyDecorators = transformLegacyDecorators;") - ); - // `ts.transformES5` - text = removeSubmodule(text, (text) => - text.includes("ts.transformES5 = transformES5;") - ); - // `ts.transformES2015` - text = removeSubmodule(text, (text) => - text.includes("ts.transformES2015 = transformES2015;") - ); - // `ts.transformES2016` - text = removeSubmodule(text, (text) => - text.includes("ts.transformES2016 = transformES2016;") - ); - // `ts.transformES2017` & `ts.createSuperAccessVariableStatement` - text = removeSubmodule( - text, - (text) => - text.includes("ts.transformES2017 = transformES2017;") && - text.includes( - "ts.createSuperAccessVariableStatement = createSuperAccessVariableStatement;" - ) - ); - // `ts.transformES2018` - text = removeSubmodule(text, (text) => - text.includes("ts.transformES2018 = transformES2018;") - ); - // `ts.transformES2019` - text = removeSubmodule(text, (text) => - text.includes("ts.transformES2019 = transformES2019;") - ); - // `ts.transformES2020` - text = removeSubmodule(text, (text) => - text.includes("ts.transformES2020 = transformES2020;") - ); - // `ts.transformES2021` - text = removeSubmodule(text, (text) => - text.includes("ts.transformES2021 = transformES2021;") - ); - // `ts.transformESNext` - text = removeSubmodule(text, (text) => - text.includes("ts.transformESNext = transformESNext;") - ); - // `ts.transformJsx` - text = removeSubmodule(text, (text) => - text.includes("ts.transformJsx = transformJsx;") - ); - // `ts.transformGenerators` - text = removeSubmodule(text, (text) => - text.includes("ts.transformGenerators = transformGenerators;") - ); - // `ts.transformModule` - text = removeSubmodule(text, (text) => - text.includes("ts.transformModule = transformModule;") - ); - // `ts.transformSystemModule` - text = removeSubmodule(text, (text) => - text.includes("ts.transformSystemModule = transformSystemModule;") - ); - // `ts.transformECMAScriptModule` - text = removeSubmodule(text, (text) => - text.includes("ts.transformECMAScriptModule = transformECMAScriptModule;") - ); - // `ts.transformNodeModule` - text = removeSubmodule(text, (text) => - text.includes("ts.transformNodeModule = transformNodeModule;") - ); - // `ts.transformClassFields` - text = removeSubmodule(text, (text) => - text.includes("ts.transformClassFields = transformClassFields;") - ); - // `ts.transformDeclarations` - text = removeSubmodule(text, (text) => - text.includes("ts.transformDeclarations = transformDeclarations;") - ); + source + // `ts.transformLegacyDecorators` + .removeSubmodule((text) => + text.includes("ts.transformLegacyDecorators = transformLegacyDecorators;") + ) + // `ts.transformES5` + .removeSubmodule((text) => text.includes("ts.transformES5 = transformES5;")) + // `ts.transformES2015` + .removeSubmodule((text) => + text.includes("ts.transformES2015 = transformES2015;") + ) + // `ts.transformES2016` + .removeSubmodule((text) => + text.includes("ts.transformES2016 = transformES2016;") + ) + // `ts.transformES2017` & `ts.createSuperAccessVariableStatement` + .removeSubmodule( + (text) => + text.includes("ts.transformES2017 = transformES2017;") && + text.includes( + "ts.createSuperAccessVariableStatement = createSuperAccessVariableStatement;" + ) + ) + // `ts.transformES2018` + .removeSubmodule((text) => + text.includes("ts.transformES2018 = transformES2018;") + ) + // `ts.transformES2019` + .removeSubmodule((text) => + text.includes("ts.transformES2019 = transformES2019;") + ) + // `ts.transformES2020` + .removeSubmodule((text) => + text.includes("ts.transformES2020 = transformES2020;") + ) + // `ts.transformES2021` + .removeSubmodule((text) => + text.includes("ts.transformES2021 = transformES2021;") + ) + // `ts.transformESNext` + .removeSubmodule((text) => + text.includes("ts.transformESNext = transformESNext;") + ) + // `ts.transformJsx` + .removeSubmodule((text) => text.includes("ts.transformJsx = transformJsx;")) + // `ts.transformGenerators` + .removeSubmodule((text) => + text.includes("ts.transformGenerators = transformGenerators;") + ) + // `ts.transformModule` + .removeSubmodule((text) => + text.includes("ts.transformModule = transformModule;") + ) + // `ts.transformSystemModule` + .removeSubmodule((text) => + text.includes("ts.transformSystemModule = transformSystemModule;") + ) + // `ts.transformECMAScriptModule` + .removeSubmodule((text) => + text.includes("ts.transformECMAScriptModule = transformECMAScriptModule;") + ) + // `ts.transformNodeModule` + .removeSubmodule((text) => + text.includes("ts.transformNodeModule = transformNodeModule;") + ) + // `ts.transformClassFields` + .removeSubmodule((text) => + text.includes("ts.transformClassFields = transformClassFields;") + ) + // `ts.transformDeclarations` + .removeSubmodule((text) => + text.includes("ts.transformDeclarations = transformDeclarations;") + ); + // `ts.transformNodes` and more - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.includes("ts.transformNodes = transformNodes;") ); // `ts.server` - text = removeSubmodule(text, (text) => text.includes("(ts.server = {})")); + source.removeSubmodule((text) => text.includes("(ts.server = {})")); // `ts.JsTyping` - text = removeSubmodule(text, (text) => text.includes("(ts.JsTyping = {})")); + source.removeSubmodule((text) => text.includes("(ts.JsTyping = {})")); // `ts.ClassificationType` - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.includes("(ts.ClassificationType = {})") ); // Build - text = removeSubmodule(text, (text) => - text.includes("ts.createSolutionBuilder = createSolutionBuilder;") - ); - text = removeSubmodule(text, (text) => - text.includes("ts.parseBuildCommand = parseBuildCommand;") - ); - text = removeSubmodule(text, (text) => - text.includes("ts.createBuilderProgram = createBuilderProgram;") - ); - text = removeSubmodule(text, (text) => - text.includes( - "ts.createSemanticDiagnosticsBuilderProgram = createSemanticDiagnosticsBuilderProgram;" + source + .removeSubmodule((text) => + text.includes("ts.createSolutionBuilder = createSolutionBuilder;") ) - ); - text = removeSubmodule(text, (text) => - text.includes("ts.createResolutionCache = createResolutionCache;") - ); - text = removeSubmodule(text, (text) => - text.includes("ts.createWatchCompilerHost = createWatchCompilerHost;") - ); - text = removeSubmodule(text, (text) => - text.includes( - "ts.resolveConfigFileProjectName = resolveConfigFileProjectName;" + .removeSubmodule((text) => + text.includes("ts.parseBuildCommand = parseBuildCommand;") ) - ); - text = removeSubmodule(text, (text) => - text.includes("ts.getBuildInfo = getBuildInfo;") - ); + .removeSubmodule((text) => + text.includes("ts.createBuilderProgram = createBuilderProgram;") + ) + .removeSubmodule((text) => + text.includes( + "ts.createSemanticDiagnosticsBuilderProgram = createSemanticDiagnosticsBuilderProgram;" + ) + ) + .removeSubmodule((text) => + text.includes("ts.createResolutionCache = createResolutionCache;") + ) + .removeSubmodule((text) => + text.includes("ts.createWatchCompilerHost = createWatchCompilerHost;") + ) + .removeSubmodule((text) => + text.includes( + "ts.resolveConfigFileProjectName = resolveConfigFileProjectName;" + ) + ) + .removeSubmodule((text) => + text.includes("ts.getBuildInfo = getBuildInfo;") + ); // Compile - text = removeSubmodule(text, (text) => - text.includes("ts.createCompilerHost = createCompilerHost;") - ); - text = removeSubmodule(text, (text) => - text.includes("(ts.BuilderState = {})") - ); - text = removeSubmodule(text, (text) => - text.includes("ts.transpile = transpile;") - ); + source + .removeSubmodule((text) => + text.includes("ts.createCompilerHost = createCompilerHost;") + ) + .removeSubmodule((text) => text.includes("(ts.BuilderState = {})")) + .removeSubmodule((text) => text.includes("ts.transpile = transpile;")); // Watch - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.includes("ts.getWatchFactory = getWatchFactory;") ); // `ts.canProduceDiagnostics`, `ts.createGetSymbolAccessibilityDiagnosticForNode`, and `ts.createGetSymbolAccessibilityDiagnosticForNode` - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.includes("ts.canProduceDiagnostics = canProduceDiagnostics;") ); // `ts.moduleSpecifiers` - text = removeSubmodule(text, (text) => - text.includes("(ts.moduleSpecifiers = {})") - ); + source.removeSubmodule((text) => text.includes("(ts.moduleSpecifiers = {})")); // `ts.trace` - text = removeSubmodule(text, (text) => text.includes("ts.trace = trace;")); + source.removeSubmodule((text) => text.includes("ts.trace = trace;")); // `ts.createTypeChecker` - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.includes("ts.createTypeChecker = createTypeChecker;") ); // `ts.DocumentHighlights` - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.includes("(ts.DocumentHighlights = {})") ); // `ts.createDocumentRegistry` - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.includes("ts.createDocumentRegistry = createDocumentRegistry;") ); // `ts.CallHierarchy` - text = removeSubmodule(text, (text) => - text.includes("(ts.CallHierarchy = {})") - ); + source.removeSubmodule((text) => text.includes("(ts.CallHierarchy = {})")); // `ts.flattenDestructuringAssignment` and `ts.flattenDestructuringBinding` - text = removeSubmodule( - text, + source.removeSubmodule( (text) => text.includes( "ts.flattenDestructuringAssignment = flattenDestructuringAssignment" @@ -386,65 +407,57 @@ function modifyTypescriptModule(text) { ); // `ts.processTaggedTemplateExpression` - text = removeSubmodule(text, (text) => + source.removeSubmodule((text) => text.includes( "ts.processTaggedTemplateExpression = processTaggedTemplateExpression" ) ); // Editor - text = removeSubmodule(text, (text) => - text.includes("ts.getEditsForFileRename = getEditsForFileRename;") - ); - text = removeSubmodule(text, (text) => - text.includes("(ts.GoToDefinition = {})") - ); - text = removeSubmodule(text, (text) => text.includes("(ts.JsDoc = {})")); - text = removeSubmodule(text, (text) => text.includes("(ts.NavigateTo = {})")); - text = removeSubmodule(text, (text) => - text.includes("(ts.NavigationBar = {})") - ); - text = removeSubmodule(text, (text) => - text.includes("(ts.OrganizeImports = {})") - ); - text = removeSubmodule(text, (text) => - text.includes("(ts.OutliningElementsCollector = {})") - ); - text = removeSubmodule(text, (text) => - text.includes("ts.createPatternMatcher = createPatternMatcher;") - ); - text = removeSubmodule(text, (text) => - text.includes("(ts.SymbolDisplay = {})") - ); + source + .removeSubmodule((text) => + text.includes("ts.getEditsForFileRename = getEditsForFileRename;") + ) + .removeSubmodule((text) => text.includes("(ts.GoToDefinition = {})")) + .removeSubmodule((text) => text.includes("(ts.JsDoc = {})")) + .removeSubmodule((text) => text.includes("(ts.NavigateTo = {})")) + .removeSubmodule((text) => text.includes("(ts.NavigationBar = {})")) + .removeSubmodule((text) => text.includes("(ts.OrganizeImports = {})")) + .removeSubmodule((text) => + text.includes("(ts.OutliningElementsCollector = {})") + ) + .removeSubmodule((text) => + text.includes("ts.createPatternMatcher = createPatternMatcher;") + ) + .removeSubmodule((text) => text.includes("(ts.SymbolDisplay = {})")); // `ts.refactor` (multiple) - text = removeMultipleSubmodules(text, (text) => + source.removeMultipleSubmodules((text) => text.trimStart().startsWith("var refactor;") ); // `ts.codefix` (multiple) - text = removeMultipleSubmodules(text, (text) => + source.removeMultipleSubmodules((text) => text.trimStart().startsWith("var codefix;") ); // `ts.formatting` (multiple) - text = removeMultipleSubmodules(text, (text) => + source.removeMultipleSubmodules((text) => text.trimStart().startsWith("var formatting;") ); // `ts.Completions` (multiple) - text = removeMultipleSubmodules(text, (text) => + source.removeMultipleSubmodules((text) => text.trimStart().startsWith("var Completions;") ); // `ts.FindAllReferences` (multiple) - text = removeMultipleSubmodules(text, (text) => + source.removeMultipleSubmodules((text) => text.trimStart().startsWith("var FindAllReferences;") ); // Performance - text = replaceSubmodule( - text, + source.replaceSubmodule( (text) => text.includes( "ts.tryGetNativePerformanceHooks = tryGetNativePerformanceHooks;" @@ -463,15 +476,15 @@ function modifyTypescriptModule(text) { "ts.sys && ts.sys.require": "false", "require(etwModulePath)": "undefined", })) { - text = text.replaceAll(find, replacement); + source.replaceAll(find, replacement); } - text = replaceAlignedCode(text, { + source.replaceAlignedCode({ start: "var debugObjectHost = (function () {", end: "})();", }); - return text; + return source.toString(); } // Save modified code to `{PROJECT_ROOT}/.tmp/modified-typescript.js` for debug diff --git a/yarn.lock b/yarn.lock index 0be6db91d6bb..d7250d3eacc7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4885,6 +4885,13 @@ magic-string@0.26.1: dependencies: sourcemap-codec "^1.4.8" +magic-string@0.26.4: + version "0.26.4" + resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.26.4.tgz#3d057d3d0234c3b179aa3f421b33fe5d8a4044a8" + integrity sha512-e5uXtVJ22aEpK9u1+eQf0fSxHeqwyV19K+uGnlROCxUhzwRip9tBsaMViK/0vC3viyPd5Gtucp3UmEp/Q2cPTQ== + dependencies: + sourcemap-codec "^1.4.8" + magic-string@^0.25.3: version "0.25.7" resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.7.tgz#3f497d6fd34c669c6798dcb821f2ef31f5445051" From 2bc757554b83f25b12db67acb37b2228d32cc440 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 22 Sep 2022 19:11:34 +0800 Subject: [PATCH 018/136] Update `acorn` & `espree` (#13506) --- package.json | 6 +- .../__snapshots__/jsfmt.spec.js.snap | 4 +- yarn.lock | 103 +++++++++++------- 3 files changed, 66 insertions(+), 47 deletions(-) diff --git a/package.json b/package.json index c8b85a22ca6d..5fe4ede9a2ce 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "@glimmer/syntax": "0.84.2", "@iarna/toml": "2.2.5", "@typescript-eslint/typescript-estree": "5.30.0", - "acorn": "8.7.0", + "acorn": "8.8.0", "acorn-jsx": "5.3.2", "angular-estree-parser": "2.5.1", "angular-html-parser": "1.8.0", @@ -43,7 +43,7 @@ "editorconfig": "0.15.3", "editorconfig-to-prettier": "0.2.0", "escape-string-regexp": "5.0.0", - "espree": "9.3.1", + "espree": "9.4.0", "esutils": "2.0.3", "fast-glob": "3.2.11", "fast-json-stable-stringify": "2.1.0", @@ -112,7 +112,7 @@ "enquirer": "2.3.6", "esbuild": "0.14.42", "esbuild-visualizer": "0.3.1", - "eslint": "8.14.0", + "eslint": "8.23.1", "eslint-config-prettier": "8.5.0", "eslint-formatter-friendly": "7.0.0", "eslint-plugin-compat": "4.0.2", diff --git a/tests/format/misc/errors/js/assignment/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/js/assignment/__snapshots__/jsfmt.spec.js.snap index 1f677eedcf20..1ece57b5bafd 100644 --- a/tests/format/misc/errors/js/assignment/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/errors/js/assignment/__snapshots__/jsfmt.spec.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`snippet: #0 [acorn] format 1`] = ` -"Parenthesized pattern (1:1) +"Assigning to rvalue (1:1) > 1 | ({}) = x; | ^" `; @@ -19,7 +19,7 @@ exports[`snippet: #0 [babel-ts] format 1`] = ` `; exports[`snippet: #0 [espree] format 1`] = ` -"Parenthesized pattern (1:1) +"Assigning to rvalue (1:1) > 1 | ({}) = x; | ^" `; diff --git a/yarn.lock b/yarn.lock index d7250d3eacc7..e545351d8422 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1229,19 +1229,19 @@ escape-string-regexp "^4.0.0" rollup-plugin-node-polyfills "^0.2.1" -"@eslint/eslintrc@^1.2.2": - version "1.2.2" - resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-1.2.2.tgz#4989b9e8c0216747ee7cca314ae73791bb281aae" - integrity sha512-lTVWHs7O2hjBFZunXTZYnYqtB9GakA1lnxIf+gKq2nY5gxkkNi/lQvveW6t8gFdOHTg6nG50Xs95PrLqVpcaLg== +"@eslint/eslintrc@^1.3.2": + version "1.3.2" + resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-1.3.2.tgz#58b69582f3b7271d8fa67fe5251767a5b38ea356" + integrity sha512-AXYd23w1S/bv3fTs3Lz0vjiYemS08jWkI3hYyS9I1ry+0f+Yjs1wm+sU0BS8qDOPrBIkp4qHYC16I8uVtpLajQ== dependencies: ajv "^6.12.4" debug "^4.3.2" - espree "^9.3.1" - globals "^13.9.0" + espree "^9.4.0" + globals "^13.15.0" ignore "^5.2.0" import-fresh "^3.2.1" js-yaml "^4.1.0" - minimatch "^3.0.4" + minimatch "^3.1.2" strip-json-comments "^3.1.1" "@glimmer/env@0.1.7", "@glimmer/env@^0.1.7": @@ -1306,15 +1306,25 @@ resolved "https://registry.yarnpkg.com/@handlebars/parser/-/parser-2.0.0.tgz#5e8b7298f31ff8f7b260e6b7363c7e9ceed7d9c5" integrity sha512-EP9uEDZv/L5Qh9IWuMUGJRfwhXJ4h1dqKTT4/3+tY0eu7sPis7xh23j61SYUnNF4vqCQvvUXpDo9Bh/+q1zASA== -"@humanwhocodes/config-array@^0.9.2": - version "0.9.3" - resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.9.3.tgz#f2564c744b387775b436418491f15fce6601f63e" - integrity sha512-3xSMlXHh03hCcCmFc0rbKp3Ivt2PFEJnQUJDDMTJQ2wkECZWdq4GePs2ctc5H8zV+cHPaq8k2vU8mrQjA6iHdQ== +"@humanwhocodes/config-array@^0.10.4": + version "0.10.5" + resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.10.5.tgz#bb679745224745fff1e9a41961c1d45a49f81c04" + integrity sha512-XVVDtp+dVvRxMoxSiSfasYaG02VEe1qH5cKgMQJWhol6HwzbcqoCMJi8dAGoYAO57jhUyhI6cWuRiTcRaDaYug== dependencies: "@humanwhocodes/object-schema" "^1.2.1" debug "^4.1.1" minimatch "^3.0.4" +"@humanwhocodes/gitignore-to-minimatch@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@humanwhocodes/gitignore-to-minimatch/-/gitignore-to-minimatch-1.0.2.tgz#316b0a63b91c10e53f242efb4ace5c3b34e8728d" + integrity sha512-rSqmMJDdLFUsyxR6FMtD00nfQKKLFb1kv+qBbOVKqErvloEIJLo5bDTJTQNTYgeyp78JsA7u/NPi5jT1GR/MuA== + +"@humanwhocodes/module-importer@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz#af5b2691a22b44be847b0ca81641c5fb6ad0172c" + integrity sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA== + "@humanwhocodes/object-schema@^1.2.1": version "1.2.1" resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45" @@ -1850,7 +1860,7 @@ acorn-globals@^6.0.0: acorn "^7.1.1" acorn-walk "^7.1.1" -acorn-jsx@5.3.2, acorn-jsx@^5.3.1: +acorn-jsx@5.3.2, acorn-jsx@^5.3.2: version "5.3.2" resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937" integrity sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ== @@ -1860,16 +1870,21 @@ acorn-walk@^7.1.1: resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-7.2.0.tgz#0de889a601203909b0fbe07b8938dc21d2e967bc" integrity sha512-OPdCF6GsMIP+Az+aWfAAOEt2/+iVDKE7oy6lJ098aoe59oAmK76qV6Gw60SbZ8jHuG2wH058GF4pLFbYamYrVA== -acorn@8.7.0, acorn@^8.2.4, acorn@^8.7.0: - version "8.7.0" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.0.tgz#90951fde0f8f09df93549481e5fc141445b791cf" - integrity sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ== +acorn@8.8.0, acorn@^8.8.0: + version "8.8.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.0.tgz#88c0187620435c7f6015803f5539dae05a9dbea8" + integrity sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w== acorn@^7.1.1: version "7.4.1" resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa" integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== +acorn@^8.2.4: + version "8.7.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.0.tgz#90951fde0f8f09df93549481e5fc141445b791cf" + integrity sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ== + agent-base@6: version "6.0.2" resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77" @@ -3185,13 +3200,15 @@ eslint-visitor-keys@^3.0.0, eslint-visitor-keys@^3.3.0: resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz#f6480fa6b1f30efe2d1968aa8ac745b862469826" integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA== -eslint@8.14.0: - version "8.14.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.14.0.tgz#62741f159d9eb4a79695b28ec4989fcdec623239" - integrity sha512-3/CE4aJX7LNEiE3i6FeodHmI/38GZtWCsAtsymScmzYapx8q1nVVb+eLcLSzATmCPXw5pT4TqVs1E0OmxAd9tw== +eslint@8.23.1: + version "8.23.1" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.23.1.tgz#cfd7b3f7fdd07db8d16b4ac0516a29c8d8dca5dc" + integrity sha512-w7C1IXCc6fNqjpuYd0yPlcTKKmHlHHktRkzmBPZ+7cvNBQuiNjx0xaMTjAJGCafJhQkrFJooREv0CtrVzmHwqg== dependencies: - "@eslint/eslintrc" "^1.2.2" - "@humanwhocodes/config-array" "^0.9.2" + "@eslint/eslintrc" "^1.3.2" + "@humanwhocodes/config-array" "^0.10.4" + "@humanwhocodes/gitignore-to-minimatch" "^1.0.2" + "@humanwhocodes/module-importer" "^1.0.1" ajv "^6.10.0" chalk "^4.0.0" cross-spawn "^7.0.2" @@ -3201,30 +3218,32 @@ eslint@8.14.0: eslint-scope "^7.1.1" eslint-utils "^3.0.0" eslint-visitor-keys "^3.3.0" - espree "^9.3.1" + espree "^9.4.0" esquery "^1.4.0" esutils "^2.0.2" fast-deep-equal "^3.1.3" file-entry-cache "^6.0.1" - functional-red-black-tree "^1.0.1" + find-up "^5.0.0" glob-parent "^6.0.1" - globals "^13.6.0" + globals "^13.15.0" + globby "^11.1.0" + grapheme-splitter "^1.0.4" ignore "^5.2.0" import-fresh "^3.0.0" imurmurhash "^0.1.4" is-glob "^4.0.0" + js-sdsl "^4.1.4" js-yaml "^4.1.0" json-stable-stringify-without-jsonify "^1.0.1" levn "^0.4.1" lodash.merge "^4.6.2" - minimatch "^3.0.4" + minimatch "^3.1.2" natural-compare "^1.4.0" optionator "^0.9.1" regexpp "^3.2.0" strip-ansi "^6.0.1" strip-json-comments "^3.1.0" text-table "^0.2.0" - v8-compile-cache "^2.0.3" esm-utils@3.0.0: version "3.0.0" @@ -3233,13 +3252,13 @@ esm-utils@3.0.0: dependencies: url-or-path "2.1.0" -espree@9.3.1, espree@^9.3.1: - version "9.3.1" - resolved "https://registry.yarnpkg.com/espree/-/espree-9.3.1.tgz#8793b4bc27ea4c778c19908e0719e7b8f4115bcd" - integrity sha512-bvdyLmJMfwkV3NCRl5ZhJf22zBFo1y8bYh3VYb+bfzqNB4Je68P2sSuXyuFquzWLebHpNd2/d5uv7yoP9ISnGQ== +espree@9.4.0, espree@^9.4.0: + version "9.4.0" + resolved "https://registry.yarnpkg.com/espree/-/espree-9.4.0.tgz#cd4bc3d6e9336c433265fc0aa016fc1aaf182f8a" + integrity sha512-DQmnRpLj7f6TgN/NYb0MTzJXL+vJF9h3pHy4JhCIs3zwcgez8xmGg3sXHcEO97BrmO2OSvCwMdfdlyl+E9KjOw== dependencies: - acorn "^8.7.0" - acorn-jsx "^5.3.1" + acorn "^8.8.0" + acorn-jsx "^5.3.2" eslint-visitor-keys "^3.3.0" esprima@^4.0.0, esprima@^4.0.1: @@ -3598,10 +3617,10 @@ globals@^11.1.0: resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e" integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA== -globals@^13.6.0, globals@^13.9.0: - version "13.12.1" - resolved "https://registry.yarnpkg.com/globals/-/globals-13.12.1.tgz#ec206be932e6c77236677127577aa8e50bf1c5cb" - integrity sha512-317dFlgY2pdJZ9rspXDks7073GpDmXdfbM3vYYp0HAMKGDh1FfWPleI2ljVNLQX5M5lXcAslTcPTrOrMEFOjyw== +globals@^13.15.0: + version "13.17.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-13.17.0.tgz#902eb1e680a41da93945adbdcb5a9f361ba69bd4" + integrity sha512-1C+6nQRb1GwGMKm2dH/E7enFAMxGTmGI7/dEdhy/DNelv85w9B72t3uc5frtMNXIbzrarJJ/lTCjcaZwbLJmyw== dependencies: type-fest "^0.20.2" @@ -4636,6 +4655,11 @@ jest@27.5.1: import-local "^3.0.2" jest-cli "^27.5.1" +js-sdsl@^4.1.4: + version "4.1.4" + resolved "https://registry.yarnpkg.com/js-sdsl/-/js-sdsl-4.1.4.tgz#78793c90f80e8430b7d8dc94515b6c77d98a26a6" + integrity sha512-Y2/yD55y5jteOAmY50JbUZYwk3CP3wnLPEZnlR1w9oKhITrBEtAxwuWKebFf8hMrPMgbYwFoWK/lH2sBkErELw== + "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" @@ -6608,11 +6632,6 @@ url-or-path@2.1.0: resolved "https://registry.yarnpkg.com/url-or-path/-/url-or-path-2.1.0.tgz#8bb39a2a2b7e8f2e31c7883d8207b0cbd07acb9f" integrity sha512-dsBD6GbytSMj9YDb3jVzSRENwFh50oUORnWBeSHfo0Lnwv2KMm/J4npyGy1P9rivUPsUGLjTA53XqAFqpe0nww== -v8-compile-cache@^2.0.3: - version "2.3.0" - resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee" - integrity sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA== - v8-to-istanbul@^8.1.0: version "8.1.1" resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-8.1.1.tgz#77b752fd3975e31bbcef938f85e9bd1c7a8d60ed" From 38611cb16eb9af9332a1c9d5f6125a5cd714437d Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Sun, 25 Sep 2022 23:04:50 -0400 Subject: [PATCH 019/136] [handlebars] correctly format custom "else if" blocks (#13507) Co-authored-by: fisker Cheung --- changelog_unreleased/handlebars/13507.md | 33 +++ src/language-handlebars/printer-glimmer.js | 20 +- .../__snapshots__/jsfmt.spec.js.snap | 225 ++++++++++++++++++ .../block-statement/custom-else.hbs | 108 +++++++++ 4 files changed, 377 insertions(+), 9 deletions(-) create mode 100644 changelog_unreleased/handlebars/13507.md create mode 100644 tests/format/handlebars/block-statement/custom-else.hbs diff --git a/changelog_unreleased/handlebars/13507.md b/changelog_unreleased/handlebars/13507.md new file mode 100644 index 000000000000..4a67473ebf8d --- /dev/null +++ b/changelog_unreleased/handlebars/13507.md @@ -0,0 +1,33 @@ +#### Correctly format custom "else if" blocks (#13507 by @jamescdavis) + +A template transform can be used to create custom block keywords that behave similar to `if`. This updates printer-glimmer to correctly recognize and format the "else if" case when "if" is a custom keyword. + + +```hbs +{{! Input }} +{{#when isAtWork}} + Ship that code! +{{else when isReading}} + You can finish War and Peace eventually... +{{else}} + Go to bed! +{{/when}} + +{{! Prettier stable }} +{{#when isAtWork}} + Ship that code! +{{else}}{{#when isReading}} + You can finish War and Peace eventually... + {{else}} + Go to bed! + {{/when}}{{/when}} + +{{! Prettier main }} +{{#when isAtWork}} + Ship that code! +{{else when isReading}} + You can finish War and Peace eventually... +{{else}} + Go to bed! +{{/when}} +``` diff --git a/src/language-handlebars/printer-glimmer.js b/src/language-handlebars/printer-glimmer.js index 6310f4fd11e5..12c6b52d6965 100644 --- a/src/language-handlebars/printer-glimmer.js +++ b/src/language-handlebars/printer-glimmer.js @@ -96,16 +96,16 @@ function print(path, options, print) { case "BlockStatement": { const pp = path.getParentNode(1); - const isElseIf = + const isElseIfLike = pp && pp.inverse && pp.inverse.body.length === 1 && pp.inverse.body[0] === node && - pp.inverse.body[0].path.parts[0] === "if"; + pp.inverse.body[0].path.parts[0] === pp.path.parts[0]; - if (isElseIf) { + if (isElseIfLike) { return [ - printElseIfBlock(path, print), + printElseIfLikeBlock(path, print, pp.inverse.body[0].path.parts[0]), printProgram(path, print, options), printInverse(path, print, options), ]; @@ -562,12 +562,14 @@ function printElseBlock(node, options) { ]; } -function printElseIfBlock(path, print) { +function printElseIfLikeBlock(path, print, ifLikeKeyword) { const parentNode = path.getParentNode(1); return [ printInverseBlockOpeningMustache(parentNode), - "else if ", + "else ", + ifLikeKeyword, + " ", printParams(path, print), printInverseBlockClosingMustache(parentNode), ]; @@ -603,12 +605,12 @@ function blockStatementHasOnlyWhitespaceInProgram(node) { ); } -function blockStatementHasElseIf(node) { +function blockStatementHasElseIfLike(node) { return ( blockStatementHasElse(node) && node.inverse.body.length === 1 && isNodeOfSomeType(node.inverse.body[0], ["BlockStatement"]) && - node.inverse.body[0].path.parts[0] === "if" + node.inverse.body[0].path.parts[0] === node.path.parts[0] ); } @@ -641,7 +643,7 @@ function printInverse(path, print, options) { ? [hardline, inverse] : inverse; - if (blockStatementHasElseIf(node)) { + if (blockStatementHasElseIfLike(node)) { return printed; } diff --git a/tests/format/handlebars/block-statement/__snapshots__/jsfmt.spec.js.snap b/tests/format/handlebars/block-statement/__snapshots__/jsfmt.spec.js.snap index 3c835f71fd95..c9e5f615504f 100644 --- a/tests/format/handlebars/block-statement/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/handlebars/block-statement/__snapshots__/jsfmt.spec.js.snap @@ -159,6 +159,231 @@ printWidth: 80 ================================================================================ `; +exports[`custom-else.hbs format 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== +

+{{#when isAtWork}} + Ship that code! +{{else when isReading}} + You can finish War and Peace eventually... +{{else}} + Go to bed! +{{/when}} +

+ +

+{{#when a}} + A +{{else}} + B +{{/when}} +

+ +{{#when a}} + b +{{else when c}} + d +{{else}} + e +{{/when}} + +{{#when a}} + b +{{else when c}} + d +{{else}} + hello + {{#when f}} + g + {{/when}} + e +{{/when}} + +{{#when a}} + b +{{else when c}} + d +{{else when e}} + f +{{else when g}} + h +{{else}} + j +{{/when}} + +
+ {{#when a}} + b + {{else when c}} + d + {{else}} + e + {{/when}} +
+ +
+
+ {{#when a}} + b + {{else when c}} + d + {{else}} + e + {{/when}} +
+
+ +{{#when a}} + b +{{else}} + {{#each c as |d|}} + e + {{/each}} +{{/when}} + +{{#when a}} + {{#when b}} + ab + {{else when c}} + ac + {{/when}} +{{/when}} + +{{#when a}} + a +
b
+ c +{{else}} + {{#when c}} + a + b +
c
+ {{/when}} +
a
+ b + c +{{/when}} + +{{~#when someCondition~}} + One thing +{{~else when anotherCondition~}} + Another thing +{{~/when~}} + +=====================================output===================================== +

+ {{#when isAtWork}} + Ship that code! + {{else when isReading}} + You can finish War and Peace eventually... + {{else}} + Go to bed! + {{/when}} +

+ +

+ {{#when a}} + A + {{else}} + B + {{/when}} +

+ +{{#when a}} + b +{{else when c}} + d +{{else}} + e +{{/when}} + +{{#when a}} + b +{{else when c}} + d +{{else}} + hello + {{#when f}} + g + {{/when}} + e +{{/when}} + +{{#when a}} + b +{{else when c}} + d +{{else when e}} + f +{{else when g}} + h +{{else}} + j +{{/when}} + +
+ {{#when a}} + b + {{else when c}} + d + {{else}} + e + {{/when}} +
+ +
+
+ {{#when a}} + b + {{else when c}} + d + {{else}} + e + {{/when}} +
+
+ +{{#when a}} + b +{{else}} + {{#each c as |d|}} + e + {{/each}} +{{/when}} + +{{#when a}} + {{#when b}} + ab + {{else when c}} + ac + {{/when}} +{{/when}} + +{{#when a}} + a +
b
+ c +{{else}} + {{#when c}} + a b +
c
+ {{/when}} +
a
+ b c +{{/when}} + +{{~#when someCondition~}} + One thing +{{~else when anotherCondition~}} + Another thing +{{~/when~}} +================================================================================ +`; + exports[`each.hbs format 1`] = ` ====================================options===================================== parsers: ["glimmer"] diff --git a/tests/format/handlebars/block-statement/custom-else.hbs b/tests/format/handlebars/block-statement/custom-else.hbs new file mode 100644 index 000000000000..156d61268cb0 --- /dev/null +++ b/tests/format/handlebars/block-statement/custom-else.hbs @@ -0,0 +1,108 @@ +

+{{#when isAtWork}} + Ship that code! +{{else when isReading}} + You can finish War and Peace eventually... +{{else}} + Go to bed! +{{/when}} +

+ +

+{{#when a}} + A +{{else}} + B +{{/when}} +

+ +{{#when a}} + b +{{else when c}} + d +{{else}} + e +{{/when}} + +{{#when a}} + b +{{else when c}} + d +{{else}} + hello + {{#when f}} + g + {{/when}} + e +{{/when}} + +{{#when a}} + b +{{else when c}} + d +{{else when e}} + f +{{else when g}} + h +{{else}} + j +{{/when}} + +
+ {{#when a}} + b + {{else when c}} + d + {{else}} + e + {{/when}} +
+ +
+
+ {{#when a}} + b + {{else when c}} + d + {{else}} + e + {{/when}} +
+
+ +{{#when a}} + b +{{else}} + {{#each c as |d|}} + e + {{/each}} +{{/when}} + +{{#when a}} + {{#when b}} + ab + {{else when c}} + ac + {{/when}} +{{/when}} + +{{#when a}} + a +
b
+ c +{{else}} + {{#when c}} + a + b +
c
+ {{/when}} +
a
+ b + c +{{/when}} + +{{~#when someCondition~}} + One thing +{{~else when anotherCondition~}} + Another thing +{{~/when~}} From 2bbbe1a8d17961101d076ac530309fd2c6b06cbe Mon Sep 17 00:00:00 2001 From: Nick Rutten <2504906+nickrttn@users.noreply.github.com> Date: Wed, 28 Sep 2022 04:02:17 +0200 Subject: [PATCH 020/136] Improve MDX range ignore support (#12208) Co-authored-by: Nick Rutten Co-authored-by: fisker Cheung --- changelog_unreleased/mdx/12208.md | 29 ++++++ src/language-markdown/printer-markdown.js | 19 +++- .../__snapshots__/jsfmt.spec.js.snap | 95 +++++++++++++++++++ .../multiline-comments.mdx | 40 ++++++++ 4 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 changelog_unreleased/mdx/12208.md create mode 100644 tests/format/mdx/embedded-language-formatting/multiline-comments.mdx diff --git a/changelog_unreleased/mdx/12208.md b/changelog_unreleased/mdx/12208.md new file mode 100644 index 000000000000..df8cd122d8a3 --- /dev/null +++ b/changelog_unreleased/mdx/12208.md @@ -0,0 +1,29 @@ +#### Improve MDX range ignore support (#12208 by @nickrttn) + +Adds support for using Markdown [range ignore](https://prettier.io/docs/en/ignore.html#range-ignore) directives in MDX, using JSX comments. + + +```mdx +// Input +{/* prettier-ignore-start */} + +export const Hello = () => { + return (

+ Hello

) +} + +{/* prettier-ignore-end */} + +// Prettier stable (throws an error) +TypeError: Cannot read properties of undefined (reading 'type') + +// Prettier main +{/* prettier-ignore-start */} + +export const Hello = () => { + return (

+ Hello

) +} + +{/* prettier-ignore-end */} +``` diff --git a/src/language-markdown/printer-markdown.js b/src/language-markdown/printer-markdown.js index f13f116bdd0f..6bc1918d9055 100644 --- a/src/language-markdown/printer-markdown.js +++ b/src/language-markdown/printer-markdown.js @@ -673,12 +673,12 @@ function printRoot(path, options, print) { if (index === ignoreRange.start.index) { return [ - children[ignoreRange.start.index].value, + printIgnoreComment(children[ignoreRange.start.index]), options.originalText.slice( ignoreRange.start.offset, ignoreRange.end.offset ), - children[ignoreRange.end.index].value, + printIgnoreComment(children[ignoreRange.end.index]), ]; } @@ -750,6 +750,21 @@ function printChildren(path, options, print, events = {}) { return postprocessor ? postprocessor(parts) : parts; } +function printIgnoreComment(node) { + if (node.type === "html") { + return node.value; + } + + if ( + node.type === "paragraph" && + Array.isArray(node.children) && + node.children.length === 1 && + node.children[0].type === "esComment" + ) { + return ["{/* ", node.children[0].value, " */}"]; + } +} + function getLastDescendantNode(node) { let current = node; while (isNonEmptyArray(current.children)) { diff --git a/tests/format/mdx/embedded-language-formatting/__snapshots__/jsfmt.spec.js.snap b/tests/format/mdx/embedded-language-formatting/__snapshots__/jsfmt.spec.js.snap index 92feb846722b..be533aa3529c 100644 --- a/tests/format/mdx/embedded-language-formatting/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/mdx/embedded-language-formatting/__snapshots__/jsfmt.spec.js.snap @@ -29,6 +29,101 @@ LF: Line Feed, \\n ================================================================================ `; +exports[`multiline-comments.mdx - {"embeddedLanguageFormatting":"off"} format 1`] = ` +====================================options===================================== +embeddedLanguageFormatting: "off" +parsers: ["mdx"] +printWidth: 80 + | printWidth +=====================================input====================================== +# title + +{/* prettier-ignore-start */} +export const Test = () => { + return

test

; + }; + +{/* prettier-ignore-end */} + +{/* prettier-ignore-start */} + +export const Test = () => { + return

test

; + }; + +{/* prettier-ignore-end */} + +{/* prettier-ignore-start */} +export const Test = () => { + return

test

; + }; + + +{/* prettier-ignore-end */} + +{/* prettier-ignore-start */} + +export const Test = () => { + return

test

; + }; + + +{/* prettier-ignore-end */} + + +export const Test = () => { + return

test

; + }; + + + +=====================================output===================================== +# title + +{/* prettier-ignore-start */} +export const Test = () => { +return

test

; +}; + + +{/* prettier-ignore-end */} + +{/* prettier-ignore-start */} + +export const Test = () => { + return

test

; + }; + +{/* prettier-ignore-end */} + +{/* prettier-ignore-start */} +export const Test = () => { + return

test

; + }; + + +{/* prettier-ignore-end */} + +{/* prettier-ignore-start */} + +export const Test = () => { + return

test

; + }; + + +{/* prettier-ignore-end */} + + + +export const Test = () => { + return

test

; + }; + + + +================================================================================ +`; + exports[`pull-11563.mdx - {"embeddedLanguageFormatting":"off"} format 1`] = ` ====================================options===================================== embeddedLanguageFormatting: "off" diff --git a/tests/format/mdx/embedded-language-formatting/multiline-comments.mdx b/tests/format/mdx/embedded-language-formatting/multiline-comments.mdx new file mode 100644 index 000000000000..ac7f6d57f64f --- /dev/null +++ b/tests/format/mdx/embedded-language-formatting/multiline-comments.mdx @@ -0,0 +1,40 @@ +# title + +{/* prettier-ignore-start */} +export const Test = () => { + return

test

; + }; + +{/* prettier-ignore-end */} + +{/* prettier-ignore-start */} + +export const Test = () => { + return

test

; + }; + +{/* prettier-ignore-end */} + +{/* prettier-ignore-start */} +export const Test = () => { + return

test

; + }; + + +{/* prettier-ignore-end */} + +{/* prettier-ignore-start */} + +export const Test = () => { + return

test

; + }; + + +{/* prettier-ignore-end */} + + +export const Test = () => { + return

test

; + }; + + From bfb09bf214fcdb0e47ed7cb1c702281396c61753 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Sun, 2 Oct 2022 11:11:44 -0400 Subject: [PATCH 021/136] Format pseudo-selector args like a function call (#13577) --- changelog_unreleased/css/13577.md | 32 ++++ src/language-css/printer-postcss.js | 7 +- .../indent/__snapshots__/jsfmt.spec.js.snap | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 138 ++++++++++++++++++ tests/format/css/pseudo-call/is.css | 33 +++++ tests/format/css/pseudo-call/where.css | 19 +++ 6 files changed, 231 insertions(+), 2 deletions(-) create mode 100644 changelog_unreleased/css/13577.md create mode 100644 tests/format/css/pseudo-call/is.css create mode 100644 tests/format/css/pseudo-call/where.css diff --git a/changelog_unreleased/css/13577.md b/changelog_unreleased/css/13577.md new file mode 100644 index 000000000000..e19fe8491181 --- /dev/null +++ b/changelog_unreleased/css/13577.md @@ -0,0 +1,32 @@ +#### Fix formatting of long `:is`, `:where`, and `:not` selectors (#13577 by @j-f1) + +Pseudo-selectors like `:is`, `:where`, and `:not` that can take multiple selectors as arguments are now formatted like function calls are in other languages. Previously, no special significance was attached to the commas between their “arguments,” leading to confusing wrapping behavior. There are likely still improvements to be made here — please open an issue with some example code if you find something that doesn’t look as expected. + + +```css +/* Input */ +:where( + label > input:valid, + label > textarea:not(:empty), + label > button[disabled] +) ~ .errors > .error { display: none; } + +/* Prettier stable */ +:where(label > input:valid, label > textarea:not(:empty), label + > button[disabled]) + ~ .errors + > .error { + display: none; +} + +/* Prettier main */ +:where( + label > input:valid, + label > textarea:not(:empty), + label > button[disabled] + ) + ~ .errors + > .error { + display: none; +} +``` diff --git a/src/language-css/printer-postcss.js b/src/language-css/printer-postcss.js index 744646020238..f8bbd02966e2 100644 --- a/src/language-css/printer-postcss.js +++ b/src/language-css/printer-postcss.js @@ -461,7 +461,12 @@ function genericPrint(path, options, print) { return [ maybeToLowerCase(node.value), isNonEmptyArray(node.nodes) - ? ["(", join(", ", path.map(print, "nodes")), ")"] + ? group([ + "(", + indent([softline, join([",", line], path.map(print, "nodes"))]), + softline, + ")", + ]) : "", ]; } diff --git a/tests/format/css/indent/__snapshots__/jsfmt.spec.js.snap b/tests/format/css/indent/__snapshots__/jsfmt.spec.js.snap index e7457a6851d3..b00a54f5cb29 100644 --- a/tests/format/css/indent/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/css/indent/__snapshots__/jsfmt.spec.js.snap @@ -42,7 +42,9 @@ a { =====================================output===================================== a { - ~ .Pagination-itemWrapper:not(.is-separator):not([data-priority^="#{$priority}"]) + ~ .Pagination-itemWrapper:not(.is-separator):not( + [data-priority^="#{$priority}"] + ) ~ .Pagination-itemWrapper.is-separator[data-priority^="#{$priority}"] { display: flex; } diff --git a/tests/format/css/pseudo-call/__snapshots__/jsfmt.spec.js.snap b/tests/format/css/pseudo-call/__snapshots__/jsfmt.spec.js.snap index 50ebc77cb6dc..5a3dbabd431e 100644 --- a/tests/format/css/pseudo-call/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/css/pseudo-call/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,86 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`is.css format 1`] = ` +====================================options===================================== +parsers: ["css"] +printWidth: 80 + | printWidth +=====================================input====================================== +:is(ol, ul, menu:unsupported) :is(ol, ul) { + color: green; +} + +:is(ol, ul) :is(ol, ul) ol { + list-style-type: lower-greek; + color: chocolate; +} + +:is(ol, ul, menu, dir) :is(ol, ul, menu, dir) :is(ul, menu, dir) { + list-style-type: square; +} + +/* Level 0 */ +h1 { + font-size: 30px; +} +/* Level 1 */ +:is(section, article, aside, nav) h1 { + font-size: 25px; +} +/* Level 2 */ +:is(section, article, aside, nav) :is(section, article, aside, nav) h1 { + font-size: 20px; +} +/* Level 3 */ +:is(section, article, aside, nav) :is(section, article, aside, nav) :is(section, article, aside, nav) h1 { + font-size: 15px; +} + +some-element:is(::before, ::after) { + display: block; +} + +=====================================output===================================== +:is(ol, ul, menu:unsupported) :is(ol, ul) { + color: green; +} + +:is(ol, ul) :is(ol, ul) ol { + list-style-type: lower-greek; + color: chocolate; +} + +:is(ol, ul, menu, dir) :is(ol, ul, menu, dir) :is(ul, menu, dir) { + list-style-type: square; +} + +/* Level 0 */ +h1 { + font-size: 30px; +} +/* Level 1 */ +:is(section, article, aside, nav) h1 { + font-size: 25px; +} +/* Level 2 */ +:is(section, article, aside, nav) :is(section, article, aside, nav) h1 { + font-size: 20px; +} +/* Level 3 */ +:is(section, article, aside, nav) + :is(section, article, aside, nav) + :is(section, article, aside, nav) + h1 { + font-size: 15px; +} + +some-element:is(::before, ::after) { + display: block; +} + +================================================================================ +`; + exports[`pseudo_call.css format 1`] = ` ====================================options===================================== parsers: ["css"] @@ -15,3 +96,60 @@ div:not(:last-child) { ================================================================================ `; + +exports[`where.css format 1`] = ` +====================================options===================================== +parsers: ["css"] +printWidth: 80 + | printWidth +=====================================input====================================== +:where(#p0:checked ~ #play:checked ~ #c1:checked, #p1:checked ~ #play:checked ~ #c2:checked, #p2:checked ~ #play:checked ~ #cO:checked) ~ #result > +#c { display: block; } + +:where(ol, ul, menu:unsupported) :where(ol, ul) { + color: green; +} + +:where(ol, ul) :where(ol, ul) ol { + list-style-type: lower-greek; + color: chocolate; +} + +:is(section.is-styling, aside.is-styling, footer.is-styling) a { + color: red; +} + +:where(section.where-styling, aside.where-styling, footer.where-styling) a { + color: orange; +} + +=====================================output===================================== +:where( + #p0:checked ~ #play:checked ~ #c1:checked, + #p1:checked ~ #play:checked ~ #c2:checked, + #p2:checked ~ #play:checked ~ #cO:checked + ) + ~ #result + > #c { + display: block; +} + +:where(ol, ul, menu:unsupported) :where(ol, ul) { + color: green; +} + +:where(ol, ul) :where(ol, ul) ol { + list-style-type: lower-greek; + color: chocolate; +} + +:is(section.is-styling, aside.is-styling, footer.is-styling) a { + color: red; +} + +:where(section.where-styling, aside.where-styling, footer.where-styling) a { + color: orange; +} + +================================================================================ +`; diff --git a/tests/format/css/pseudo-call/is.css b/tests/format/css/pseudo-call/is.css new file mode 100644 index 000000000000..4b26a4aa1ef9 --- /dev/null +++ b/tests/format/css/pseudo-call/is.css @@ -0,0 +1,33 @@ +:is(ol, ul, menu:unsupported) :is(ol, ul) { + color: green; +} + +:is(ol, ul) :is(ol, ul) ol { + list-style-type: lower-greek; + color: chocolate; +} + +:is(ol, ul, menu, dir) :is(ol, ul, menu, dir) :is(ul, menu, dir) { + list-style-type: square; +} + +/* Level 0 */ +h1 { + font-size: 30px; +} +/* Level 1 */ +:is(section, article, aside, nav) h1 { + font-size: 25px; +} +/* Level 2 */ +:is(section, article, aside, nav) :is(section, article, aside, nav) h1 { + font-size: 20px; +} +/* Level 3 */ +:is(section, article, aside, nav) :is(section, article, aside, nav) :is(section, article, aside, nav) h1 { + font-size: 15px; +} + +some-element:is(::before, ::after) { + display: block; +} diff --git a/tests/format/css/pseudo-call/where.css b/tests/format/css/pseudo-call/where.css new file mode 100644 index 000000000000..a52b9af4665b --- /dev/null +++ b/tests/format/css/pseudo-call/where.css @@ -0,0 +1,19 @@ +:where(#p0:checked ~ #play:checked ~ #c1:checked, #p1:checked ~ #play:checked ~ #c2:checked, #p2:checked ~ #play:checked ~ #cO:checked) ~ #result > +#c { display: block; } + +:where(ol, ul, menu:unsupported) :where(ol, ul) { + color: green; +} + +:where(ol, ul) :where(ol, ul) ol { + list-style-type: lower-greek; + color: chocolate; +} + +:is(section.is-styling, aside.is-styling, footer.is-styling) a { + color: red; +} + +:where(section.where-styling, aside.where-styling, footer.where-styling) a { + color: orange; +} From f38111fec6c35b513370832a84bdac8b5663763d Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sun, 9 Oct 2022 06:53:12 -0700 Subject: [PATCH 022/136] markdown: Preserve inline code line breaks if --prose-wrap=preserve (#11373) --- changelog_unreleased/markdown/11373.md | 15 +++++++++++ src/language-markdown/print-preprocess.js | 6 ++--- .../__snapshots__/jsfmt.spec.js.snap | 26 +++++++++++++++++++ .../inline-code-newline.md | 6 +++++ .../prose-wrap-preserve/jsfmt.spec.js | 1 + 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 changelog_unreleased/markdown/11373.md create mode 100644 tests/format/markdown/prose-wrap-preserve/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/markdown/prose-wrap-preserve/inline-code-newline.md create mode 100644 tests/format/markdown/prose-wrap-preserve/jsfmt.spec.js diff --git a/changelog_unreleased/markdown/11373.md b/changelog_unreleased/markdown/11373.md new file mode 100644 index 000000000000..8eb18b15ed75 --- /dev/null +++ b/changelog_unreleased/markdown/11373.md @@ -0,0 +1,15 @@ +#### Preserve inline code line breaks if `--prose-wrap=preserve` (#11373 by @andersk) + + +```markdown + +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod `tempor +incididunt` ut labore et dolore magna aliqua. + + +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod `tempor incididunt` ut labore et dolore magna aliqua. + + +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod `tempor +incididunt` ut labore et dolore magna aliqua. +``` diff --git a/src/language-markdown/print-preprocess.js b/src/language-markdown/print-preprocess.js index fa1b04335ec1..96cf53694a4d 100644 --- a/src/language-markdown/print-preprocess.js +++ b/src/language-markdown/print-preprocess.js @@ -9,7 +9,7 @@ const isSingleCharRegex = /^.$/su; function preprocess(ast, options) { ast = restoreUnescapedCharacter(ast, options); ast = mergeContinuousTexts(ast); - ast = transformInlineCode(ast); + ast = transformInlineCode(ast, options); ast = transformIndentedCodeblockAndMarkItsParentList(ast, options); ast = markAlignedList(ast, options); ast = splitTextIntoSentences(ast, options); @@ -28,9 +28,9 @@ function transformImportExport(ast) { }); } -function transformInlineCode(ast) { +function transformInlineCode(ast, options) { return mapAst(ast, (node) => { - if (node.type !== "inlineCode") { + if (node.type !== "inlineCode" || options.proseWrap === "preserve") { return node; } diff --git a/tests/format/markdown/prose-wrap-preserve/__snapshots__/jsfmt.spec.js.snap b/tests/format/markdown/prose-wrap-preserve/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..3e177ccb63b7 --- /dev/null +++ b/tests/format/markdown/prose-wrap-preserve/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,26 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`inline-code-newline.md - {"proseWrap":"preserve"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "preserve" + | printWidth +=====================================input====================================== +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod \`tempor +incididunt\` ut labore et dolore magna aliqua. Ut enim ad minim veniam, \`quis +nostrud\` exercitation ullamco laboris nisi ut aliquip ex ea commodo \`consequat. +Duis\` aute irure dolor in reprehenderit in voluptate velit esse cillum dolore \`eu +fugiat\` nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in +culpa qui officia deserunt mollit anim id est laborum. + +=====================================output===================================== +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod \`tempor +incididunt\` ut labore et dolore magna aliqua. Ut enim ad minim veniam, \`quis +nostrud\` exercitation ullamco laboris nisi ut aliquip ex ea commodo \`consequat. +Duis\` aute irure dolor in reprehenderit in voluptate velit esse cillum dolore \`eu +fugiat\` nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in +culpa qui officia deserunt mollit anim id est laborum. + +================================================================================ +`; diff --git a/tests/format/markdown/prose-wrap-preserve/inline-code-newline.md b/tests/format/markdown/prose-wrap-preserve/inline-code-newline.md new file mode 100644 index 000000000000..c2b9f6b8cf82 --- /dev/null +++ b/tests/format/markdown/prose-wrap-preserve/inline-code-newline.md @@ -0,0 +1,6 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod `tempor +incididunt` ut labore et dolore magna aliqua. Ut enim ad minim veniam, `quis +nostrud` exercitation ullamco laboris nisi ut aliquip ex ea commodo `consequat. +Duis` aute irure dolor in reprehenderit in voluptate velit esse cillum dolore `eu +fugiat` nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in +culpa qui officia deserunt mollit anim id est laborum. diff --git a/tests/format/markdown/prose-wrap-preserve/jsfmt.spec.js b/tests/format/markdown/prose-wrap-preserve/jsfmt.spec.js new file mode 100644 index 000000000000..9080881c6d92 --- /dev/null +++ b/tests/format/markdown/prose-wrap-preserve/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["markdown"], { proseWrap: "preserve" }); From ca246afacee8e6d5db508dae01730c9523bbff1d Mon Sep 17 00:00:00 2001 From: Milly Date: Mon, 24 Oct 2022 23:55:36 +0900 Subject: [PATCH 023/136] Fix --cache set only if with --write or no-different (#13016) * Fixed typo * Return early if file does not exist * Added tests for cache * Added `mockWriteFileErrors` option to run helper * Added tests for write error * Remove files with differences from cache * Add `getCliArguments` utility function Refactor * Fix lint * Revert "Fix lint" This reverts commit 18be64b7c42cd669496d59ff64bd534b8e03c3df. * Revert "Add `getCliArguments` utility function" This reverts commit d653fe10a92390102ae97cb43b2efcbb5c3c9140. * Refactor with `cliArguments` variable Co-authored-by: Sosuke Suzuki --- src/cli/format-results-cache.js | 22 ++- src/cli/format.js | 14 +- tests/integration/__tests__/cache.js | 252 +++++++++++++++++++++------ tests/integration/run-prettier.js | 4 + 4 files changed, 222 insertions(+), 70 deletions(-) diff --git a/src/cli/format-results-cache.js b/src/cli/format-results-cache.js index 3dfb79d16535..4f14c27ca0e9 100644 --- a/src/cli/format-results-cache.js +++ b/src/cli/format-results-cache.js @@ -40,7 +40,7 @@ function getMetadataFromFileDescriptor(fileDescriptor) { class FormatResultsCache { /** - * @param {string} cacheFileLocation The path of cache file location. (default: `node_modules/.cache/prettier/prettier-cache`) + * @param {string} cacheFileLocation The path of cache file location. (default: `node_modules/.cache/prettier/.prettier-cache`) * @param {string} cacheStrategy */ constructor(cacheFileLocation, cacheStrategy) { @@ -60,20 +60,17 @@ class FormatResultsCache { */ existsAvailableFormatResultsCache(filePath, options) { const fileDescriptor = this.fileEntryCache.getFileDescriptor(filePath); - const hashOfOptions = getHashOfOptions(options); - const meta = getMetadataFromFileDescriptor(fileDescriptor); - const changed = - fileDescriptor.changed || meta.hashOfOptions !== hashOfOptions; if (fileDescriptor.notFound) { return false; } - if (changed) { - return false; - } + const hashOfOptions = getHashOfOptions(options); + const meta = getMetadataFromFileDescriptor(fileDescriptor); + const changed = + fileDescriptor.changed || meta.hashOfOptions !== hashOfOptions; - return true; + return !changed; } /** @@ -88,6 +85,13 @@ class FormatResultsCache { } } + /** + * @param {string} filePath + */ + removeFormatResultsCache(filePath) { + this.fileEntryCache.removeEntry(filePath); + } + reconcile() { this.fileEntryCache.reconcile(); } diff --git a/src/cli/format.js b/src/cli/format.js index 6d91998ac91b..278060302d5a 100644 --- a/src/cli/format.js +++ b/src/cli/format.js @@ -407,9 +407,8 @@ async function formatFiles(context) { continue; } - formatResultsCache?.setFormatResultsCache(filename, options); - const isDifferent = output !== input; + let shouldSetCache = !isDifferent; if (printedFilename) { // Remove previously printed filename to log it with duration. @@ -433,14 +432,15 @@ async function formatFiles(context) { try { await fs.writeFile(filename, output, "utf8"); + + // Set cache if format succeeds + shouldSetCache = true; } catch (error) { - /* istanbul ignore next */ context.logger.error( `Unable to write file: ${filename}\n${error.message}` ); // Don't exit the process if one file failed - /* istanbul ignore next */ process.exitCode = 2; } } else if (!context.argv.check && !context.argv.listDifferent) { @@ -462,6 +462,12 @@ async function formatFiles(context) { writeOutput(context, result, options); } + if (shouldSetCache) { + formatResultsCache?.setFormatResultsCache(filename, options); + } else { + formatResultsCache?.removeFormatResultsCache(filename); + } + if (isDifferent) { if (context.argv.check) { context.logger.warn(filename); diff --git a/tests/integration/__tests__/cache.js b/tests/integration/__tests__/cache.js index a15618395436..62fc80be232e 100644 --- a/tests/integration/__tests__/cache.js +++ b/tests/integration/__tests__/cache.js @@ -96,7 +96,7 @@ describe("--cache option", () => { await expect(fs.stat(defaultCacheFile)).resolves.not.toThrowError(); }); - it("does'nt format when cache is available", async () => { + it("doesn't format when cache is available", async () => { const { stdout: firstStdout } = await runPrettier(dir, [ "--cache", "--write", @@ -127,13 +127,14 @@ describe("--cache option", () => { }); it("re-formats when a file has been updated.", async () => { - const { stdout: firstStdout } = await runPrettier(dir, [ + const cliArguments = [ "--cache", "--write", "--cache-strategy", "metadata", ".", - ]); + ]; + const { stdout: firstStdout } = await runPrettier(dir, cliArguments); expect(stripAnsi(firstStdout).split("\n").filter(Boolean)).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), @@ -144,13 +145,7 @@ describe("--cache option", () => { // Update `a.js` await fs.writeFile(path.join(dir, "a.js"), "const a = `a`;"); - const { stdout: secondStdout } = await runPrettier(dir, [ - "--cache", - "--write", - "--cache-strategy", - "metadata", - ".", - ]); + const { stdout: secondStdout } = await runPrettier(dir, cliArguments); expect(stripAnsi(secondStdout).split("\n").filter(Boolean)).toEqual( // the cache of `b.js` is only available. expect.arrayContaining([ @@ -161,13 +156,14 @@ describe("--cache option", () => { }); it("re-formats when timestamp has been updated", async () => { - const { stdout: firstStdout } = await runPrettier(dir, [ + const cliArguments = [ "--cache", "--write", "--cache-strategy", "metadata", ".", - ]); + ]; + const { stdout: firstStdout } = await runPrettier(dir, cliArguments); expect(stripAnsi(firstStdout).split("\n").filter(Boolean)).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), @@ -179,13 +175,7 @@ describe("--cache option", () => { const time = new Date(); await fs.utimes(path.join(dir, "a.js"), time, time); - const { stdout: secondStdout } = await runPrettier(dir, [ - "--cache", - "--write", - "--cache-strategy", - "metadata", - ".", - ]); + const { stdout: secondStdout } = await runPrettier(dir, cliArguments); expect(stripAnsi(secondStdout).split("\n").filter(Boolean)).toEqual( // the cache of `b.js` is only available. expect.arrayContaining([ @@ -227,6 +217,90 @@ describe("--cache option", () => { ); }); + it("re-formats after execution without write.", async () => { + await runPrettier(dir, ["--cache", "--cache-strategy", "metadata", "."]); + + const { stdout: secondStdout } = await runPrettier(dir, [ + "--write", + "--cache", + "--cache-strategy", + "metadata", + ".", + ]); + expect(stripAnsi(secondStdout).split("\n").filter(Boolean)).toEqual( + expect.arrayContaining([ + expect.stringMatching(/^a\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(cached\)$/), + ]) + ); + }); + + it("re-formats when multiple cached files are updated.", async () => { + const cliArguments = [ + "--write", + "--cache", + "--cache-strategy", + "metadata", + ".", + ]; + await runPrettier(dir, cliArguments); + + // Update `a.js` to unformatted + await fs.writeFile(path.join(dir, "a.js"), "const a = `a`; "); + + // Update `b.js` but still formatted + const time = new Date(); + await fs.utimes(path.join(dir, "b.js"), time, time); + + await runPrettier(dir, ["--cache", "--cache-strategy", "metadata", "."]); + + const { stdout: thirdStdout } = await runPrettier(dir, cliArguments); + expect(stripAnsi(thirdStdout).split("\n").filter(Boolean)).toEqual( + expect.arrayContaining([ + expect.stringMatching(/^a\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(cached\)$/), + ]) + ); + }); + + it("doesn't cache files when write error.", async () => { + const { + stdout: firstStdout, + stderr: firstStderr, + status: firstStatus, + } = await runPrettier( + dir, + ["--write", "--cache", "--cache-strategy", "metadata", "."], + { + mockWriteFileErrors: { + "a.js": "EACCES: permission denied (mock error)", + }, + } + ); + expect(firstStatus).toBe(2); + expect(stripAnsi(firstStderr).split("\n").filter(Boolean)).toEqual([ + "[error] Unable to write file: a.js", + "[error] EACCES: permission denied (mock error)", + ]); + expect(stripAnsi(firstStdout).split("\n").filter(Boolean)).toEqual( + expect.arrayContaining([ + expect.stringMatching(/^a\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms$/), + ]) + ); + + const { stdout: secondStdout } = await runPrettier(dir, [ + "--list-different", + "--cache", + "--cache-strategy", + "metadata", + ".", + ]); + expect(stripAnsi(secondStdout).split("\n").filter(Boolean)).toEqual([ + "a.js", + ]); + }); + it("removes cache file when run Prettier without `--cache` option", async () => { await runPrettier(dir, [ "--cache", @@ -251,14 +325,15 @@ describe("--cache option", () => { await expect(fs.stat(defaultCacheFile)).resolves.not.toThrowError(); }); - it("does'nt format when cache is available", async () => { - const { stdout: firstStdout } = await runPrettier(dir, [ + it("doesn't format when cache is available", async () => { + const cliArguments = [ "--cache", "--cache-strategy", "content", "--write", ".", - ]); + ]; + const { stdout: firstStdout } = await runPrettier(dir, cliArguments); expect(stripAnsi(firstStdout).split("\n").filter(Boolean)).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), @@ -266,13 +341,7 @@ describe("--cache option", () => { ]) ); - const { stdout: secondStdout } = await runPrettier(dir, [ - "--cache", - "--cache-strategy", - "content", - "--write", - ".", - ]); + const { stdout: secondStdout } = await runPrettier(dir, cliArguments); expect(stripAnsi(secondStdout).split("\n").filter(Boolean)).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms \(cached\)$/), @@ -282,13 +351,14 @@ describe("--cache option", () => { }); it("re-formats when a file has been updated.", async () => { - const { stdout: firstStdout } = await runPrettier(dir, [ + const cliArguments = [ "--cache", "--cache-strategy", "content", "--write", ".", - ]); + ]; + const { stdout: firstStdout } = await runPrettier(dir, cliArguments); expect(stripAnsi(firstStdout).split("\n").filter(Boolean)).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), @@ -299,13 +369,7 @@ describe("--cache option", () => { // Update `a.js` await fs.writeFile(path.join(dir, "a.js"), "const a = `a`;"); - const { stdout: secondStdout } = await runPrettier(dir, [ - "--cache", - "--cache-strategy", - "content", - "--write", - ".", - ]); + const { stdout: secondStdout } = await runPrettier(dir, cliArguments); expect(stripAnsi(secondStdout).split("\n").filter(Boolean)).toEqual( // the cache of `b.js` is only available. expect.arrayContaining([ @@ -315,14 +379,15 @@ describe("--cache option", () => { ); }); - it("does'nt re-format when timestamp has been updated", async () => { - const { stdout: firstStdout } = await runPrettier(dir, [ + it("doesn't re-format when timestamp has been updated", async () => { + const cliArguments = [ "--cache", "--cache-strategy", "content", "--write", ".", - ]); + ]; + const { stdout: firstStdout } = await runPrettier(dir, cliArguments); expect(stripAnsi(firstStdout).split("\n").filter(Boolean)).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), @@ -334,13 +399,7 @@ describe("--cache option", () => { const time = new Date(); await fs.utimes(path.join(dir, "a.js"), time, time); - const { stdout: secondStdout } = await runPrettier(dir, [ - "--cache", - "--cache-strategy", - "content", - "--write", - ".", - ]); + const { stdout: secondStdout } = await runPrettier(dir, cliArguments); expect(stripAnsi(secondStdout).split("\n").filter(Boolean)).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms \(cached\)$/), @@ -381,6 +440,90 @@ describe("--cache option", () => { ); }); + it("re-formats after execution without write.", async () => { + await runPrettier(dir, ["--cache", "--cache-strategy", "content", "."]); + + const { stdout: secondStdout } = await runPrettier(dir, [ + "--write", + "--cache", + "--cache-strategy", + "content", + ".", + ]); + expect(stripAnsi(secondStdout).split("\n").filter(Boolean)).toEqual( + expect.arrayContaining([ + expect.stringMatching(/^a\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(cached\)$/), + ]) + ); + }); + + it("re-formats when multiple cached files are updated.", async () => { + const cliArguments = [ + "--write", + "--cache", + "--cache-strategy", + "content", + ".", + ]; + await runPrettier(dir, cliArguments); + + // Update `a.js` to unformatted + await fs.writeFile(path.join(dir, "a.js"), "const a = `a`; "); + + // Update `b.js` but still formatted + const time = new Date(); + await fs.utimes(path.join(dir, "b.js"), time, time); + + await runPrettier(dir, ["--cache", "--cache-strategy", "content", "."]); + + const { stdout: thirdStdout } = await runPrettier(dir, cliArguments); + expect(stripAnsi(thirdStdout).split("\n").filter(Boolean)).toEqual( + expect.arrayContaining([ + expect.stringMatching(/^a\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(cached\)$/), + ]) + ); + }); + + it("doesn't cache files when write error.", async () => { + const { + stdout: firstStdout, + stderr: firstStderr, + status: firstStatus, + } = await runPrettier( + dir, + ["--write", "--cache", "--cache-strategy", "content", "."], + { + mockWriteFileErrors: { + "a.js": "EACCES: permission denied (mock error)", + }, + } + ); + expect(firstStatus).toBe(2); + expect(stripAnsi(firstStderr).split("\n").filter(Boolean)).toEqual([ + "[error] Unable to write file: a.js", + "[error] EACCES: permission denied (mock error)", + ]); + expect(stripAnsi(firstStdout).split("\n").filter(Boolean)).toEqual( + expect.arrayContaining([ + expect.stringMatching(/^a\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms$/), + ]) + ); + + const { stdout: secondStdout } = await runPrettier(dir, [ + "--list-different", + "--cache", + "--cache-strategy", + "content", + ".", + ]); + expect(stripAnsi(secondStdout).split("\n").filter(Boolean)).toEqual([ + "a.js", + ]); + }); + it("removes cache file when run Prettier without `--cache` option", async () => { await runPrettier(dir, ["--cache", "--write", "."]); await expect(fs.stat(defaultCacheFile)).resolves.not.toThrowError(); @@ -437,13 +580,14 @@ describe("--cache option", () => { }); it("does'nt format when cache is available", async () => { - const { stdout: firstStdout } = await runPrettier(dir, [ + const cliArguments = [ "--cache", "--write", "--cache-location", nonDefaultCacheFileName, ".", - ]); + ]; + const { stdout: firstStdout } = await runPrettier(dir, cliArguments); expect(stripAnsi(firstStdout).split("\n").filter(Boolean)).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms$/), @@ -451,13 +595,7 @@ describe("--cache option", () => { ]) ); - const { stdout: secondStdout } = await runPrettier(dir, [ - "--cache", - "--write", - "--cache-location", - nonDefaultCacheFileName, - ".", - ]); + const { stdout: secondStdout } = await runPrettier(dir, cliArguments); expect(stripAnsi(secondStdout).split("\n").filter(Boolean)).toEqual( expect.arrayContaining([ expect.stringMatching(/^a\.js .+ms \(cached\)$/), diff --git a/tests/integration/run-prettier.js b/tests/integration/run-prettier.js index 441b1402563e..88b9ab9cfd51 100644 --- a/tests/integration/run-prettier.js +++ b/tests/integration/run-prettier.js @@ -46,6 +46,10 @@ async function run(dir, args, options) { .spyOn(fs.promises, "writeFile") // eslint-disable-next-line require-await .mockImplementation(async (filename, content) => { + const error = (options.mockWriteFileErrors || {})[filename]; + if (error) { + throw new Error(error); + } write.push({ filename, content }); }); From ff0529ac2ee37a88b4ae290efd2f08ecc1f0cacd Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Fri, 4 Nov 2022 11:35:50 +0900 Subject: [PATCH 024/136] Backport "Support TS4.9 `satisfies` operator (#13764)" (#13783) --- package.json | 8 +- src/language-js/loc.js | 16 +- src/language-js/needs-parens.js | 14 +- .../parse/postprocess/typescript.js | 47 +- src/language-js/print/call-arguments.js | 3 +- src/language-js/print/decorators.js | 3 +- src/language-js/print/template-literal.js | 3 +- src/language-js/print/ternary.js | 3 +- src/language-js/print/typescript.js | 4 +- src/language-js/utils/index.js | 11 +- tests/config/format-test.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 57 +- .../__snapshots__/jsfmt.spec.js.snap | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 1130 +++++++++++++++++ .../satisfies-operators/argument-expansion.ts | 19 + .../satisfies-operators/assignment.ts | 21 + .../typescript/satisfies-operators/basic.ts | 30 + .../satisfies-operators/comments-unstable.ts | 7 + .../satisfies-operators/comments.ts | 3 + .../satisfies-operators/export-default-as.ts | 1 + .../typescript/satisfies-operators/gt-lt.ts | 2 + .../satisfies-operators/hug-args.ts | 6 + .../satisfies-operators/jsfmt.spec.js | 2 + .../typescript/satisfies-operators/lhs.ts | 5 + .../nested-await-and-satisfies.ts | 7 + .../satisfies-operators/non-null.ts | 3 + .../satisfies-operators/satisfies.ts | 22 + .../satisfies-operators/template-literal.ts | 5 + .../typescript/satisfies-operators/ternary.ts | 40 + .../satisfies-operators/types-comments.ts | 3 + yarn.lock | 109 +- 31 files changed, 1460 insertions(+), 128 deletions(-) create mode 100644 tests/format/typescript/satisfies-operators/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/typescript/satisfies-operators/argument-expansion.ts create mode 100644 tests/format/typescript/satisfies-operators/assignment.ts create mode 100644 tests/format/typescript/satisfies-operators/basic.ts create mode 100644 tests/format/typescript/satisfies-operators/comments-unstable.ts create mode 100644 tests/format/typescript/satisfies-operators/comments.ts create mode 100644 tests/format/typescript/satisfies-operators/export-default-as.ts create mode 100644 tests/format/typescript/satisfies-operators/gt-lt.ts create mode 100644 tests/format/typescript/satisfies-operators/hug-args.ts create mode 100644 tests/format/typescript/satisfies-operators/jsfmt.spec.js create mode 100644 tests/format/typescript/satisfies-operators/lhs.ts create mode 100644 tests/format/typescript/satisfies-operators/nested-await-and-satisfies.ts create mode 100644 tests/format/typescript/satisfies-operators/non-null.ts create mode 100644 tests/format/typescript/satisfies-operators/satisfies.ts create mode 100644 tests/format/typescript/satisfies-operators/template-literal.ts create mode 100644 tests/format/typescript/satisfies-operators/ternary.ts create mode 100644 tests/format/typescript/satisfies-operators/types-comments.ts diff --git a/package.json b/package.json index 5fe4ede9a2ce..892575d86af6 100644 --- a/package.json +++ b/package.json @@ -24,10 +24,10 @@ "dependencies": { "@angular/compiler": "12.2.16", "@babel/code-frame": "7.16.7", - "@babel/parser": "7.18.0", + "@babel/parser": "7.20.1", "@glimmer/syntax": "0.84.2", "@iarna/toml": "2.2.5", - "@typescript-eslint/typescript-estree": "5.30.0", + "@typescript-eslint/typescript-estree": "5.36.2", "acorn": "8.8.0", "acorn-jsx": "5.3.2", "angular-estree-parser": "2.5.1", @@ -85,7 +85,7 @@ "semver": "7.3.7", "string-width": "5.0.1", "strip-ansi": "7.0.1", - "typescript": "4.7.2", + "typescript": "4.8.2", "unicode-regex": "3.0.0", "unified": "9.2.1", "vnopts": "1.0.2", @@ -102,7 +102,7 @@ "@types/file-entry-cache": "5.0.2", "@types/find-cache-dir": "3.2.1", "@types/jest": "27.4.1", - "@typescript-eslint/eslint-plugin": "5.20.0", + "@typescript-eslint/eslint-plugin": "5.36.2", "babel-jest": "27.5.1", "benchmark": "2.1.4", "browserslist-to-esbuild": "1.1.1", diff --git a/src/language-js/loc.js b/src/language-js/loc.js index 15f07e8d9146..4be972e1ec95 100644 --- a/src/language-js/loc.js +++ b/src/language-js/loc.js @@ -6,20 +6,16 @@ const isNonEmptyArray = require("../utils/is-non-empty-array.js"); * @typedef {import("./types/estree").Node} Node */ -function locStart(node, opts) { - const { ignoreDecorators } = opts || {}; +function locStart(node) { + const start = node.range ? node.range[0] : node.start; // Handle nodes with decorators. They should start at the first decorator - if (!ignoreDecorators) { - const decorators = - (node.declaration && node.declaration.decorators) || node.decorators; - - if (isNonEmptyArray(decorators)) { - return locStart(decorators[0]); - } + const decorators = node.declaration?.decorators ?? node.decorators; + if (isNonEmptyArray(decorators)) { + return Math.min(locStart(decorators[0]), start); } - return node.range ? node.range[0] : node.start; + return start; } function locEnd(node) { diff --git a/src/language-js/needs-parens.js b/src/language-js/needs-parens.js index 1a71011ecdca..94d95febc44a 100644 --- a/src/language-js/needs-parens.js +++ b/src/language-js/needs-parens.js @@ -15,6 +15,7 @@ const { isCallExpression, isMemberExpression, isObjectProperty, + isTSTypeExpression, } = require("./utils/index.js"); function needsParens(path, options) { @@ -244,14 +245,16 @@ function needsParens(path, options) { // fallthrough case "TSTypeAssertion": case "TSAsExpression": + case "TSSatisfiesExpression": case "LogicalExpression": switch (parent.type) { + case "TSSatisfiesExpression": case "TSAsExpression": // example: foo as unknown as Bar - return node.type !== "TSAsExpression"; + return !isTSTypeExpression(node); case "ConditionalExpression": - return node.type === "TSAsExpression"; + return isTSTypeExpression(node); case "CallExpression": case "NewExpression": @@ -282,7 +285,7 @@ function needsParens(path, options) { case "AssignmentPattern": return ( name === "left" && - (node.type === "TSTypeAssertion" || node.type === "TSAsExpression") + (node.type === "TSTypeAssertion" || isTSTypeExpression(node)) ); case "LogicalExpression": @@ -363,7 +366,7 @@ function needsParens(path, options) { if ( parent.type === "UnaryExpression" || parent.type === "AwaitExpression" || - parent.type === "TSAsExpression" || + isTSTypeExpression(parent) || parent.type === "TSNonNullExpression" ) { return true; @@ -377,6 +380,7 @@ function needsParens(path, options) { case "SpreadElement": case "SpreadProperty": case "TSAsExpression": + case "TSSatisfiesExpression": case "TSNonNullExpression": case "BindExpression": return true; @@ -612,6 +616,7 @@ function needsParens(path, options) { case "TSTypeAssertion": case "TypeCastExpression": case "TSAsExpression": + case "TSSatisfiesExpression": case "TSNonNullExpression": return true; @@ -661,6 +666,7 @@ function needsParens(path, options) { return name === "object"; case "TSAsExpression": + case "TSSatisfiesExpression": case "TSNonNullExpression": case "BindExpression": case "TaggedTemplateExpression": diff --git a/src/language-js/parse/postprocess/typescript.js b/src/language-js/parse/postprocess/typescript.js index aea24d9dde46..2f613bbf4d76 100644 --- a/src/language-js/parse/postprocess/typescript.js +++ b/src/language-js/parse/postprocess/typescript.js @@ -1,33 +1,36 @@ "use strict"; +const isNonEmptyArray = require("../../../utils/is-non-empty-array.js"); const visitNode = require("./visit-node.js"); const throwSyntaxError = require("./throw-syntax-error.js"); +// Copied from https://unpkg.com/typescript@4.8.2/lib/typescript.js +function getSourceFileOfNode(node) { + while (node && node.kind !== 305 /* SyntaxKind.SourceFile */) { + node = node.parent; + } + return node; +} + // Invalid decorators are removed since `@typescript-eslint/typescript-estree` v4 // https://github.com/typescript-eslint/typescript-eslint/pull/2375 -function throwErrorForInvalidDecorator( - tsNode, - esTreeNode, - tsNodeToESTreeNodeMap -) { - const tsDecorators = tsNode.decorators; - if (!Array.isArray(tsDecorators)) { +// There is a `checkGrammarDecorators` in `typescript` package, consider use it directly in future +function throwErrorForInvalidDecorator(tsNode) { + const { illegalDecorators } = tsNode; + if (!isNonEmptyArray(illegalDecorators)) { return; } - const esTreeDecorators = esTreeNode.decorators; - if ( - !Array.isArray(esTreeDecorators) || - esTreeDecorators.length !== tsDecorators.length || - tsDecorators.some((tsDecorator) => { - const esTreeDecorator = tsNodeToESTreeNodeMap.get(tsDecorator); - return !esTreeDecorator || !esTreeDecorators.includes(esTreeDecorator); - }) - ) { - throwSyntaxError( - esTreeNode, - "Leading decorators must be attached to a class declaration" - ); - } + + const [{ expression }] = illegalDecorators; + + const sourceFile = getSourceFileOfNode(expression); + const [start, end] = [expression.pos, expression.end].map((position) => { + const { line, character: column } = + sourceFile.getLineAndCharacterOfPosition(position); + return { line: line + 1, column }; + }); + + throwSyntaxError({ loc: { start, end } }, "Decorators are not valid here."); } // Values of abstract property is removed since `@typescript-eslint/typescript-estree` v5 @@ -66,7 +69,7 @@ function throwErrorForInvalidNodes(ast, options) { return; } - throwErrorForInvalidDecorator(tsNode, esTreeNode, tsNodeToESTreeNodeMap); + throwErrorForInvalidDecorator(tsNode); throwErrorForInvalidAbstractProperty(tsNode, esTreeNode); }); } diff --git a/src/language-js/print/call-arguments.js b/src/language-js/print/call-arguments.js index 187521a04460..6bd36e3421db 100644 --- a/src/language-js/print/call-arguments.js +++ b/src/language-js/print/call-arguments.js @@ -16,6 +16,7 @@ const { isCallExpression, isStringLiteral, isObjectProperty, + isTSTypeExpression, } = require("../utils/index.js"); const { @@ -190,7 +191,7 @@ function couldGroupArg(arg, arrowChainRecursion = false) { (arg.type === "ArrayExpression" && (arg.elements.length > 0 || hasComment(arg))) || (arg.type === "TSTypeAssertion" && couldGroupArg(arg.expression)) || - (arg.type === "TSAsExpression" && couldGroupArg(arg.expression)) || + (isTSTypeExpression(arg) && couldGroupArg(arg.expression)) || arg.type === "FunctionExpression" || (arg.type === "ArrowFunctionExpression" && // we want to avoid breaking inside composite return types but not simple keywords diff --git a/src/language-js/print/decorators.js b/src/language-js/print/decorators.js index 2b679b4d5f32..1bca71a541f7 100644 --- a/src/language-js/print/decorators.js +++ b/src/language-js/print/decorators.js @@ -72,8 +72,7 @@ function hasDecoratorsBeforeExport(node) { const decorators = node.declaration && node.declaration.decorators; return ( - isNonEmptyArray(decorators) && - locStart(node, { ignoreDecorators: true }) > locStart(decorators[0]) + isNonEmptyArray(decorators) && locStart(node) === locStart(decorators[0]) ); } diff --git a/src/language-js/print/template-literal.js b/src/language-js/print/template-literal.js index c7bd2119552a..e46505cc33eb 100644 --- a/src/language-js/print/template-literal.js +++ b/src/language-js/print/template-literal.js @@ -22,6 +22,7 @@ const { isSimpleTemplateLiteral, hasComment, isMemberExpression, + isTSTypeExpression, } = require("../utils/index.js"); function printTemplateLiteral(path, print, options) { @@ -90,7 +91,7 @@ function printTemplateLiteral(path, print, options) { isMemberExpression(expression) || expression.type === "ConditionalExpression" || expression.type === "SequenceExpression" || - expression.type === "TSAsExpression" || + isTSTypeExpression(expression) || isBinaryish(expression) ) { printed = [indent([softline, printed]), softline]; diff --git a/src/language-js/print/ternary.js b/src/language-js/print/ternary.js index 18c9c8d156c6..542e15b21847 100644 --- a/src/language-js/print/ternary.js +++ b/src/language-js/print/ternary.js @@ -6,6 +6,7 @@ const { getComments, isCallExpression, isMemberExpression, + isTSTypeExpression, } = require("../utils/index.js"); const { locStart, locEnd } = require("../loc.js"); const isBlockComment = require("../utils/is-block-comment.js"); @@ -165,7 +166,7 @@ function shouldExtraIndentForConditionalExpression(path) { if ( (node.type === "NewExpression" && node.callee === child) || - (node.type === "TSAsExpression" && node.expression === child) + (isTSTypeExpression(node) && node.expression === child) ) { parent = path.getParentNode(ancestorCount + 1); child = node; diff --git a/src/language-js/print/typescript.js b/src/language-js/print/typescript.js index b755c7458c66..a67193627da1 100644 --- a/src/language-js/print/typescript.js +++ b/src/language-js/print/typescript.js @@ -148,8 +148,10 @@ function printTypescript(path, options, print) { return printTypeParameters(path, options, print, "params"); case "TSTypeParameter": return printTypeParameter(path, options, print); + case "TSSatisfiesExpression": case "TSAsExpression": { - parts.push(print("expression"), " as ", print("typeAnnotation")); + const operator = node.type === "TSAsExpression" ? "as" : "satisfies"; + parts.push(print("expression"), ` ${operator} `, print("typeAnnotation")); const parent = path.getParentNode(); if ( (isCallExpression(parent) && parent.callee === node) || diff --git a/src/language-js/utils/index.js b/src/language-js/utils/index.js index 1a11a0b0b105..8406ac296f26 100644 --- a/src/language-js/utils/index.js +++ b/src/language-js/utils/index.js @@ -106,7 +106,7 @@ function hasNakedLeftSide(node) { node.type === "TaggedTemplateExpression" || node.type === "BindExpression" || (node.type === "UpdateExpression" && !node.prefix) || - node.type === "TSAsExpression" || + isTSTypeExpression(node) || node.type === "TSNonNullExpression" ); } @@ -998,6 +998,8 @@ function startsWithNoLookaheadToken(node, forbidFunctionClassAndDoExpr) { node.expressions[0], forbidFunctionClassAndDoExpr ); + // @ts-expect-error + case "TSSatisfiesExpression": case "TSAsExpression": case "TSNonNullExpression": return startsWithNoLookaheadToken( @@ -1305,6 +1307,12 @@ const markerForIfWithoutBlockAndSameLineComment = Symbol( "ifWithoutBlockAndSameLineComment" ); +function isTSTypeExpression(node) { + return ( + node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression" + ); +} + module.exports = { getFunctionParameters, iterateFunctionParametersPath, @@ -1369,4 +1377,5 @@ module.exports = { getComments, CommentCheckFlags, markerForIfWithoutBlockAndSameLineComment, + isTSTypeExpression, }; diff --git a/tests/config/format-test.js b/tests/config/format-test.js index 743e03ee71ba..3574fddf1e40 100644 --- a/tests/config/format-test.js +++ b/tests/config/format-test.js @@ -40,6 +40,7 @@ const unstableTests = new Map( "typescript/prettier-ignore/mapped-types.ts", "js/comments/html-like/comment.js", "js/for/continue-and-break-comment-without-blocks.js", + "typescript/satisfies-operators/comments-unstable.ts", ].map((fixture) => { const [file, isUnstable = () => true] = Array.isArray(fixture) ? fixture diff --git a/tests/format/misc/errors/invalid-typescript-decorators/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/invalid-typescript-decorators/__snapshots__/jsfmt.spec.js.snap index 8d1286b597dd..26d9fed0966b 100644 --- a/tests/format/misc/errors/invalid-typescript-decorators/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/errors/invalid-typescript-decorators/__snapshots__/jsfmt.spec.js.snap @@ -10,13 +10,12 @@ exports[`decorator.ts [babel-ts] format 1`] = ` `; exports[`decorator.ts [typescript] format 1`] = ` -"Leading decorators must be attached to a class declaration (3:1) +"Decorators are not valid here. (3:2) 1 | declare function dec(target: T): T; 2 | > 3 | @dec - | ^^^^ -> 4 | enum E {} - | ^^^^^^^^^^ + | ^^^ + 4 | enum E {} 5 |" `; @@ -32,24 +31,14 @@ exports[`enums.ts [babel-ts] format 1`] = ` `; exports[`enums.ts [typescript] format 1`] = ` -"Leading decorators must be attached to a class declaration (3:1) - 1 | // https://github.com/typescript-eslint/typescript-eslint/pull/2375 - 2 | -> 3 | @decorator() - | ^^^^^^^^^^^^ -> 4 | enum Direction { - | ^^^^^^^^^^^^^^^^ -> 5 | Up = 1, - | ^^^^^^^^^^^^^^^^ -> 6 | Down, - | ^^^^^^^^^^^^^^^^ -> 7 | Left, - | ^^^^^^^^^^^^^^^^ -> 8 | Right - | ^^^^^^^^^^^^^^^^ -> 9 | } - | ^^ - 10 |" +"Decorators are not valid here. (3:2) + 1 | // https://github.com/typescript-eslint/typescript-eslint/pull/2375 + 2 | +> 3 | @decorator() + | ^^^^^^^^^^^ + 4 | enum Direction { + 5 | Up = 1, + 6 | Down," `; exports[`function.ts [babel-ts] format 1`] = ` @@ -62,13 +51,12 @@ exports[`function.ts [babel-ts] format 1`] = ` `; exports[`function.ts [typescript] format 1`] = ` -"Leading decorators must be attached to a class declaration (3:1) +"Decorators are not valid here. (3:2) 1 | // https://github.com/typescript-eslint/typescript-eslint/pull/2375 2 | > 3 | @decorator() - | ^^^^^^^^^^^^ -> 4 | function foo( ){} - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^ + 4 | function foo( ){} 5 |" `; @@ -83,15 +71,13 @@ exports[`interface.ts [babel-ts] format 1`] = ` `; exports[`interface.ts [typescript] format 1`] = ` -"Leading decorators must be attached to a class declaration (4:1) +"Decorators are not valid here. (4:2) 2 | // #4632 3 | > 4 | @hello() - | ^^^^^^^^ -> 5 | interface MyInterface {id: string; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -> 6 | } - | ^^ + | ^^^^^^^ + 5 | interface MyInterface {id: string; + 6 | } 7 |" `; @@ -105,11 +91,10 @@ exports[`issue-9102.ts [babel-ts] format 1`] = ` `; exports[`issue-9102.ts [typescript] format 1`] = ` -"Leading decorators must be attached to a class declaration (1:1) +"Decorators are not valid here. (1:2) > 1 | @Decorator() - | ^^^^^^^^^^^^ -> 2 | type T = 1; - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^ + 2 | type T = 1; 3 | class C {} 4 |" `; diff --git a/tests/format/typescript/instantiation-expression/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/instantiation-expression/__snapshots__/jsfmt.spec.js.snap index 974c9bdab73a..75e7a6721b94 100644 --- a/tests/format/typescript/instantiation-expression/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/instantiation-expression/__snapshots__/jsfmt.spec.js.snap @@ -26,7 +26,8 @@ new A < B > C =====================================output===================================== -new A() < B > C; +new A(); +C; ================================================================================ `; diff --git a/tests/format/typescript/satisfies-operators/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/satisfies-operators/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..7580e493ffc8 --- /dev/null +++ b/tests/format/typescript/satisfies-operators/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,1130 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`argument-expansion.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +const bar1 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, ([] satisfies unknown) satisfies number[]); + +const bar2 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, ([1, 2, 3] satisfies unknown) satisfies number[]); + +const bar3 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, ({} satisfies unknown) satisfies {[key: number]: boolean}); + +const bar4 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, ({1: true} satisfies unknown) satisfies {[key: number]: boolean}); + +const bar5 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, [] satisfies foo); + +=====================================output===================================== +const bar1 = [1, 2, 3].reduce((carry, value) => { + return [...carry, value] +}, [] satisfies unknown satisfies number[]) + +const bar2 = [1, 2, 3].reduce( + (carry, value) => { + return [...carry, value] + }, + [1, 2, 3] satisfies unknown satisfies number[] +) + +const bar3 = [1, 2, 3].reduce((carry, value) => { + return { ...carry, [value]: true } +}, {} satisfies unknown satisfies { [key: number]: boolean }) + +const bar4 = [1, 2, 3].reduce( + (carry, value) => { + return { ...carry, [value]: true } + }, + { 1: true } satisfies unknown satisfies { [key: number]: boolean } +) + +const bar5 = [1, 2, 3].reduce((carry, value) => { + return [...carry, value] +}, [] satisfies foo) + +================================================================================ +`; + +exports[`argument-expansion.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +const bar1 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, ([] satisfies unknown) satisfies number[]); + +const bar2 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, ([1, 2, 3] satisfies unknown) satisfies number[]); + +const bar3 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, ({} satisfies unknown) satisfies {[key: number]: boolean}); + +const bar4 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, ({1: true} satisfies unknown) satisfies {[key: number]: boolean}); + +const bar5 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, [] satisfies foo); + +=====================================output===================================== +const bar1 = [1, 2, 3].reduce((carry, value) => { + return [...carry, value]; +}, [] satisfies unknown satisfies number[]); + +const bar2 = [1, 2, 3].reduce( + (carry, value) => { + return [...carry, value]; + }, + [1, 2, 3] satisfies unknown satisfies number[] +); + +const bar3 = [1, 2, 3].reduce((carry, value) => { + return { ...carry, [value]: true }; +}, {} satisfies unknown satisfies { [key: number]: boolean }); + +const bar4 = [1, 2, 3].reduce( + (carry, value) => { + return { ...carry, [value]: true }; + }, + { 1: true } satisfies unknown satisfies { [key: number]: boolean } +); + +const bar5 = [1, 2, 3].reduce((carry, value) => { + return [...carry, value]; +}, [] satisfies foo); + +================================================================================ +`; + +exports[`assignment.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +const extraRendererAttrs = ((attrs.rendererAttrs && + this.utils.safeParseJsonString(attrs.rendererAttrs)) || + Object.create(null)) satisfies FieldService.RendererAttributes; + +const annotate = (angular.injector satisfies any).$$annotate satisfies ( + fn: Function +) => string[]; + +const originalPrototype = originalConstructor.prototype satisfies TComponent & InjectionTarget, + propertyToServiceName = originalPrototype._inject; + +this.previewPlayerHandle = (setInterval(async () => { + if (this.previewIsPlaying) { + await this.fetchNextPreviews(); + this.currentPreviewIndex++; + } +}, this.refreshDelay) satisfies unknown) satisfies number; + +this.intervalID = (setInterval(() => { + self.step(); +}, 30) satisfies unknown) satisfies number; + +=====================================output===================================== +const extraRendererAttrs = ((attrs.rendererAttrs && + this.utils.safeParseJsonString(attrs.rendererAttrs)) || + Object.create(null)) satisfies FieldService.RendererAttributes + +const annotate = (angular.injector satisfies any).$$annotate satisfies ( + fn: Function +) => string[] + +const originalPrototype = originalConstructor.prototype satisfies TComponent & + InjectionTarget, + propertyToServiceName = originalPrototype._inject + +this.previewPlayerHandle = setInterval(async () => { + if (this.previewIsPlaying) { + await this.fetchNextPreviews() + this.currentPreviewIndex++ + } +}, this.refreshDelay) satisfies unknown satisfies number + +this.intervalID = setInterval(() => { + self.step() +}, 30) satisfies unknown satisfies number + +================================================================================ +`; + +exports[`assignment.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +const extraRendererAttrs = ((attrs.rendererAttrs && + this.utils.safeParseJsonString(attrs.rendererAttrs)) || + Object.create(null)) satisfies FieldService.RendererAttributes; + +const annotate = (angular.injector satisfies any).$$annotate satisfies ( + fn: Function +) => string[]; + +const originalPrototype = originalConstructor.prototype satisfies TComponent & InjectionTarget, + propertyToServiceName = originalPrototype._inject; + +this.previewPlayerHandle = (setInterval(async () => { + if (this.previewIsPlaying) { + await this.fetchNextPreviews(); + this.currentPreviewIndex++; + } +}, this.refreshDelay) satisfies unknown) satisfies number; + +this.intervalID = (setInterval(() => { + self.step(); +}, 30) satisfies unknown) satisfies number; + +=====================================output===================================== +const extraRendererAttrs = ((attrs.rendererAttrs && + this.utils.safeParseJsonString(attrs.rendererAttrs)) || + Object.create(null)) satisfies FieldService.RendererAttributes; + +const annotate = (angular.injector satisfies any).$$annotate satisfies ( + fn: Function +) => string[]; + +const originalPrototype = originalConstructor.prototype satisfies TComponent & + InjectionTarget, + propertyToServiceName = originalPrototype._inject; + +this.previewPlayerHandle = setInterval(async () => { + if (this.previewIsPlaying) { + await this.fetchNextPreviews(); + this.currentPreviewIndex++; + } +}, this.refreshDelay) satisfies unknown satisfies number; + +this.intervalID = setInterval(() => { + self.step(); +}, 30) satisfies unknown satisfies number; + +================================================================================ +`; + +exports[`basic.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +const t1 = { a: 1 } satisfies I1; +const t2 = { a: 1, b: 1 } satisfies I1; +const t3 = { } satisfies I1; +const t4: T1 = { a: "a" } satisfies T1; +const t5 = (m => m.substring(0)) satisfies T2; +const t6 = [1, 2] satisfies [number, number]; +let t7 = { a: 'test' } satisfies A; +let t8 = { a: 'test', b: 'test' } satisfies A; + +const p = { + isEven: n => n % 2 === 0, + isOdd: n => n % 2 === 1 +} satisfies Predicates; + +let obj: { f(s: string): void } & Record = { + f(s) { }, + g(s) { } +} satisfies { g(s: string): void } & Record; + +({ f(x) { } }) satisfies { f(s: string): void }; + +const car = { + start() { }, + move(d) { + // d should be number + }, + stop() { } +} satisfies Movable & Record; + +var v = undefined satisfies 1; + +=====================================output===================================== +const t1 = { a: 1 } satisfies I1 +const t2 = { a: 1, b: 1 } satisfies I1 +const t3 = {} satisfies I1 +const t4: T1 = { a: "a" } satisfies T1 +const t5 = ((m) => m.substring(0)) satisfies T2 +const t6 = [1, 2] satisfies [number, number] +let t7 = { a: "test" } satisfies A +let t8 = { a: "test", b: "test" } satisfies A + +const p = { + isEven: (n) => n % 2 === 0, + isOdd: (n) => n % 2 === 1, +} satisfies Predicates + +let obj: { f(s: string): void } & Record = { + f(s) {}, + g(s) {}, +} satisfies { g(s: string): void } & Record + +;({ f(x) {} } satisfies { f(s: string): void }) + +const car = { + start() {}, + move(d) { + // d should be number + }, + stop() {}, +} satisfies Movable & Record + +var v = undefined satisfies 1 + +================================================================================ +`; + +exports[`basic.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +const t1 = { a: 1 } satisfies I1; +const t2 = { a: 1, b: 1 } satisfies I1; +const t3 = { } satisfies I1; +const t4: T1 = { a: "a" } satisfies T1; +const t5 = (m => m.substring(0)) satisfies T2; +const t6 = [1, 2] satisfies [number, number]; +let t7 = { a: 'test' } satisfies A; +let t8 = { a: 'test', b: 'test' } satisfies A; + +const p = { + isEven: n => n % 2 === 0, + isOdd: n => n % 2 === 1 +} satisfies Predicates; + +let obj: { f(s: string): void } & Record = { + f(s) { }, + g(s) { } +} satisfies { g(s: string): void } & Record; + +({ f(x) { } }) satisfies { f(s: string): void }; + +const car = { + start() { }, + move(d) { + // d should be number + }, + stop() { } +} satisfies Movable & Record; + +var v = undefined satisfies 1; + +=====================================output===================================== +const t1 = { a: 1 } satisfies I1; +const t2 = { a: 1, b: 1 } satisfies I1; +const t3 = {} satisfies I1; +const t4: T1 = { a: "a" } satisfies T1; +const t5 = ((m) => m.substring(0)) satisfies T2; +const t6 = [1, 2] satisfies [number, number]; +let t7 = { a: "test" } satisfies A; +let t8 = { a: "test", b: "test" } satisfies A; + +const p = { + isEven: (n) => n % 2 === 0, + isOdd: (n) => n % 2 === 1, +} satisfies Predicates; + +let obj: { f(s: string): void } & Record = { + f(s) {}, + g(s) {}, +} satisfies { g(s: string): void } & Record; + +({ f(x) {} } satisfies { f(s: string): void }); + +const car = { + start() {}, + move(d) { + // d should be number + }, + stop() {}, +} satisfies Movable & Record; + +var v = undefined satisfies 1; + +================================================================================ +`; + +exports[`comments.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +const t2 = {} /* comment */ satisfies {}; +const t3 = {} satisfies /* comment */ {}; +const t4 = {} /* comment1 */ satisfies /* comment2 */ {}; + +=====================================output===================================== +const t2 = {} /* comment */ satisfies {} +const t3 = {} satisfies /* comment */ {} +const t4 = {} /* comment1 */ satisfies /* comment2 */ {} + +================================================================================ +`; + +exports[`comments.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +const t2 = {} /* comment */ satisfies {}; +const t3 = {} satisfies /* comment */ {}; +const t4 = {} /* comment1 */ satisfies /* comment2 */ {}; + +=====================================output===================================== +const t2 = {} /* comment */ satisfies {}; +const t3 = {} satisfies /* comment */ {}; +const t4 = {} /* comment1 */ satisfies /* comment2 */ {}; + +================================================================================ +`; + +exports[`comments-unstable.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +const t1 = { + prop1: 1, + prop2: 2, + prop3: 3 +} satisfies +// Comment +Record; + +=====================================output===================================== +const t1 = { + prop1: 1, + prop2: 2, + prop3: 3, +} satisfies // Comment +Record + +================================================================================ +`; + +exports[`comments-unstable.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +const t1 = { + prop1: 1, + prop2: 2, + prop3: 3 +} satisfies +// Comment +Record; + +=====================================output===================================== +const t1 = { + prop1: 1, + prop2: 2, + prop3: 3, +} satisfies // Comment +Record; + +================================================================================ +`; + +exports[`export-default-as.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +export default (function log() {} satisfies typeof console.log) + +=====================================output===================================== +export default (function log() {} satisfies typeof console.log) + +================================================================================ +`; + +exports[`export-default-as.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +export default (function log() {} satisfies typeof console.log) + +=====================================output===================================== +export default (function log() {} satisfies typeof console.log); + +================================================================================ +`; + +exports[`gt-lt.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +x satisfies boolean <= y; // (x satisfies boolean) <= y; +x satisfies boolean ?? y; // (x satisfies boolean) ?? y; + +=====================================output===================================== +;(x satisfies boolean) <= y // (x satisfies boolean) <= y; +;(x satisfies boolean) ?? y // (x satisfies boolean) ?? y; + +================================================================================ +`; + +exports[`gt-lt.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +x satisfies boolean <= y; // (x satisfies boolean) <= y; +x satisfies boolean ?? y; // (x satisfies boolean) ?? y; + +=====================================output===================================== +(x satisfies boolean) <= y; // (x satisfies boolean) <= y; +(x satisfies boolean) ?? y; // (x satisfies boolean) ?? y; + +================================================================================ +`; + +exports[`hug-args.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +window.postMessage( + { + context: item.context, + topic: item.topic + } satisfies IActionMessage + ); + +=====================================output===================================== +window.postMessage({ + context: item.context, + topic: item.topic, +} satisfies IActionMessage) + +================================================================================ +`; + +exports[`hug-args.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +window.postMessage( + { + context: item.context, + topic: item.topic + } satisfies IActionMessage + ); + +=====================================output===================================== +window.postMessage({ + context: item.context, + topic: item.topic, +} satisfies IActionMessage); + +================================================================================ +`; + +exports[`lhs.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +(a satisfies number) = 42; +({ a: (b satisfies any) = 2000 } = x); +(this.selectorElem satisfies any) = this.multiselectWidget = this.initialValues = undefined; +(this.configuration satisfies any) = (this.editor satisfies any) = (this + .editorBody satisfies any) = undefined; + +=====================================output===================================== +;(a satisfies number) = 42 +;({ a: (b satisfies any) = 2000 } = x) +;(this.selectorElem satisfies any) = + this.multiselectWidget = + this.initialValues = + undefined +;(this.configuration satisfies any) = + (this.editor satisfies any) = + (this.editorBody satisfies any) = + undefined + +================================================================================ +`; + +exports[`lhs.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +(a satisfies number) = 42; +({ a: (b satisfies any) = 2000 } = x); +(this.selectorElem satisfies any) = this.multiselectWidget = this.initialValues = undefined; +(this.configuration satisfies any) = (this.editor satisfies any) = (this + .editorBody satisfies any) = undefined; + +=====================================output===================================== +(a satisfies number) = 42; +({ a: (b satisfies any) = 2000 } = x); +(this.selectorElem satisfies any) = + this.multiselectWidget = + this.initialValues = + undefined; +(this.configuration satisfies any) = + (this.editor satisfies any) = + (this.editorBody satisfies any) = + undefined; + +================================================================================ +`; + +exports[`nested-await-and-satisfies.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +const getAccountCount = async () => + (await + ((await ( + await focusOnSection(BOOKMARKED_PROJECTS_SECTION_NAME) + ).findItem("My bookmarks")) satisfies TreeItem + ).getChildren() + ).length + +=====================================output===================================== +const getAccountCount = async () => + ( + await ( + (await ( + await focusOnSection(BOOKMARKED_PROJECTS_SECTION_NAME) + ).findItem("My bookmarks")) satisfies TreeItem + ).getChildren() + ).length + +================================================================================ +`; + +exports[`nested-await-and-satisfies.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +const getAccountCount = async () => + (await + ((await ( + await focusOnSection(BOOKMARKED_PROJECTS_SECTION_NAME) + ).findItem("My bookmarks")) satisfies TreeItem + ).getChildren() + ).length + +=====================================output===================================== +const getAccountCount = async () => + ( + await ( + (await ( + await focusOnSection(BOOKMARKED_PROJECTS_SECTION_NAME) + ).findItem("My bookmarks")) satisfies TreeItem + ).getChildren() + ).length; + +================================================================================ +`; + +exports[`non-null.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +// the 2nd line needs ASI protection +const el = ReactDOM.findDOMNode(ref) +;(el satisfies HTMLElement)!.style.cursor = 'pointer' + +=====================================output===================================== +// the 2nd line needs ASI protection +const el = ReactDOM.findDOMNode(ref) +;(el satisfies HTMLElement)!.style.cursor = "pointer" + +================================================================================ +`; + +exports[`non-null.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +// the 2nd line needs ASI protection +const el = ReactDOM.findDOMNode(ref) +;(el satisfies HTMLElement)!.style.cursor = 'pointer' + +=====================================output===================================== +// the 2nd line needs ASI protection +const el = ReactDOM.findDOMNode(ref); +(el satisfies HTMLElement)!.style.cursor = "pointer"; + +================================================================================ +`; + +exports[`satisfies.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +({}) satisfies {}; +({}) satisfies X; +() => ({}) satisfies X; +this.isTabActionBar((e.target || e.srcElement) satisfies HTMLElement); + +'current' in (props.pagination satisfies Object); +('current' in props.pagination) satisfies Object; +start + (yearSelectTotal satisfies number); +(start + yearSelectTotal) satisfies number; +scrollTop > (visibilityHeight satisfies number); +(scrollTop > visibilityHeight) satisfies number; +(bValue satisfies boolean) ? 0 : -1; + +async function g1() { + const test = (await 'foo') satisfies number; +} + +var x = (v => v) satisfies (x: number) => string; + +foo satisfies unknown satisfies Bar; +foo satisfies unknown as Bar; +foo as unknown satisfies Bar; + +=====================================output===================================== +;({} satisfies {}) +;({} satisfies X) +;() => ({} satisfies X) +this.isTabActionBar((e.target || e.srcElement) satisfies HTMLElement) + +"current" in (props.pagination satisfies Object) +;("current" in props.pagination) satisfies Object +start + (yearSelectTotal satisfies number) +;(start + yearSelectTotal) satisfies number +scrollTop > (visibilityHeight satisfies number) +;(scrollTop > visibilityHeight) satisfies number +;(bValue satisfies boolean) ? 0 : -1 + +async function g1() { + const test = (await "foo") satisfies number +} + +var x = ((v) => v) satisfies (x: number) => string + +foo satisfies unknown satisfies Bar +foo satisfies unknown as Bar +foo as unknown satisfies Bar + +================================================================================ +`; + +exports[`satisfies.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +({}) satisfies {}; +({}) satisfies X; +() => ({}) satisfies X; +this.isTabActionBar((e.target || e.srcElement) satisfies HTMLElement); + +'current' in (props.pagination satisfies Object); +('current' in props.pagination) satisfies Object; +start + (yearSelectTotal satisfies number); +(start + yearSelectTotal) satisfies number; +scrollTop > (visibilityHeight satisfies number); +(scrollTop > visibilityHeight) satisfies number; +(bValue satisfies boolean) ? 0 : -1; + +async function g1() { + const test = (await 'foo') satisfies number; +} + +var x = (v => v) satisfies (x: number) => string; + +foo satisfies unknown satisfies Bar; +foo satisfies unknown as Bar; +foo as unknown satisfies Bar; + +=====================================output===================================== +({} satisfies {}); +({} satisfies X); +() => ({} satisfies X); +this.isTabActionBar((e.target || e.srcElement) satisfies HTMLElement); + +"current" in (props.pagination satisfies Object); +("current" in props.pagination) satisfies Object; +start + (yearSelectTotal satisfies number); +(start + yearSelectTotal) satisfies number; +scrollTop > (visibilityHeight satisfies number); +(scrollTop > visibilityHeight) satisfies number; +(bValue satisfies boolean) ? 0 : -1; + +async function g1() { + const test = (await "foo") satisfies number; +} + +var x = ((v) => v) satisfies (x: number) => string; + +foo satisfies unknown satisfies Bar; +foo satisfies unknown as Bar; +foo as unknown satisfies Bar; + +================================================================================ +`; + +exports[`template-literal.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +const a = \`\${(foo + bar) satisfies baz}\`; +const b = \`\${(veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFoo + bar) satisfies baz}\`; +const b = \`\${(foo + veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBar) satisfies baz}\`; +const b = \`\${(foo + bar) satisfies veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBaz}\`; +const b = \`\${(veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFoo + veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBar) satisfies veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBaz}\`; + +=====================================output===================================== +const a = \`\${(foo + bar) satisfies baz}\` +const b = \`\${ + (veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFoo + bar) satisfies baz +}\` +const b = \`\${ + (foo + veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBar) satisfies baz +}\` +const b = \`\${ + (foo + bar) satisfies veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBaz +}\` +const b = \`\${ + (veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFoo + + veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBar) satisfies veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBaz +}\` + +================================================================================ +`; + +exports[`template-literal.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +const a = \`\${(foo + bar) satisfies baz}\`; +const b = \`\${(veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFoo + bar) satisfies baz}\`; +const b = \`\${(foo + veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBar) satisfies baz}\`; +const b = \`\${(foo + bar) satisfies veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBaz}\`; +const b = \`\${(veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFoo + veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBar) satisfies veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBaz}\`; + +=====================================output===================================== +const a = \`\${(foo + bar) satisfies baz}\`; +const b = \`\${ + (veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFoo + bar) satisfies baz +}\`; +const b = \`\${ + (foo + veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBar) satisfies baz +}\`; +const b = \`\${ + (foo + bar) satisfies veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBaz +}\`; +const b = \`\${ + (veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFoo + + veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBar) satisfies veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBaz +}\`; + +================================================================================ +`; + +exports[`ternary.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +foo = (coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz) satisfies Fooooooooooo; + +foo = (condition ? firstValue : secondValue) satisfies SomeType; + +const foo = (coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz) satisfies Fooooooooooo; + +function foo() { + return (coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz) satisfies Fooooooooooo; +} + +function foo() { + throw (coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz) satisfies Fooooooooooo; +} + +function foo() { + void ((coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz) satisfies Fooooooooooo); +} + +bifornCringerMoshedPerplexSawder = + askTrovenaBeenaDependsRowans + + ((glimseGlyphsHazardNoopsTieTie === 0 + ? averredBathersBoxroomBuggyNurl + : anodyneCondosMalateOverateRetinol) satisfies AnnularCooeedSplicesWalksWayWay); + +bifornCringerMoshedPerplexSawder = + askTrovenaBeenaDependsRowans + + ((glimseGlyphsHazardNoopsTieTie === 0 && + kochabCooieGameOnOboleUnweave === Math.PI + ? averredBathersBoxroomBuggyNurl + : anodyneCondosMalateOverateRetinol) satisfies AnnularCooeedSplicesWalksWayWay); + +=====================================output===================================== +foo = ( + coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz +) satisfies Fooooooooooo + +foo = (condition ? firstValue : secondValue) satisfies SomeType + +const foo = ( + coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz +) satisfies Fooooooooooo + +function foo() { + return ( + coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz + ) satisfies Fooooooooooo +} + +function foo() { + throw ( + coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz + ) satisfies Fooooooooooo +} + +function foo() { + void (( + coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz + ) satisfies Fooooooooooo) +} + +bifornCringerMoshedPerplexSawder = + askTrovenaBeenaDependsRowans + + ((glimseGlyphsHazardNoopsTieTie === 0 + ? averredBathersBoxroomBuggyNurl + : anodyneCondosMalateOverateRetinol) satisfies AnnularCooeedSplicesWalksWayWay) + +bifornCringerMoshedPerplexSawder = + askTrovenaBeenaDependsRowans + + ((glimseGlyphsHazardNoopsTieTie === 0 && + kochabCooieGameOnOboleUnweave === Math.PI + ? averredBathersBoxroomBuggyNurl + : anodyneCondosMalateOverateRetinol) satisfies AnnularCooeedSplicesWalksWayWay) + +================================================================================ +`; + +exports[`ternary.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +foo = (coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz) satisfies Fooooooooooo; + +foo = (condition ? firstValue : secondValue) satisfies SomeType; + +const foo = (coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz) satisfies Fooooooooooo; + +function foo() { + return (coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz) satisfies Fooooooooooo; +} + +function foo() { + throw (coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz) satisfies Fooooooooooo; +} + +function foo() { + void ((coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz) satisfies Fooooooooooo); +} + +bifornCringerMoshedPerplexSawder = + askTrovenaBeenaDependsRowans + + ((glimseGlyphsHazardNoopsTieTie === 0 + ? averredBathersBoxroomBuggyNurl + : anodyneCondosMalateOverateRetinol) satisfies AnnularCooeedSplicesWalksWayWay); + +bifornCringerMoshedPerplexSawder = + askTrovenaBeenaDependsRowans + + ((glimseGlyphsHazardNoopsTieTie === 0 && + kochabCooieGameOnOboleUnweave === Math.PI + ? averredBathersBoxroomBuggyNurl + : anodyneCondosMalateOverateRetinol) satisfies AnnularCooeedSplicesWalksWayWay); + +=====================================output===================================== +foo = ( + coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz +) satisfies Fooooooooooo; + +foo = (condition ? firstValue : secondValue) satisfies SomeType; + +const foo = ( + coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz +) satisfies Fooooooooooo; + +function foo() { + return ( + coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz + ) satisfies Fooooooooooo; +} + +function foo() { + throw ( + coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz + ) satisfies Fooooooooooo; +} + +function foo() { + void (( + coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz + ) satisfies Fooooooooooo); +} + +bifornCringerMoshedPerplexSawder = + askTrovenaBeenaDependsRowans + + ((glimseGlyphsHazardNoopsTieTie === 0 + ? averredBathersBoxroomBuggyNurl + : anodyneCondosMalateOverateRetinol) satisfies AnnularCooeedSplicesWalksWayWay); + +bifornCringerMoshedPerplexSawder = + askTrovenaBeenaDependsRowans + + ((glimseGlyphsHazardNoopsTieTie === 0 && + kochabCooieGameOnOboleUnweave === Math.PI + ? averredBathersBoxroomBuggyNurl + : anodyneCondosMalateOverateRetinol) satisfies AnnularCooeedSplicesWalksWayWay); + +================================================================================ +`; + +exports[`types-comments.ts - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +(() => { + // swallow error and fallback to using directory as path +}) satisfies string[]; + +=====================================output===================================== +;(() => { + // swallow error and fallback to using directory as path +}) satisfies string[] + +================================================================================ +`; + +exports[`types-comments.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +(() => { + // swallow error and fallback to using directory as path +}) satisfies string[]; + +=====================================output===================================== +(() => { + // swallow error and fallback to using directory as path +}) satisfies string[]; + +================================================================================ +`; diff --git a/tests/format/typescript/satisfies-operators/argument-expansion.ts b/tests/format/typescript/satisfies-operators/argument-expansion.ts new file mode 100644 index 000000000000..aef1a1410c1a --- /dev/null +++ b/tests/format/typescript/satisfies-operators/argument-expansion.ts @@ -0,0 +1,19 @@ +const bar1 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, ([] satisfies unknown) satisfies number[]); + +const bar2 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, ([1, 2, 3] satisfies unknown) satisfies number[]); + +const bar3 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, ({} satisfies unknown) satisfies {[key: number]: boolean}); + +const bar4 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, ({1: true} satisfies unknown) satisfies {[key: number]: boolean}); + +const bar5 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, [] satisfies foo); diff --git a/tests/format/typescript/satisfies-operators/assignment.ts b/tests/format/typescript/satisfies-operators/assignment.ts new file mode 100644 index 000000000000..9b7139253bc4 --- /dev/null +++ b/tests/format/typescript/satisfies-operators/assignment.ts @@ -0,0 +1,21 @@ +const extraRendererAttrs = ((attrs.rendererAttrs && + this.utils.safeParseJsonString(attrs.rendererAttrs)) || + Object.create(null)) satisfies FieldService.RendererAttributes; + +const annotate = (angular.injector satisfies any).$$annotate satisfies ( + fn: Function +) => string[]; + +const originalPrototype = originalConstructor.prototype satisfies TComponent & InjectionTarget, + propertyToServiceName = originalPrototype._inject; + +this.previewPlayerHandle = (setInterval(async () => { + if (this.previewIsPlaying) { + await this.fetchNextPreviews(); + this.currentPreviewIndex++; + } +}, this.refreshDelay) satisfies unknown) satisfies number; + +this.intervalID = (setInterval(() => { + self.step(); +}, 30) satisfies unknown) satisfies number; diff --git a/tests/format/typescript/satisfies-operators/basic.ts b/tests/format/typescript/satisfies-operators/basic.ts new file mode 100644 index 000000000000..3eff7182b432 --- /dev/null +++ b/tests/format/typescript/satisfies-operators/basic.ts @@ -0,0 +1,30 @@ +const t1 = { a: 1 } satisfies I1; +const t2 = { a: 1, b: 1 } satisfies I1; +const t3 = { } satisfies I1; +const t4: T1 = { a: "a" } satisfies T1; +const t5 = (m => m.substring(0)) satisfies T2; +const t6 = [1, 2] satisfies [number, number]; +let t7 = { a: 'test' } satisfies A; +let t8 = { a: 'test', b: 'test' } satisfies A; + +const p = { + isEven: n => n % 2 === 0, + isOdd: n => n % 2 === 1 +} satisfies Predicates; + +let obj: { f(s: string): void } & Record = { + f(s) { }, + g(s) { } +} satisfies { g(s: string): void } & Record; + +({ f(x) { } }) satisfies { f(s: string): void }; + +const car = { + start() { }, + move(d) { + // d should be number + }, + stop() { } +} satisfies Movable & Record; + +var v = undefined satisfies 1; diff --git a/tests/format/typescript/satisfies-operators/comments-unstable.ts b/tests/format/typescript/satisfies-operators/comments-unstable.ts new file mode 100644 index 000000000000..0f658aa54605 --- /dev/null +++ b/tests/format/typescript/satisfies-operators/comments-unstable.ts @@ -0,0 +1,7 @@ +const t1 = { + prop1: 1, + prop2: 2, + prop3: 3 +} satisfies +// Comment +Record; diff --git a/tests/format/typescript/satisfies-operators/comments.ts b/tests/format/typescript/satisfies-operators/comments.ts new file mode 100644 index 000000000000..9ab0ae58c20c --- /dev/null +++ b/tests/format/typescript/satisfies-operators/comments.ts @@ -0,0 +1,3 @@ +const t2 = {} /* comment */ satisfies {}; +const t3 = {} satisfies /* comment */ {}; +const t4 = {} /* comment1 */ satisfies /* comment2 */ {}; diff --git a/tests/format/typescript/satisfies-operators/export-default-as.ts b/tests/format/typescript/satisfies-operators/export-default-as.ts new file mode 100644 index 000000000000..6d6905150d89 --- /dev/null +++ b/tests/format/typescript/satisfies-operators/export-default-as.ts @@ -0,0 +1 @@ +export default (function log() {} satisfies typeof console.log) diff --git a/tests/format/typescript/satisfies-operators/gt-lt.ts b/tests/format/typescript/satisfies-operators/gt-lt.ts new file mode 100644 index 000000000000..bdc95deefbed --- /dev/null +++ b/tests/format/typescript/satisfies-operators/gt-lt.ts @@ -0,0 +1,2 @@ +x satisfies boolean <= y; // (x satisfies boolean) <= y; +x satisfies boolean ?? y; // (x satisfies boolean) ?? y; diff --git a/tests/format/typescript/satisfies-operators/hug-args.ts b/tests/format/typescript/satisfies-operators/hug-args.ts new file mode 100644 index 000000000000..c35cf66fb521 --- /dev/null +++ b/tests/format/typescript/satisfies-operators/hug-args.ts @@ -0,0 +1,6 @@ +window.postMessage( + { + context: item.context, + topic: item.topic + } satisfies IActionMessage + ); diff --git a/tests/format/typescript/satisfies-operators/jsfmt.spec.js b/tests/format/typescript/satisfies-operators/jsfmt.spec.js new file mode 100644 index 000000000000..3727c175bda6 --- /dev/null +++ b/tests/format/typescript/satisfies-operators/jsfmt.spec.js @@ -0,0 +1,2 @@ +run_spec(__dirname, ["babel-ts"]); +run_spec(__dirname, ["babel-ts"], { semi: false }); diff --git a/tests/format/typescript/satisfies-operators/lhs.ts b/tests/format/typescript/satisfies-operators/lhs.ts new file mode 100644 index 000000000000..fbdbe1c91062 --- /dev/null +++ b/tests/format/typescript/satisfies-operators/lhs.ts @@ -0,0 +1,5 @@ +(a satisfies number) = 42; +({ a: (b satisfies any) = 2000 } = x); +(this.selectorElem satisfies any) = this.multiselectWidget = this.initialValues = undefined; +(this.configuration satisfies any) = (this.editor satisfies any) = (this + .editorBody satisfies any) = undefined; diff --git a/tests/format/typescript/satisfies-operators/nested-await-and-satisfies.ts b/tests/format/typescript/satisfies-operators/nested-await-and-satisfies.ts new file mode 100644 index 000000000000..d9c2b4a600be --- /dev/null +++ b/tests/format/typescript/satisfies-operators/nested-await-and-satisfies.ts @@ -0,0 +1,7 @@ +const getAccountCount = async () => + (await + ((await ( + await focusOnSection(BOOKMARKED_PROJECTS_SECTION_NAME) + ).findItem("My bookmarks")) satisfies TreeItem + ).getChildren() + ).length diff --git a/tests/format/typescript/satisfies-operators/non-null.ts b/tests/format/typescript/satisfies-operators/non-null.ts new file mode 100644 index 000000000000..9e1e0b3ac0b0 --- /dev/null +++ b/tests/format/typescript/satisfies-operators/non-null.ts @@ -0,0 +1,3 @@ +// the 2nd line needs ASI protection +const el = ReactDOM.findDOMNode(ref) +;(el satisfies HTMLElement)!.style.cursor = 'pointer' diff --git a/tests/format/typescript/satisfies-operators/satisfies.ts b/tests/format/typescript/satisfies-operators/satisfies.ts new file mode 100644 index 000000000000..f9b3f6f2acb3 --- /dev/null +++ b/tests/format/typescript/satisfies-operators/satisfies.ts @@ -0,0 +1,22 @@ +({}) satisfies {}; +({}) satisfies X; +() => ({}) satisfies X; +this.isTabActionBar((e.target || e.srcElement) satisfies HTMLElement); + +'current' in (props.pagination satisfies Object); +('current' in props.pagination) satisfies Object; +start + (yearSelectTotal satisfies number); +(start + yearSelectTotal) satisfies number; +scrollTop > (visibilityHeight satisfies number); +(scrollTop > visibilityHeight) satisfies number; +(bValue satisfies boolean) ? 0 : -1; + +async function g1() { + const test = (await 'foo') satisfies number; +} + +var x = (v => v) satisfies (x: number) => string; + +foo satisfies unknown satisfies Bar; +foo satisfies unknown as Bar; +foo as unknown satisfies Bar; diff --git a/tests/format/typescript/satisfies-operators/template-literal.ts b/tests/format/typescript/satisfies-operators/template-literal.ts new file mode 100644 index 000000000000..d4152adc97e5 --- /dev/null +++ b/tests/format/typescript/satisfies-operators/template-literal.ts @@ -0,0 +1,5 @@ +const a = `${(foo + bar) satisfies baz}`; +const b = `${(veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFoo + bar) satisfies baz}`; +const b = `${(foo + veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBar) satisfies baz}`; +const b = `${(foo + bar) satisfies veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBaz}`; +const b = `${(veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongFoo + veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBar) satisfies veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongBaz}`; diff --git a/tests/format/typescript/satisfies-operators/ternary.ts b/tests/format/typescript/satisfies-operators/ternary.ts new file mode 100644 index 000000000000..0baab89c6c37 --- /dev/null +++ b/tests/format/typescript/satisfies-operators/ternary.ts @@ -0,0 +1,40 @@ +foo = (coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz) satisfies Fooooooooooo; + +foo = (condition ? firstValue : secondValue) satisfies SomeType; + +const foo = (coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz) satisfies Fooooooooooo; + +function foo() { + return (coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz) satisfies Fooooooooooo; +} + +function foo() { + throw (coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz) satisfies Fooooooooooo; +} + +function foo() { + void ((coooooooooooooooooooooooooooooooooooooooooooooooooooond + ? baaaaaaaaaaaaaaaaaaaaar + : baaaaaaaaaaaaaaaaaaaaaz) satisfies Fooooooooooo); +} + +bifornCringerMoshedPerplexSawder = + askTrovenaBeenaDependsRowans + + ((glimseGlyphsHazardNoopsTieTie === 0 + ? averredBathersBoxroomBuggyNurl + : anodyneCondosMalateOverateRetinol) satisfies AnnularCooeedSplicesWalksWayWay); + +bifornCringerMoshedPerplexSawder = + askTrovenaBeenaDependsRowans + + ((glimseGlyphsHazardNoopsTieTie === 0 && + kochabCooieGameOnOboleUnweave === Math.PI + ? averredBathersBoxroomBuggyNurl + : anodyneCondosMalateOverateRetinol) satisfies AnnularCooeedSplicesWalksWayWay); diff --git a/tests/format/typescript/satisfies-operators/types-comments.ts b/tests/format/typescript/satisfies-operators/types-comments.ts new file mode 100644 index 000000000000..8ef9413c2a31 --- /dev/null +++ b/tests/format/typescript/satisfies-operators/types-comments.ts @@ -0,0 +1,3 @@ +(() => { + // swallow error and fallback to using directory as path +}) satisfies string[]; diff --git a/yarn.lock b/yarn.lock index e545351d8422..53ae360e305d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -306,10 +306,10 @@ chalk "^2.0.0" js-tokens "^4.0.0" -"@babel/parser@7.18.0": - version "7.18.0" - resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.18.0.tgz#10a8d4e656bc01128d299a787aa006ce1a91e112" - integrity sha512-AqDccGC+m5O/iUStSJy3DGRIUFu7WbY/CppZYwrEUB4N0tZlnI8CSTsgL7v5fHVFmUbRv2sd+yy27o8Ydt4MGg== +"@babel/parser@7.20.1": + version "7.20.1" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.20.1.tgz#3e045a92f7b4623cafc2425eddcb8cf2e54f9cc5" + integrity sha512-hp0AYxaZJhxULfM1zyp7Wgr+pSUKBcP3M+PHnSzWGdXOzg/kHWIgiUWARvubhUKGOEw3xqY4x+lyZ9ytBVcELw== "@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.16.7", "@babel/parser@^7.17.9": version "7.17.9" @@ -1751,19 +1751,19 @@ dependencies: "@types/yargs-parser" "*" -"@typescript-eslint/eslint-plugin@5.20.0": - version "5.20.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.20.0.tgz#022531a639640ff3faafaf251d1ce00a2ef000a1" - integrity sha512-fapGzoxilCn3sBtC6NtXZX6+P/Hef7VDbyfGqTTpzYydwhlkevB+0vE0EnmHPVTVSy68GUncyJ/2PcrFBeCo5Q== +"@typescript-eslint/eslint-plugin@5.36.2": + version "5.36.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.36.2.tgz#6df092a20e0f9ec748b27f293a12cb39d0c1fe4d" + integrity sha512-OwwR8LRwSnI98tdc2z7mJYgY60gf7I9ZfGjN5EjCwwns9bdTuQfAXcsjSB2wSQ/TVNYSGKf4kzVXbNGaZvwiXw== dependencies: - "@typescript-eslint/scope-manager" "5.20.0" - "@typescript-eslint/type-utils" "5.20.0" - "@typescript-eslint/utils" "5.20.0" - debug "^4.3.2" + "@typescript-eslint/scope-manager" "5.36.2" + "@typescript-eslint/type-utils" "5.36.2" + "@typescript-eslint/utils" "5.36.2" + debug "^4.3.4" functional-red-black-tree "^1.0.1" - ignore "^5.1.8" + ignore "^5.2.0" regexpp "^3.2.0" - semver "^7.3.5" + semver "^7.3.7" tsutils "^3.21.0" "@typescript-eslint/scope-manager@5.20.0": @@ -1774,13 +1774,22 @@ "@typescript-eslint/types" "5.20.0" "@typescript-eslint/visitor-keys" "5.20.0" -"@typescript-eslint/type-utils@5.20.0": - version "5.20.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.20.0.tgz#151c21cbe9a378a34685735036e5ddfc00223be3" - integrity sha512-WxNrCwYB3N/m8ceyoGCgbLmuZwupvzN0rE8NBuwnl7APgjv24ZJIjkNzoFBXPRCGzLNkoU/WfanW0exvp/+3Iw== +"@typescript-eslint/scope-manager@5.36.2": + version "5.36.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.36.2.tgz#a75eb588a3879ae659514780831370642505d1cd" + integrity sha512-cNNP51L8SkIFSfce8B1NSUBTJTu2Ts4nWeWbFrdaqjmn9yKrAaJUBHkyTZc0cL06OFHpb+JZq5AUHROS398Orw== dependencies: - "@typescript-eslint/utils" "5.20.0" - debug "^4.3.2" + "@typescript-eslint/types" "5.36.2" + "@typescript-eslint/visitor-keys" "5.36.2" + +"@typescript-eslint/type-utils@5.36.2": + version "5.36.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.36.2.tgz#752373f4babf05e993adf2cd543a763632826391" + integrity sha512-rPQtS5rfijUWLouhy6UmyNquKDPhQjKsaKH0WnY6hl/07lasj8gPaH2UD8xWkePn6SC+jW2i9c2DZVDnL+Dokw== + dependencies: + "@typescript-eslint/typescript-estree" "5.36.2" + "@typescript-eslint/utils" "5.36.2" + debug "^4.3.4" tsutils "^3.21.0" "@typescript-eslint/types@5.20.0": @@ -1788,10 +1797,10 @@ resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.20.0.tgz#fa39c3c2aa786568302318f1cb51fcf64258c20c" integrity sha512-+d8wprF9GyvPwtoB4CxBAR/s0rpP25XKgnOvMf/gMXYDvlUC3rPFHupdTQ/ow9vn7UDe5rX02ovGYQbv/IUCbg== -"@typescript-eslint/types@5.30.0": - version "5.30.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.30.0.tgz#db7d81d585a3da3801432a9c1d2fafbff125e110" - integrity sha512-vfqcBrsRNWw/LBXyncMF/KrUTYYzzygCSsVqlZ1qGu1QtGs6vMkt3US0VNSQ05grXi5Yadp3qv5XZdYLjpp8ag== +"@typescript-eslint/types@5.36.2": + version "5.36.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.36.2.tgz#a5066e500ebcfcee36694186ccc57b955c05faf9" + integrity sha512-9OJSvvwuF1L5eS2EQgFUbECb99F0mwq501w0H0EkYULkhFa19Qq7WFbycdw1PexAc929asupbZcgjVIe6OK/XQ== "@typescript-eslint/typescript-estree@5.20.0": version "5.20.0" @@ -1806,20 +1815,32 @@ semver "^7.3.5" tsutils "^3.21.0" -"@typescript-eslint/typescript-estree@5.30.0": - version "5.30.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.30.0.tgz#4565ee8a6d2ac368996e20b2344ea0eab1a8f0bb" - integrity sha512-hDEawogreZB4n1zoqcrrtg/wPyyiCxmhPLpZ6kmWfKF5M5G0clRLaEexpuWr31fZ42F96SlD/5xCt1bT5Qm4Nw== +"@typescript-eslint/typescript-estree@5.36.2": + version "5.36.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.36.2.tgz#0c93418b36c53ba0bc34c61fe9405c4d1d8fe560" + integrity sha512-8fyH+RfbKc0mTspfuEjlfqA4YywcwQK2Amcf6TDOwaRLg7Vwdu4bZzyvBZp4bjt1RRjQ5MDnOZahxMrt2l5v9w== dependencies: - "@typescript-eslint/types" "5.30.0" - "@typescript-eslint/visitor-keys" "5.30.0" + "@typescript-eslint/types" "5.36.2" + "@typescript-eslint/visitor-keys" "5.36.2" debug "^4.3.4" globby "^11.1.0" is-glob "^4.0.3" semver "^7.3.7" tsutils "^3.21.0" -"@typescript-eslint/utils@5.20.0", "@typescript-eslint/utils@^5.10.0": +"@typescript-eslint/utils@5.36.2": + version "5.36.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.36.2.tgz#b01a76f0ab244404c7aefc340c5015d5ce6da74c" + integrity sha512-uNcopWonEITX96v9pefk9DC1bWMdkweeSsewJ6GeC7L6j2t0SJywisgkr9wUTtXk90fi2Eljj90HSHm3OGdGRg== + dependencies: + "@types/json-schema" "^7.0.9" + "@typescript-eslint/scope-manager" "5.36.2" + "@typescript-eslint/types" "5.36.2" + "@typescript-eslint/typescript-estree" "5.36.2" + eslint-scope "^5.1.1" + eslint-utils "^3.0.0" + +"@typescript-eslint/utils@^5.10.0": version "5.20.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.20.0.tgz#b8e959ed11eca1b2d5414e12417fd94cae3517a5" integrity sha512-lHONGJL1LIO12Ujyx8L8xKbwWSkoUKFSO+0wDAqGXiudWB2EO7WEUT+YZLtVbmOmSllAjLb9tpoIPwpRe5Tn6w== @@ -1839,12 +1860,12 @@ "@typescript-eslint/types" "5.20.0" eslint-visitor-keys "^3.0.0" -"@typescript-eslint/visitor-keys@5.30.0": - version "5.30.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.30.0.tgz#07721d23daca2ec4c2da7f1e660d41cd78bacac3" - integrity sha512-6WcIeRk2DQ3pHKxU1Ni0qMXJkjO/zLjBymlYBy/53qxe7yjEFSvzKLDToJjURUhSl2Fzhkl4SMXQoETauF74cw== +"@typescript-eslint/visitor-keys@5.36.2": + version "5.36.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.36.2.tgz#2f8f78da0a3bad3320d2ac24965791ac39dace5a" + integrity sha512-BtRvSR6dEdrNt7Net2/XDjbYKU5Ml6GqJgVfXT0CxTCJlnIqK7rAGreuWKMT2t8cFUT2Msv5oxw0GMRD7T5J7A== dependencies: - "@typescript-eslint/types" "5.30.0" + "@typescript-eslint/types" "5.36.2" eslint-visitor-keys "^3.3.0" abab@^2.0.3, abab@^2.0.5: @@ -2241,9 +2262,9 @@ camelcase@^5.3.1: integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg== caniuse-lite@^1.0.30001286, caniuse-lite@^1.0.30001304: - version "1.0.30001341" - resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001341.tgz" - integrity sha512-2SodVrFFtvGENGCv0ChVJIDQ0KPaS1cg7/qtfMaICgeMolDdo/Z2OD32F0Aq9yl6F4YFwGPBS5AaPqNYiW4PoA== + version "1.0.30001429" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001429.tgz" + integrity sha512-511ThLu1hF+5RRRt0zYCf2U2yRr9GPF6m5y90SBCWsvSoYoW7yAGlv/elyPaNfvGCkp6kj/KFZWU0BMA69Prsg== ccount@^1.0.0: version "1.1.0" @@ -3768,7 +3789,7 @@ iconv-lite@0.4.24: dependencies: safer-buffer ">= 2.1.2 < 3" -ignore@5.2.0, ignore@^5.1.8, ignore@^5.2.0: +ignore@5.2.0, ignore@^5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a" integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ== @@ -6483,10 +6504,10 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" -typescript@4.7.2: - version "4.7.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.2.tgz#1f9aa2ceb9af87cca227813b4310fff0b51593c4" - integrity sha512-Mamb1iX2FDUpcTRzltPxgWMKy3fhg0TN378ylbktPGPK/99KbDtMQ4W1hwgsbPAsG3a0xKa1vmw4VKZQbkvz5A== +typescript@4.8.2: + version "4.8.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.2.tgz#e3b33d5ccfb5914e4eeab6699cf208adee3fd790" + integrity sha512-C0I1UsrrDHo2fYI5oaCGbSejwX4ch+9Y5jTQELvovfmFkK3HHSZJB8MSJcWLmCUBzQBchCrZ9rMRV6GuNrvGtw== unbox-primitive@^1.0.1: version "1.0.1" From ae4d85ab3c8172f9fa866fbbca8d7b8b05e3ee73 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Fri, 4 Nov 2022 11:14:12 +0800 Subject: [PATCH 025/136] Update description of `vueIndentScriptAndStyle` option (#13781) --- docs/options.md | 2 +- website/versioned_docs/version-stable/options.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/options.md b/docs/options.md index 60ce3d3acc2a..0e26e7d9e681 100644 --- a/docs/options.md +++ b/docs/options.md @@ -385,7 +385,7 @@ Valid options: _First available in v1.19.0_ -Whether or not to indent the code inside ` - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + +