Refactor node type check functions (#18758)
This commit is contained in:
1 parent
8cdcd486ef
commit
f58d550470
45 files changed
+245
-208
No files matched your search
@@ -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";
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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",
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
isCallExpression,
|
||||
isChainElementWrapper,
|
||||
isMemberExpression,
|
||||
} from "../utilities/index.js";
|
||||
} from "../utilities/node-types.js";
|
||||
|
||||
/**
|
||||
@import {Node} from "../types/estree.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";
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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" */
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ import {
|
||||
getCallArguments,
|
||||
getFunctionParameters,
|
||||
hasComment,
|
||||
isCallExpression,
|
||||
isMethod,
|
||||
} from "../utilities/index.js";
|
||||
import { isCallExpression } from "../utilities/node-types.js";
|
||||
import {
|
||||
printFunctionParameters,
|
||||
shouldBreakFunctionParameters,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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) =>
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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";
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
isChainElementWrapper,
|
||||
isJsxElement,
|
||||
isMemberExpression,
|
||||
} from "../utilities/index.js";
|
||||
} from "../utilities/node-types.js";
|
||||
|
||||
/**
|
||||
* @import {Doc} from "../../document/index.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";
|
||||
|
||||
/**
|
||||
|
||||
@@ -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";
|
||||
|
||||
/**
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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 (
|
||||
|
||||
Vendored
+4
@@ -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 });
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
@@ -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";
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user