diff --git a/src/language-js/comments/handle-comments.js b/src/language-js/comments/handle-comments.js index fdc3cd65b..815a5fc6f 100644 --- a/src/language-js/comments/handle-comments.js +++ b/src/language-js/comments/handle-comments.js @@ -15,20 +15,22 @@ import { createTypeCheckFunction, getCallArguments, getFunctionParameters, + isMethod, + isObjectProperty, + isPrettierIgnoreComment, +} from "../utilities/index.js"; +import isBlockComment from "../utilities/is-block-comment.js"; +import isLineComment from "../utilities/is-line-comment.js"; +import isTypeCastComment from "../utilities/is-type-cast-comment.js"; +import { isBinaryCastExpression, isCallLikeExpression, isCallOrNewExpression, isConditionalType, isIntersectionType, isMemberExpression, - isMethod, - isObjectProperty, - isPrettierIgnoreComment, isUnionType, -} from "../utilities/index.js"; -import isBlockComment from "../utilities/is-block-comment.js"; -import isLineComment from "../utilities/is-line-comment.js"; -import isTypeCastComment from "../utilities/is-type-cast-comment.js"; +} from "../utilities/node-types.js"; /** @import {Node, Comment, NodeMap} from "../types/estree.js"; diff --git a/src/language-js/comments/will-print-own-comments.js b/src/language-js/comments/will-print-own-comments.js index 963120ee8..e36fc8ead 100644 --- a/src/language-js/comments/will-print-own-comments.js +++ b/src/language-js/comments/will-print-own-comments.js @@ -2,10 +2,9 @@ import { createTypeCheckFunction, hasNodeIgnoreComment, isIifeCalleeOrTaggedTemplateExpressionTag, - isJsxElement, - isUnionType, shouldUnionTypePrintOwnComments, } from "../utilities/index.js"; +import { isJsxElement, isUnionType } from "../utilities/node-types.js"; /** @import {Node} from "../types/estree.js"; diff --git a/src/language-js/embed/utilities.js b/src/language-js/embed/utilities.js index 86ff723ac..1fb097ec9 100644 --- a/src/language-js/embed/utilities.js +++ b/src/language-js/embed/utilities.js @@ -1,18 +1,18 @@ import { CommentCheckFlags, hasComment, - isArrayExpression, isObjectProperty, } from "../utilities/index.js"; +import { isArrayExpression } from "../utilities/node-types.js"; const angularComponentObjectExpressionPredicates = [ - (node, name) => node.type === "ObjectExpression" && name === "properties", + (node, name) => name === "properties" && node.type === "ObjectExpression", (node, name) => + name === "arguments" && node.type === "CallExpression" && node.callee.type === "Identifier" && - node.callee.name === "Component" && - name === "arguments", - (node, name) => node.type === "Decorator" && name === "expression", + node.callee.name === "Component", + (node, name) => name === "expression" && node.type === "Decorator", ]; /** diff --git a/src/language-js/massage-ast/chain-expression.js b/src/language-js/massage-ast/chain-expression.js index 3d0e9ab0c..7fc99a99a 100644 --- a/src/language-js/massage-ast/chain-expression.js +++ b/src/language-js/massage-ast/chain-expression.js @@ -2,7 +2,7 @@ import { isCallExpression, isChainElementWrapper, isMemberExpression, -} from "../utilities/index.js"; +} from "../utilities/node-types.js"; /** @import {Node} from "../types/estree.js" diff --git a/src/language-js/massage-ast/index.js b/src/language-js/massage-ast/index.js index 15e711c39..dc65ebb25 100644 --- a/src/language-js/massage-ast/index.js +++ b/src/language-js/massage-ast/index.js @@ -1,9 +1,9 @@ +import { isMeaningfulEmptyStatement } from "../utilities/index.js"; import { isArrayExpression, isBigIntLiteral, - isMeaningfulEmptyStatement, isStringLiteral, -} from "../utilities/index.js"; +} from "../utilities/node-types.js"; import { cleanChainExpression } from "./chain-expression.js"; import { cleanKey } from "./key.js"; import { cleanRegExpLiteral } from "./regexp-literal.js"; diff --git a/src/language-js/massage-ast/key.js b/src/language-js/massage-ast/key.js index beefa7dfa..a43d112e9 100644 --- a/src/language-js/massage-ast/key.js +++ b/src/language-js/massage-ast/key.js @@ -1,4 +1,4 @@ -import { isNumericLiteral, isStringLiteral } from "../utilities/index.js"; +import { isNumericLiteral, isStringLiteral } from "../utilities/node-types.js"; /** @import {Node} from "../types/estree.js" diff --git a/src/language-js/parentheses/identifier.js b/src/language-js/parentheses/identifier.js index bff40895b..1a3ec0678 100644 --- a/src/language-js/parentheses/identifier.js +++ b/src/language-js/parentheses/identifier.js @@ -1,7 +1,5 @@ -import { - isBinaryCastExpression, - startsWithNoLookaheadToken, -} from "../utilities/index.js"; +import { startsWithNoLookaheadToken } from "../utilities/index.js"; +import { isBinaryCastExpression } from "../utilities/node-types.js"; function shouldAddParenthesesToIdentifier(path) { const { node } = path; diff --git a/src/language-js/parentheses/needs-parentheses.js b/src/language-js/parentheses/needs-parentheses.js index 8e5031e8e..551fd7287 100644 --- a/src/language-js/parentheses/needs-parentheses.js +++ b/src/language-js/parentheses/needs-parentheses.js @@ -7,24 +7,26 @@ import { hasComment, hasNakedLeftSide, hasNode, + isBitwiseOperator, + isNullishCoalescing, + isObjectProperty, + shouldFlatten, + startsWithNoLookaheadToken, + stripChainElementWrappers, +} from "../utilities/index.js"; +import { isArrayExpression, isBinaryCastExpression, - isBitwiseOperator, isCallExpression, isCallOrNewExpression, isConditionalType, isIntersectionType, isMemberExpression, - isNullishCoalescing, isNumericLiteral, isObjectExpression, - isObjectProperty, isReturnOrThrowStatement, isUnionType, - shouldFlatten, - startsWithNoLookaheadToken, - stripChainElementWrappers, -} from "../utilities/index.js"; +} from "../utilities/node-types.js"; import { returnArgumentHasLeadingComment } from "../utilities/return-statement-has-leading-comment.js"; import { shouldAddParenthesesToChainElement } from "./chain-expression.js"; import { shouldAddParenthesesToIdentifier } from "./identifier.js"; diff --git a/src/language-js/print/array.js b/src/language-js/print/array.js index 653289f57..91485f288 100644 --- a/src/language-js/print/array.js +++ b/src/language-js/print/array.js @@ -16,13 +16,15 @@ import { locEnd, locStart } from "../loc.js"; import { CommentCheckFlags, hasComment, + isSignedNumericLiteral, + shouldPrintComma, +} from "../utilities/index.js"; +import { isArrayExpression, isNumericLiteral, isObjectExpression, - isSignedNumericLiteral, isTupleType, - shouldPrintComma, -} from "../utilities/index.js"; +} from "../utilities/node-types.js"; import { printDanglingCommentsInList, printOptionalToken, diff --git a/src/language-js/print/arrow-function.js b/src/language-js/print/arrow-function.js index 414db24d6..0586376c7 100644 --- a/src/language-js/print/arrow-function.js +++ b/src/language-js/print/arrow-function.js @@ -19,15 +19,17 @@ import { getFunctionParameters, hasComment, hasLeadingOwnLineComment, + isTemplateOnItsOwnLine, + shouldPrintComma, + startsWithNoLookaheadToken, +} from "../utilities/index.js"; +import { isArrayExpression, isBinaryish, isCallLikeExpression, isJsxElement, isObjectExpression, - isTemplateOnItsOwnLine, - shouldPrintComma, - startsWithNoLookaheadToken, -} from "../utilities/index.js"; +} from "../utilities/node-types.js"; import { printReturnType, shouldPrintParamsWithoutParens } from "./function.js"; import { printFunctionParameters } from "./function-parameters.js"; diff --git a/src/language-js/print/assignment.js b/src/language-js/print/assignment.js index d8ec2f2a7..30d378a30 100644 --- a/src/language-js/print/assignment.js +++ b/src/language-js/print/assignment.js @@ -13,19 +13,21 @@ import isNonEmptyArray from "../../utilities/is-non-empty-array.js"; import { getCallArguments, hasLeadingOwnLineComment, + isLoneShortArgument, + isObjectProperty, +} from "../utilities/index.js"; +import { isBinaryish, isBooleanLiteral, isCallExpression, isChainElementWrapper, isIntersectionType, - isLoneShortArgument, isMemberExpression, isNumericLiteral, - isObjectProperty, isStringLiteral, isTypeAlias, isUnionType, -} from "../utilities/index.js"; +} from "../utilities/node-types.js"; import { shouldInlineLogicalExpression } from "./binaryish.js"; import { printCallExpression } from "./call-expression.js"; diff --git a/src/language-js/print/await-expression.js b/src/language-js/print/await-expression.js index 0b6c41987..50bd87bda 100644 --- a/src/language-js/print/await-expression.js +++ b/src/language-js/print/await-expression.js @@ -1,9 +1,9 @@ import { group, indent, softline } from "../../document/index.js"; +import { startsWithNoLookaheadToken } from "../utilities/index.js"; import { isCallExpression, isMemberExpression, - startsWithNoLookaheadToken, -} from "../utilities/index.js"; +} from "../utilities/node-types.js"; /** * @import AstPath from "../../common/ast-path.js" diff --git a/src/language-js/print/binaryish.js b/src/language-js/print/binaryish.js index 12655d932..651e1cc4f 100644 --- a/src/language-js/print/binaryish.js +++ b/src/language-js/print/binaryish.js @@ -18,18 +18,20 @@ import { CommentCheckFlags, hasComment, hasLeadingOwnLineComment, - isArrayExpression, - isBinaryish, isBooleanTypeCoercion, - isCallOrNewExpression, - isJsxElement, - isMemberExpression, - isObjectExpression, isObjectProperty, shouldFlatten, } from "../utilities/index.js"; import isTypeCastComment from "../utilities/is-type-cast-comment.js"; -import { isReturnOrThrowStatement } from "../utilities/node-types.js"; +import { + isArrayExpression, + isBinaryish, + isCallOrNewExpression, + isJsxElement, + isMemberExpression, + isObjectExpression, + isReturnOrThrowStatement, +} from "../utilities/node-types.js"; /** @import {Doc} from "../../document/index.js" */ diff --git a/src/language-js/print/call-arguments.js b/src/language-js/print/call-arguments.js index 598e42bf6..d33b3ee28 100644 --- a/src/language-js/print/call-arguments.js +++ b/src/language-js/print/call-arguments.js @@ -16,25 +16,27 @@ import { getCallArgumentSelector, getFunctionParameters, hasComment, + isFunctionCompositionArgs, + isLongCurriedCallExpression, + isNextLineEmpty, + isObjectProperty, + isSimpleCallArgument, + isSimpleType, + iterateCallArgumentsPath, + shouldPrintComma, + stripChainElementWrappers, +} from "../utilities/index.js"; +import { isArrayExpression, isBinaryCastExpression, isBinaryish, isCallExpression, isCallLikeExpression, - isFunctionCompositionArgs, isJsxElement, - isLongCurriedCallExpression, - isNextLineEmpty, isObjectExpression, - isObjectProperty, isRegExpLiteral, - isSimpleCallArgument, - isSimpleType, isStringLiteral, - iterateCallArgumentsPath, - shouldPrintComma, - stripChainElementWrappers, -} from "../utilities/index.js"; +} from "../utilities/node-types.js"; import { isConciselyPrintedArray } from "./array.js"; import { printDanglingCommentsInList } from "./miscellaneous.js"; diff --git a/src/language-js/print/call-expression.js b/src/language-js/print/call-expression.js index d8742f322..ca10b9461 100644 --- a/src/language-js/print/call-expression.js +++ b/src/language-js/print/call-expression.js @@ -3,13 +3,12 @@ import needsParentheses from "../parentheses/needs-parentheses.js"; import { getCallArguments, hasComment, - isCallExpression, isMemberish, isNodeMatches, - isStringLiteral, isTemplateOnItsOwnLine, iterateCallArgumentsPath, } from "../utilities/index.js"; +import { isCallExpression, isStringLiteral } from "../utilities/node-types.js"; import { isTestCall } from "../utilities/test-libraries.js"; import printCallArguments from "./call-arguments.js"; import printMemberChain from "./member-chain.js"; diff --git a/src/language-js/print/cast-expression.js b/src/language-js/print/cast-expression.js index 9c3cf5f57..ff78ff9a6 100644 --- a/src/language-js/print/cast-expression.js +++ b/src/language-js/print/cast-expression.js @@ -1,14 +1,9 @@ import { group, indent, softline } from "../../document/index.js"; import { - createTypeCheckFunction, isCallOrNewExpression, isMemberExpression, -} from "../utilities/index.js"; - -const isSatisfiesExpression = createTypeCheckFunction([ - "SatisfiesExpression", - "TSSatisfiesExpression", -]); + isSatisfiesExpression, +} from "../utilities/node-types.js"; function printBinaryCastExpression(path, options, print) { const { parent, node, key } = path; diff --git a/src/language-js/print/class.js b/src/language-js/print/class.js index c3caa1c7b..4bd7e137c 100644 --- a/src/language-js/print/class.js +++ b/src/language-js/print/class.js @@ -18,9 +18,9 @@ import { CommentCheckFlags, createTypeCheckFunction, hasComment, - isMemberExpression, stripChainElementWrappers, } from "../utilities/index.js"; +import { isMemberExpression } from "../utilities/node-types.js"; import { printAssignment } from "./assignment.js"; import { printClassMemberDecorators } from "./decorators.js"; import { printMethod } from "./function.js"; diff --git a/src/language-js/print/decorators.js b/src/language-js/print/decorators.js index ac0487211..1515f07f4 100644 --- a/src/language-js/print/decorators.js +++ b/src/language-js/print/decorators.js @@ -8,8 +8,8 @@ import { import hasNewline from "../../utilities/has-newline.js"; import isNonEmptyArray from "../../utilities/is-non-empty-array.js"; import { hasSameLocStart, locEnd } from "../loc.js"; -import { isExportDeclaration } from "../utilities/index.js"; import isIgnored from "../utilities/is-ignored.js"; +import { isExportDeclaration } from "../utilities/node-types.js"; function printClassMemberDecorators(path, options, print) { const { node } = path; diff --git a/src/language-js/print/estree.js b/src/language-js/print/estree.js index 66aba617f..35e1e1104 100644 --- a/src/language-js/print/estree.js +++ b/src/language-js/print/estree.js @@ -10,12 +10,14 @@ import UnexpectedNodeError from "../../utilities/unexpected-node-error.js"; import { CommentCheckFlags, hasComment, - isArrayExpression, - isLiteral, isMeaningfulEmptyStatement, isMethod, - isObjectExpression, } from "../utilities/index.js"; +import { + isArrayExpression, + isLiteral, + isObjectExpression, +} from "../utilities/node-types.js"; import { printArray } from "./array.js"; import { printArrowFunction } from "./arrow-function.js"; import { diff --git a/src/language-js/print/function-parameters.js b/src/language-js/print/function-parameters.js index fb338a345..319b17fc8 100644 --- a/src/language-js/print/function-parameters.js +++ b/src/language-js/print/function-parameters.js @@ -14,16 +14,18 @@ import { getFunctionParameters, hasComment, hasRestParameter, - isArrayExpression, isFlowObjectTypePropertyAFunction, isNextLineEmpty, - isObjectExpression, - isObjectType, isSimpleType, isTypeAnnotationAFunction, iterateFunctionParametersPath, shouldPrintComma, } from "../utilities/index.js"; +import { + isArrayExpression, + isObjectExpression, + isObjectType, +} from "../utilities/node-types.js"; import { isTestCall } from "../utilities/test-libraries.js"; import { printDanglingCommentsInList } from "./miscellaneous.js"; diff --git a/src/language-js/print/function.js b/src/language-js/print/function.js index ada6b03ee..616fa731e 100644 --- a/src/language-js/print/function.js +++ b/src/language-js/print/function.js @@ -5,9 +5,9 @@ import { getCallArguments, getFunctionParameters, hasComment, - isCallExpression, isMethod, } from "../utilities/index.js"; +import { isCallExpression } from "../utilities/node-types.js"; import { printFunctionParameters, shouldBreakFunctionParameters, diff --git a/src/language-js/print/intersection-type.js b/src/language-js/print/intersection-type.js index 92626d989..b650e3c7a 100644 --- a/src/language-js/print/intersection-type.js +++ b/src/language-js/print/intersection-type.js @@ -1,5 +1,6 @@ import { group, indent, line } from "../../document/index.js"; -import { hasLeadingOwnLineComment, isObjectType } from "../utilities/index.js"; +import { hasLeadingOwnLineComment } from "../utilities/index.js"; +import { isObjectType } from "../utilities/node-types.js"; // `TSIntersectionType` and `IntersectionTypeAnnotation` function printIntersectionType(path, options, print) { diff --git a/src/language-js/print/jsx.js b/src/language-js/print/jsx.js index d40a70ff9..82856a107 100644 --- a/src/language-js/print/jsx.js +++ b/src/language-js/print/jsx.js @@ -28,14 +28,16 @@ import { createTypeCheckFunction, hasComment, hasNodeIgnoreComment, + stripChainElementWrappers, +} from "../utilities/index.js"; +import { isArrayExpression, isBinaryish, isCallExpression, isJsxElement, isObjectExpression, isStringLiteral, - stripChainElementWrappers, -} from "../utilities/index.js"; +} from "../utilities/node-types.js"; /** @import AstPath from "../../common/ast-path.js"; diff --git a/src/language-js/print/key.js b/src/language-js/print/key.js index b457af03c..14ee31623 100644 --- a/src/language-js/print/key.js +++ b/src/language-js/print/key.js @@ -3,7 +3,7 @@ import { printComments } from "../../main/comments/print.js"; import printNumber from "../../utilities/print-number.js"; import printString from "../../utilities/print-string.js"; import getRaw from "../utilities/get-raw.js"; -import { isNumericLiteral, isStringLiteral } from "../utilities/index.js"; +import { isNumericLiteral, isStringLiteral } from "../utilities/node-types.js"; /** @import {Node, NodeMap, NumericLiteral, StringLiteral} from "../types/estree.js" diff --git a/src/language-js/print/member-chain.js b/src/language-js/print/member-chain.js index 915d87133..7fdd0886f 100644 --- a/src/language-js/print/member-chain.js +++ b/src/language-js/print/member-chain.js @@ -16,15 +16,17 @@ import needsParentheses from "../parentheses/needs-parentheses.js"; import { CommentCheckFlags, hasComment, - isCallExpression, - isFunctionOrArrowExpression, isLongCurriedCallExpression, - isMemberExpression, isMemberish, isNextLineEmpty, - isNumericLiteral, isSimpleCallArgument, } from "../utilities/index.js"; +import { + isCallExpression, + isFunctionOrArrowExpression, + isMemberExpression, + isNumericLiteral, +} from "../utilities/node-types.js"; import { printBindExpressionCallee } from "./bind-expression.js"; import printCallArguments from "./call-arguments.js"; import { printMemberLookup } from "./member.js"; diff --git a/src/language-js/print/member.js b/src/language-js/print/member.js index 7ec980284..0685b8fd4 100644 --- a/src/language-js/print/member.js +++ b/src/language-js/print/member.js @@ -7,12 +7,14 @@ import { } from "../../document/index.js"; import { getCallArguments, + stripChainElementWrappers, +} from "../utilities/index.js"; +import { isCallExpression, isChainElementWrapper, isMemberExpression, isNumericLiteral, - stripChainElementWrappers, -} from "../utilities/index.js"; +} from "../utilities/node-types.js"; import { printOptionalToken } from "./miscellaneous.js"; const isCallExpressionWithArguments = (node) => diff --git a/src/language-js/print/miscellaneous.js b/src/language-js/print/miscellaneous.js index b5aa5d616..5788281ec 100644 --- a/src/language-js/print/miscellaneous.js +++ b/src/language-js/print/miscellaneous.js @@ -10,9 +10,11 @@ import { CommentCheckFlags, createTypeCheckFunction, hasComment, +} from "../utilities/index.js"; +import { isCallExpression, isMemberExpression, -} from "../utilities/index.js"; +} from "../utilities/node-types.js"; /** @import AstPath from "../../common/ast-path.js" diff --git a/src/language-js/print/module.js b/src/language-js/print/module.js index 41da353cf..db7f451a8 100644 --- a/src/language-js/print/module.js +++ b/src/language-js/print/module.js @@ -18,10 +18,10 @@ import { createTypeCheckFunction, hasComment, isShorthandSpecifier, - isStringLiteral, needsHardlineAfterDanglingComment, shouldPrintComma, } from "../utilities/index.js"; +import { isStringLiteral } from "../utilities/node-types.js"; import { printDecoratorsBeforeExport } from "./decorators.js"; import { printDeclareToken } from "./miscellaneous.js"; import { printObject } from "./object.js"; diff --git a/src/language-js/print/object.js b/src/language-js/print/object.js index 417770b81..a7a1bc99b 100644 --- a/src/language-js/print/object.js +++ b/src/language-js/print/object.js @@ -19,9 +19,9 @@ import { getComments, hasComment, isNextLineEmpty, - isObjectType, shouldPrintComma, } from "../utilities/index.js"; +import { isObjectType } from "../utilities/node-types.js"; import { shouldHugTheOnlyParameter } from "./function-parameters.js"; import { printDanglingCommentsInList, diff --git a/src/language-js/print/return-statement.js b/src/language-js/print/return-statement.js index 8add1e05f..4efcf2277 100644 --- a/src/language-js/print/return-statement.js +++ b/src/language-js/print/return-statement.js @@ -6,11 +6,8 @@ import { softline, } from "../../document/index.js"; import { printDanglingComments } from "../../main/comments/print.js"; -import { - CommentCheckFlags, - hasComment, - isBinaryish, -} from "../utilities/index.js"; +import { CommentCheckFlags, hasComment } from "../utilities/index.js"; +import { isBinaryish } from "../utilities/node-types.js"; import { returnArgumentHasLeadingComment } from "../utilities/return-statement-has-leading-comment.js"; /** diff --git a/src/language-js/print/sequence-expression.js b/src/language-js/print/sequence-expression.js index 6cf9e030f..99c323ce2 100644 --- a/src/language-js/print/sequence-expression.js +++ b/src/language-js/print/sequence-expression.js @@ -7,7 +7,7 @@ import { softline, } from "../../document/index.js"; import needsParentheses from "../parentheses/needs-parentheses.js"; -import { isReturnOrThrowStatement } from "../utilities/index.js"; +import { isReturnOrThrowStatement } from "../utilities/node-types.js"; function shouldIndentSequenceExpression(path, options) { const { key, parent } = path; diff --git a/src/language-js/print/template-literal.js b/src/language-js/print/template-literal.js index 61caf78af..867ed76e0 100644 --- a/src/language-js/print/template-literal.js +++ b/src/language-js/print/template-literal.js @@ -19,11 +19,13 @@ import { CommentCheckFlags, getComments, hasComment, + stripChainElementWrappers, +} from "../utilities/index.js"; +import { isBinaryCastExpression, isBinaryish, isMemberExpression, - stripChainElementWrappers, -} from "../utilities/index.js"; +} from "../utilities/node-types.js"; /** * @import {Doc} from "../../document/index.js" diff --git a/src/language-js/print/ternary-old.js b/src/language-js/print/ternary-old.js index 290506037..28ec1efc3 100644 --- a/src/language-js/print/ternary-old.js +++ b/src/language-js/print/ternary-old.js @@ -13,7 +13,7 @@ import { isChainElementWrapper, isJsxElement, isMemberExpression, -} from "../utilities/index.js"; +} from "../utilities/node-types.js"; /** * @import {Doc} from "../../document/index.js" diff --git a/src/language-js/print/ternary.js b/src/language-js/print/ternary.js index 32fc1fa2c..93d289cb1 100644 --- a/src/language-js/print/ternary.js +++ b/src/language-js/print/ternary.js @@ -16,17 +16,19 @@ import { CommentCheckFlags, getComments, hasComment, + isLoneShortArgument, + isSimpleExpressionByNodeCount, +} from "../utilities/index.js"; +import isBlockComment from "../utilities/is-block-comment.js"; +import { isBinaryCastExpression, isCallExpression, isChainElementWrapper, isConditionalType, isJsxElement, - isLoneShortArgument, isMemberExpression, isReturnOrThrowStatement, - isSimpleExpressionByNodeCount, -} from "../utilities/index.js"; -import isBlockComment from "../utilities/is-block-comment.js"; +} from "../utilities/node-types.js"; import { printTernaryOld } from "./ternary-old.js"; /** diff --git a/src/language-js/print/type-annotation.js b/src/language-js/print/type-annotation.js index d56a4e7f2..099ddafc2 100644 --- a/src/language-js/print/type-annotation.js +++ b/src/language-js/print/type-annotation.js @@ -1,10 +1,9 @@ import { CommentCheckFlags, hasComment, - isObjectType, isSimpleType, - isUnionType, } from "../utilities/index.js"; +import { isObjectType, isUnionType } from "../utilities/node-types.js"; import { shouldHugUnionType } from "./union-type.js"; /** diff --git a/src/language-js/print/type-assertion.js b/src/language-js/print/type-assertion.js index 9869df5e5..74512d95c 100644 --- a/src/language-js/print/type-assertion.js +++ b/src/language-js/print/type-assertion.js @@ -5,7 +5,10 @@ import { indent, softline, } from "../../document/index.js"; -import { isArrayExpression, isObjectExpression } from "../utilities/index.js"; +import { + isArrayExpression, + isObjectExpression, +} from "../utilities/node-types.js"; /* - `TSTypeAssertion` (TypeScript) diff --git a/src/language-js/print/type-parameters.js b/src/language-js/print/type-parameters.js index 26f50bb53..5e8990ee8 100644 --- a/src/language-js/print/type-parameters.js +++ b/src/language-js/print/type-parameters.js @@ -16,9 +16,9 @@ import { CommentCheckFlags, getFunctionParameters, hasComment, - isObjectType, shouldPrintComma, } from "../utilities/index.js"; +import { isObjectType } from "../utilities/node-types.js"; import { isTestCall } from "../utilities/test-libraries.js"; import { isArrowFunctionVariableDeclarator } from "./assignment.js"; import { diff --git a/src/language-js/print/union-type.js b/src/language-js/print/union-type.js index 85a230e61..5134cd27f 100644 --- a/src/language-js/print/union-type.js +++ b/src/language-js/print/union-type.js @@ -17,11 +17,13 @@ import { createTypeCheckFunction, hasComment, hasLeadingOwnLineComment, + shouldUnionTypePrintOwnComments, +} from "../utilities/index.js"; +import { isConditionalType, isTupleType, isTypeAlias, - shouldUnionTypePrintOwnComments, -} from "../utilities/index.js"; +} from "../utilities/node-types.js"; /** @import {Doc} from "../../document/index.js"; diff --git a/src/language-js/semicolon/semicolon.js b/src/language-js/semicolon/semicolon.js index ed62a76c5..a06ad4f22 100644 --- a/src/language-js/semicolon/semicolon.js +++ b/src/language-js/semicolon/semicolon.js @@ -1,10 +1,7 @@ import needsParentheses from "../parentheses/needs-parentheses.js"; import { shouldPrintParamsWithoutParens } from "../print/function.js"; -import { - getLeftSidePathName, - hasNakedLeftSide, - isJsxElement, -} from "../utilities/index.js"; +import { getLeftSidePathName, hasNakedLeftSide } from "../utilities/index.js"; +import { isJsxElement } from "../utilities/node-types.js"; function shouldPrintLeadingSemicolon(path, options) { if ( diff --git a/src/language-js/types/estree.d.ts b/src/language-js/types/estree.d.ts index dcbc9e1af..b672c237f 100644 --- a/src/language-js/types/estree.d.ts +++ b/src/language-js/types/estree.d.ts @@ -77,3 +77,7 @@ export type RegExpLiteral = export type BigIntLiteral = | NodeMap["BigIntLiteral"] | (NodeMap["Literal"] & { bigint: string }); + +export type BooleanLiteral = + | NodeMap["BigIntLiteral"] + | (NodeMap["BooleanLiteral"] & { value: boolean }); diff --git a/src/language-js/utilities/index.js b/src/language-js/utilities/index.js index 288258736..126fff5ae 100644 --- a/src/language-js/utilities/index.js +++ b/src/language-js/utilities/index.js @@ -22,23 +22,18 @@ import isTsKeywordType from "./is-ts-keyword-type.js"; import { isArrayExpression, isBinaryCastExpression, - isBinaryish, isCallExpression, isCallLikeExpression, - isCallOrNewExpression, isChainElementWrapper, - isConditionalType, - isExportDeclaration, isFunctionOrArrowExpression, isIntersectionType, isJsxElement, isLiteral, isMemberExpression, + isNumericLiteral, isObjectExpression, - isObjectType, - isReturnOrThrowStatement, - isTupleType, - isTypeAlias, + isRegExpLiteral, + isStringLiteral, isUnionType, } from "./node-types.js"; @@ -137,27 +132,9 @@ function isNullishCoalescing(node) { return node.type === "LogicalExpression" && node.operator === "??"; } -/** - * @param {Node} node - * @returns {node is NumericLiteral} - */ -function isNumericLiteral(node) { - return ( - node.type === "NumericLiteral" || - (node.type === "Literal" && typeof node.value === "number") - ); -} - -function isBooleanLiteral(node) { - return ( - node.type === "BooleanLiteral" || - (node.type === "Literal" && typeof node.value === "boolean") - ); -} - /** @param {Node} node -@returns {node is NodeMap["UnaryExpression"]} +@returns {node is NodeMap["UnaryExpression"] & {operator: "+" | "-", argument: NumericLiteral}} */ function isSignedNumericLiteral(node) { return ( @@ -167,43 +144,6 @@ function isSignedNumericLiteral(node) { ); } -/** - * @param {Node} node - * @returns {node is StringLiteral} - */ -function isStringLiteral(node) { - return ( - node?.type === "StringLiteral" || - (node?.type === "Literal" && typeof node.value === "string") - ); -} - -/** - * @param {Node} node - * @returns {node is RegExpLiteral} - */ -function isRegExpLiteral(node) { - return ( - node.type === "RegExpLiteral" || - (node.type === "Literal" && - // @ts-expect-error -- Safe - Boolean(node.regex)) - ); -} - -/** - * @param {Node} node - * @returns {node is BigIntLiteral} - */ -function isBigIntLiteral(node) { - return ( - node.type === "BigIntLiteral" || - (node.type === "Literal" && - // @ts-expect-error -- Safe - Boolean(node.bigint)) - ); -} - const isSingleWordType = createTypeCheckFunction([ "Identifier", "ThisExpression", @@ -1034,52 +974,27 @@ export { hasNode, hasNodeIgnoreComment, hasRestParameter, - isArrayExpression, - isBigIntLiteral, - isBinaryCastExpression, - isBinaryish, isBitwiseOperator, - isBooleanLiteral, isBooleanTypeCoercion, - isCallExpression, - isCallLikeExpression, - isCallOrNewExpression, - isChainElementWrapper, - isConditionalType, - isExportDeclaration, isFlowObjectTypePropertyAFunction, isFunctionCompositionArgs, - isFunctionOrArrowExpression, isIifeCalleeOrTaggedTemplateExpressionTag, - isIntersectionType, - isJsxElement, - isLiteral, isLoneShortArgument, isLongCurriedCallExpression, - isMemberExpression, isMemberish, isMethod, isNextLineEmpty, isNullishCoalescing, - isNumericLiteral, - isObjectExpression, isObjectProperty, - isObjectType, isPrettierIgnoreComment, - isRegExpLiteral, - isReturnOrThrowStatement, isShorthandSpecifier, isSignedNumericLiteral, isSimpleCallArgument, isSimpleExpressionByNodeCount, isSimpleType, - isStringLiteral, isTemplateOnItsOwnLine, isTsAsConstExpression, - isTupleType, - isTypeAlias, isTypeAnnotationAFunction, - isUnionType, iterateCallArgumentsPath, iterateFunctionParametersPath, needsHardlineAfterDanglingComment, diff --git a/src/language-js/utilities/literal.js b/src/language-js/utilities/literal.js new file mode 100644 index 000000000..9eb87d63b --- /dev/null +++ b/src/language-js/utilities/literal.js @@ -0,0 +1,79 @@ +/** +@import { + Node, + NodeMap, + Comment, + NumericLiteral, + StringLiteral, + RegExpLiteral, + BigIntLiteral, + BooleanLiteral, +} from "../types/estree.js"; +*/ + +/** + * @param {Node} node + * @returns {node is BigIntLiteral} + */ +function isBigIntLiteral(node) { + return ( + node.type === "BigIntLiteral" || + (node.type === "Literal" && + // @ts-expect-error -- Safe + Boolean(node.bigint)) + ); +} + +/** + * @param {Node} node + * @returns {node is BooleanLiteral} + */ +function isBooleanLiteral(node) { + return ( + node.type === "BooleanLiteral" || + (node.type === "Literal" && typeof node.value === "boolean") + ); +} + +/** + * @param {Node} node + * @returns {node is NumericLiteral} + */ +function isNumericLiteral(node) { + return ( + node.type === "NumericLiteral" || + (node.type === "Literal" && typeof node.value === "number") + ); +} + +/** + * @param {Node} node + * @returns {node is RegExpLiteral} + */ +function isRegExpLiteral(node) { + return ( + node.type === "RegExpLiteral" || + (node.type === "Literal" && + // @ts-expect-error -- Safe + Boolean(node.regex)) + ); +} + +/** + * @param {Node} node + * @returns {node is StringLiteral} + */ +function isStringLiteral(node) { + return ( + node?.type === "StringLiteral" || + (node?.type === "Literal" && typeof node.value === "string") + ); +} + +export { + isBigIntLiteral, + isBooleanLiteral, + isNumericLiteral, + isRegExpLiteral, + isStringLiteral, +}; diff --git a/src/language-js/utilities/node-types.js b/src/language-js/utilities/node-types.js index 864ff3aa4..db2c24efd 100644 --- a/src/language-js/utilities/node-types.js +++ b/src/language-js/utilities/node-types.js @@ -1,5 +1,17 @@ import createTypeCheckFunction from "./create-type-check-function.js"; +/** +@import { + Node, + NodeMap, + Comment, + NumericLiteral, + StringLiteral, + RegExpLiteral, + BigIntLiteral, +} from "../types/estree.js"; +*/ + export const isBinaryCastExpression = createTypeCheckFunction([ // TS "TSAsExpression", @@ -10,6 +22,11 @@ export const isBinaryCastExpression = createTypeCheckFunction([ "SatisfiesExpression", ]); +export const isSatisfiesExpression = createTypeCheckFunction([ + "SatisfiesExpression", + "TSSatisfiesExpression", +]); + export const isUnionType = createTypeCheckFunction([ "TSUnionType", "UnionTypeAnnotation", @@ -114,3 +131,5 @@ export const isChainElementWrapper = createTypeCheckFunction([ "ChainExpression", "TSNonNullExpression", ]); + +export * from "./literal.js"; diff --git a/src/language-js/utilities/return-statement-has-leading-comment.js b/src/language-js/utilities/return-statement-has-leading-comment.js index 9e304e448..ff81453aa 100644 --- a/src/language-js/utilities/return-statement-has-leading-comment.js +++ b/src/language-js/utilities/return-statement-has-leading-comment.js @@ -6,8 +6,8 @@ import { hasComment, hasLeadingOwnLineComment, hasNakedLeftSide, - isJsxElement, } from "./index.js"; +import { isJsxElement } from "./node-types.js"; // This recurses the return argument, looking for the first token // (the leftmost leaf node) and, if it (or its parents) has any diff --git a/src/language-js/utilities/test-libraries.js b/src/language-js/utilities/test-libraries.js index 224590511..e52c4ceb6 100644 --- a/src/language-js/utilities/test-libraries.js +++ b/src/language-js/utilities/test-libraries.js @@ -1,11 +1,11 @@ +import { getCallArguments, getFunctionParameters } from "./index.js"; +import isNodeMatches from "./is-node-matches.js"; import { - getCallArguments, - getFunctionParameters, + isCallExpression, + isFunctionOrArrowExpression, isNumericLiteral, isStringLiteral, -} from "./index.js"; -import isNodeMatches from "./is-node-matches.js"; -import { isCallExpression, isFunctionOrArrowExpression } from "./node-types.js"; +} from "./node-types.js"; /** @import {