Bump Prettier dependency to 3.9.0

This commit is contained in:
fisker committed 2026-06-27 18:35:59 +08:00
1 parent 05cf896cfc
commit bb817b1bd0
20 files changed
+168 -255

No files matched your search

+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "prettier",
"version": "3.9.0",
"version": "3.10.0-dev",
"description": "Prettier is an opinionated code formatter",
"bin": "./bin/prettier.cjs",
"repository": "prettier/prettier",
@@ -179,7 +179,7 @@
"node-style-text": "2.1.2",
"npm-run-all2": "9.0.2",
"open-editor": "6.0.0",
"prettier": "3.8.5",
"prettier": "3.9.0",
"pretty-bytes": "7.1.0",
"pretty-ms": "9.3.0",
"puppeteer": "25.2.1",
@@ -107,13 +107,11 @@ function setupOnResolveListener(build, { concepts, replacements }) {
// Use a `Set` to avoid infinite loop
const seenModules = new Set();
build.onResolve(concepts, async (args) => {
if (
!(
args.kind === "require-call" ||
args.kind === "import-statement" ||
args.kind === "dynamic-import"
)
) {
if (!(
args.kind === "require-call" ||
args.kind === "import-statement" ||
args.kind === "dynamic-import"
)) {
return;
}
@@ -134,14 +134,12 @@ function unwrap(text) {
function getExports(entry) {
let lines = entry.code.trim().split("\n");
if (
!(
lines[0] === "var typescript_exports = {};" &&
lines[1] === "__export(typescript_exports, {" &&
lines.at(-2) === "});" &&
lines.at(-1) === "module.exports = __toCommonJS(typescript_exports);"
)
) {
if (!(
lines[0] === "var typescript_exports = {};" &&
lines[1] === "__export(typescript_exports, {" &&
lines.at(-2) === "});" &&
lines.at(-1) === "module.exports = __toCommonJS(typescript_exports);"
)) {
throw new Error("Unexpected source");
}
@@ -20,15 +20,13 @@ const docProperties = new Set(["builders", "debug", "printer", "utils"]);
function fix(source, context) {
// only fix `import doc from './document/public.js'`
if (
!(
source.parent.type === "ImportDeclaration" &&
source.parent.specifiers.length === 1 &&
source.parent.specifiers[0].type === "ImportDefaultSpecifier" &&
source.parent.specifiers[0].local.type === "Identifier" &&
source.parent.specifiers[0].local.name === "doc"
)
) {
if (!(
source.parent.type === "ImportDeclaration" &&
source.parent.specifiers.length === 1 &&
source.parent.specifiers[0].type === "ImportDefaultSpecifier" &&
source.parent.specifiers[0].local.type === "Identifier" &&
source.parent.specifiers[0].local.name === "doc"
)) {
return;
}
@@ -45,24 +43,22 @@ function fix(source, context) {
// Only fix `const {builders: {}} = doc`
const [{ identifier }] = references;
if (
!(
identifier.parent.type === "VariableDeclarator" &&
identifier.parent.init === identifier &&
identifier.parent.id.type === "ObjectPattern" &&
identifier.parent.id.properties.every(
(property) =>
property.type === "Property" &&
!property.computed &&
property.key.type === "Identifier" &&
docProperties.has(property.key.name),
) &&
identifier.parent.parent.type === "VariableDeclaration" &&
identifier.parent.parent.kind === "const" &&
identifier.parent.parent.declarations.length === 1 &&
identifier.parent.parent.declarations[0] === identifier.parent
)
) {
if (!(
identifier.parent.type === "VariableDeclarator" &&
identifier.parent.init === identifier &&
identifier.parent.id.type === "ObjectPattern" &&
identifier.parent.id.properties.every(
(property) =>
property.type === "Property" &&
!property.computed &&
property.key.type === "Identifier" &&
docProperties.has(property.key.name),
) &&
identifier.parent.parent.type === "VariableDeclaration" &&
identifier.parent.parent.kind === "const" &&
identifier.parent.parent.declarations.length === 1 &&
identifier.parent.parent.declarations[0] === identifier.parent
)) {
return;
}
@@ -111,21 +111,19 @@ export default {
CallExpression(callExpression) {
const { callee } = callExpression;
if (
!(
!callExpression.optional &&
callExpression.arguments.length > 0 &&
callee.type === "MemberExpression" &&
!callee.optional &&
!callee.computed &&
callee.object.type === "Identifier" &&
callee.property.type === "Identifier" &&
(callee.property.name === "call" ||
callee.property.name === "callParent" ||
callee.property.name === "each" ||
callee.property.name === "map")
)
) {
if (!(
!callExpression.optional &&
callExpression.arguments.length > 0 &&
callee.type === "MemberExpression" &&
!callee.optional &&
!callee.computed &&
callee.object.type === "Identifier" &&
callee.property.type === "Identifier" &&
(callee.property.name === "call" ||
callee.property.name === "callParent" ||
callee.property.name === "each" ||
callee.property.name === "map")
)) {
return;
}
@@ -135,12 +133,10 @@ export default {
}
const [callback] = callExpression.arguments;
if (
!(
callback.type === "FunctionExpression" ||
callback.type === "ArrowFunctionExpression"
)
) {
if (!(
callback.type === "FunctionExpression" ||
callback.type === "ArrowFunctionExpression"
)) {
return;
}
@@ -292,21 +292,19 @@ export default {
continue;
}
if (
!(
referenceIdentifier.parent.type === "MemberExpression" &&
referenceIdentifier.parent.object === referenceIdentifier &&
!referenceIdentifier.parent.optional &&
!referenceIdentifier.parent.computed &&
referenceIdentifier.parent.property.type === "Identifier" &&
referenceIdentifier.parent.property.name === "has" &&
referenceIdentifier.parent.parent.type === "CallExpression" &&
referenceIdentifier.parent.parent.callee ===
referenceIdentifier.parent &&
!referenceIdentifier.parent.parent.optional &&
referenceIdentifier.parent.parent.arguments.length === 1
)
) {
if (!(
referenceIdentifier.parent.type === "MemberExpression" &&
referenceIdentifier.parent.object === referenceIdentifier &&
!referenceIdentifier.parent.optional &&
!referenceIdentifier.parent.computed &&
referenceIdentifier.parent.property.type === "Identifier" &&
referenceIdentifier.parent.property.name === "has" &&
referenceIdentifier.parent.parent.type === "CallExpression" &&
referenceIdentifier.parent.parent.callee ===
referenceIdentifier.parent &&
!referenceIdentifier.parent.parent.optional &&
referenceIdentifier.parent.parent.arguments.length === 1
)) {
return;
}
@@ -316,14 +314,12 @@ export default {
? typeNode.expression
: typeNode;
if (
!(
memberExpression.type === "MemberExpression" &&
!memberExpression.computed &&
memberExpression.property.type === "Identifier" &&
memberExpression.property.name === "type"
)
) {
if (!(
memberExpression.type === "MemberExpression" &&
!memberExpression.computed &&
memberExpression.property.type === "Identifier" &&
memberExpression.property.name === "type"
)) {
return;
}
+5 -7
View File
@@ -77,13 +77,11 @@ const assertAlignType =
process.env.NODE_ENV === "production"
? noop
: function (alignType) {
if (
!(
typeof alignType === "number" ||
typeof alignType === "string" ||
alignType?.type === "root"
)
) {
if (!(
typeof alignType === "number" ||
typeof alignType === "string" ||
alignType?.type === "root"
)) {
throw new TypeError(`Invalid alignType '${alignType}'.`);
}
};
+8 -24
View File
@@ -22,8 +22,7 @@ export namespace doc {
// It comes from this issue: microsoft/TypeScript#29729:
// https://github.com/microsoft/TypeScript/issues/29729#issuecomment-700527227
export type LiteralUnion<T extends U, U = string> =
| T
| (Pick<U, never> & { _?: never | undefined });
T | (Pick<U, never> & { _?: never | undefined });
export type AST = any;
export type Doc = doc.builders.Doc;
@@ -521,8 +520,7 @@ export interface Printer<T = any> {
| null)
| undefined;
preprocess?:
| ((ast: T, options: ParserOptions<T>) => T | Promise<T>)
| undefined;
((ast: T, options: ParserOptions<T>) => T | Promise<T>) | undefined;
insertPragma?: (text: string) => string;
/**
* @returns `null` if you want to remove this node
@@ -530,15 +528,13 @@ export interface Printer<T = any> {
* @returns anything if you want to replace the node with it
*/
massageAstNode?:
| ((original: any, cloned: any, parent: any) => any)
| undefined;
((original: any, cloned: any, parent: any) => any) | undefined;
hasPrettierIgnore?: ((path: AstPath<T>) => boolean) | undefined;
canAttachComment?: ((node: T, ancestors: T[]) => boolean) | undefined;
isBlockComment?: ((node: T) => boolean) | undefined;
willPrintOwnComments?: ((path: AstPath<T>) => boolean) | undefined;
printComment?:
| ((commentPath: AstPath<T>, options: ParserOptions<T>) => Doc)
| undefined;
((commentPath: AstPath<T>, options: ParserOptions<T>) => Doc) | undefined;
/**
* By default, Prettier searches all object properties (except for a few predefined ones) of each node recursively.
* This function can be provided to override that behavior.
@@ -547,8 +543,7 @@ export interface Printer<T = any> {
* @returns `[]` if the node has no children or `undefined` to fall back on the default behavior.
*/
getCommentChildNodes?:
| ((node: T, options: ParserOptions<T>) => T[] | undefined)
| undefined;
((node: T, options: ParserOptions<T>) => T[] | undefined) | undefined;
handleComments?:
| {
ownLine?:
@@ -581,8 +576,7 @@ export interface Printer<T = any> {
}
| undefined;
getVisitorKeys?:
| ((node: T, nonTraversableKeys: Set<string>) => string[])
| undefined;
((node: T, nonTraversableKeys: Set<string>) => string[]) | undefined;
}
export interface CursorOptions extends Options {
@@ -702,20 +696,10 @@ export interface SupportOptionRange {
}
export type SupportOptionType =
| "int"
| "string"
| "boolean"
| "choice"
| "path";
"int" | "string" | "boolean" | "choice" | "path";
export type CoreCategoryType =
| "Config"
| "Editor"
| "Format"
| "Other"
| "Output"
| "Global"
| "Special";
"Config" | "Editor" | "Format" | "Other" | "Output" | "Global" | "Special";
export interface BaseSupportOption<Type extends SupportOptionType> {
readonly name?: string | undefined;
+6 -8
View File
@@ -7,14 +7,12 @@ function embed(path /* , options*/) {
const { parent } = path;
if (
!(
parent.type === "ElementNode" &&
parent.tag === "style" &&
parent.children.length === 1 &&
parent.children[0] === node
)
) {
if (!(
parent.type === "ElementNode" &&
parent.tag === "style" &&
parent.children.length === 1 &&
parent.children[0] === node
)) {
return;
}
@@ -19,13 +19,11 @@ function handleWhileLikeComments({
followingNode,
text,
}) {
if (
!(
(enclosingNode?.type === "WhileStatement" ||
enclosingNode?.type === "WithStatement") &&
followingNode
)
) {
if (!(
(enclosingNode?.type === "WhileStatement" ||
enclosingNode?.type === "WithStatement") &&
followingNode
)) {
return false;
}
@@ -50,7 +50,7 @@ function isBabelOptionalChainRoot(path) {
}
return !(
(path.key === "expression" && path.parent.type === "TSNonNullExpression")
path.key === "expression" && path.parent.type === "TSNonNullExpression"
// We should exclude if it's in `OptionalCallExpression` or `OptionalMemberExpression`
// But in these cases it should not matter, since we don't need parentheses anyway
);
+19 -21
View File
@@ -32,27 +32,25 @@ function printBlock(path, options, print) {
parts.push(indent([hardline, bodyDoc]), hardline);
} else {
const parentParent = path.grandparent;
if (
!(
parent.type === "ArrowFunctionExpression" ||
parent.type === "FunctionExpression" ||
parent.type === "FunctionDeclaration" ||
parent.type === "ComponentDeclaration" ||
parent.type === "HookDeclaration" ||
parent.type === "ObjectMethod" ||
parent.type === "ClassMethod" ||
parent.type === "ClassPrivateMethod" ||
parent.type === "ForStatement" ||
parent.type === "WhileStatement" ||
parent.type === "DoWhileStatement" ||
parent.type === "DoExpression" ||
parent.type === "ModuleExpression" ||
(parent.type === "CatchClause" && !parentParent.finalizer) ||
parent.type === "TSModuleDeclaration" ||
parent.type === "MatchStatementCase" ||
node.type === "StaticBlock"
)
) {
if (!(
parent.type === "ArrowFunctionExpression" ||
parent.type === "FunctionExpression" ||
parent.type === "FunctionDeclaration" ||
parent.type === "ComponentDeclaration" ||
parent.type === "HookDeclaration" ||
parent.type === "ObjectMethod" ||
parent.type === "ClassMethod" ||
parent.type === "ClassPrivateMethod" ||
parent.type === "ForStatement" ||
parent.type === "WhileStatement" ||
parent.type === "DoWhileStatement" ||
parent.type === "DoExpression" ||
parent.type === "ModuleExpression" ||
(parent.type === "CatchClause" && !parentParent.finalizer) ||
parent.type === "TSModuleDeclaration" ||
parent.type === "MatchStatementCase" ||
node.type === "StaticBlock"
)) {
parts.push(hardline);
}
}
+15 -19
View File
@@ -133,25 +133,21 @@ const moduleImportCallees = [
function isSimpleModuleImport(path) {
const { node } = path;
if (
!(
// `import("foo")`
(
node.type === "ImportExpression" ||
// `type foo = import("foo")`
node.type === "TSImportType" ||
// `import type A = require("foo")`
node.type === "TSExternalModuleReference" ||
// `require("foo")`
// `require.resolve("foo")`
// `require.resolve.paths("foo")`
// `import.meta.resolve("foo")`
(node.type === "CallExpression" &&
!node.optional &&
isNodeMatches(node.callee, moduleImportCallees))
)
)
) {
if (!(
// `import("foo")`
node.type === "ImportExpression" ||
// `type foo = import("foo")`
node.type === "TSImportType" ||
// `import type A = require("foo")`
node.type === "TSExternalModuleReference" ||
// `require("foo")`
// `require.resolve("foo")`
// `require.resolve.paths("foo")`
// `import.meta.resolve("foo")`
(node.type === "CallExpression" &&
!node.optional &&
isNodeMatches(node.callee, moduleImportCallees))
)) {
return false;
}
+4 -7
View File
@@ -21,13 +21,10 @@ const isCallExpressionWithArguments = (node) =>
function shouldInlineNewExpressionCallee(path) {
let { node: child, ancestors } = path;
for (const ancestor of ancestors) {
if (
!(
(isMemberExpression(ancestor) && ancestor.object === child) ||
(ancestor.type === "TSNonNullExpression" &&
ancestor.expression === child)
)
) {
if (!(
(isMemberExpression(ancestor) && ancestor.object === child) ||
(ancestor.type === "TSNonNullExpression" && ancestor.expression === child)
)) {
return ancestor.type === "NewExpression" && ancestor.callee === child;
}
+4 -8
View File
@@ -69,21 +69,17 @@ type ExtendNode<Input> = Input extends _Node
: Input;
export type NumericLiteral =
| NodeMap["NumericLiteral"]
| (NodeMap["Literal"] & { value: number });
NodeMap["NumericLiteral"] | (NodeMap["Literal"] & { value: number });
export type StringLiteral =
| NodeMap["StringLiteral"]
| (NodeMap["Literal"] & { value: string });
NodeMap["StringLiteral"] | (NodeMap["Literal"] & { value: string });
export type RegExpLiteral =
| NodeMap["RegExpLiteral"]
| (NodeMap["Literal"] & { regexp: { pattern: string; flags: string } });
export type BigIntLiteral =
| NodeMap["BigIntLiteral"]
| (NodeMap["Literal"] & { bigint: string });
NodeMap["BigIntLiteral"] | (NodeMap["Literal"] & { bigint: string });
export type BooleanLiteral =
| NodeMap["BigIntLiteral"]
| (NodeMap["BooleanLiteral"] & { value: boolean });
NodeMap["BigIntLiteral"] | (NodeMap["BooleanLiteral"] & { value: boolean });
+14 -46
View File
@@ -273,10 +273,7 @@ export type BindingPattern = ArrayPattern | ObjectPattern;
export type RestElementPattern = AssignmentPattern | BindingName | RestElement;
export type FunctionParameter = AssignmentPattern | BindingName | RestElement;
export type DestructuringPattern =
| BindingName
| AssignmentPattern
| MemberExpression
| RestElement;
BindingName | AssignmentPattern | MemberExpression | RestElement;
interface BaseFunction extends BaseNode {
params: ReadonlyArray<FunctionParameter>;
@@ -288,9 +285,7 @@ interface BaseFunction extends BaseNode {
}
export type AFunction =
| FunctionDeclaration
| FunctionExpression
| ArrowFunctionExpression;
FunctionDeclaration | FunctionExpression | ArrowFunctionExpression;
export type Statement =
| BlockStatement
@@ -347,10 +342,7 @@ export type StatementParentSingle =
| ForOfStatement;
// nodes that can be the parent of a statement that store the statements in an array
export type StatementParentArray =
| SwitchCase
| Program
| BlockStatement
| StaticBlock;
SwitchCase | Program | BlockStatement | StaticBlock;
export type StatementParent = StatementParentSingle | StatementParentArray;
export interface EmptyStatement extends BaseNode {
@@ -571,10 +563,7 @@ export interface ObjectExpression extends BaseNode {
export type Property = ObjectProperty | DestructuringObjectProperty;
export type ObjectPropertyKey =
| Identifier
| StringLiteral
| NumericLiteral
| BigIntLiteral;
Identifier | StringLiteral | NumericLiteral | BigIntLiteral;
export type ObjectProperty =
| ObjectPropertyWithNonShorthandStaticName
@@ -736,8 +725,7 @@ export interface NewExpression extends BaseCallExpression {
}
export type MemberExpression =
| MemberExpressionWithComputedName
| MemberExpressionWithNonComputedName;
MemberExpressionWithComputedName | MemberExpressionWithNonComputedName;
export interface MemberExpressionWithComputedName extends BaseNode {
type: "MemberExpression";
object: Expression | Super;
@@ -842,13 +830,7 @@ export interface StringLiteral extends BaseNode {
}
export type UnaryOperator =
| "-"
| "+"
| "!"
| "~"
| "typeof"
| "void"
| "delete";
"-" | "+" | "!" | "~" | "typeof" | "void" | "delete";
export type BinaryOperatorWithoutIn =
| "=="
@@ -981,12 +963,10 @@ interface BaseClass extends BaseNode {
}
export type PropertyName =
| ClassPropertyNameComputed
| ClassPropertyNameNonComputed;
ClassPropertyNameComputed | ClassPropertyNameNonComputed;
export type ClassPropertyNameComputed = Expression;
export type ClassPropertyNameNonComputed =
| PrivateIdentifier
| ObjectPropertyKey;
PrivateIdentifier | ObjectPropertyKey;
export type ClassMember = PropertyDefinition | MethodDefinition | StaticBlock;
export type ClassMemberWithNonComputedName =
@@ -1036,8 +1016,7 @@ export interface MethodDefinitionWithNonComputedName extends MethodDefinitionBas
// `PropertyDefinition` is the new standard for all class properties
export type PropertyDefinition =
| PropertyDefinitionWithComputedName
| PropertyDefinitionWithNonComputedName;
PropertyDefinitionWithComputedName | PropertyDefinitionWithNonComputedName;
interface PropertyDefinitionBase extends BaseNode {
value: null | Expression;
typeAnnotation: null | TypeAnnotation;
@@ -1174,8 +1153,7 @@ export interface ExportNamedDeclarationWithDeclaration extends ExportNamedDeclar
specifiers: [];
}
export type ExportNamedDeclaration =
| ExportNamedDeclarationWithSpecifiers
| ExportNamedDeclarationWithDeclaration;
ExportNamedDeclarationWithSpecifiers | ExportNamedDeclarationWithDeclaration;
export interface ExportSpecifier extends BaseNode {
type: "ExportSpecifier";
@@ -1435,14 +1413,10 @@ export interface ConditionalTypeAnnotation extends BaseNode {
}
export type TypeOperator =
| RendersTypeOperator
| RendersStarTypeOperator
| RendersQuestionTypeOperator;
RendersTypeOperator | RendersStarTypeOperator | RendersQuestionTypeOperator;
export type RendersType =
| RendersTypeOperator
| RendersStarTypeOperator
| RendersQuestionTypeOperator;
RendersTypeOperator | RendersStarTypeOperator | RendersQuestionTypeOperator;
interface TypeOperatorBase extends BaseNode {
type: "TypeOperator";
@@ -1962,16 +1936,10 @@ export interface DeclaredPredicate extends BaseNode {
**********************/
export type JSXChild =
| JSXElement
| JSXExpression
| JSXFragment
| JSXText
| JSXSpreadChild;
JSXElement | JSXExpression | JSXFragment | JSXText | JSXSpreadChild;
export type JSXExpression = JSXEmptyExpression | JSXExpressionContainer;
export type JSXTagNameExpression =
| JSXIdentifier
| JSXMemberExpression
| JSXNamespacedName;
JSXIdentifier | JSXMemberExpression | JSXNamespacedName;
export type JSXNode =
| JSXAttribute
+5 -7
View File
@@ -20,13 +20,11 @@ function parseEmptyJson(text) {
// Not an empty JSON
/* c8 ignore next */
if (
!(
program.body.length === 0 &&
program.directives.length === 0 &&
!program.interpreter
)
) {
if (!(
program.body.length === 0 &&
program.directives.length === 0 &&
!program.interpreter
)) {
return;
}
+1 -1
View File
@@ -182,7 +182,7 @@ function getFlowScalarLineContents(nodeType, content, options) {
words.length > 0 &&
!(
// trailing backslash in quoteDouble should be preserved
(nodeType === "quoteDouble" && lines.at(-1).at(-1).endsWith("\\"))
nodeType === "quoteDouble" && lines.at(-1).at(-1).endsWith("\\")
)
) {
lines[lines.length - 1] = [...lines.at(-1), ...words];
+4 -6
View File
@@ -56,12 +56,10 @@ function makeWidthIndicator(printWidth) {
const defaultWidthIndicator = makeWidthIndicator();
function printWidthIndicator(printWidth) {
if (
!(
printWidth === undefined ||
(Number.isSafeInteger(printWidth) && printWidth > 0)
)
) {
if (!(
printWidth === undefined ||
(Number.isSafeInteger(printWidth) && printWidth > 0)
)) {
return "";
}
+5 -5
View File
@@ -7905,12 +7905,12 @@ __metadata:
languageName: node
linkType: hard
"prettier@npm:3.8.5":
version: 3.8.5
resolution: "prettier@npm:3.8.5"
"prettier@npm:3.9.0":
version: 3.9.0
resolution: "prettier@npm:3.9.0"
bin:
prettier: bin/prettier.cjs
checksum: 10/61b59be2f6fdb06850aa8add77a4c3ea31d9536ae25ee9206cdd7a52de968276270a69f4bb71a6e23cbe7bfe6705a74eebdfae2022659c4ccea246e45c290c94
checksum: 10/146bd970fda6ec01928455b438674581b98ef6d0696146c44d5110176ba104fad023a42d9f41b8b43197684f1ee0cfe7eab5f6777ef914d8cc888575af6fa50d
languageName: node
linkType: hard
@@ -8036,7 +8036,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.8.5"
prettier: "npm:3.9.0"
pretty-bytes: "npm:7.1.0"
pretty-ms: "npm:9.3.0"
puppeteer: "npm:25.2.1"