Add isTypeAnnotation (#19921)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-08-26 03:29:23 +08:00
1 parent bb52ae36d5
commit 893fd3b120
5 files changed
+16 -11

No files matched your search

+2 -2
View File
@@ -28,6 +28,7 @@ import {
isIntersectionType,
isMemberExpression,
isTypeAlias,
isTypeAnnotation,
isUnionType,
} from "../utilities/node-types.js";
import { stripComments } from "../utilities/strip-comments.js";
@@ -994,8 +995,7 @@ function handleCommentsInDestructuringPattern({
(enclosingNode.type === "ObjectPattern" ||
enclosingNode.type === "ArrayPattern") &&
enclosingNode.typeAnnotation === followingNode &&
(followingNode.type === "TSTypeAnnotation" ||
followingNode.type === "TypeAnnotation")
isTypeAnnotation(followingNode)
) {
if (
getNextNonSpaceNonCommentCharacter(text, locEnd(comment)) ===
+2 -3
View File
@@ -23,6 +23,7 @@ import {
isArrayExpression,
isObjectExpression,
isObjectType,
isTypeAnnotation,
} from "../utilities/node-types.js";
import { isTestCall } from "../utilities/test-libraries.js";
import {
@@ -209,9 +210,7 @@ function shouldHugTheOnlyFunctionParameter(node) {
(parameter.type === "ObjectPattern" ||
parameter.type === "ArrayPattern" ||
(parameter.type === "Identifier" &&
parameter.typeAnnotation &&
(parameter.typeAnnotation.type === "TypeAnnotation" ||
parameter.typeAnnotation.type === "TSTypeAnnotation") &&
isTypeAnnotation(parameter.typeAnnotation) &&
isObjectType(parameter.typeAnnotation.typeAnnotation)) ||
(parameter.type === "FunctionTypeParam" &&
isObjectType(parameter.typeAnnotation) &&
+6 -5
View File
@@ -1,6 +1,10 @@
import { CommentCheckFlags, hasComment } from "../utilities/comments.js";
import { isSimpleType } from "../utilities/is-simple-type.js";
import { isObjectType, isUnionType } from "../utilities/node-types.js";
import {
isObjectType,
isTypeAnnotation,
isUnionType,
} from "../utilities/node-types.js";
import { shouldHugUnionType } from "./union-type.js";
/**
@@ -40,10 +44,7 @@ function printTypeAnnotationProperty(
let shouldPrintLeadingSpace = false;
if (
typeAnnotation.type === "TSTypeAnnotation" ||
typeAnnotation.type === "TypeAnnotation"
) {
if (isTypeAnnotation(typeAnnotation)) {
const firstToken = path.call(getTypeAnnotationFirstToken, propertyName);
if (
@@ -5,7 +5,7 @@ import { hasSameLocStart } from "../location/index.js";
// var f: (a) => void;
function isTypeAnnotationAFunction(node) {
return (
(node.type === "TypeAnnotation" || node.type === "TSTypeAnnotation") &&
node.type === "TypeAnnotation" &&
node.typeAnnotation.type === "FunctionTypeAnnotation" &&
!node.static &&
!hasSameLocStart(node, node.typeAnnotation)
+5
View File
@@ -142,4 +142,9 @@ export const isTypeParameterInstantiation = createTypeCheckFunction([
"TypeParameterInstantiation",
]);
export const isTypeAnnotation = createTypeCheckFunction([
"TSTypeAnnotation",
"TypeAnnotation",
]);
export * from "./literal.js";