From 80c3ec14ee8e9b2822b55ff33b5bf48aa04372f9 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Thu, 8 Dec 2022 02:29:08 +0900 Subject: [PATCH 01/42] Update dependents count --- website/pages/en/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/pages/en/index.js b/website/pages/en/index.js index d8f903fae7dd..e0d2361ebac4 100755 --- a/website/pages/en/index.js +++ b/website/pages/en/index.js @@ -320,7 +320,7 @@ const UsersSection = ({ language }) => {

More than{" "} - 5 million{" "} + 5.1 million{" "} dependent repositories on GitHub

; +// This chain of ConditionalExpressions prints in JSX mode because the parent of +// the outermost ConditionalExpression is a JSXExpressionContainer. It is +// breaking. +
+ {thisIsASongAboutYourPoorSickPenguinHeHasAFeverAndHisToesAreBlueButIfISingToYourPoorSickPenguinHeWillFeelBetterInADayOrTwo ? "a" : b ? "b" : "c"} +
; + // This chain of ConditionalExpressions prints in JSX mode because there is a // JSX element somewhere in the chain. It is non-breaking. cable ? "satellite" : isPublic ? "affairs" : network ? : "dun"; @@ -1243,6 +1250,17 @@ jsxModeFromElementBreaking ? ( // non-breaking.
{a ? "a" : b ? "b" : "c"}
; +// This chain of ConditionalExpressions prints in JSX mode because the parent of +// the outermost ConditionalExpression is a JSXExpressionContainer. It is +// breaking. +
+ {thisIsASongAboutYourPoorSickPenguinHeHasAFeverAndHisToesAreBlueButIfISingToYourPoorSickPenguinHeWillFeelBetterInADayOrTwo + ? "a" + : b + ? "b" + : "c"} +
; + // This chain of ConditionalExpressions prints in JSX mode because there is a // JSX element somewhere in the chain. It is non-breaking. cable ? "satellite" : isPublic ? "affairs" : network ? : "dun"; @@ -1401,6 +1419,13 @@ jsxModeFromElementBreaking ? ( {a ? "a" : b ? "b" : "c"} ; +// This chain of ConditionalExpressions prints in JSX mode because the parent of +// the outermost ConditionalExpression is a JSXExpressionContainer. It is +// breaking. +
+ {thisIsASongAboutYourPoorSickPenguinHeHasAFeverAndHisToesAreBlueButIfISingToYourPoorSickPenguinHeWillFeelBetterInADayOrTwo ? "a" : b ? "b" : "c"} +
; + // This chain of ConditionalExpressions prints in JSX mode because there is a // JSX element somewhere in the chain. It is non-breaking. cable ? "satellite" : isPublic ? "affairs" : network ? : "dun"; @@ -1542,6 +1567,17 @@ jsxModeFromElementBreaking ? ( // non-breaking.
{a ? "a" : b ? "b" : "c"}
; +// This chain of ConditionalExpressions prints in JSX mode because the parent of +// the outermost ConditionalExpression is a JSXExpressionContainer. It is +// breaking. +
+ {thisIsASongAboutYourPoorSickPenguinHeHasAFeverAndHisToesAreBlueButIfISingToYourPoorSickPenguinHeWillFeelBetterInADayOrTwo + ? "a" + : b + ? "b" + : "c"} +
; + // This chain of ConditionalExpressions prints in JSX mode because there is a // JSX element somewhere in the chain. It is non-breaking. cable ? "satellite" : isPublic ? "affairs" : network ? : "dun"; @@ -1700,6 +1736,13 @@ jsxModeFromElementBreaking ? ( {a ? "a" : b ? "b" : "c"} ; +// This chain of ConditionalExpressions prints in JSX mode because the parent of +// the outermost ConditionalExpression is a JSXExpressionContainer. It is +// breaking. +
+ {thisIsASongAboutYourPoorSickPenguinHeHasAFeverAndHisToesAreBlueButIfISingToYourPoorSickPenguinHeWillFeelBetterInADayOrTwo ? "a" : b ? "b" : "c"} +
; + // This chain of ConditionalExpressions prints in JSX mode because there is a // JSX element somewhere in the chain. It is non-breaking. cable ? "satellite" : isPublic ? "affairs" : network ? : "dun"; @@ -1841,6 +1884,17 @@ jsxModeFromElementBreaking ? ( // non-breaking.
{a ? 'a' : b ? 'b' : 'c'}
; +// This chain of ConditionalExpressions prints in JSX mode because the parent of +// the outermost ConditionalExpression is a JSXExpressionContainer. It is +// breaking. +
+ {thisIsASongAboutYourPoorSickPenguinHeHasAFeverAndHisToesAreBlueButIfISingToYourPoorSickPenguinHeWillFeelBetterInADayOrTwo + ? 'a' + : b + ? 'b' + : 'c'} +
; + // This chain of ConditionalExpressions prints in JSX mode because there is a // JSX element somewhere in the chain. It is non-breaking. cable ? 'satellite' : isPublic ? 'affairs' : network ? : 'dun'; @@ -1999,6 +2053,13 @@ jsxModeFromElementBreaking ? ( {a ? "a" : b ? "b" : "c"} ; +// This chain of ConditionalExpressions prints in JSX mode because the parent of +// the outermost ConditionalExpression is a JSXExpressionContainer. It is +// breaking. +
+ {thisIsASongAboutYourPoorSickPenguinHeHasAFeverAndHisToesAreBlueButIfISingToYourPoorSickPenguinHeWillFeelBetterInADayOrTwo ? "a" : b ? "b" : "c"} +
; + // This chain of ConditionalExpressions prints in JSX mode because there is a // JSX element somewhere in the chain. It is non-breaking. cable ? "satellite" : isPublic ? "affairs" : network ? : "dun"; @@ -2140,6 +2201,17 @@ jsxModeFromElementBreaking ? ( // non-breaking.
{a ? 'a' : b ? 'b' : 'c'}
; +// This chain of ConditionalExpressions prints in JSX mode because the parent of +// the outermost ConditionalExpression is a JSXExpressionContainer. It is +// breaking. +
+ {thisIsASongAboutYourPoorSickPenguinHeHasAFeverAndHisToesAreBlueButIfISingToYourPoorSickPenguinHeWillFeelBetterInADayOrTwo + ? 'a' + : b + ? 'b' + : 'c'} +
; + // This chain of ConditionalExpressions prints in JSX mode because there is a // JSX element somewhere in the chain. It is non-breaking. cable ? 'satellite' : isPublic ? 'affairs' : network ? : 'dun'; diff --git a/tests/format/jsx/jsx/conditional-expression.js b/tests/format/jsx/jsx/conditional-expression.js index 3283d9c6a941..703ce4d95535 100644 --- a/tests/format/jsx/jsx/conditional-expression.js +++ b/tests/format/jsx/jsx/conditional-expression.js @@ -84,6 +84,13 @@ jsxModeFromElementBreaking ? ( {a ? "a" : b ? "b" : "c"} ; +// This chain of ConditionalExpressions prints in JSX mode because the parent of +// the outermost ConditionalExpression is a JSXExpressionContainer. It is +// breaking. +
+ {thisIsASongAboutYourPoorSickPenguinHeHasAFeverAndHisToesAreBlueButIfISingToYourPoorSickPenguinHeWillFeelBetterInADayOrTwo ? "a" : b ? "b" : "c"} +
; + // This chain of ConditionalExpressions prints in JSX mode because there is a // JSX element somewhere in the chain. It is non-breaking. cable ? "satellite" : isPublic ? "affairs" : network ? : "dun"; 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 7231c3da425e..e598947c2b6a 100644 --- a/tests/format/typescript/conditional-types/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/conditional-types/__snapshots__/jsfmt.spec.js.snap @@ -347,3 +347,87 @@ type Foo3 = ( ================================================================================ `; + +exports[`new-ternary-spec.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +// TypeScript has the same behavior, including a line break after =, but no parens around "conditional": +type KnownKeys = + { + [K in keyof T]: string extends K ? never + : number extends K ? never + : K; + } extends { [_ in keyof T]: infer U } ? + {} extends U ? never + : U + : never; + +type KnownKeysWithLongExtends = + { + [K in keyof T]: string extends K ? never + : number extends K ? never + : K; + } extends { + [_ in keyof T]: SomeReallyLongThingThatBreaksTheLine + } ? U + : never; + +// TypeScript examples: +type TypeName = + T extends string ? "string" + : T extends number ? "number" + : T extends boolean ? "boolean" + : T extends undefined ? "undefined" + : T extends Function ? "function" + : "object"; + +type Unpacked = + T extends (infer U)[] ? U + : T extends (...args: any[]) => infer U ? + SomeReallyLongThingThatBreaksTheLine + : T extends Promise ? U + : T; +=====================================output===================================== +// TypeScript has the same behavior, including a line break after =, but no parens around "conditional": +type KnownKeys = { + [K in keyof T]: string extends K ? never : number extends K ? never : K; +} extends { [_ in keyof T]: infer U } + ? {} extends U + ? never + : U + : never; + +type KnownKeysWithLongExtends = { + [K in keyof T]: string extends K ? never : number extends K ? never : K; +} extends { + [_ in keyof T]: SomeReallyLongThingThatBreaksTheLine; +} + ? U + : never; + +// TypeScript examples: +type TypeName = T extends string + ? "string" + : T extends number + ? "number" + : T extends boolean + ? "boolean" + : T extends undefined + ? "undefined" + : T extends Function + ? "function" + : "object"; + +type Unpacked = T extends (infer U)[] + ? U + : T extends (...args: any[]) => infer U + ? SomeReallyLongThingThatBreaksTheLine + : T extends Promise + ? U + : T; + +================================================================================ +`; diff --git a/tests/format/typescript/conditional-types/new-ternary-spec.ts b/tests/format/typescript/conditional-types/new-ternary-spec.ts new file mode 100644 index 000000000000..972d3e9352b4 --- /dev/null +++ b/tests/format/typescript/conditional-types/new-ternary-spec.ts @@ -0,0 +1,36 @@ +// TypeScript has the same behavior, including a line break after =, but no parens around "conditional": +type KnownKeys = + { + [K in keyof T]: string extends K ? never + : number extends K ? never + : K; + } extends { [_ in keyof T]: infer U } ? + {} extends U ? never + : U + : never; + +type KnownKeysWithLongExtends = + { + [K in keyof T]: string extends K ? never + : number extends K ? never + : K; + } extends { + [_ in keyof T]: SomeReallyLongThingThatBreaksTheLine + } ? U + : never; + +// TypeScript examples: +type TypeName = + T extends string ? "string" + : T extends number ? "number" + : T extends boolean ? "boolean" + : T extends undefined ? "undefined" + : T extends Function ? "function" + : "object"; + +type Unpacked = + T extends (infer U)[] ? U + : T extends (...args: any[]) => infer U ? + SomeReallyLongThingThatBreaksTheLine + : T extends Promise ? U + : T; \ No newline at end of file From 521de3bf4d585b5bff731c3de3e606862e037407 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Mon, 12 Dec 2022 17:26:29 +0800 Subject: [PATCH 07/42] Don't run scheduled workflows in forks (#13981) --- .github/workflows/bundler-friendly.yml | 2 ++ .github/workflows/dev-package-test.yml | 1 + .github/workflows/lock.yml | 1 + .github/workflows/no-response.yml | 5 +++-- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bundler-friendly.yml b/.github/workflows/bundler-friendly.yml index c7d98ac40bf4..b9bd035a85d6 100644 --- a/.github/workflows/bundler-friendly.yml +++ b/.github/workflows/bundler-friendly.yml @@ -12,6 +12,7 @@ on: jobs: build: + if: github.event_name != 'schedule' || github.repository == 'prettier/prettier' name: Build runs-on: ubuntu-latest steps: @@ -36,6 +37,7 @@ jobs: path: dist webpack: + if: github.event_name != 'schedule' || github.repository == 'prettier/prettier' name: Bundle Prettier with webpack runs-on: ubuntu-latest needs: [build] diff --git a/.github/workflows/dev-package-test.yml b/.github/workflows/dev-package-test.yml index cf44ac4fdc39..6bfe936af3db 100644 --- a/.github/workflows/dev-package-test.yml +++ b/.github/workflows/dev-package-test.yml @@ -14,6 +14,7 @@ on: jobs: test: + if: github.event_name != 'schedule' || github.repository == 'prettier/prettier' timeout-minutes: 60 strategy: fail-fast: false diff --git a/.github/workflows/lock.yml b/.github/workflows/lock.yml index 68524e76ef1b..7c37a1a5a757 100644 --- a/.github/workflows/lock.yml +++ b/.github/workflows/lock.yml @@ -7,6 +7,7 @@ on: jobs: lock: + if: github.event_name != 'schedule' || github.repository == 'prettier/prettier' runs-on: ubuntu-latest steps: - uses: dessant/lock-threads@v3 diff --git a/.github/workflows/no-response.yml b/.github/workflows/no-response.yml index 5981ff4b70ef..e2ce85eaccdd 100644 --- a/.github/workflows/no-response.yml +++ b/.github/workflows/no-response.yml @@ -7,14 +7,15 @@ on: types: - created schedule: - # “At minute 0.” https://crontab.guru/#0_*_*_*_* - - cron: "0 * * * *" + # “At 00:00.” https://crontab.guru/#0_0_*_*_* + - cron: "0 0 * * *" permissions: issues: write jobs: no-response: + if: github.event_name != 'schedule' || github.repository == 'prettier/prettier' runs-on: ubuntu-latest steps: - uses: lee-dohm/no-response@v0.5.0 From df1f6ad1acd55600f0d711e42026f5ab3766e8a7 Mon Sep 17 00:00:00 2001 From: David De Sloovere Date: Thu, 15 Dec 2022 07:50:24 +0100 Subject: [PATCH 08/42] Update Husky.Net info (#13883) Co-authored-by: fisker Cheung --- docs/precommit.md | 3 ++- website/versioned_docs/version-stable/precommit.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/precommit.md b/docs/precommit.md index bacd0d28687f..b093dad18701 100644 --- a/docs/precommit.md +++ b/docs/precommit.md @@ -66,9 +66,10 @@ Read more at [mirror of prettier package for pre-commit](https://github.com/pre- **Use Case:** A dotnet solution to use Prettier along with other code quality tools (e.g. dotnet-format, ESLint, Stylelint, etc.). It supports multiple file states (staged - last-commit, git-files etc.) ```bash +dotnet new tool-manifest dotnet tool install husky dotnet husky install -dotnet husky add .husky/pre-commit +dotnet husky add pre-commit ``` after installation you can add prettier task to the `task-runner.json`. diff --git a/website/versioned_docs/version-stable/precommit.md b/website/versioned_docs/version-stable/precommit.md index 06ca39090849..ef04f80c0b2f 100644 --- a/website/versioned_docs/version-stable/precommit.md +++ b/website/versioned_docs/version-stable/precommit.md @@ -67,9 +67,10 @@ Read more at [mirror of prettier package for pre-commit](https://github.com/pre- **Use Case:** A dotnet solution to use Prettier along with other code quality tools (e.g. dotnet-format, ESLint, Stylelint, etc.). It supports multiple file states (staged - last-commit, git-files etc.) ```bash +dotnet new tool-manifest dotnet tool install husky dotnet husky install -dotnet husky add .husky/pre-commit +dotnet husky add pre-commit ``` after installation you can add prettier task to the `task-runner.json`. From 40d0f27055092ff189b4044dabcf720617118936 Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Thu, 15 Dec 2022 01:50:51 -0500 Subject: [PATCH 09/42] [handlebars] allow custom "else if"-like with block params (#13930) --- changelog_unreleased/handlebars/13930.md | 42 ++++++++++++++++ src/language-handlebars/printer-glimmer.js | 24 +++++++--- .../__snapshots__/jsfmt.spec.js.snap | 48 +++++++++++++++++++ .../block-statement/custom-else.hbs | 20 ++++++++ 4 files changed, 128 insertions(+), 6 deletions(-) create mode 100644 changelog_unreleased/handlebars/13930.md diff --git a/changelog_unreleased/handlebars/13930.md b/changelog_unreleased/handlebars/13930.md new file mode 100644 index 000000000000..6e824a32e02c --- /dev/null +++ b/changelog_unreleased/handlebars/13930.md @@ -0,0 +1,42 @@ +#### Allow custom "else if"-like blocks with block params (#13930 by @jamescdavis) + +#13507 added support for custom block keywords used with `else`, but failed to allow block params. This updates printer-glimmer to allow block params with custom "else if"-like blocks. + + +```hbs +{{! Input }} +{#when isAtWork as |work|}} + Ship that + {{work}}! +{{else when isReading as |book|}} + You can finish + {{book}} + eventually... +{{else}} + Go to bed! +{{/when}} + +{{! Prettier stable }} +{{#when isAtWork as |work|}} + Ship that + {{work}}! +{{else when isReading}} + You can finish + {{book}} + eventually... +{{else}} + Go to bed! +{{/when}} + +{{! Prettier main }} +{#when isAtWork as |work|}} + Ship that + {{work}}! +{{else when isReading as |book|}} + You can finish + {{book}} + eventually... +{{else}} + Go to bed! +{{/when}} +``` diff --git a/src/language-handlebars/printer-glimmer.js b/src/language-handlebars/printer-glimmer.js index 12c6b52d6965..19249ff52a9a 100644 --- a/src/language-handlebars/printer-glimmer.js +++ b/src/language-handlebars/printer-glimmer.js @@ -563,16 +563,28 @@ function printElseBlock(node, options) { } function printElseIfLikeBlock(path, print, ifLikeKeyword) { + const node = path.getValue(); + let blockParams = []; + + if (isNonEmptyArray(node.program.blockParams)) { + blockParams = [line, printBlockParams(node.program)]; + } + const parentNode = path.getParentNode(1); - return [ + return group([ printInverseBlockOpeningMustache(parentNode), - "else ", - ifLikeKeyword, - " ", - printParams(path, print), + indent( + group([ + group(["else", line, ifLikeKeyword]), + line, + printParams(path, print), + ]) + ), + indent(blockParams), + softline, printInverseBlockClosingMustache(parentNode), - ]; + ]); } function printCloseBlock(path, print, options) { 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 c9e5f615504f..8894daaed253 100644 --- a/tests/format/handlebars/block-statement/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/handlebars/block-statement/__snapshots__/jsfmt.spec.js.snap @@ -274,6 +274,26 @@ printWidth: 80 Another thing {{~/when~}} +{{#when a as |b|}} + {{b}} +{{else when c as |d|}} + {{d}} +{{else when e as |f|}} + {{f}} +{{else when g as |h|}} + {{h}} +{{else}} + j +{{/when}} + +{{#when abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst as |b|}} + {{b}} +{{else when abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnop as |d|}} + {{d}} +{{else when abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz as |f|}} + {{f}} +{{/when}} + =====================================output=====================================

{{#when isAtWork}} @@ -381,6 +401,34 @@ printWidth: 80 {{~else when anotherCondition~}} Another thing {{~/when~}} + +{{#when a as |b|}} + {{b}} +{{else when c as |d|}} + {{d}} +{{else when e as |f|}} + {{f}} +{{else when g as |h|}} + {{h}} +{{else}} + j +{{/when}} + +{{#when + abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst + as |b| +}} + {{b}} +{{else when abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnop + as |d| +}} + {{d}} +{{else when + abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz + as |f| +}} + {{f}} +{{/when}} ================================================================================ `; diff --git a/tests/format/handlebars/block-statement/custom-else.hbs b/tests/format/handlebars/block-statement/custom-else.hbs index 156d61268cb0..72580285e949 100644 --- a/tests/format/handlebars/block-statement/custom-else.hbs +++ b/tests/format/handlebars/block-statement/custom-else.hbs @@ -106,3 +106,23 @@ {{~else when anotherCondition~}} Another thing {{~/when~}} + +{{#when a as |b|}} + {{b}} +{{else when c as |d|}} + {{d}} +{{else when e as |f|}} + {{f}} +{{else when g as |h|}} + {{h}} +{{else}} + j +{{/when}} + +{{#when abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst as |b|}} + {{b}} +{{else when abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnop as |d|}} + {{d}} +{{else when abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz as |f|}} + {{f}} +{{/when}} From 44db370ca612564e272a2a33e41863055c26c0e9 Mon Sep 17 00:00:00 2001 From: Derek Lewis Date: Thu, 15 Dec 2022 01:51:19 -0500 Subject: [PATCH 10/42] Don't lowercase Markdown link definition labels (#13155) Co-authored-by: fisker Cheung --- changelog_unreleased/markdown/13155.md | 20 +++ package.json | 1 + src/language-markdown/clean.js | 12 +- src/language-markdown/printer-markdown.js | 27 +++-- .../__snapshots__/jsfmt.spec.js.snap | 114 ++++++++++++++++++ .../case-and-space/case-and-space.md | 19 +++ .../case-and-space/issue-3835.md | 1 + .../case-and-space/issue-7118.md | 18 +++ .../case-and-space/jsfmt.spec.js | 1 + .../spec/__snapshots__/jsfmt.spec.js.snap | 22 ++-- yarn.lock | 2 +- 11 files changed, 211 insertions(+), 26 deletions(-) create mode 100644 changelog_unreleased/markdown/13155.md create mode 100644 tests/format/markdown/linkReference/case-and-space/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/markdown/linkReference/case-and-space/case-and-space.md create mode 100644 tests/format/markdown/linkReference/case-and-space/issue-3835.md create mode 100644 tests/format/markdown/linkReference/case-and-space/issue-7118.md create mode 100644 tests/format/markdown/linkReference/case-and-space/jsfmt.spec.js diff --git a/changelog_unreleased/markdown/13155.md b/changelog_unreleased/markdown/13155.md new file mode 100644 index 000000000000..ca3b25123442 --- /dev/null +++ b/changelog_unreleased/markdown/13155.md @@ -0,0 +1,20 @@ +#### Don't lowercase link references (#13155 by @DerekNonGeneric & @fisker) + + +```markdown + +We now don't strictly follow the release notes format suggested by [Keep a Changelog]. + +[Keep a Changelog]: https://example.com/ + + +We now don't strictly follow the release notes format suggested by [Keep a Changelog]. + +[keep a changelog]: https://example.com/ + + + + +``` diff --git a/package.json b/package.json index c81c9e64a72e..d87d6b49792f 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "chalk": "5.0.1", "ci-info": "3.3.0", "cjk-regex": "2.0.1", + "collapse-white-space": "1.0.6", "cosmiconfig": "7.0.1", "css-units-list": "1.1.0", "dashify": "2.0.0", diff --git a/src/language-markdown/clean.js b/src/language-markdown/clean.js index 60c3c7caac3a..29eac8a2ba6a 100644 --- a/src/language-markdown/clean.js +++ b/src/language-markdown/clean.js @@ -1,5 +1,6 @@ "use strict"; +const collapseWhiteSpace = require("collapse-white-space"); const { isFrontMatterNode } = require("../common/util.js"); const { startWithPragma } = require("./pragma.js"); @@ -42,11 +43,12 @@ function clean(ast, newObj, parent) { newObj.value = ast.value.trim().replace(/[\t\n]+/g, " "); } - if (ast.type === "definition" || ast.type === "linkReference") { - newObj.label = ast.label - .trim() - .replace(/[\t\n ]+/g, " ") - .toLowerCase(); + if ( + ast.type === "definition" || + ast.type === "linkReference" || + ast.type === "imageReference" + ) { + newObj.label = collapseWhiteSpace(ast.label); } if ( diff --git a/src/language-markdown/printer-markdown.js b/src/language-markdown/printer-markdown.js index 6bc1918d9055..f1c6613689b2 100644 --- a/src/language-markdown/printer-markdown.js +++ b/src/language-markdown/printer-markdown.js @@ -1,5 +1,6 @@ "use strict"; +const collapseWhiteSpace = require("collapse-white-space"); const { getLast, getMinNotPresentContinuousCount, @@ -352,7 +353,7 @@ function genericPrint(path, options, print) { printChildren(path, options, print), "]", node.referenceType === "full" - ? ["[", node.identifier, "]"] + ? printLinkReference(node) : node.referenceType === "collapsed" ? "[]" : "", @@ -360,7 +361,7 @@ function genericPrint(path, options, print) { case "imageReference": switch (node.referenceType) { case "full": - return ["![", node.alt || "", "][", node.identifier, "]"]; + return ["![", node.alt || "", "]", printLinkReference(node)]; default: return [ "![", @@ -372,9 +373,8 @@ function genericPrint(path, options, print) { case "definition": { const lineOrSpace = options.proseWrap === "always" ? line : " "; return group([ - "[", - node.identifier, - "]:", + printLinkReference(node), + ":", indent([ lineOrSpace, printUrl(node.url), @@ -390,7 +390,7 @@ function genericPrint(path, options, print) { case "footnote": return ["[^", printChildren(path, options, print), "]"]; case "footnoteReference": - return ["[^", node.identifier, "]"]; + return printFootnoteReference(node); case "footnoteDefinition": { const nextNode = path.getParentNode().children[path.getName() + 1]; const shouldInlineFootnote = @@ -401,9 +401,8 @@ function genericPrint(path, options, print) { node.children[0].position.start.line === node.children[0].position.end.line)); return [ - "[^", - node.identifier, - "]: ", + printFootnoteReference(node), + ": ", shouldInlineFootnote ? printChildren(path, options, print) : group([ @@ -928,6 +927,16 @@ function hasPrettierIgnore(path) { return isPrettierIgnore(prevNode) === "next"; } +// `remark-parse` lowercase the `label` as `identifier`, we don't want do that +// https://github.com/remarkjs/remark/blob/daddcb463af2d5b2115496c395d0571c0ff87d15/packages/remark-parse/lib/tokenize/reference.js +function printLinkReference(node) { + return `[${collapseWhiteSpace(node.label)}]`; +} + +function printFootnoteReference(node) { + return `[^${node.label}]`; +} + module.exports = { preprocess, print: genericPrint, diff --git a/tests/format/markdown/linkReference/case-and-space/__snapshots__/jsfmt.spec.js.snap b/tests/format/markdown/linkReference/case-and-space/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..2a9d689f2704 --- /dev/null +++ b/tests/format/markdown/linkReference/case-and-space/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,114 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`case-and-space.md format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 + | printWidth +=====================================input====================================== +# \`linkReference\` + +[ See \`AsyncGeneratorFunction\` ][ See \`AsyncGeneratorFunction\` ] + +# \`imageReference\` + +![ See \`AsyncGeneratorFunction\` ][ See \`AsyncGeneratorFunction\` ] + +# \`definition\` + +[ See \`AsyncGeneratorFunction\` ]: ./index.html + +# \`footnoteReference\` + +[^See\`AsyncGeneratorFunction\`] + +# \`footnoteDefinition\` + +[^See\`AsyncGeneratorFunction\`]: ./index.html + +=====================================output===================================== +# \`linkReference\` + +[ See \`AsyncGeneratorFunction\` ][ See \`AsyncGeneratorFunction\` ] + +# \`imageReference\` + +![ See \`AsyncGeneratorFunction\` ][ See \`AsyncGeneratorFunction\` ] + +# \`definition\` + +[ See \`AsyncGeneratorFunction\` ]: ./index.html + +# \`footnoteReference\` + +[^See\`AsyncGeneratorFunction\`] + +# \`footnoteDefinition\` + +[^See\`AsyncGeneratorFunction\`]: ./index.html + +================================================================================ +`; + +exports[`issue-3835.md format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 + | printWidth +=====================================input====================================== +[1][Test Text](http://example.com) + +=====================================output===================================== +[1][Test Text](http://example.com) + +================================================================================ +`; + +exports[`issue-7118.md format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 + | printWidth +=====================================input====================================== +- see[Link to Foo][master-LinkToFoo] + +[master-LinkToFoo]: http://foo.com + +Bla bla [PascalCase][] bla. + +[PascalCase]: ./PascalCase.md + +## [Unreleased] +… +[Unreleased]: https://github.com/username/project/compare/v1.0.0...HEAD + +[darktable]: https://www.darktable.org/ +[js;dr]: https://indieweb.org/js;dr +[LinuxFest Northwest]: https://www.linuxfestnorthwest.org/ +[OpenStreetMap]: https://www.openstreetmap.org/about +[SeaGL]: https://seagl.org/ +[uBlock Origin]: https://github.com/gorhill/uBlock + +=====================================output===================================== +- see[Link to Foo][master-LinkToFoo] + +[master-LinkToFoo]: http://foo.com + +Bla bla [PascalCase][] bla. + +[PascalCase]: ./PascalCase.md + +## [Unreleased] + +… +[Unreleased]: https://github.com/username/project/compare/v1.0.0...HEAD + +[darktable]: https://www.darktable.org/ +[js;dr]: https://indieweb.org/js;dr +[LinuxFest Northwest]: https://www.linuxfestnorthwest.org/ +[OpenStreetMap]: https://www.openstreetmap.org/about +[SeaGL]: https://seagl.org/ +[uBlock Origin]: https://github.com/gorhill/uBlock + +================================================================================ +`; diff --git a/tests/format/markdown/linkReference/case-and-space/case-and-space.md b/tests/format/markdown/linkReference/case-and-space/case-and-space.md new file mode 100644 index 000000000000..f849494fd66c --- /dev/null +++ b/tests/format/markdown/linkReference/case-and-space/case-and-space.md @@ -0,0 +1,19 @@ +# `linkReference` + +[ See `AsyncGeneratorFunction` ][ See `AsyncGeneratorFunction` ] + +# `imageReference` + +![ See `AsyncGeneratorFunction` ][ See `AsyncGeneratorFunction` ] + +# `definition` + +[ See `AsyncGeneratorFunction` ]: ./index.html + +# `footnoteReference` + +[^See`AsyncGeneratorFunction`] + +# `footnoteDefinition` + +[^See`AsyncGeneratorFunction`]: ./index.html diff --git a/tests/format/markdown/linkReference/case-and-space/issue-3835.md b/tests/format/markdown/linkReference/case-and-space/issue-3835.md new file mode 100644 index 000000000000..b8d5aa7e4c01 --- /dev/null +++ b/tests/format/markdown/linkReference/case-and-space/issue-3835.md @@ -0,0 +1 @@ +[1][Test Text](http://example.com) diff --git a/tests/format/markdown/linkReference/case-and-space/issue-7118.md b/tests/format/markdown/linkReference/case-and-space/issue-7118.md new file mode 100644 index 000000000000..9507886e22ba --- /dev/null +++ b/tests/format/markdown/linkReference/case-and-space/issue-7118.md @@ -0,0 +1,18 @@ +- see[Link to Foo][master-LinkToFoo] + +[master-LinkToFoo]: http://foo.com + +Bla bla [PascalCase][] bla. + +[PascalCase]: ./PascalCase.md + +## [Unreleased] +… +[Unreleased]: https://github.com/username/project/compare/v1.0.0...HEAD + +[darktable]: https://www.darktable.org/ +[js;dr]: https://indieweb.org/js;dr +[LinuxFest Northwest]: https://www.linuxfestnorthwest.org/ +[OpenStreetMap]: https://www.openstreetmap.org/about +[SeaGL]: https://seagl.org/ +[uBlock Origin]: https://github.com/gorhill/uBlock diff --git a/tests/format/markdown/linkReference/case-and-space/jsfmt.spec.js b/tests/format/markdown/linkReference/case-and-space/jsfmt.spec.js new file mode 100644 index 000000000000..ff3b58b03c88 --- /dev/null +++ b/tests/format/markdown/linkReference/case-and-space/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["markdown"]); diff --git a/tests/format/markdown/spec/__snapshots__/jsfmt.spec.js.snap b/tests/format/markdown/spec/__snapshots__/jsfmt.spec.js.snap index 4be0bcab9465..cb8e1af7eb71 100644 --- a/tests/format/markdown/spec/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/markdown/spec/__snapshots__/jsfmt.spec.js.snap @@ -3074,7 +3074,7 @@ proseWrap: "always" [Foo*bar\\]] =====================================output===================================== -[foo*bar\\]]: my_(url) "title (with parens)" +[Foo*bar\\]]: my_(url) "title (with parens)" [Foo*bar\\]] @@ -3095,7 +3095,7 @@ proseWrap: "always" [Foo bar] =====================================output===================================== -[foo bar]: my%20url "title" +[Foo bar]: my%20url "title" [Foo bar] @@ -3235,7 +3235,7 @@ proseWrap: "always" [Foo] =====================================output===================================== -[foo]: /url +[FOO]: /url [Foo] @@ -3254,7 +3254,7 @@ proseWrap: "always" [αγω] =====================================output===================================== -[αγω]: /φου +[ΑΓΩ]: /φου [αγω] @@ -8889,7 +8889,7 @@ proseWrap: "always" [bar]: /url "title" =====================================output===================================== -[foo][bar] +[foo][BaR] [bar]: /url "title" @@ -8908,9 +8908,9 @@ proseWrap: "always" [ТОЛПОЙ]: /url =====================================output===================================== -[Толпой][толпой] is a Russian word. +[Толпой][Толпой] is a Russian word. -[толпой]: /url +[ТОЛПОЙ]: /url ================================================================================ `; @@ -8928,9 +8928,9 @@ proseWrap: "always" [Baz][Foo bar] =====================================output===================================== -[foo bar]: /url +[Foo bar]: /url -[Baz][foo bar] +[Baz][Foo bar] ================================================================================ `; @@ -9558,7 +9558,7 @@ proseWrap: "always" =====================================output===================================== ![foo *bar*][foobar] -[foobar]: train.jpg "train & tracks" +[FOOBAR]: train.jpg "train & tracks" ================================================================================ `; @@ -9656,7 +9656,7 @@ proseWrap: "always" =====================================output===================================== ![foo][bar] -[bar]: /url +[BAR]: /url ================================================================================ `; diff --git a/yarn.lock b/yarn.lock index 4145f37c0162..172f1f94fa58 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2295,7 +2295,7 @@ co@^4.6.0: resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184" integrity sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ= -collapse-white-space@^1.0.2: +collapse-white-space@1.0.6, collapse-white-space@^1.0.2: version "1.0.6" resolved "https://registry.yarnpkg.com/collapse-white-space/-/collapse-white-space-1.0.6.tgz#e63629c0016665792060dbbeb79c42239d2c5287" integrity sha512-jEovNnrhMuqyCcjfEJA56v0Xq8SkIoPKDyaHahwo3POf4qcSXqMYuwNcOTzp74vTsR9Tn08z4MxWqAhcekogkQ== From d24d74930e0d038984d0861c57aff3c1323d5fb4 Mon Sep 17 00:00:00 2001 From: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com> Date: Thu, 15 Dec 2022 07:52:09 +0100 Subject: [PATCH 11/42] Rewrite sentence (#13686) Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com> Co-authored-by: fisker Cheung --- website/pages/en/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/pages/en/index.js b/website/pages/en/index.js index e0d2361ebac4..0424dfd7148c 100755 --- a/website/pages/en/index.js +++ b/website/pages/en/index.js @@ -96,7 +96,7 @@ const TldrSection = ({ language }) => (

Why?

From b77d912c0c1a5df85e3e9b5b192fc92523e411ee Mon Sep 17 00:00:00 2001 From: Cyrille David Date: Wed, 4 Jan 2023 11:51:39 +0100 Subject: [PATCH 38/42] ember / glimmer: Preserve self-closing tags (#13691) --- changelog_unreleased/handlebars/13691.md | 34 +++++++++++++++++++ src/language-handlebars/utils.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 18 ++++++++++ .../handlebars/element-node/element-node.hbs | 9 +++++ .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 12 +++---- 6 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 changelog_unreleased/handlebars/13691.md diff --git a/changelog_unreleased/handlebars/13691.md b/changelog_unreleased/handlebars/13691.md new file mode 100644 index 000000000000..ab836c2d16dc --- /dev/null +++ b/changelog_unreleased/handlebars/13691.md @@ -0,0 +1,34 @@ +#### Preserve self-closing tags (#13691 by @dcyriller) + + +```hbs +{{! Input }} +
+
+ + + + + + + +{{! Prettier stable }} +
+
+ + + + + + + +{{! Prettier main }} +
+
+ + + + + + +``` diff --git a/src/language-handlebars/utils.js b/src/language-handlebars/utils.js index 07e4c57544f6..aef7f46f813f 100644 --- a/src/language-handlebars/utils.js +++ b/src/language-handlebars/utils.js @@ -41,6 +41,7 @@ const voidTags = new Set(htmlVoidElements); function isVoid(node) { return ( voidTags.has(node.tag) || + node.selfClosing === true || (isGlimmerComponent(node) && node.children.every((node) => isWhitespaceNode(node))) ); diff --git a/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap b/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap index 7d36706bc63a..c1aeb2e785b0 100644 --- a/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap @@ -45,6 +45,15 @@ printWidth: 80 +
+
+ + + + + + + =====================================output=====================================
Hello @@ -91,5 +100,14 @@ printWidth: 80 @prop4={{true}} as |thing| /> + +
+
+ + + + + + ================================================================================ `; diff --git a/tests/format/handlebars/element-node/element-node.hbs b/tests/format/handlebars/element-node/element-node.hbs index 0c12a8da0aad..c4ed2d380765 100644 --- a/tests/format/handlebars/element-node/element-node.hbs +++ b/tests/format/handlebars/element-node/element-node.hbs @@ -36,3 +36,12 @@ + +
+
+ + + + + + diff --git a/tests/format/handlebars/html-whitespace-sensitivity/__snapshots__/jsfmt.spec.js.snap b/tests/format/handlebars/html-whitespace-sensitivity/__snapshots__/jsfmt.spec.js.snap index 33cc64a9404a..73daa2ee6685 100644 --- a/tests/format/handlebars/html-whitespace-sensitivity/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/handlebars/html-whitespace-sensitivity/__snapshots__/jsfmt.spec.js.snap @@ -702,7 +702,7 @@ printWidth: 40 =====================================input======================================   |   =====================================output===================================== -   |   +   |   ================================================================================ `; diff --git a/tests/format/handlebars/single-quote-option/__snapshots__/jsfmt.spec.js.snap b/tests/format/handlebars/single-quote-option/__snapshots__/jsfmt.spec.js.snap index 4229856d7e11..a26517e85ba6 100644 --- a/tests/format/handlebars/single-quote-option/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/handlebars/single-quote-option/__snapshots__/jsfmt.spec.js.snap @@ -99,8 +99,8 @@ singleQuote: false
-
-
+
+
@@ -126,7 +126,7 @@ singleQuote: false class="padding {{if foo (if fooAgain 'bar' (if fooAgainAgain 'bar' 'foo'))}} baz" ->
+/> ================================================================================ `; @@ -161,8 +161,8 @@ singleQuote: true
-
-
+
+
@@ -188,7 +188,7 @@ singleQuote: true class='padding {{if foo (if fooAgain "bar" (if fooAgainAgain "bar" "foo"))}} baz' ->
+/> ================================================================================ `; From 0c5d4f34587817d1da09fc04a03e49fb5c048a76 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Fri, 6 Jan 2023 17:13:41 +0900 Subject: [PATCH 39/42] Fix removing commas from function arguments in maps (#14089) Co-authored-by: fisker Cheung --- changelog_unreleased/scss/14089.md | 22 ++++++++ src/language-css/parser-postcss.js | 17 ------- src/language-css/printer-postcss.js | 29 ++++++----- .../__snapshots__/jsfmt.spec.js.snap | 51 +++++++++++++++++++ .../function-argument-2.scss | 18 +++++++ 5 files changed, 106 insertions(+), 31 deletions(-) create mode 100644 changelog_unreleased/scss/14089.md create mode 100644 tests/format/scss/map/function-argument/function-argument-2.scss diff --git a/changelog_unreleased/scss/14089.md b/changelog_unreleased/scss/14089.md new file mode 100644 index 000000000000..45e6ce2841b1 --- /dev/null +++ b/changelog_unreleased/scss/14089.md @@ -0,0 +1,22 @@ +#### Fix removing commas from function arguments in maps (#14089 by @sosukesuzuki) + + +```scss +/* Input */ +$foo: map-fn( + ( + "#{prop}": inner-fn($first, $second), + ) +); + +/* Prettier stable */ +$foo: map-fn(("#{prop}": inner-fn($first $second))); + +/* Prettier main */ +$foo: map-fn( + ( + "#{prop}": inner-fn($first, $second), + ) +); + +``` diff --git a/src/language-css/parser-postcss.js b/src/language-css/parser-postcss.js index 13b42c4670f2..652f968f9a43 100644 --- a/src/language-css/parser-postcss.js +++ b/src/language-css/parser-postcss.js @@ -122,23 +122,6 @@ function parseValueNode(valueNode, options) { parenGroupStack.pop(); parenGroup = getLast(parenGroupStack); } else if (node.type === "comma") { - if (commaGroup.groups.length > 1) { - for (const group of commaGroup.groups) { - // if css interpolation - if ( - group.value && - typeof group.value === "string" && - group.value.includes("#{") - ) { - commaGroup.groups = [ - stringifyNode({ - groups: commaGroup.groups, - }).trim(), - ]; - break; - } - } - } parenGroup.groups.push(commaGroup); commaGroup = { groups: [], diff --git a/src/language-css/printer-postcss.js b/src/language-css/printer-postcss.js index c847279b3910..44d11d50228f 100644 --- a/src/language-css/printer-postcss.js +++ b/src/language-css/printer-postcss.js @@ -547,6 +547,7 @@ function genericPrint(path, options, print) { let insideSCSSInterpolationInString = false; let didBreak = false; + for (let i = 0; i < node.groups.length; ++i) { parts.push(printed[i]); @@ -594,20 +595,20 @@ function genericPrint(path, options, print) { } // Ignore spaces before/after string interpolation (i.e. `"#{my-fn("_")}"`) - const isStartSCSSInterpolationInString = - iNode.type === "value-string" && iNode.value.startsWith("#{"); - const isEndingSCSSInterpolationInString = - insideSCSSInterpolationInString && - iNextNode.type === "value-string" && - iNextNode.value.endsWith("}"); - - if ( - isStartSCSSInterpolationInString || - isEndingSCSSInterpolationInString - ) { - insideSCSSInterpolationInString = !insideSCSSInterpolationInString; - - continue; + if (iNode.type === "value-string" && iNode.quoted) { + const positionOfOpeningInterpolation = iNode.value.lastIndexOf("#{"); + const positionOfClosingInterpolation = iNode.value.lastIndexOf("}"); + if ( + positionOfOpeningInterpolation !== -1 && + positionOfClosingInterpolation !== -1 + ) { + insideSCSSInterpolationInString = + positionOfOpeningInterpolation > positionOfClosingInterpolation; + } else if (positionOfOpeningInterpolation !== -1) { + insideSCSSInterpolationInString = true; + } else if (positionOfClosingInterpolation !== -1) { + insideSCSSInterpolationInString = false; + } } if (insideSCSSInterpolationInString) { diff --git a/tests/format/scss/map/function-argument/__snapshots__/jsfmt.spec.js.snap b/tests/format/scss/map/function-argument/__snapshots__/jsfmt.spec.js.snap index 0ea75e6bb2b6..e74fed620aa7 100644 --- a/tests/format/scss/map/function-argument/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/scss/map/function-argument/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,56 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`function-argument-2.scss format 1`] = ` +====================================options===================================== +parsers: ["scss"] +printWidth: 80 + | printWidth +=====================================input====================================== +$display-breakpoints: map-deep-merge( + ( + "sm-only": "only screen and (min-width: #{$map-get + $grid-breakpoints + "hogehoge"}) and (max-width: #{$a})", + "sm-only": "inside a long long long long long long long long long long long long long long string #{call("")}", + "sm-only": "inside a long long long long long long long long long long long long long long string #{$foo} and #{call("")}", + "sm-only": "inside a long long long long long long long long long long long long long long string #{call($a)}", + ), + $display-breakpoints +); + +@each $name, $hue in $hues { + $map: map.merge( + $map, + ( + '#{$prefix}-#{$name}': blend.set($base, $hue: $hue), + ) + ); +} + +=====================================output===================================== +$display-breakpoints: map-deep-merge( + ( + "sm-only": "only screen and (min-width: #{$map-get + $grid-breakpoints + "hogehoge"}) and (max-width: #{$a})", + "sm-only": + "inside a long long long long long long long long long long long long long long string #{call("")}", + "sm-only": + "inside a long long long long long long long long long long long long long long string #{$foo} and #{call("")}", + "sm-only": + "inside a long long long long long long long long long long long long long long string #{call($a)}", + ), + $display-breakpoints +); + +@each $name, $hue in $hues { + $map: map.merge( + $map, + ( + "#{$prefix}-#{$name}": blend.set($base, $hue: $hue), + ) + ); +} + +================================================================================ +`; + exports[`functional-argument.scss format 1`] = ` ====================================options===================================== parsers: ["scss"] diff --git a/tests/format/scss/map/function-argument/function-argument-2.scss b/tests/format/scss/map/function-argument/function-argument-2.scss new file mode 100644 index 000000000000..4af8674e8ca9 --- /dev/null +++ b/tests/format/scss/map/function-argument/function-argument-2.scss @@ -0,0 +1,18 @@ +$display-breakpoints: map-deep-merge( + ( + "sm-only": "only screen and (min-width: #{$map-get + $grid-breakpoints + "hogehoge"}) and (max-width: #{$a})", + "sm-only": "inside a long long long long long long long long long long long long long long string #{call("")}", + "sm-only": "inside a long long long long long long long long long long long long long long string #{$foo} and #{call("")}", + "sm-only": "inside a long long long long long long long long long long long long long long string #{call($a)}", + ), + $display-breakpoints +); + +@each $name, $hue in $hues { + $map: map.merge( + $map, + ( + '#{$prefix}-#{$name}': blend.set($base, $hue: $hue), + ) + ); +} From 9e09a78cf50e47535688b3f9ca4f24f440cfe012 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Sat, 7 Jan 2023 16:43:15 +0800 Subject: [PATCH 40/42] Stop inserting space in LESS property access (#14103) --- changelog_unreleased/less/14103.md | 17 ++++++++++++++ src/language-css/clean.js | 21 ++++++++++++++++++ src/language-css/printer-postcss.js | 21 +++++++++++++++++- .../case/__snapshots__/jsfmt.spec.js.snap | 22 ++++++++++++++----- tests/format/less/case/variable.less | 6 +++++ 5 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 changelog_unreleased/less/14103.md diff --git a/changelog_unreleased/less/14103.md b/changelog_unreleased/less/14103.md new file mode 100644 index 000000000000..cddb91e0f786 --- /dev/null +++ b/changelog_unreleased/less/14103.md @@ -0,0 +1,17 @@ +#### Do not insert space in LESS property access (#14103 by @fisker) + + +```less +// Input +a { + color: @colors[@white]; +} + +// Prettier stable +a { + color: @colors[ @white]; +} + +// Prettier main + +``` diff --git a/src/language-css/clean.js b/src/language-css/clean.js index 8dc592570c93..eee08eda6e0e 100644 --- a/src/language-css/clean.js +++ b/src/language-css/clean.js @@ -183,6 +183,27 @@ function clean(ast, newObj, parent) { }); } } + + // We parse `@var[ foo ]` and `@var[foo]` differently + if ( + ast.type === "value-comma_group" && + ast.groups.some( + (node) => + (node.type === "value-atword" && node.value.endsWith("[")) || + (node.type === "value-word" && node.value.startsWith("]")) + ) + ) { + return { + type: "value-atword", + value: ast.groups.map((node) => node.value).join(""), + group: { + open: null, + close: null, + groups: [], + type: "value-paren_group", + }, + }; + } } clean.ignoredProperties = ignoredProperties; diff --git a/src/language-css/printer-postcss.js b/src/language-css/printer-postcss.js index 44d11d50228f..ca5719e93350 100644 --- a/src/language-css/printer-postcss.js +++ b/src/language-css/printer-postcss.js @@ -621,7 +621,26 @@ function genericPrint(path, options, print) { } // Ignore `@` in Less (i.e. `@@var;`) - if (iNode.type === "value-atword" && iNode.value === "") { + if ( + iNode.type === "value-atword" && + (iNode.value === "" || + /* + @var[ @notVarNested ][notVar] + ^^^^^ + */ + iNode.value.endsWith("[")) + ) { + continue; + } + + /* + @var[ @notVarNested ][notVar] + ^^^^^^^^^ + */ + if ( + iNextNode.type === "value-word" && + iNextNode.value.startsWith("]") + ) { continue; } diff --git a/tests/format/less/case/__snapshots__/jsfmt.spec.js.snap b/tests/format/less/case/__snapshots__/jsfmt.spec.js.snap index 9abe3bd1d0b1..f67031abd06b 100644 --- a/tests/format/less/case/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/less/case/__snapshots__/jsfmt.spec.js.snap @@ -389,9 +389,15 @@ printWidth: 80 canChangeCase: @var[@notVarNested][notVar]; canChangeCase: @var[ @notVarNested][notVar]; canChangeCase: @var[@notVarNested ][notVar]; + canChangeCase: @var[ @notVarNested ][notVar]; + canChangeCase: @var[@notVarNested][notVar]; canChangeCase: @var[@notVarNested][ notVar]; canChangeCase: @var[@notVarNested][notVar ]; + canChangeCase: @var[@notVarNested][ notVar ]; canChangeCase: @var[notVar]; + canChangeCase: @var[ notVar]; + canChangeCase: @var[notVar ]; + canChangeCase: @var[ notVar ]; } =====================================output===================================== @@ -453,11 +459,17 @@ printWidth: 80 }; @not-var { - canchangecase: @var[ @notVarNested][notVar]; - canchangecase: @var[ @notVarNested][notVar]; - canchangecase: @var[ @notVarNested ][notVar]; - canchangecase: @var[ @notVarNested][ notVar]; - canchangecase: @var[ @notVarNested][notVar ]; + canchangecase: @var[@notVarNested][notVar]; + canchangecase: @var[@notVarNested][notVar]; + canchangecase: @var[@notVarNested][notVar]; + canchangecase: @var[@notVarNested][notVar]; + canchangecase: @var[@notVarNested][notVar]; + canchangecase: @var[@notVarNested][notVar]; + canchangecase: @var[@notVarNested][notVar]; + canchangecase: @var[@notVarNested][notVar]; + canchangecase: @var[notVar]; + canchangecase: @var[notVar]; + canchangecase: @var[notVar]; canchangecase: @var[notVar]; } diff --git a/tests/format/less/case/variable.less b/tests/format/less/case/variable.less index 29fdd9052f67..599c34754f1e 100644 --- a/tests/format/less/case/variable.less +++ b/tests/format/less/case/variable.less @@ -59,7 +59,13 @@ canChangeCase: @var[@notVarNested][notVar]; canChangeCase: @var[ @notVarNested][notVar]; canChangeCase: @var[@notVarNested ][notVar]; + canChangeCase: @var[ @notVarNested ][notVar]; + canChangeCase: @var[@notVarNested][notVar]; canChangeCase: @var[@notVarNested][ notVar]; canChangeCase: @var[@notVarNested][notVar ]; + canChangeCase: @var[@notVarNested][ notVar ]; canChangeCase: @var[notVar]; + canChangeCase: @var[ notVar]; + canChangeCase: @var[notVar ]; + canChangeCase: @var[ notVar ]; } From aaf919014fbdb3c05590f818428de4dcc6899c9c Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Sat, 7 Jan 2023 16:43:44 +0800 Subject: [PATCH 41/42] Fix comments after directive (#14081) --- changelog_unreleased/javascript/14081.md | 13 + src/language-js/print/literal.js | 14 +- src/language-js/print/misc.js | 19 + src/language-js/printer-estree.js | 28 +- .../comments/__snapshots__/jsfmt.spec.js.snap | 569 ++++++++++++++++++ .../js/directives/comments/jsfmt.spec.js | 55 ++ tests/format/markdown/auto-link/jsfmt.spec.js | 1 + 7 files changed, 672 insertions(+), 27 deletions(-) create mode 100644 changelog_unreleased/javascript/14081.md create mode 100644 tests/format/js/directives/comments/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/js/directives/comments/jsfmt.spec.js diff --git a/changelog_unreleased/javascript/14081.md b/changelog_unreleased/javascript/14081.md new file mode 100644 index 000000000000..92a794cbc73d --- /dev/null +++ b/changelog_unreleased/javascript/14081.md @@ -0,0 +1,13 @@ +#### Fix comments after directive (#14081 by @fisker) + + +```jsx +// Input +"use strict" /* comment */; + +// Prettier stable (with other js parsers except `babel`) +Error: Comment "comment" was not printed. Please report this error! + +// Prettier main + +``` diff --git a/src/language-js/print/literal.js b/src/language-js/print/literal.js index a614bd5f4ba1..252cf4925a50 100644 --- a/src/language-js/print/literal.js +++ b/src/language-js/print/literal.js @@ -1,6 +1,7 @@ "use strict"; const { printString, printNumber } = require("../../common/util.js"); const { replaceTextEndOfLine } = require("../../document/doc-utils.js"); +const { printDirective } = require("./misc.js"); function printLiteral(path, options /*, print*/) { const node = path.getNode(); @@ -41,7 +42,9 @@ function printLiteral(path, options /*, print*/) { } if (typeof value === "string") { - return replaceTextEndOfLine(printString(node.raw, options)); + return isDirective(path) + ? printDirective(node.raw, options) + : replaceTextEndOfLine(printString(node.raw, options)); } return String(value); @@ -49,6 +52,15 @@ function printLiteral(path, options /*, print*/) { } } +function isDirective(path) { + if (path.getName() !== "expression") { + return; + } + + const parent = path.getParentNode(); + return parent.type === "ExpressionStatement" && parent.directive; +} + function printBigInt(raw) { return raw.toLowerCase(); } diff --git a/src/language-js/print/misc.js b/src/language-js/print/misc.js index 3d5a7d0f8194..44ae0ce9c761 100644 --- a/src/language-js/print/misc.js +++ b/src/language-js/print/misc.js @@ -93,6 +93,24 @@ function printRestSpread(path, options, print) { return ["...", print("argument"), printTypeAnnotation(path, options, print)]; } +function printDirective(rawText, options) { + const rawContent = rawText.slice(1, -1); + + // Check for the alternate quote, to determine if we're allowed to swap + // the quotes on a DirectiveLiteral. + if (rawContent.includes('"') || rawContent.includes("'")) { + return rawText; + } + + const enclosingQuote = options.singleQuote ? "'" : '"'; + + // Directives are exact code unit sequences, which means that you can't + // change the escape sequences they use. + // See https://github.com/prettier/prettier/issues/1555 + // and https://tc39.github.io/ecma262/#directive-prologue + return enclosingQuote + rawContent + enclosingQuote; +} + module.exports = { printOptionalToken, printDefiniteToken, @@ -102,4 +120,5 @@ module.exports = { printTypeAnnotation, printRestSpread, adjustClause, + printDirective, }; diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 75e8a71f89c3..6d76502f7926 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -23,7 +23,6 @@ const { isLineComment, isNextLineEmpty, needsHardlineAfterDanglingComment, - rawText, hasIgnoreComment, isCallExpression, isMemberExpression, @@ -47,6 +46,7 @@ const { adjustClause, printRestSpread, printDefiniteToken, + printDirective, } = require("./print/misc.js"); const { printImportDeclaration, @@ -215,11 +215,6 @@ function printPathNoParens(path, options, print, args) { case "EmptyStatement": return ""; case "ExpressionStatement": { - // Detect Flow and TypeScript directives - if (node.directive) { - return [printDirective(node.expression, options), semi]; - } - if ( options.parser === "__vue_event_binding" || options.parser === "__vue_ts_event_binding" @@ -429,7 +424,7 @@ function printPathNoParens(path, options, print, args) { case "Directive": return [print("value"), semi]; // Babel 6 case "DirectiveLiteral": - return printDirective(node, options); + return printDirective(node.extra.raw, options); case "UnaryExpression": parts.push(node.operator); @@ -813,25 +808,6 @@ function printPathNoParens(path, options, print, args) { } } -function printDirective(node, options) { - const raw = rawText(node); - const rawContent = raw.slice(1, -1); - - // Check for the alternate quote, to determine if we're allowed to swap - // the quotes on a DirectiveLiteral. - if (rawContent.includes('"') || rawContent.includes("'")) { - return raw; - } - - const enclosingQuote = options.singleQuote ? "'" : '"'; - - // Directives are exact code unit sequences, which means that you can't - // change the escape sequences they use. - // See https://github.com/prettier/prettier/issues/1555 - // and https://tc39.github.io/ecma262/#directive-prologue - return enclosingQuote + rawContent + enclosingQuote; -} - function canAttachComment(node) { return ( node.type && diff --git a/tests/format/js/directives/comments/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/directives/comments/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..62f891b2ff16 --- /dev/null +++ b/tests/format/js/directives/comments/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,569 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`snippet: #0 - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +/* comment */ 'use strict'; +=====================================output===================================== +/* comment */ "use strict" + +================================================================================ +`; + +exports[`snippet: #0 format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +/* comment */ 'use strict'; +=====================================output===================================== +/* comment */ "use strict"; + +================================================================================ +`; + +exports[`snippet: #1 - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +function foo() { + /* comment */ 'use strict'; +} +=====================================output===================================== +function foo() { + /* comment */ "use strict" +} + +================================================================================ +`; + +exports[`snippet: #1 format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +function foo() { + /* comment */ 'use strict'; +} +=====================================output===================================== +function foo() { + /* comment */ "use strict"; +} + +================================================================================ +`; + +exports[`snippet: #2 - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +'use strict' /* comment */; +=====================================output===================================== +"use strict" /* comment */ + +================================================================================ +`; + +exports[`snippet: #2 format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +'use strict' /* comment */; +=====================================output===================================== +"use strict" /* comment */; + +================================================================================ +`; + +exports[`snippet: #3 - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +function foo() { + 'use strict' /* comment */; +} +=====================================output===================================== +function foo() { + "use strict" /* comment */ +} + +================================================================================ +`; + +exports[`snippet: #3 format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +function foo() { + 'use strict' /* comment */; +} +=====================================output===================================== +function foo() { + "use strict" /* comment */; +} + +================================================================================ +`; + +exports[`snippet: #4 - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +// comment +'use strict'; +=====================================output===================================== +// comment +"use strict" + +================================================================================ +`; + +exports[`snippet: #4 format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +// comment +'use strict'; +=====================================output===================================== +// comment +"use strict"; + +================================================================================ +`; + +exports[`snippet: #5 - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +function foo() { + // comment + 'use strict'; +} +=====================================output===================================== +function foo() { + // comment + "use strict" +} + +================================================================================ +`; + +exports[`snippet: #5 format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +function foo() { + // comment + 'use strict'; +} +=====================================output===================================== +function foo() { + // comment + "use strict"; +} + +================================================================================ +`; + +exports[`snippet: #6 - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +'use strict' // comment +=====================================output===================================== +"use strict" // comment + +================================================================================ +`; + +exports[`snippet: #6 format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +'use strict' // comment +=====================================output===================================== +"use strict"; // comment + +================================================================================ +`; + +exports[`snippet: #7 - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +function foo() { + 'use strict' // comment +} +=====================================output===================================== +function foo() { + "use strict" // comment +} + +================================================================================ +`; + +exports[`snippet: #7 format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +function foo() { + 'use strict' // comment +} +=====================================output===================================== +function foo() { + "use strict"; // comment +} + +================================================================================ +`; + +exports[`snippet: #8 - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +'use strict'; +/* comment */ +(function () {})(); +=====================================output===================================== +"use strict" +/* comment */ +;(function () {})() + +================================================================================ +`; + +exports[`snippet: #8 format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +'use strict'; +/* comment */ +(function () {})(); +=====================================output===================================== +"use strict"; +/* comment */ +(function () {})(); + +================================================================================ +`; + +exports[`snippet: #9 - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +function foo() { + 'use strict'; + /* comment */ + (function () {})(); +} +=====================================output===================================== +function foo() { + "use strict" + /* comment */ + ;(function () {})() +} + +================================================================================ +`; + +exports[`snippet: #9 format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +function foo() { + 'use strict'; + /* comment */ + (function () {})(); +} +=====================================output===================================== +function foo() { + "use strict"; + /* comment */ + (function () {})(); +} + +================================================================================ +`; + +exports[`snippet: #10 - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +/* comment */ +'use strict'; +(function () {})(); +=====================================output===================================== +/* comment */ +"use strict" +;(function () {})() + +================================================================================ +`; + +exports[`snippet: #10 format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +/* comment */ +'use strict'; +(function () {})(); +=====================================output===================================== +/* comment */ +"use strict"; +(function () {})(); + +================================================================================ +`; + +exports[`snippet: #11 - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +function foo() { + /* comment */ + 'use strict'; + (function () {})(); +} +=====================================output===================================== +function foo() { + /* comment */ + "use strict" + ;(function () {})() +} + +================================================================================ +`; + +exports[`snippet: #11 format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +function foo() { + /* comment */ + 'use strict'; + (function () {})(); +} +=====================================output===================================== +function foo() { + /* comment */ + "use strict"; + (function () {})(); +} + +================================================================================ +`; + +exports[`snippet: #12 - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +'use strict'; +// comment +(function () {})(); +=====================================output===================================== +"use strict" +// comment +;(function () {})() + +================================================================================ +`; + +exports[`snippet: #12 format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +'use strict'; +// comment +(function () {})(); +=====================================output===================================== +"use strict"; +// comment +(function () {})(); + +================================================================================ +`; + +exports[`snippet: #13 - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +function foo() { + 'use strict'; + // comment + (function () {})(); +} +=====================================output===================================== +function foo() { + "use strict" + // comment + ;(function () {})() +} + +================================================================================ +`; + +exports[`snippet: #13 format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +function foo() { + 'use strict'; + // comment + (function () {})(); +} +=====================================output===================================== +function foo() { + "use strict"; + // comment + (function () {})(); +} + +================================================================================ +`; + +exports[`snippet: #14 - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +// comment +'use strict'; +(function () {})(); +=====================================output===================================== +// comment +"use strict" +;(function () {})() + +================================================================================ +`; + +exports[`snippet: #14 format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +// comment +'use strict'; +(function () {})(); +=====================================output===================================== +// comment +"use strict"; +(function () {})(); + +================================================================================ +`; + +exports[`snippet: #15 - {"semi":false} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +function foo() { + // comment + 'use strict'; + (function () {})(); +} +=====================================output===================================== +function foo() { + // comment + "use strict" + ;(function () {})() +} + +================================================================================ +`; + +exports[`snippet: #15 format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +function foo() { + // comment + 'use strict'; + (function () {})(); +} +=====================================output===================================== +function foo() { + // comment + "use strict"; + (function () {})(); +} + +================================================================================ +`; diff --git a/tests/format/js/directives/comments/jsfmt.spec.js b/tests/format/js/directives/comments/jsfmt.spec.js new file mode 100644 index 000000000000..e85b3df3ed9b --- /dev/null +++ b/tests/format/js/directives/comments/jsfmt.spec.js @@ -0,0 +1,55 @@ +const { outdent } = require("outdent"); +const indent = (text) => + text + .split("\n") + .map((line) => (line ? ` ${line}` : line)) + .join("\n"); +// TODO: Remove this when we drop support for Node.js v10 +// eslint-disable-next-line unicorn/prefer-spread +const flat = (array) => [].concat(...array); + +const snippets = flat( + [ + "/* comment */ 'use strict';", + "'use strict' /* comment */;", + outdent` + // comment + 'use strict'; + `, + outdent` + 'use strict' // comment + `, + outdent` + 'use strict'; + /* comment */ + (function () {})(); + `, + outdent` + /* comment */ + 'use strict'; + (function () {})(); + `, + outdent` + 'use strict'; + // comment + (function () {})(); + `, + outdent` + // comment + 'use strict'; + (function () {})(); + `, + ].map((code) => [ + code, + outdent` + function foo() { + ${indent(code)} + } + `, + ]) +); + +run_spec({ dirname: __dirname, snippets }, ["babel", "flow", "typescript"]); +run_spec({ dirname: __dirname, snippets }, ["babel", "flow", "typescript"], { + semi: false, +}); diff --git a/tests/format/markdown/auto-link/jsfmt.spec.js b/tests/format/markdown/auto-link/jsfmt.spec.js index 176a31f1886b..8f65afa30464 100644 --- a/tests/format/markdown/auto-link/jsfmt.spec.js +++ b/tests/format/markdown/auto-link/jsfmt.spec.js @@ -3,6 +3,7 @@ * @param {Array>} array * @returns {Array} */ +// TODO: Remove this when we drop support for Node.js v10 // eslint-disable-next-line unicorn/prefer-spread const flat = (array) => [].concat(...array); From ac88438d654be6e2285e1cab8a6aa3d9a84ac875 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sat, 7 Jan 2023 20:15:48 +0900 Subject: [PATCH 42/42] Release 2.8.2 --- .github/ISSUE_TEMPLATE/formatting.md | 2 +- .github/ISSUE_TEMPLATE/integration.md | 2 +- CHANGELOG.md | 461 ++++++++++++++++++ docs/browser.md | 30 +- package.json | 2 +- .../versioned_docs/version-stable/browser.md | 30 +- 6 files changed, 494 insertions(+), 33 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/formatting.md b/.github/ISSUE_TEMPLATE/formatting.md index 4299ace0e232..340fab2a4f0e 100644 --- a/.github/ISSUE_TEMPLATE/formatting.md +++ b/.github/ISSUE_TEMPLATE/formatting.md @@ -26,7 +26,7 @@ Don't fill the form below manually! Let a program create a report for you: --> -**Prettier 2.8.1** +**Prettier 2.8.2** [Playground link](https://prettier.io/playground/#.....) ```sh diff --git a/.github/ISSUE_TEMPLATE/integration.md b/.github/ISSUE_TEMPLATE/integration.md index a7477dbe920d..b397119d2a0a 100644 --- a/.github/ISSUE_TEMPLATE/integration.md +++ b/.github/ISSUE_TEMPLATE/integration.md @@ -20,7 +20,7 @@ BEFORE SUBMITTING AN ISSUE: **Environments:** -- Prettier Version: 2.8.1 +- Prettier Version: 2.8.2 - Running Prettier via: - Runtime: - Operating System: diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b9bd9142fa7..e87fe40b2b10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,464 @@ +# 2.8.2 + +[diff](https://github.com/prettier/prettier/compare/2.8.1...2.8.2) + +#### Don't lowercase link references ([#13155](https://github.com/prettier/prettier/pull/13155) by [@DerekNonGeneric](https://github.com/DerekNonGeneric) & [@fisker](https://github.com/fisker)) + + +```markdown + +We now don't strictly follow the release notes format suggested by [Keep a Changelog]. + +[Keep a Changelog]: https://example.com/ + + +We now don't strictly follow the release notes format suggested by [Keep a Changelog]. + +[keep a changelog]: https://example.com/ + + + + +``` + +#### Preserve self-closing tags ([#13691](https://github.com/prettier/prettier/pull/13691) by [@dcyriller](https://github.com/dcyriller)) + + +```hbs +{{! Input }} +
+
+ + + + + + + +{{! Prettier 2.8.1 }} +
+
+ + + + + + + +{{! Prettier 2.8.2 }} +
+
+ + + + + + +``` + +#### Allow custom "else if"-like blocks with block params ([#13930](https://github.com/prettier/prettier/pull/13930) by [@jamescdavis](https://github.com/jamescdavis)) + +#13507 added support for custom block keywords used with `else`, but failed to allow block params. This updates printer-glimmer to allow block params with custom "else if"-like blocks. + + +```hbs +{{! Input }} +{#when isAtWork as |work|}} + Ship that + {{work}}! +{{else when isReading as |book|}} + You can finish + {{book}} + eventually... +{{else}} + Go to bed! +{{/when}} + +{{! Prettier 2.8.1 }} +{{#when isAtWork as |work|}} + Ship that + {{work}}! +{{else when isReading}} + You can finish + {{book}} + eventually... +{{else}} + Go to bed! +{{/when}} + +{{! Prettier 2.8.2 }} +{#when isAtWork as |work|}} + Ship that + {{work}}! +{{else when isReading as |book|}} + You can finish + {{book}} + eventually... +{{else}} + Go to bed! +{{/when}} +``` + +#### Preserve empty lines between nested SCSS maps ([#13931](https://github.com/prettier/prettier/pull/13931) by [@jneander](https://github.com/jneander)) + + +```scss +/* Input */ +$map: ( + 'one': ( + 'key': 'value', + ), + + 'two': ( + 'key': 'value', + ), +) + +/* Prettier 2.8.1 */ +$map: ( + 'one': ( + 'key': 'value', + ), + 'two': ( + 'key': 'value', + ), +) + +/* Prettier 2.8.2 */ +$map: ( + 'one': ( + 'key': 'value', + ), + + 'two': ( + 'key': 'value', + ), +) +``` + +#### Fix missing parentheses when an expression statement starts with `let[` ([#14000](https://github.com/prettier/prettier/pull/14000), [#14044](https://github.com/prettier/prettier/pull/14044) by [@fisker](https://github.com/fisker), [@thorn0](https://github.com/thorn0)) + + +```jsx +// Input +(let[0] = 2); + +// Prettier 2.8.1 +let[0] = 2; + +// Prettier 2.8.1 (second format) +SyntaxError: Unexpected token (1:5) +> 1 | let[0] = 2; + | ^ + 2 | + +// Prettier 2.8.2 +(let)[0] = 2; +``` + +#### Fix semicolon duplicated at the end of LESS file ([#14007](https://github.com/prettier/prettier/pull/14007) by [@mvorisek](https://github.com/mvorisek)) + + +```less +// Input +@variable: { + field: something; +}; + +// Prettier 2.8.1 +@variable: { + field: something; +}; ; + +// Prettier 2.8.2 +@variable: { + field: something; +}; +``` + +#### Fix no space after unary minus when followed by opening parenthesis in LESS ([#14008](https://github.com/prettier/prettier/pull/14008) by [@mvorisek](https://github.com/mvorisek)) + + +```less +// Input +.unary_minus_single { + margin: -(@a); +} + +.unary_minus_multi { + margin: 0 -(@a); +} + +.binary_minus { + margin: 0 - (@a); +} + +// Prettier 2.8.1 +.unary_minus_single { + margin: - (@a); +} + +.unary_minus_multi { + margin: 0 - (@a); +} + +.binary_minus { + margin: 0 - (@a); +} + +// Prettier 2.8.2 +.unary_minus_single { + margin: -(@a); +} + +.unary_minus_multi { + margin: 0 -(@a); +} + +.binary_minus { + margin: 0 - (@a); +} +``` + +#### Do not change case of property name if inside a variable declaration in LESS ([#14034](https://github.com/prettier/prettier/pull/14034) by [@mvorisek](https://github.com/mvorisek)) + + +```less +// Input +@var: { + preserveCase: 0; +}; + +// Prettier 2.8.1 +@var: { + preservecase: 0; +}; + +// Prettier 2.8.2 +@var: { + preserveCase: 0; +}; +``` + +#### Fix formatting for auto-accessors with comments ([#14038](https://github.com/prettier/prettier/pull/14038) by [@fisker](https://github.com/fisker)) + + +```jsx +// Input +class A { + @dec() + // comment + accessor b; +} + +// Prettier 2.8.1 +class A { + @dec() + accessor // comment + b; +} + +// Prettier 2.8.1 (second format) +class A { + @dec() + accessor; // comment + b; +} + +// Prettier 2.8.2 +class A { + @dec() + // comment + accessor b; +} +``` + +#### Add parentheses for TSTypeQuery to improve readability ([#14042](https://github.com/prettier/prettier/pull/14042) by [@onishi-kohei](https://github.com/onishi-kohei)) + + +```tsx +// Input +a as (typeof node.children)[number] +a as (typeof node.children)[] +a as ((typeof node.children)[number])[] + +// Prettier 2.8.1 +a as typeof node.children[number]; +a as typeof node.children[]; +a as typeof node.children[number][]; + +// Prettier 2.8.2 +a as (typeof node.children)[number]; +a as (typeof node.children)[]; +a as (typeof node.children)[number][]; +``` + +#### Fix displacing of comments in default switch case ([#14047](https://github.com/prettier/prettier/pull/14047) by [@thorn0](https://github.com/thorn0)) + +It was a regression in Prettier 2.6.0. + + +```jsx +// Input +switch (state) { + default: + result = state; // no change + break; +} + +// Prettier 2.8.1 +switch (state) { + default: // no change + result = state; + break; +} + +// Prettier 2.8.2 +switch (state) { + default: + result = state; // no change + break; +} +``` + +#### Support type annotations on auto accessors via `babel-ts` ([#14049](https://github.com/prettier/prettier/pull/14049) by [@sosukesuzuki](https://github.com/sosukesuzuki)) + +[The bug that `@babel/parser` cannot parse auto accessors with type annotations](https://github.com/babel/babel/issues/15205) has been fixed. So we now support it via `babel-ts` parser. + + +```tsx +class Foo { + accessor prop: number; +} +``` + +#### Fix formatting of empty type parameters ([#14073](https://github.com/prettier/prettier/pull/14073) by [@fisker](https://github.com/fisker)) + + +```jsx +// Input +const foo: bar = () => baz; + +// Prettier 2.8.1 +Error: Comment "comment" was not printed. Please report this error! + +// Prettier 2.8.2 +const foo: bar = () => baz; +``` + +#### Add parentheses to head of `ExpressionStatement` instead of the whole statement ([#14077](https://github.com/prettier/prettier/pull/14077) by [@fisker](https://github.com/fisker)) + + +```jsx +// Input +({}).toString.call(foo) === "[object Array]" + ? foo.forEach(iterateArray) + : iterateObject(foo); + +// Prettier 2.8.1 +({}.toString.call(foo) === "[object Array]" + ? foo.forEach(iterateArray) + : iterateObject(foo)); + +// Prettier 2.8.2 +({}).toString.call(foo.forEach) === "[object Array]" + ? foo.forEach(iterateArray) + : iterateObject(foo); +``` + +#### Fix comments after directive ([#14081](https://github.com/prettier/prettier/pull/14081) by [@fisker](https://github.com/fisker)) + + +```jsx +// Input +"use strict" /* comment */; + +// Prettier 2.8.1 (with other js parsers except `babel`) +Error: Comment "comment" was not printed. Please report this error! + +// Prettier 2.8.2 + +``` + +#### Fix formatting for comments inside JSX attribute ([#14082](https://github.com/prettier/prettier/pull/14082) with by [@fisker](https://github.com/fisker)) + + +```jsx +// Input +function MyFunctionComponent() { + +} + +// Prettier 2.8.1 +Error: Comment "old" was not printed. Please report this error! + +// Prettier 2.8.2 +function MyFunctionComponent() { + ; +} +``` + +#### Quote numeric keys for json-stringify parser ([#14083](https://github.com/prettier/prettier/pull/14083) by [@fisker](https://github.com/fisker)) + + +```jsx +// Input +{0: 'value'} + +// Prettier 2.8.1 +{ + 0: "value" +} + +// Prettier 2.8.2 +{ + "0": "value" +} +``` + +#### Fix removing commas from function arguments in maps ([#14089](https://github.com/prettier/prettier/pull/14089) by [@sosukesuzuki](https://github.com/sosukesuzuki)) + + +```scss +/* Input */ +$foo: map-fn( + ( + "#{prop}": inner-fn($first, $second), + ) +); + +/* Prettier 2.8.1 */ +$foo: map-fn(("#{prop}": inner-fn($first $second))); + +/* Prettier 2.8.2 */ +$foo: map-fn( + ( + "#{prop}": inner-fn($first, $second), + ) +); + +``` + +#### Do not insert space in LESS property access ([#14103](https://github.com/prettier/prettier/pull/14103) by [@fisker](https://github.com/fisker)) + + +```less +// Input +a { + color: @colors[@white]; +} + +// Prettier 2.8.1 +a { + color: @colors[ @white]; +} + +// Prettier 2.8.2 + +``` + # 2.8.1 [diff](https://github.com/prettier/prettier/compare/2.8.0...2.8.1) diff --git a/docs/browser.md b/docs/browser.md index d5637b9ef6c5..1db441def451 100644 --- a/docs/browser.md +++ b/docs/browser.md @@ -20,8 +20,8 @@ Required options: - **`plugins`**: Unlike the `format` function from the [Node.js-based API](api.md#prettierformatsource--options), this function doesn’t load plugins automatically. The `plugins` option is required because all the parsers included in the Prettier package come as plugins (for reasons of file size). These plugins are files named - - `parser-*.js` in and - - `parser-*.mjs` in + - `parser-*.js` in and + - `parser-*.mjs` in You need to load the ones that you’re going to use and pass them to `prettier.format` using the `plugins` option. @@ -32,8 +32,8 @@ See below for examples. ### Global ```html - - + + - + +