Merge branch 'v3.9.x'

This commit is contained in:
fisker committed 2026-06-29 19:43:56 +08:00
commit 7b7d85f5b1
12 files changed
+325 -78

No files matched your search

+1 -1
View File
@@ -26,7 +26,7 @@ Don't fill the form below manually! Let a program create a report for you:
-->
**Prettier 3.9.1**
**Prettier 3.9.3**
[Playground link](https://prettier.io/playground/#.....)
```sh
+1 -1
View File
@@ -20,7 +20,7 @@ BEFORE SUBMITTING AN ISSUE:
**Environments:**
- Prettier Version: 3.9.1
- Prettier Version: 3.9.3
- Running Prettier via: <!-- CLI, Node.js API, Browser API, etc. -->
- Runtime: <!-- Node.js v14, Chrome v83, etc. -->
- Operating System: <!-- Windows, Linux, macOS, etc. -->
+46
View File
@@ -1,3 +1,49 @@
# 3.9.3
[diff](https://github.com/prettier/prettier/compare/3.9.1...3.9.3)
#### Markdown: Fix unexpected removal of characters in liquid syntax ([#19489](https://github.com/prettier/prettier/pull/19489) by [@seiyab](https://github.com/seiyab))
<!-- prettier-ignore -->
```md
// Input
<!-- Input -->
{{ page.title
}} text
<!-- Prettier 3.9.1 -->
{{ page.title
text
<!-- Prettier 3.9.3 -->
{{ page.title
}} text
```
#### TypeScript: Allow decorators to be used with declare on class fields ([#19492](https://github.com/prettier/prettier/pull/19492) by [@evoactivity](https://github.com/evoactivity))
Extensively used within the Ember ecosystem, decorators with `declare` on class fields will ignore the babel parser error and allow Prettier to format the code without breaking it.
<!-- prettier-ignore -->
```ts
// Input
export default class ProjectStatusComponent extends Component<ProjectStatusSig> {
@service declare server: ServerService;
}
// Prettier 3.9.1
// SyntaxError: Decorators can't be used with a declare field. (2:3)
// 1 | export default class ProjectStatusComponent extends Component<ProjectStatusSig> {
//> 2 | @service declare server: ServerService;
// | ^
// 3 | }
// Prettier 3.9.3
export default class ProjectStatusComponent extends Component<ProjectStatusSig> {
@service declare server: ServerService;
}
```
# 3.9.1
[diff](https://github.com/prettier/prettier/compare/3.9.0...3.9.1)
+1 -1
View File
@@ -181,7 +181,7 @@
"node-style-text": "2.1.2",
"npm-run-all2": "9.0.2",
"open-editor": "6.0.0",
"prettier": "3.9.1",
"prettier": "3.9.3",
"pretty-bytes": "7.1.0",
"pretty-ms": "9.3.0",
"puppeteer": "25.2.1",
@@ -33,10 +33,10 @@ function liquidFromMarkdown() {
/** @type {Handle} */
function exit(token) {
const d = this.resume();
this.resume();
/** @type {any} */
const node = this.stack.at(-1);
node.value = d;
node.value = this.sliceSerialize(token);
this.exit(token);
}
}
@@ -55,6 +55,9 @@ function liquidSyntax() {
};
function tokenize(effects, ok, nok) {
/** @type {typeof codes.rightCurlyBrace | typeof codes.percentSign} */
let closingCode;
return start;
/** @type {State} */
@@ -66,6 +69,10 @@ function liquidSyntax() {
switch (code) {
case codes.percentSign:
case codes.leftCurlyBrace:
closingCode =
code === codes.percentSign
? codes.percentSign
: codes.rightCurlyBrace;
effects.consume(code);
return inside;
default:
@@ -77,9 +84,9 @@ function liquidSyntax() {
/** @type {State} */
function inside(code) {
switch (code) {
case codes.percentSign:
case codes.rightCurlyBrace:
return effects.check({ tokenize: tokenizeClose }, close, data)(code);
case closingCode:
effects.consume(code);
return mayClose;
case codes.eof:
return nok(code);
default:
@@ -91,54 +98,22 @@ function liquidSyntax() {
effects.enter(types.data);
return inside;
}
return data(code);
}
}
/** @type {State} */
function data(code) {
effects.consume(code);
return inside;
}
function tokenizeClose(effects, ok, nok) {
return startClose;
/** @type {State} */
function startClose(code) {
switch (code) {
case codes.percentSign:
case codes.rightCurlyBrace:
effects.consume(code);
return endClose;
default:
return nok(code);
}
}
/** @type {State} */
function endClose(code) {
if (code !== codes.rightCurlyBrace) {
return nok(code);
}
effects.consume(code);
return ok;
}
}
/** @type {State} */
function close(code) {
effects.consume(code);
return closeEnd;
}
/** @type {State} */
function closeEnd(code) {
function mayClose(code) {
if (code === codes.rightCurlyBrace) {
effects.consume(code);
effects.exit(types.data);
effects.exit(nodeType);
return ok;
}
return inside;
}
}
}
@@ -1,5 +1,63 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`character-after-closing-tokens.md - {"proseWrap":"always"} format 1`] = `
====================================options=====================================
parsers: ["markdown"]
proseWrap: "always"
printWidth: 80 (default) |
=====================================input======================================
{{ page.title
}} a
---
{%
if user
%} Hello, {{ user }}!
{% endif %}
=====================================output=====================================
{{ page.title
}} a
---
{%
if user
%} Hello, {{ user }}! {% endif %}
================================================================================
`;
exports[`character-after-closing-tokens.md format 1`] = `
====================================options=====================================
parsers: ["markdown"]
printWidth: 80 (default) |
=====================================input======================================
{{ page.title
}} a
---
{%
if user
%} Hello, {{ user }}!
{% endif %}
=====================================output=====================================
{{ page.title
}} a
---
{%
if user
%} Hello, {{ user }}!
{% endif %}
================================================================================
`;
exports[`example-1.md - {"proseWrap":"always"} format 1`] = `
====================================options=====================================
parsers: ["markdown"]
@@ -216,6 +274,138 @@ parsers: ["markdown"]
================================================================================
`;
exports[`issue-19488.md - {"proseWrap":"always"} format 1`] = `
====================================options=====================================
parsers: ["markdown"]
proseWrap: "always"
printWidth: 80 (default) |
=====================================input======================================
{{% blocks/cover
title="Welcome"
%}}
This input uses Hugo shortcode. Prettier doesn't support this explicitly but it shouldn't break it either.
{{% /blocks/cover %}}
---
{{% blocks/cover
%}}
{{% blocks/cover
%%}}
{{% blocks/cover
}}}
{{{% blocks/cover
%}}
{% blocks/cover
%}}
{{ blocks/cover
%}}
=====================================output=====================================
{{% blocks/cover
title="Welcome"
%}}
This input uses Hugo shortcode. Prettier doesn't support this explicitly but it
shouldn't break it either.
{{% /blocks/cover %}}
---
{{% blocks/cover
%}}
{{% blocks/cover
%%}}
{{% blocks/cover
}}}
{{{% blocks/cover
%}}
{% blocks/cover
%}}
{{ blocks/cover
%}}
================================================================================
`;
exports[`issue-19488.md format 1`] = `
====================================options=====================================
parsers: ["markdown"]
printWidth: 80 (default) |
=====================================input======================================
{{% blocks/cover
title="Welcome"
%}}
This input uses Hugo shortcode. Prettier doesn't support this explicitly but it shouldn't break it either.
{{% /blocks/cover %}}
---
{{% blocks/cover
%}}
{{% blocks/cover
%%}}
{{% blocks/cover
}}}
{{{% blocks/cover
%}}
{% blocks/cover
%}}
{{ blocks/cover
%}}
=====================================output=====================================
{{% blocks/cover
title="Welcome"
%}}
This input uses Hugo shortcode. Prettier doesn't support this explicitly but it shouldn't break it either.
{{% /blocks/cover %}}
---
{{% blocks/cover
%}}
{{% blocks/cover
%%}}
{{% blocks/cover
}}}
{{{% blocks/cover
%}}
{% blocks/cover
%}}
{{ blocks/cover
%}}
================================================================================
`;
exports[`unbalanced-mismatched-braces.md - {"proseWrap":"always"} format 1`] = `
====================================options=====================================
parsers: ["markdown"]
@@ -226,8 +416,8 @@ proseWrap: "always"
Braces {% doesn't match so these words should not be considered as *liquid node* }}
=====================================output=====================================
Braces
{% doesn't match so these words should not be considered as *liquid node* }}
Braces {% doesn't match so these words should not be considered as _liquid node_
}}
================================================================================
`;
@@ -241,7 +431,7 @@ parsers: ["markdown"]
Braces {% doesn't match so these words should not be considered as *liquid node* }}
=====================================output=====================================
Braces {% doesn't match so these words should not be considered as *liquid node* }}
Braces {% doesn't match so these words should not be considered as _liquid node_ }}
================================================================================
`;
@@ -0,0 +1,9 @@
{{ page.title
}} a
---
{%
if user
%} Hello, {{ user }}!
{% endif %}
@@ -0,0 +1,27 @@
{{% blocks/cover
title="Welcome"
%}}
This input uses Hugo shortcode. Prettier doesn't support this explicitly but it shouldn't break it either.
{{% /blocks/cover %}}
---
{{% blocks/cover
%}}
{{% blocks/cover
%%}}
{{% blocks/cover
}}}
{{{% blocks/cover
%}}
{% blocks/cover
%}}
{{ blocks/cover
%}}
@@ -21,7 +21,7 @@ Required options:
- **[`parser`](options.md#parser) (or [`filepath`](options.md#file-path))**: One of these options has to be specified for Prettier to know which parser to use.
- **`plugins`**: Unlike the `format` function from the [Node.js-based API](api.md#prettierformatsource-options), this function doesn’t load plugins automatically. The `plugins` option is required because all the parsers included in the Prettier package come as plugins (for reasons of file size). These plugins are files in [https://unpkg.com/browse/prettier@3.9.1/plugins](https://unpkg.com/browse/prettier@3.9.1/plugins). 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 [https://unpkg.com/browse/prettier@3.9.3/plugins](https://unpkg.com/browse/prettier@3.9.3/plugins). 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.
@@ -32,8 +32,8 @@ See below for examples.
### Global
```html
<script src="https://unpkg.com/prettier@3.9.1/standalone.js"></script>
<script src="https://unpkg.com/prettier@3.9.1/plugins/graphql.js"></script>
<script src="https://unpkg.com/prettier@3.9.3/standalone.js"></script>
<script src="https://unpkg.com/prettier@3.9.3/plugins/graphql.js"></script>
<script>
(async () => {
const formatted = await prettier.format("type Query { hello: String }", {
@@ -50,8 +50,8 @@ Note that the [`unpkg` field](https://unpkg.com/#examples) in Prettier’s `pack
```html
<script type="module">
import * as prettier from "https://unpkg.com/prettier@3.9.1/standalone.mjs";
import * as prettierPluginGraphql from "https://unpkg.com/prettier@3.9.1/plugins/graphql.mjs";
import * as prettier from "https://unpkg.com/prettier@3.9.3/standalone.mjs";
import * as prettierPluginGraphql from "https://unpkg.com/prettier@3.9.3/plugins/graphql.mjs";
const formatted = await prettier.format("type Query { hello: String }", {
parser: "graphql",
@@ -64,8 +64,8 @@ Note that the [`unpkg` field](https://unpkg.com/#examples) in Prettier’s `pack
```js
define([
"https://unpkg.com/prettier@3.9.1/standalone.js",
"https://unpkg.com/prettier@3.9.1/plugins/graphql.js",
"https://unpkg.com/prettier@3.9.3/standalone.js",
"https://unpkg.com/prettier@3.9.3/plugins/graphql.js",
], async (prettier, ...plugins) => {
const formatted = await prettier.format("type Query { hello: String }", {
parser: "graphql",
@@ -96,8 +96,8 @@ This syntax doesn’t necessarily work in the browser, but it can be used when b
<TabItem value="module" label="Module worker">
```js
import * as prettier from "https://unpkg.com/prettier@3.9.1/standalone.mjs";
import * as prettierPluginGraphql from "https://unpkg.com/prettier@3.9.11/plugins/graphql.mjs";
import * as prettier from "https://unpkg.com/prettier@3.9.3/standalone.mjs";
import * as prettierPluginGraphql from "https://unpkg.com/prettier@3.9.31/plugins/graphql.mjs";
const formatted = await prettier.format("type Query { hello: String }", {
parser: "graphql",
@@ -110,8 +110,8 @@ const formatted = await prettier.format("type Query { hello: String }", {
```js
importScripts(
"https://unpkg.com/prettier@3.9.1/standalone.js",
"https://unpkg.com/prettier@3.9.1/plugins/graphql.js",
"https://unpkg.com/prettier@3.9.3/standalone.js",
"https://unpkg.com/prettier@3.9.3/plugins/graphql.js",
);
(async () => {
@@ -131,9 +131,9 @@ If you want to format [embedded code](options.md#embedded-language-formatting),
```html
<script type="module">
import * as prettier from "https://unpkg.com/prettier@3.9.1/standalone.mjs";
import * as prettierPluginBabel from "https://unpkg.com/prettier@3.9.1/plugins/babel.mjs";
import * as prettierPluginEstree from "https://unpkg.com/prettier@3.9.1/plugins/estree.mjs";
import * as prettier from "https://unpkg.com/prettier@3.9.3/standalone.mjs";
import * as prettierPluginBabel from "https://unpkg.com/prettier@3.9.3/plugins/babel.mjs";
import * as prettierPluginEstree from "https://unpkg.com/prettier@3.9.3/plugins/estree.mjs";
console.log(
await prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
@@ -149,10 +149,10 @@ The HTML code embedded in JavaScript stays unformatted because the `html` parser
```html
<script type="module">
import * as prettier from "https://unpkg.com/prettier@3.9.1/standalone.mjs";
import * as prettierPluginBabel from "https://unpkg.com/prettier@3.9.1/plugins/babel.mjs";
import * as prettierPluginEstree from "https://unpkg.com/prettier@3.9.1/plugins/estree.mjs";
import * as prettierPluginHtml from "https://unpkg.com/prettier@3.9.1/plugins/html.mjs";
import * as prettier from "https://unpkg.com/prettier@3.9.3/standalone.mjs";
import * as prettierPluginBabel from "https://unpkg.com/prettier@3.9.3/plugins/babel.mjs";
import * as prettierPluginEstree from "https://unpkg.com/prettier@3.9.3/plugins/estree.mjs";
import * as prettierPluginHtml from "https://unpkg.com/prettier@3.9.3/plugins/html.mjs";
console.log(
await prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
@@ -12,35 +12,35 @@ First, install Prettier locally:
<TabItem value="npm">
```bash
npm install --save-dev --save-exact prettier@3.9.1
npm install --save-dev --save-exact prettier@3.9.3
```
</TabItem>
<TabItem value="yarn">
```bash
yarn add --dev --exact prettier@3.9.1
yarn add --dev --exact prettier@3.9.3
```
</TabItem>
<TabItem value="pnpm">
```bash
pnpm add --save-dev --save-exact prettier@3.9.1
pnpm add --save-dev --save-exact prettier@3.9.3
```
</TabItem>
<TabItem value="bun">
```bash
bun add --dev --exact prettier@3.9.1
bun add --dev --exact prettier@3.9.3
```
</TabItem>
<TabItem value="deno">
```bash
deno install --dev --save-exact prettier@3.9.1
deno install --dev --save-exact prettier@3.9.3
```
</TabItem>
@@ -46,7 +46,7 @@ Example `package.json`:
"prettier": ">=3.0.0"
},
"devDependencies": {
"prettier": "3.9.1"
"prettier": "3.9.3"
}
}
```
@@ -193,7 +193,7 @@ export default config;
"prettier": ">=3.0.0"
},
"devDependencies": {
"prettier": "3.9.1"
"prettier": "3.9.3"
}
}
```
+5 -5
View File
@@ -7919,12 +7919,12 @@ __metadata:
languageName: node
linkType: hard
"prettier@npm:3.9.1":
version: 3.9.1
resolution: "prettier@npm:3.9.1"
"prettier@npm:3.9.3":
version: 3.9.3
resolution: "prettier@npm:3.9.3"
bin:
prettier: bin/prettier.cjs
checksum: 10/1b4317674aa9e90ff79c347fd19f91bb305df98b3122e7131d6815291707781305c45a13cd982474c2f74ed748f2fd0a9aa094f9856609ed1b6f092de8152058
checksum: 10/2aa4232a7ae2204a6d0758e8083117509f13a499ae49f87ed8e4a9c15967083f400e4e189a64948de60987974d3441f4b5e5110e7a3e56f9b83f4e2904cef376
languageName: node
linkType: hard
@@ -8052,7 +8052,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.9.1"
prettier: "npm:3.9.3"
pretty-bytes: "npm:7.1.0"
pretty-ms: "npm:9.3.0"
puppeteer: "npm:25.2.1"