Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-api-utils

Package Overview
Dependencies
Maintainers
1
Versions
40
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.26 to 0.0.27

2

lib/index.d.ts

@@ -45,3 +45,3 @@ import * as ts from 'typescript';

interface NamedDeclarationWithName extends ts.NamedDeclaration {
name: NonNullable<ts.NamedDeclaration["name"]>;
name: ts.DeclarationName;
}

@@ -48,0 +48,0 @@ declare function isNamedDeclarationWithName(node: ts.Declaration): node is NamedDeclarationWithName;

@@ -596,2 +596,5 @@ // src/comments.ts

// src/types/getters.ts
import * as ts12 from "typescript";
// src/types/typeGuards/objects.ts

@@ -707,8 +710,11 @@ import * as ts11 from "typescript";

for (const prop of type.getProperties()) {
if (!prop.name.startsWith(prefix))
if (!prop.name.startsWith(prefix)) {
continue;
}
const declaration = prop.valueDeclaration ?? prop.getDeclarations()[0];
if (!isNamedDeclarationWithName(declaration) || declaration.name === void 0 || !ts12.isComputedPropertyName(declaration.name)) {
continue;
}
const globalSymbol = typeChecker.getApparentType(
typeChecker.getTypeAtLocation(
prop.valueDeclaration.name.expression
)
typeChecker.getTypeAtLocation(declaration.name.expression)
).symbol;

@@ -740,8 +746,8 @@ if (prop.escapedName === getPropertyNameOfWellKnownSymbol(

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

@@ -754,11 +760,11 @@ function isInConstContext(node) {

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

@@ -769,3 +775,3 @@ break outer;

}
case ts12.SyntaxKind.PropertyAssignment:
case ts13.SyntaxKind.PropertyAssignment:
if (parent.initializer !== current)

@@ -775,9 +781,9 @@ return false;

break;
case ts12.SyntaxKind.ShorthandPropertyAssignment:
case ts13.SyntaxKind.ShorthandPropertyAssignment:
current = parent.parent;
break;
case ts12.SyntaxKind.ParenthesizedExpression:
case ts12.SyntaxKind.ArrayLiteralExpression:
case ts12.SyntaxKind.ObjectLiteralExpression:
case ts12.SyntaxKind.TemplateExpression:
case ts13.SyntaxKind.ParenthesizedExpression:
case ts13.SyntaxKind.ArrayLiteralExpression:
case ts13.SyntaxKind.ObjectLiteralExpression:
case ts13.SyntaxKind.TemplateExpression:
current = parent;

@@ -793,6 +799,6 @@ break;

function isBooleanLiteralType(type, literal) {
return isTypeFlagSet(type, ts13.TypeFlags.BooleanLiteral) && type.intrinsicName === (literal ? "true" : "false");
return isTypeFlagSet(type, ts14.TypeFlags.BooleanLiteral) && type.intrinsicName === (literal ? "true" : "false");
}
function isFalsyType(type) {
if (type.flags & (ts13.TypeFlags.Undefined | ts13.TypeFlags.Null | ts13.TypeFlags.Void))
if (type.flags & (ts14.TypeFlags.Undefined | ts14.TypeFlags.Null | ts14.TypeFlags.Void))
return true;

@@ -808,3 +814,3 @@ if (isLiteralType(type))

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

@@ -820,11 +826,11 @@ return subType.target.readonly;

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

@@ -853,3 +859,3 @@ return modifiersType && isPropertyReadonlyInType(modifiersType, name, typeChecker);

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

@@ -877,3 +883,3 @@ if (seenProperty)

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

@@ -898,4 +904,4 @@ }

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

@@ -902,0 +908,0 @@ }

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

@@ -5,0 +5,0 @@ "repository": {

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