Socket
Socket
Sign inDemoInstall

ts-api-utils

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-api-utils - npm Package Compare versions

Comparing version 0.0.29 to 0.0.30

74

lib/index.d.ts

@@ -186,7 +186,8 @@ import * as ts from 'typescript';

declare const enum ScopeBoundary {
None = 0,
Function = 1
}
declare function isFunctionScopeBoundary(node: ts.Node): ScopeBoundary;
/**
* Is the node a scope boundary, specifically due to it being a function.
*
* @category Scopes
*/
declare function isFunctionScopeBoundary(node: ts.Node): boolean;

@@ -213,2 +214,61 @@ declare function isAssignmentKind(kind: ts.SyntaxKind): boolean;

/**
* `LiteralType` from typescript except that it allows for it to work on arbitrary types.
*
* @category Type Types
*/
interface UnknownLiteralType extends ts.Type {
freshType: UnknownLiteralType;
regularType: UnknownLiteralType;
value: unknown;
}
/**
* A boolean literal.
*
* @category Type Types
*/
interface BooleanLiteralType extends UnknownLiteralType {
value: boolean;
}
/**
* A "true" literal.
*
* @category Type Types
*/
interface TrueLiteralType extends BooleanLiteralType {
value: true;
}
/**
* A "false" literal.
*
* @category Type Types
*/
interface FalseLiteralType extends BooleanLiteralType {
value: false;
}
/**
* Test if a type is a {@link UnknownLiteralType}?
*
* @param type
* @returns
*/
declare function isUnknownLiteralType(type: ts.Type): type is UnknownLiteralType;
/**
* Determines whether the given type is a boolean literal type.
*
* @category Types - Utilities
*/
declare function isBooleanLiteralType(type: ts.Type): type is BooleanLiteralType;
/**
* Determines whether the given type is a boolean literal type for "true".
*
* @category Types - Utilities
*/
declare function isTrueLiteralType(type: ts.Type): type is TrueLiteralType;
/**
* Determines whether the given type is a boolean literal type for "false".
*
* @category Types - Utilities
*/
declare function isFalseLiteralType(type: ts.Type): type is FalseLiteralType;
declare function isTupleTypeReference(type: ts.Type): type is ts.TupleTypeReference;

@@ -240,4 +300,2 @@

/** Determines whether the given type is a boolean literal type and matches the given boolean literal. */
declare function isBooleanLiteralType(type: ts.Type, literal: boolean): boolean;
/** Determines whether a type is definitely falsy. This function doesn't unwrap union types. */

@@ -257,2 +315,2 @@ declare function isFalsyType(type: ts.Type): boolean;

export { AnyKeyword, BigIntKeyword, BooleanCompilerOptions, BooleanKeyword, ConstAssertionExpression, ConstAssertionIdentifier, FalseKeyword, ForEachCommentCallback, ForEachTokenCallback, ImportKeyword, NamedDeclarationWithName, NeverKeyword, NullKeyword, NumberKeyword, NumericOrStringLikeLiteral, ObjectKeyword, ScopeBoundary, SomeTypePartCallback, SomeTypePartPredicate, StrictCompilerOption, StringKeyword, SuperKeyword, SymbolKeyword, ThisKeyword, TrueKeyword, UndefinedKeyword, UnknownKeyword, 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, 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, isLiteralType, 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, isTupleType, isTupleTypeReference, isTypeFlagSet, isTypeOnlyCompatibleAliasDeclaration, isTypeParameter, isTypeReference, isTypeReferenceType, isTypeVariable, isUndefinedKeyword, isUnionOrIntersectionType, isUnionOrIntersectionTypeNode, isUnionType, isUniqueESSymbolType, isUnknownKeyword, 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, 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, isLiteralType, 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 };

90

lib/index.js

@@ -568,7 +568,2 @@ // src/comments.ts

import * as ts9 from "typescript";
var ScopeBoundary = /* @__PURE__ */ ((ScopeBoundary2) => {
ScopeBoundary2[ScopeBoundary2["None"] = 0] = "None";
ScopeBoundary2[ScopeBoundary2["Function"] = 1] = "Function";
return ScopeBoundary2;
})(ScopeBoundary || {});
function isFunctionScopeBoundary(node) {

@@ -592,7 +587,7 @@ switch (node.kind) {

case ts9.SyntaxKind.FunctionType:
return 1 /* Function */;
return true;
case ts9.SyntaxKind.SourceFile:
return ts9.isExternalModule(node) ? 1 /* Function */ : 0 /* None */;
return ts9.isExternalModule(node);
default:
return 0 /* None */;
return false;
}

@@ -627,2 +622,5 @@ }

// src/types/getters.ts
import * as ts14 from "typescript";
// src/types/typeGuards/compound.ts
import * as ts13 from "typescript";

@@ -705,2 +703,14 @@

// src/types/typeGuards/compound.ts
function isUnknownLiteralType(type) {
return isTypeFlagSet(type, ts13.TypeFlags.Literal);
}
function isBooleanLiteralType(type) {
return isTypeFlagSet(type, ts13.TypeFlags.BooleanLiteral);
}
function isTrueLiteralType(type) {
return isBooleanLiteralType(type) && type.intrinsicName === "true";
}
function isFalseLiteralType(type) {
return isBooleanLiteralType(type) && type.intrinsicName === "false";
}
function isTupleTypeReference(type) {

@@ -745,3 +755,3 @@ return isTypeReference(type) && isTupleType(type.target);

const declaration = prop.valueDeclaration ?? prop.getDeclarations()[0];
if (!isNamedDeclarationWithName(declaration) || declaration.name === void 0 || !ts13.isComputedPropertyName(declaration.name)) {
if (!isNamedDeclarationWithName(declaration) || declaration.name === void 0 || !ts14.isComputedPropertyName(declaration.name)) {
continue;

@@ -777,8 +787,8 @@ }

// src/types/utilities.ts
import * as ts15 from "typescript";
import * as ts16 from "typescript";
// src/nodes/utilities.ts
import * as ts14 from "typescript";
import * as ts15 from "typescript";
function isBindableObjectDefinePropertyCall(node) {
return node.arguments.length === 3 && isEntityNameExpression(node.arguments[0]) && isNumericOrStringLikeLiteral(node.arguments[1]) && ts14.isPropertyAccessExpression(node.expression) && node.expression.name.escapedText === "defineProperty" && ts14.isIdentifier(node.expression.expression) && node.expression.expression.escapedText === "Object";
return node.arguments.length === 3 && isEntityNameExpression(node.arguments[0]) && isNumericOrStringLikeLiteral(node.arguments[1]) && ts15.isPropertyAccessExpression(node.expression) && node.expression.name.escapedText === "defineProperty" && ts15.isIdentifier(node.expression.expression) && node.expression.expression.escapedText === "Object";
}

@@ -791,11 +801,11 @@ function isInConstContext(node) {

switch (parent.kind) {
case ts14.SyntaxKind.TypeAssertionExpression:
case ts14.SyntaxKind.AsExpression:
case ts15.SyntaxKind.TypeAssertionExpression:
case ts15.SyntaxKind.AsExpression:
return isConstAssertionExpression(parent);
case ts14.SyntaxKind.PrefixUnaryExpression:
if (current.kind !== ts14.SyntaxKind.NumericLiteral)
case ts15.SyntaxKind.PrefixUnaryExpression:
if (current.kind !== ts15.SyntaxKind.NumericLiteral)
return false;
switch (parent.operator) {
case ts14.SyntaxKind.PlusToken:
case ts14.SyntaxKind.MinusToken:
case ts15.SyntaxKind.PlusToken:
case ts15.SyntaxKind.MinusToken:
current = parent;

@@ -806,3 +816,3 @@ break outer;

}
case ts14.SyntaxKind.PropertyAssignment:
case ts15.SyntaxKind.PropertyAssignment:
if (parent.initializer !== current)

@@ -812,9 +822,9 @@ return false;

break;
case ts14.SyntaxKind.ShorthandPropertyAssignment:
case ts15.SyntaxKind.ShorthandPropertyAssignment:
current = parent.parent;
break;
case ts14.SyntaxKind.ParenthesizedExpression:
case ts14.SyntaxKind.ArrayLiteralExpression:
case ts14.SyntaxKind.ObjectLiteralExpression:
case ts14.SyntaxKind.TemplateExpression:
case ts15.SyntaxKind.ParenthesizedExpression:
case ts15.SyntaxKind.ArrayLiteralExpression:
case ts15.SyntaxKind.ObjectLiteralExpression:
case ts15.SyntaxKind.TemplateExpression:
current = parent;

@@ -829,11 +839,11 @@ break;

// src/types/utilities.ts
function isBooleanLiteralType(type, literal) {
return isTypeFlagSet(type, ts15.TypeFlags.BooleanLiteral) && type.intrinsicName === (literal ? "true" : "false");
}
function isFalsyType(type) {
if (type.flags & (ts15.TypeFlags.Undefined | ts15.TypeFlags.Null | ts15.TypeFlags.Void))
if (isTypeFlagSet(
type,
ts16.TypeFlags.Undefined | ts16.TypeFlags.Null | ts16.TypeFlags.Void
))
return true;
if (isLiteralType(type))
return !type.value;
return isBooleanLiteralType(type, false);
return isFalseLiteralType(type);
}

@@ -845,3 +855,3 @@ function isReadonlyPropertyIntersection(type, name, typeChecker) {

return false;
if (prop.flags & ts15.SymbolFlags.Transient) {
if (prop.flags & ts16.SymbolFlags.Transient) {
if (/^(?:[1-9]\d*|0)$/.test(name) && isTupleTypeReference(subType))

@@ -857,11 +867,11 @@ return subType.target.readonly;

}
return !!(isSymbolFlagSet(prop, ts15.SymbolFlags.ValueModule) || symbolHasReadonlyDeclaration(prop, typeChecker));
return !!(isSymbolFlagSet(prop, ts16.SymbolFlags.ValueModule) || symbolHasReadonlyDeclaration(prop, typeChecker));
});
}
function isReadonlyPropertyFromMappedType(type, name, typeChecker) {
if (!isObjectType(type) || !isObjectFlagSet(type, ts15.ObjectFlags.Mapped))
if (!isObjectType(type) || !isObjectFlagSet(type, ts16.ObjectFlags.Mapped))
return;
const declaration = type.symbol.declarations[0];
if (declaration.readonlyToken !== void 0 && !/^__@[^@]+$/.test(name))
return declaration.readonlyToken.kind !== ts15.SyntaxKind.MinusToken;
return declaration.readonlyToken.kind !== ts16.SyntaxKind.MinusToken;
const { modifiersType } = type;

@@ -890,3 +900,3 @@ return modifiersType && isPropertyReadonlyInType(modifiersType, name, typeChecker);

if (getPropertyOfType(subType, name) === void 0) {
const index = (isNumericPropertyName(name) ? typeChecker.getIndexInfoOfType(subType, ts15.IndexKind.Number) : void 0) ?? typeChecker.getIndexInfoOfType(subType, ts15.IndexKind.String);
const index = (isNumericPropertyName(name) ? typeChecker.getIndexInfoOfType(subType, ts16.IndexKind.Number) : void 0) ?? typeChecker.getIndexInfoOfType(subType, ts16.IndexKind.String);
if (index?.isReadonly) {

@@ -914,4 +924,4 @@ if (seenProperty)

return false;
const writableType = writableProp.valueDeclaration !== void 0 && ts15.isPropertyAssignment(writableProp.valueDeclaration) ? typeChecker.getTypeAtLocation(writableProp.valueDeclaration.initializer) : typeChecker.getTypeOfSymbolAtLocation(writableProp, node.arguments[2]);
return isBooleanLiteralType(writableType, false);
const writableType = writableProp.valueDeclaration !== void 0 && ts16.isPropertyAssignment(writableProp.valueDeclaration) ? typeChecker.getTypeAtLocation(writableProp.valueDeclaration.initializer) : typeChecker.getTypeOfSymbolAtLocation(writableProp, node.arguments[2]);
return isFalseLiteralType(writableType);
}

@@ -935,4 +945,4 @@ function isThenableType(typeChecker, node, type = typeChecker.getTypeAtLocation(node)) {

function symbolHasReadonlyDeclaration(symbol, typeChecker) {
return !!((symbol.flags & ts15.SymbolFlags.Accessor) === ts15.SymbolFlags.GetAccessor || symbol.declarations?.some(
(node) => isModifierFlagSet(node, ts15.ModifierFlags.Readonly) || ts15.isVariableDeclaration(node) && isNodeFlagSet(node.parent, ts15.NodeFlags.Const) || ts15.isCallExpression(node) && isReadonlyAssignmentDeclaration(node, typeChecker) || ts15.isEnumMember(node) || (ts15.isPropertyAssignment(node) || ts15.isShorthandPropertyAssignment(node)) && isInConstContext(node.parent)
return !!((symbol.flags & ts16.SymbolFlags.Accessor) === ts16.SymbolFlags.GetAccessor || symbol.declarations?.some(
(node) => isModifierFlagSet(node, ts16.ModifierFlags.Readonly) || ts16.isVariableDeclaration(node) && isNodeFlagSet(node.parent, ts16.NodeFlags.Const) || ts16.isCallExpression(node) && isReadonlyAssignmentDeclaration(node, typeChecker) || ts16.isEnumMember(node) || (ts16.isPropertyAssignment(node) || ts16.isShorthandPropertyAssignment(node)) && isInConstContext(node.parent)
));

@@ -944,3 +954,2 @@ }

export {
ScopeBoundary,
forEachComment,

@@ -1001,2 +1010,3 @@ forEachToken,

isFalseLiteral,
isFalseLiteralType,
isFalsyType,

@@ -1093,2 +1103,3 @@ isForInOrOfStatement,

isTrueLiteral,
isTrueLiteralType,
isTupleType,

@@ -1108,2 +1119,3 @@ isTupleTypeReference,

isUnknownKeyword,
isUnknownLiteralType,
isUnparsedPrologue,

@@ -1110,0 +1122,0 @@ isUnparsedSourceText,

{
"name": "ts-api-utils",
"version": "0.0.29",
"version": "0.0.30",
"description": "Utility functions for working with TypeScript's API. Successor to the wonderful tsutils.",

@@ -84,3 +84,3 @@ "repository": {

},
"packageManager": "pnpm@7.27.0",
"packageManager": "pnpm@7.27.1",
"engines": {

@@ -87,0 +87,0 @@ "node": ">=16.13.0"

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc