ts-api-utils
Advanced tools
Comparing version 0.0.39 to 0.0.40
@@ -80,7 +80,7 @@ import * as ts from 'typescript'; | ||
/** | ||
* Test if the given iterable contains a modifier of any of the given kinds. | ||
* Test if the given iterable includes a modifier of any of the given kinds. | ||
* | ||
* @category Modifier Utilities | ||
*/ | ||
declare function hasModifier(modifiers: Iterable<ts.Modifier> | undefined, ...kinds: ts.ModifierSyntaxKind[]): boolean; | ||
declare function includesModifier(modifiers: Iterable<ts.Modifier> | undefined, ...kinds: ts.ModifierSyntaxKind[]): boolean; | ||
@@ -155,7 +155,7 @@ /** | ||
/** | ||
* A number or sting literal (including string literals declare with \`\` quotes). | ||
* A number or string-like literal. | ||
* | ||
* @category Node Types | ||
*/ | ||
type NumericOrStringLikeLiteral = ts.NumericLiteral | ts.StringLiteral | ts.NoSubstitutionTemplateLiteral; | ||
type NumericOrStringLikeLiteral = ts.NumericLiteral | ts.StringLiteralLike; | ||
/** | ||
@@ -1357,22 +1357,2 @@ * Test if a node is a {@link NumericOrStringLikeLiteral}. | ||
/** | ||
* Used by {@link someTypePart}. | ||
* | ||
* @category Callbacks | ||
*/ | ||
type SomeTypePartPredicate = (subType: ts.Type) => subType is ts.UnionOrIntersectionType; | ||
/** | ||
* Used by {@link someTypePart}. | ||
* | ||
* @category Callbacks | ||
*/ | ||
type SomeTypePartCallback = (subType: ts.Type) => boolean; | ||
/** | ||
* If the given predicate holds for the given type, | ||
* test that some type part of that union or intersection passes the callback test. | ||
* Otherwise, test the give type itself with the callback. | ||
* | ||
* @category Types - Utilities | ||
*/ | ||
declare function someTypePart(type: ts.Type, predicate: SomeTypePartPredicate, callback: SomeTypePartCallback): boolean; | ||
/** | ||
* Test if the given symbol has a readonly declaration. | ||
@@ -1392,2 +1372,2 @@ * | ||
export { AnyKeyword, BigIntKeyword, BooleanCompilerOptions, BooleanKeyword, BooleanLiteralType, ConstAssertionExpression, ConstAssertionIdentifier, FalseKeyword, FalseLiteralType, ForEachCommentCallback, ForEachTokenCallback, ImportKeyword, NamedDeclarationWithName, NeverKeyword, NullKeyword, NumberKeyword, NumericOrStringLikeLiteral, ObjectKeyword, SomeTypePartCallback, SomeTypePartPredicate, StrictCompilerOption, StringKeyword, SuperKeyword, SymbolKeyword, ThisKeyword, TrueKeyword, TrueLiteralType, UndefinedKeyword, UnknownKeyword, UnknownLiteralType, VoidKeyword, forEachComment, forEachToken, getCallSignaturesOfType, getPropertyOfType, getWellKnownSymbolPropertyOfType, hasModifier, isAbstractKeyword, isAccessExpression, isAccessibilityModifier, isAccessorDeclaration, isAccessorKeyword, isAnyKeyword, isArrayBindingElement, isArrayBindingOrAssignmentPattern, isAssertKeyword, isAssertsKeyword, isAssignmentKind, isAssignmentPattern, isAsyncKeyword, isAwaitKeyword, isBigIntKeyword, isBigIntLiteralType, isBindingOrAssignmentElementRestIndicator, isBindingOrAssignmentElementTarget, isBindingOrAssignmentPattern, isBindingPattern, isBlockLike, isBooleanKeyword, isBooleanLiteral, isBooleanLiteralType, isClassLikeDeclaration, isClassMemberModifier, isColonToken, isCompilerOptionEnabled, isConditionalType, isConstAssertionExpression, isConstKeyword, isDeclarationName, isDeclarationWithTypeParameterChildren, isDeclarationWithTypeParameters, isDeclareKeyword, isDefaultKeyword, isDestructuringPattern, isDotToken, isEndOfFileToken, isEntityNameExpression, isEntityNameOrEntityNameExpression, isEnumType, isEqualsGreaterThanToken, isEqualsToken, isEvolvingArrayType, isExclamationToken, isExportKeyword, isFalseKeyword, isFalseLiteral, isFalseLiteralType, isFalsyType, isForInOrOfStatement, isFunctionLikeDeclaration, isFunctionScopeBoundary, isHasDecorators, isHasExpressionInitializer, isHasInitializer, isHasJSDoc, isHasModifiers, isHasType, isHasTypeArguments, isImportExpression, isImportKeyword, isInKeyword, isIndexType, isIndexedAccessType, isInputFiles, isInstantiableType, isIntersectionType, isIterationStatement, isJSDocComment, isJSDocNamespaceBody, isJSDocNamespaceDeclaration, isJSDocText, isJSDocTypeReferencingNode, isJsonMinusNumericLiteral, isJsonObjectExpression, isJsxAttributeLike, isJsxAttributeValue, isJsxChild, isJsxTagNameExpression, isJsxTagNamePropertyAccess, isLiteralToken, isModifierFlagSet, isModuleBody, isModuleName, isModuleReference, isNamedDeclarationWithName, isNamedImportBindings, isNamedImportsOrExports, isNamespaceBody, isNamespaceDeclaration, isNeverKeyword, isNodeFlagSet, isNullKeyword, isNullLiteral, isNumberKeyword, isNumberLiteralType, isNumericOrStringLikeLiteral, isNumericPropertyName, isObjectBindingOrAssignmentElement, isObjectBindingOrAssignmentPattern, isObjectFlagSet, isObjectKeyword, isObjectType, isObjectTypeDeclaration, isOutKeyword, isOverrideKeyword, isParameterPropertyModifier, isPrivateKeyword, isPropertyAccessEntityNameExpression, isPropertyNameLiteral, isPropertyReadonlyInType, isProtectedKeyword, isPseudoLiteralToken, isPublicKeyword, isQuestionDotToken, isQuestionToken, isReadonlyKeyword, isSignatureDeclaration, isStaticKeyword, isStrictCompilerOptionEnabled, isStringKeyword, isStringLiteralType, isStringMappingType, isSubstitutionType, isSuperElementAccessExpression, isSuperExpression, isSuperKeyword, isSuperProperty, isSuperPropertyAccessExpression, isSymbolFlagSet, isSymbolKeyword, isSyntaxList, isTemplateLiteralType, isThenableType, isThisExpression, isThisKeyword, isTrueKeyword, isTrueLiteral, isTrueLiteralType, isTupleType, isTupleTypeReference, isTypeFlagSet, isTypeOnlyCompatibleAliasDeclaration, isTypeParameter, isTypeReference, isTypeReferenceType, isTypeVariable, isUndefinedKeyword, isUnionOrIntersectionType, isUnionOrIntersectionTypeNode, isUnionType, isUniqueESSymbolType, isUnknownKeyword, isUnknownLiteralType, isUnparsedPrologue, isUnparsedSourceText, isUnparsedSyntheticReference, isValidPropertyAccess, isVariableLikeDeclaration, isVoidKeyword, someTypePart, symbolHasReadonlyDeclaration, unionTypeParts }; | ||
export { AnyKeyword, BigIntKeyword, BooleanCompilerOptions, BooleanKeyword, BooleanLiteralType, ConstAssertionExpression, ConstAssertionIdentifier, FalseKeyword, FalseLiteralType, ForEachCommentCallback, ForEachTokenCallback, ImportKeyword, NamedDeclarationWithName, NeverKeyword, NullKeyword, NumberKeyword, NumericOrStringLikeLiteral, ObjectKeyword, StrictCompilerOption, StringKeyword, SuperKeyword, SymbolKeyword, ThisKeyword, TrueKeyword, TrueLiteralType, UndefinedKeyword, UnknownKeyword, UnknownLiteralType, VoidKeyword, forEachComment, forEachToken, getCallSignaturesOfType, getPropertyOfType, getWellKnownSymbolPropertyOfType, includesModifier, isAbstractKeyword, isAccessExpression, isAccessibilityModifier, isAccessorDeclaration, isAccessorKeyword, isAnyKeyword, isArrayBindingElement, isArrayBindingOrAssignmentPattern, isAssertKeyword, isAssertsKeyword, isAssignmentKind, isAssignmentPattern, isAsyncKeyword, isAwaitKeyword, isBigIntKeyword, isBigIntLiteralType, isBindingOrAssignmentElementRestIndicator, isBindingOrAssignmentElementTarget, isBindingOrAssignmentPattern, isBindingPattern, isBlockLike, isBooleanKeyword, isBooleanLiteral, isBooleanLiteralType, isClassLikeDeclaration, isClassMemberModifier, isColonToken, isCompilerOptionEnabled, isConditionalType, isConstAssertionExpression, isConstKeyword, isDeclarationName, isDeclarationWithTypeParameterChildren, isDeclarationWithTypeParameters, isDeclareKeyword, isDefaultKeyword, isDestructuringPattern, isDotToken, isEndOfFileToken, isEntityNameExpression, isEntityNameOrEntityNameExpression, isEnumType, isEqualsGreaterThanToken, isEqualsToken, isEvolvingArrayType, isExclamationToken, isExportKeyword, isFalseKeyword, isFalseLiteral, isFalseLiteralType, isFalsyType, isForInOrOfStatement, isFunctionLikeDeclaration, isFunctionScopeBoundary, isHasDecorators, isHasExpressionInitializer, isHasInitializer, isHasJSDoc, isHasModifiers, isHasType, isHasTypeArguments, isImportExpression, isImportKeyword, isInKeyword, isIndexType, isIndexedAccessType, isInputFiles, isInstantiableType, isIntersectionType, isIterationStatement, isJSDocComment, isJSDocNamespaceBody, isJSDocNamespaceDeclaration, isJSDocText, isJSDocTypeReferencingNode, isJsonMinusNumericLiteral, isJsonObjectExpression, isJsxAttributeLike, isJsxAttributeValue, isJsxChild, isJsxTagNameExpression, isJsxTagNamePropertyAccess, isLiteralToken, isModifierFlagSet, isModuleBody, isModuleName, isModuleReference, isNamedDeclarationWithName, isNamedImportBindings, isNamedImportsOrExports, isNamespaceBody, isNamespaceDeclaration, isNeverKeyword, isNodeFlagSet, isNullKeyword, isNullLiteral, isNumberKeyword, isNumberLiteralType, isNumericOrStringLikeLiteral, isNumericPropertyName, isObjectBindingOrAssignmentElement, isObjectBindingOrAssignmentPattern, isObjectFlagSet, isObjectKeyword, isObjectType, isObjectTypeDeclaration, isOutKeyword, isOverrideKeyword, isParameterPropertyModifier, isPrivateKeyword, isPropertyAccessEntityNameExpression, isPropertyNameLiteral, isPropertyReadonlyInType, isProtectedKeyword, isPseudoLiteralToken, isPublicKeyword, isQuestionDotToken, isQuestionToken, isReadonlyKeyword, isSignatureDeclaration, isStaticKeyword, isStrictCompilerOptionEnabled, isStringKeyword, isStringLiteralType, isStringMappingType, isSubstitutionType, isSuperElementAccessExpression, isSuperExpression, isSuperKeyword, isSuperProperty, isSuperPropertyAccessExpression, isSymbolFlagSet, isSymbolKeyword, isSyntaxList, isTemplateLiteralType, isThenableType, isThisExpression, isThisKeyword, isTrueKeyword, isTrueLiteral, isTrueLiteralType, isTupleType, isTupleTypeReference, isTypeFlagSet, isTypeOnlyCompatibleAliasDeclaration, isTypeParameter, isTypeReference, isTypeReferenceType, isTypeVariable, isUndefinedKeyword, isUnionOrIntersectionType, isUnionOrIntersectionTypeNode, isUnionType, isUniqueESSymbolType, isUnknownKeyword, isUnknownLiteralType, isUnparsedPrologue, isUnparsedSourceText, isUnparsedSyntheticReference, isValidPropertyAccess, isVariableLikeDeclaration, isVoidKeyword, symbolHasReadonlyDeclaration, unionTypeParts }; |
@@ -21,3 +21,6 @@ // src/comments.ts | ||
callback(node); | ||
} else if (node.kind !== ts2.SyntaxKind.JSDocComment) { | ||
} else if ( | ||
// eslint-disable-next-line deprecation/deprecation -- need for support of TS < 4.7 | ||
node.kind !== ts2.SyntaxKind.JSDocComment | ||
) { | ||
const children = node.getChildren(sourceFile); | ||
@@ -49,3 +52,4 @@ if (children.length === 1) { | ||
case ts3.SyntaxKind.JsxSelfClosingElement: | ||
return token.end !== token.parent.end || !isJsxElementOrFragment(token.parent.parent); | ||
return token.end !== token.parent.end || // if end is not equal, this is part of the type arguments list | ||
!isJsxElementOrFragment(token.parent.parent); | ||
case ts3.SyntaxKind.JsxClosingElement: | ||
@@ -72,2 +76,3 @@ case ts3.SyntaxKind.JsxClosingFragment: | ||
fullText, | ||
// skip shebang at position 0 | ||
token.pos === 0 ? (ts3.getShebang(fullText) ?? "").length : token.pos, | ||
@@ -99,7 +104,13 @@ commentCallback | ||
case "declaration": | ||
return options.declaration || isCompilerOptionEnabled(options, "composite"); | ||
return ( | ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
options.declaration || isCompilerOptionEnabled(options, "composite") | ||
); | ||
case "incremental": | ||
return options.incremental === void 0 ? isCompilerOptionEnabled(options, "composite") : options.incremental; | ||
case "skipDefaultLibCheck": | ||
return options.skipDefaultLibCheck || isCompilerOptionEnabled(options, "skipLibCheck"); | ||
return ( | ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
options.skipDefaultLibCheck || isCompilerOptionEnabled(options, "skipLibCheck") | ||
); | ||
case "suppressImplicitAnyIndexErrors": | ||
@@ -150,3 +161,3 @@ return options.suppressImplicitAnyIndexErrors === true && isCompilerOptionEnabled(options, "noImplicitAny"); | ||
// src/modifiers.ts | ||
function hasModifier(modifiers, ...kinds) { | ||
function includesModifier(modifiers, ...kinds) { | ||
if (modifiers === void 0) | ||
@@ -772,2 +783,3 @@ return false; | ||
symbolConstructor, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access | ||
symbolConstructor.valueDeclaration | ||
@@ -777,2 +789,3 @@ ).getProperty(symbolName); | ||
knownSymbol, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access | ||
knownSymbol.valueDeclaration | ||
@@ -845,3 +858,4 @@ ); | ||
function isReadonlyPropertyIntersection(type, name, typeChecker) { | ||
return someTypePart(type, isIntersectionType, (subType) => { | ||
const typeParts = isIntersectionType(type) ? type.types : [type]; | ||
return typeParts.some((subType) => { | ||
const prop = getPropertyOfType(subType, name); | ||
@@ -861,3 +875,5 @@ if (prop === void 0) | ||
} | ||
return !!(isSymbolFlagSet(prop, ts16.SymbolFlags.ValueModule) || symbolHasReadonlyDeclaration(prop, typeChecker)); | ||
return !!// members of namespace import | ||
(isSymbolFlagSet(prop, ts16.SymbolFlags.ValueModule) || // we unwrapped every mapped type, now we can check the actual declarations | ||
symbolHasReadonlyDeclaration(prop, typeChecker)); | ||
}); | ||
@@ -933,5 +949,2 @@ } | ||
} | ||
function someTypePart(type, predicate, callback) { | ||
return predicate(type) ? type.types.some(callback) : callback(type); | ||
} | ||
function symbolHasReadonlyDeclaration(symbol, typeChecker) { | ||
@@ -951,3 +964,3 @@ return !!((symbol.flags & ts16.SymbolFlags.Accessor) === ts16.SymbolFlags.GetAccessor || symbol.declarations?.some( | ||
getWellKnownSymbolPropertyOfType, | ||
hasModifier, | ||
includesModifier, | ||
isAbstractKeyword, | ||
@@ -1115,5 +1128,4 @@ isAccessExpression, | ||
isVoidKeyword, | ||
someTypePart, | ||
symbolHasReadonlyDeclaration, | ||
unionTypeParts | ||
}; |
{ | ||
"name": "ts-api-utils", | ||
"version": "0.0.39", | ||
"version": "0.0.40", | ||
"description": "Utility functions for working with TypeScript's API. Successor to the wonderful tsutils.", | ||
@@ -68,7 +68,7 @@ "repository": { | ||
"eslint-plugin-typescript-sort-keys": "^2.1.0", | ||
"eslint-plugin-vitest": "^0.0.44", | ||
"eslint-plugin-vitest": "^0.0.48", | ||
"http-serve": "^1.0.1", | ||
"husky": "^8.0.3", | ||
"jsonc-eslint-parser": "^2.1.0", | ||
"knip": "^1.12.3", | ||
"knip": "^1.14.1", | ||
"lint-staged": "^13.1.0", | ||
@@ -96,3 +96,3 @@ "markdownlint": "^0.27.0", | ||
}, | ||
"packageManager": "pnpm@7.27.1", | ||
"packageManager": "pnpm@7.28.0", | ||
"engines": { | ||
@@ -99,0 +99,0 @@ "node": ">=16.13.0" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
203789
3794