From 5811ad00705488365e0d0baf50c92965edddf58e Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sat, 13 Jan 2024 04:18:06 +0900 Subject: [PATCH 1/9] Bump Prettier dependency to 3.2.1 --- package.json | 4 ++-- yarn.lock | 13 ++----------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index fffda3d404ce..8fc420b91944 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prettier", - "version": "3.2.1", + "version": "3.3.0-dev", "description": "Prettier is an opinionated code formatter", "bin": "./bin/prettier.cjs", "repository": "prettier/prettier", @@ -147,7 +147,7 @@ "jest-watch-typeahead": "2.2.2", "magic-string": "0.30.5", "npm-run-all2": "6.1.1", - "prettier": "3.2.0", + "prettier": "3.2.1", "pretty-bytes": "6.1.1", "rollup-plugin-license": "3.2.0", "semver": "7.5.4", diff --git a/yarn.lock b/yarn.lock index 0d503b3d4985..c000458f7d0f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7317,16 +7317,7 @@ __metadata: languageName: node linkType: hard -"prettier@npm:3.2.0": - version: 3.2.0 - resolution: "prettier@npm:3.2.0" - bin: - prettier: bin/prettier.cjs - checksum: eb2eb63038ca9aaf86bda7dc49b879a278bc8344d28236fef08a8f185e8ce721a40155acc4a494e8f91ecbcdd9a132fd326516f791c61cbfa9037c1f74d6d029 - languageName: node - linkType: hard - -"prettier@workspace:.": +"prettier@npm:3.2.1, prettier@workspace:.": version: 0.0.0-use.local resolution: "prettier@workspace:." dependencies: @@ -7431,7 +7422,7 @@ __metadata: postcss-scss: "npm:4.0.9" postcss-selector-parser: "npm:2.2.3" postcss-values-parser: "npm:2.0.1" - prettier: "npm:3.2.0" + prettier: "npm:3.2.1" pretty-bytes: "npm:6.1.1" regexp-util: "npm:2.0.0" remark-footnotes: "npm:2.0.0" From 75e66b8c444ec2a251f72917dbe5b58c4a210051 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sat, 13 Jan 2024 04:18:06 +0900 Subject: [PATCH 2/9] Git blame ignore 3.2.1 --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 7ae5ab1b2d70..7bf46148bb93 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -5,6 +5,8 @@ # See https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revs-fileltfilegt # Prettier bump after release +# 3.2.1 +5811ad00705488365e0d0baf50c92965edddf58e # 3.2.0 ee0d667fa2bf175c194f2f93c98c25a575454476 # 3.1.1 From 11aea0df1a9708c0c22f6a93b2662c1413f8d783 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sat, 13 Jan 2024 04:18:09 +0900 Subject: [PATCH 3/9] Clean changelog_unreleased --- changelog_unreleased/blog-post-intro.md | 15 --------------- changelog_unreleased/javascript/15915.md | 14 -------------- 2 files changed, 29 deletions(-) delete mode 100644 changelog_unreleased/blog-post-intro.md delete mode 100644 changelog_unreleased/javascript/15915.md diff --git a/changelog_unreleased/blog-post-intro.md b/changelog_unreleased/blog-post-intro.md deleted file mode 100644 index c80ebff3beed..000000000000 --- a/changelog_unreleased/blog-post-intro.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -author: "Sosuke Suzuki (@sosukesuzuki)" -authorURL: "https://github.com/sosukesuzuki" -title: "Prettier 3.2: Support JSONC and Angular’s ICU expression" ---- - -This release includes new features such as adding a JSONC parser, adding Angular’s ICU expressions, and many bug fixes. - -We are still seeking feedback for the `--experimental-ternaries` option released in Prettier 3.1. Please read [A curious case of the ternaries](https://prettier.io/blog/2023/11/13/curious-ternaries) and respond via the Google Forms link provided. - -Additionally, we recommend reading [Prettier's CLI: A Performance Deep Dive](https://prettier.io/blog/2023/11/30/cli-deep-dive) by [Fabio Spampinato](https://github.com/fabiospampinato). This faster CLI is slated to be released as version 4.0. - - - -If you appreciate Prettier and would like to support our work, please consider sponsoring us directly via [our OpenCollective](https://opencollective.com/prettier) or by sponsoring the projects we depend on, such as [typescript-eslint](https://opencollective.com/typescript-eslint), [remark](https://opencollective.com/unified), and [Babel](https://opencollective.com/babel). Thank you for your continued support! diff --git a/changelog_unreleased/javascript/15915.md b/changelog_unreleased/javascript/15915.md deleted file mode 100644 index b493ac1b2517..000000000000 --- a/changelog_unreleased/javascript/15915.md +++ /dev/null @@ -1,14 +0,0 @@ -#### Fix formatting error on member chain (#15915 by @sosukesuzuki) - - -```jsx -// Input -test().test2().test2(thing?.something); - -// Prettier stable -TypeError: Cannot read properties of undefined (reading 'type') - -// Prettier main -test().test2().test2(thing?.something); - -``` From 08f37968632dc2e72789160704c3f36268bf3c1c Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sat, 13 Jan 2024 04:18:34 +0900 Subject: [PATCH 4/9] Run `yarn` --- yarn.lock | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index c000458f7d0f..53222fc0f3f9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7317,7 +7317,16 @@ __metadata: languageName: node linkType: hard -"prettier@npm:3.2.1, prettier@workspace:.": +"prettier@npm:3.2.1": + version: 3.2.1 + resolution: "prettier@npm:3.2.1" + bin: + prettier: bin/prettier.cjs + checksum: a26d26a74ba5cbf23a9741074ceef4f53a08ced03c42449dc9615ecd08ada9d19d5247ad2b0dfb15b2c8e57ec9f516074627b85b9f03270b08c184c64e7d8f64 + languageName: node + linkType: hard + +"prettier@workspace:.": version: 0.0.0-use.local resolution: "prettier@workspace:." dependencies: From 4ce96dd530613b99bb4a682ec93f719f3d4109f5 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 13 Jan 2024 11:03:42 +0100 Subject: [PATCH 5/9] Fix typo (#15917) --- CHANGELOG.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a81c229859d0..dbd1f70e1043 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -350,7 +350,7 @@ function fn() { return ( /** * @type {...} - */ expresssion + */ expression ) } @@ -358,7 +358,7 @@ function fn() { function fn() { return /** * @type {...} - */ expresssion; + */ expression; } // Prettier 3.0.1 @@ -366,7 +366,7 @@ function fn() { return ( /** * @type {...} - */ expresssion + */ expression ); } ``` @@ -1694,7 +1694,7 @@ interface Foo { Date: Sun, 14 Jan 2024 03:41:45 +0100 Subject: [PATCH 6/9] Add `prettier-plugin-gherkin` to the community plugins list (#15919) Add prettier-plugin-gherkin in community plugins --- docs/plugins.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/plugins.md b/docs/plugins.md index 8ce31d7eb587..c106a6792a6d 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -49,6 +49,7 @@ Strings provided to `plugins` are ultimately passed to [`import()` expression](h - [`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-gherkin`](https://github.com/mapado/prettier-plugin-gherkin) by [**@mapado**](https://github.com/mapado) - [`prettier-plugin-glsl`](https://github.com/NaridaL/glsl-language-toolkit/tree/main/packages/prettier-plugin-glsl) by [**@NaridaL**](https://github.com/NaridaL) - [`prettier-plugin-go-template`](https://github.com/NiklasPor/prettier-plugin-go-template) by [**@NiklasPor**](https://github.com/NiklasPor) - [`prettier-plugin-java`](https://github.com/jhipster/prettier-java) by [**@JHipster**](https://github.com/jhipster) From 0bfcb2d5a544a09c94a7d6ca637f05271fa270ce Mon Sep 17 00:00:00 2001 From: Eelco Lempsink Date: Sun, 14 Jan 2024 03:42:25 +0100 Subject: [PATCH 7/9] Fix css embed in JSX when using (only) a spread attribute (#15896) --- changelog_unreleased/javascript/15896.md | 8 ++++++++ src/language-js/embed/css.js | 3 ++- .../jsx/embed/__snapshots__/jsfmt.spec.js.snap | 15 +++++++++++++++ tests/format/jsx/embed/css-embed.js | 1 + tests/format/jsx/embed/jsfmt.spec.js | 1 + 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 changelog_unreleased/javascript/15896.md create mode 100644 tests/format/jsx/embed/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/jsx/embed/css-embed.js create mode 100644 tests/format/jsx/embed/jsfmt.spec.js diff --git a/changelog_unreleased/javascript/15896.md b/changelog_unreleased/javascript/15896.md new file mode 100644 index 000000000000..1ae1ed20c121 --- /dev/null +++ b/changelog_unreleased/javascript/15896.md @@ -0,0 +1,8 @@ +#### Fix crash when parsing template literal CSS in a JSX style tag using a spread attribute (#15896 by @eelco) + +For example this code would crash before: + + +```jsx + +``` diff --git a/src/language-js/embed/css.js b/src/language-js/embed/css.js index d6be30bce44f..31787646945c 100644 --- a/src/language-js/embed/css.js +++ b/src/language-js/embed/css.js @@ -75,7 +75,8 @@ function isStyledJsx({ node, parent, grandparent }) { grandparent.type === "JSXElement" && grandparent.openingElement.name.name === "style" && grandparent.openingElement.attributes.some( - (attribute) => attribute.name.name === "jsx", + (attribute) => + attribute.type === "JSXAttribute" && attribute.name.name === "jsx", )) || (parent?.type === "TaggedTemplateExpression" && parent.tag.type === "Identifier" && diff --git a/tests/format/jsx/embed/__snapshots__/jsfmt.spec.js.snap b/tests/format/jsx/embed/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..e096fd364add --- /dev/null +++ b/tests/format/jsx/embed/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,15 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`css-embed.js format 1`] = ` +====================================options===================================== +parsers: ["flow", "babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +; + +=====================================output===================================== +; + +================================================================================ +`; diff --git a/tests/format/jsx/embed/css-embed.js b/tests/format/jsx/embed/css-embed.js new file mode 100644 index 000000000000..95ac143ca126 --- /dev/null +++ b/tests/format/jsx/embed/css-embed.js @@ -0,0 +1 @@ +; diff --git a/tests/format/jsx/embed/jsfmt.spec.js b/tests/format/jsx/embed/jsfmt.spec.js new file mode 100644 index 000000000000..04b1a619ea01 --- /dev/null +++ b/tests/format/jsx/embed/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(import.meta, ["flow", "babel"]); From cb8004f3f1141635e2a4993ab87d55fbe3b64fb7 Mon Sep 17 00:00:00 2001 From: SUZUKI Sosuke Date: Sun, 14 Jan 2024 11:50:28 +0900 Subject: [PATCH 8/9] Fix formatting error on optional call expression and member chain (#15920) --- changelog_unreleased/javascript/15920.md | 13 ++++++++ src/language-js/utils/index.js | 33 +++++++++++-------- .../__snapshots__/jsfmt.spec.js.snap | 29 ++++++++++++++++ .../format/js/chain-expression/issue-15916.js | 12 +++++++ 4 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 changelog_unreleased/javascript/15920.md create mode 100644 tests/format/js/chain-expression/issue-15916.js diff --git a/changelog_unreleased/javascript/15920.md b/changelog_unreleased/javascript/15920.md new file mode 100644 index 000000000000..b802807c5f1d --- /dev/null +++ b/changelog_unreleased/javascript/15920.md @@ -0,0 +1,13 @@ +#### Fix formatting error on optional call expression and member chain (#15920 by @sosukesuzuki) + + +```jsx +// Input +a(() => {}, c?.d()); + +// Prettier stable +TypeError: Cannot read properties of undefined (reading 'type') + +// Prettier main +a(() => {}, c?.d()); +``` diff --git a/src/language-js/utils/index.js b/src/language-js/utils/index.js index 7ba6692b74ba..5b3b82899552 100644 --- a/src/language-js/utils/index.js +++ b/src/language-js/utils/index.js @@ -405,16 +405,6 @@ function isTestCall(node, parent) { /** @return {(node: Node) => boolean} */ const skipChainExpression = (fn) => (node) => { if (node?.type === "ChainExpression") { - // @ts-expect-error - if (!node.object) { - // @ts-expect-error - node.object = node.expression.object; - } - // @ts-expect-error - if (!node.property) { - // @ts-expect-error - node.property = node.expression.property; - } node = node.expression; } @@ -429,6 +419,22 @@ const isMemberExpression = skipChainExpression( createTypeCheckFunction(["MemberExpression", "OptionalMemberExpression"]), ); +/** + * Retrieves a property from a node, considering any ChainExpression. + * If the node is a ChainExpression, the property is obtained from its expression. + * Otherwise, the property is obtained directly from the node. + * + * @param {Node} node - The AST node to be processed. + * @param {string} property - The property name to retrieve. + * @returns The property value from the node or its expression. + */ +function getChainProp(node, property) { + if (node.type === "ChainExpression") { + return node.expression[property]; + } + return node[property]; +} + /** * * @param {any} node @@ -769,7 +775,7 @@ function isSimpleCallArgument(node, depth = 2) { if (isCallLikeExpression(node)) { if ( node.type === "ImportExpression" || - isSimpleCallArgument(node.callee, depth) + isSimpleCallArgument(getChainProp(node, "callee"), depth) ) { const args = getCallArguments(node); return args.length <= depth && args.every(isChildSimple); @@ -779,8 +785,8 @@ function isSimpleCallArgument(node, depth = 2) { if (isMemberExpression(node)) { return ( - isSimpleCallArgument(node.object, depth) && - isSimpleCallArgument(node.property, depth) + isSimpleCallArgument(getChainProp(node, "object"), depth) && + isSimpleCallArgument(getChainProp(node, "property"), depth) ); } @@ -1232,6 +1238,7 @@ export { createTypeCheckFunction, getCallArguments, getCallArgumentSelector, + getChainProp, getComments, getFunctionParameters, getLeftSide, diff --git a/tests/format/js/chain-expression/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/chain-expression/__snapshots__/jsfmt.spec.js.snap index e343334486b9..adbec18c325c 100644 --- a/tests/format/js/chain-expression/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/chain-expression/__snapshots__/jsfmt.spec.js.snap @@ -97,6 +97,35 @@ test().test2().test2(thing?.something); ================================================================================ `; +exports[`issue-15916.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "typescript", "flow"] +printWidth: 80 + | printWidth +=====================================input====================================== +const randomFuncion = (value) => { + if (value.a) { + funcA( + "", + funcB( + dayjs(value.a?.toString()) + .add(1, "day") + .toISOString() + ) + ); + } +}; + +=====================================output===================================== +const randomFuncion = (value) => { + if (value.a) { + funcA("", funcB(dayjs(value.a?.toString()).add(1, "day").toISOString())); + } +}; + +================================================================================ +`; + exports[`test.js format 1`] = ` ====================================options===================================== parsers: ["babel", "typescript", "flow"] diff --git a/tests/format/js/chain-expression/issue-15916.js b/tests/format/js/chain-expression/issue-15916.js new file mode 100644 index 000000000000..f3906f78b84a --- /dev/null +++ b/tests/format/js/chain-expression/issue-15916.js @@ -0,0 +1,12 @@ +const randomFuncion = (value) => { + if (value.a) { + funcA( + "", + funcB( + dayjs(value.a?.toString()) + .add(1, "day") + .toISOString() + ) + ); + } +}; From 5f2c6df4629b1474be5002ff3c6f8ad4a666b70f Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sun, 14 Jan 2024 12:06:14 +0900 Subject: [PATCH 9/9] Release 3.2.2 --- .github/ISSUE_TEMPLATE/formatting.md | 2 +- .github/ISSUE_TEMPLATE/integration.md | 2 +- CHANGELOG.md | 27 ++++++++++++++++ docs/browser.md | 32 +++++++++---------- package.json | 2 +- .../versioned_docs/version-stable/browser.md | 32 +++++++++---------- .../versioned_docs/version-stable/plugins.md | 1 + 7 files changed, 63 insertions(+), 35 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/formatting.md b/.github/ISSUE_TEMPLATE/formatting.md index b36d796ade81..0df60bdedde0 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 3.2.1** +**Prettier 3.2.2** [Playground link](https://prettier.io/playground/#.....) ```sh diff --git a/.github/ISSUE_TEMPLATE/integration.md b/.github/ISSUE_TEMPLATE/integration.md index 74e3f9380f82..b4a5566d9946 100644 --- a/.github/ISSUE_TEMPLATE/integration.md +++ b/.github/ISSUE_TEMPLATE/integration.md @@ -20,7 +20,7 @@ BEFORE SUBMITTING AN ISSUE: **Environments:** -- Prettier Version: 3.2.1 +- Prettier Version: 3.2.2 - Running Prettier via: - Runtime: - Operating System: diff --git a/CHANGELOG.md b/CHANGELOG.md index dbd1f70e1043..0a65d7de2430 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,30 @@ +# 3.2.2 + +[diff](https://github.com/prettier/prettier/compare/3.2.1...3.2.2) + +#### Fix crash when parsing template literal CSS in a JSX style tag using a spread attribute ([#15896](https://github.com/prettier/prettier/pull/15896) by [@eelco](https://github.com/eelco)) + +For example this code would crash before: + + +```jsx + +``` + +#### Fix formatting error on optional call expression and member chain ([#15920](https://github.com/prettier/prettier/pull/15920) by [@sosukesuzuki](https://github.com/sosukesuzuki)) + + +```jsx +// Input +a(() => {}, c?.d()); + +// Prettier 3.2.1 +TypeError: Cannot read properties of undefined (reading 'type') + +// Prettier 3.2.2 +a(() => {}, c?.d()); +``` + # 3.2.1 [diff](https://github.com/prettier/prettier/compare/3.2.0...3.2.1) diff --git a/docs/browser.md b/docs/browser.md index 49236cf37e8c..ff257f9ad080 100644 --- a/docs/browser.md +++ b/docs/browser.md @@ -18,7 +18,7 @@ Required options: - **[`parser`](options.md#parser) (or [`filepath`](options.md#file-path))**: One of these options has to be specified for Prettier to know which parser to use. -- **`plugins`**: Unlike the `format` function from the [Node.js-based API](api.md#prettierformatsource--options), this function doesn’t load plugins automatically. The `plugins` option is required because all the parsers included in the Prettier package come as plugins (for reasons of file size). These plugins are files in . Note that `estree` plugin should be loaded when printing JavaScript, TypeScript, Flow, or JSON. +- **`plugins`**: Unlike the `format` function from the [Node.js-based API](api.md#prettierformatsource--options), this function doesn’t load plugins automatically. The `plugins` option is required because all the parsers included in the Prettier package come as plugins (for reasons of file size). These plugins are files in . Note that `estree` plugin should be loaded when printing JavaScript, TypeScript, Flow, or JSON. You need to load the ones that you’re going to use and pass them to `prettier.format` using the `plugins` option. @@ -29,8 +29,8 @@ See below for examples. ### Global ```html - - + + - + +