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

typescript-is

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-is - npm Package Compare versions

Comparing version 0.7.0 to 0.7.1

64

lib/transform-inline/visitor.js

@@ -30,3 +30,3 @@ "use strict";

}
function visitPropertySignature(node, accessor, visitorContext) {
function visitPropertySignature(node, accessor, checkProperty, visitorContext) {
if (node.type === undefined) {

@@ -36,7 +36,12 @@ throw new Error('Visiting property without type.');

const type = visitorContext.checker.getTypeFromTypeNode(node.type);
return createPropertyCheck(accessor, visitPropertyName(node.name, accessor, visitorContext), type, node.questionToken !== undefined, visitorContext);
if (checkProperty) {
return createPropertyCheck(accessor, visitPropertyName(node.name, accessor, visitorContext), type, node.questionToken !== undefined, visitorContext);
}
else {
return visitType(type, accessor, visitorContext);
}
}
function visitDeclaration(node, accessor, visitorContext) {
function visitDeclaration(node, accessor, checkProperty, visitorContext) {
if (ts.isPropertySignature(node)) {
return visitPropertySignature(node, accessor, visitorContext);
return visitPropertySignature(node, accessor, checkProperty, visitorContext);
}

@@ -61,2 +66,18 @@ else {

}
function visitPropertySymbol(property, accessor, visitorContext) {
const conditions = [];
if ('valueDeclaration' in property) {
conditions.push(visitDeclaration(property.valueDeclaration, accessor, true, visitorContext));
}
else {
// Using internal TypeScript API, hacky.
const propertyType = property.type;
const propertyName = property.name;
const optional = (property.flags & ts.SymbolFlags.Optional) !== 0;
if (propertyType !== undefined && propertyName !== undefined) {
conditions.push(createPropertyCheck(accessor, ts.createStringLiteral(propertyName), propertyType, optional, visitorContext));
}
}
return conditions.reduce((condition, expression) => ts.createBinary(condition, ts.SyntaxKind.AmpersandAmpersandToken, expression));
}
function visitRegularObjectType(type, accessor, visitorContext) {

@@ -104,14 +125,3 @@ const mappers = [];

for (const property of visitorContext.checker.getPropertiesOfType(type)) {
if ('valueDeclaration' in property) {
conditions.push(visitDeclaration(property.valueDeclaration, accessor, visitorContext));
}
else {
// Using internal TypeScript API, hacky.
const propertyType = property.type;
const propertyName = property.name;
const optional = (property.flags & ts.SymbolFlags.Optional) !== 0;
if (propertyType !== undefined && propertyName !== undefined) {
conditions.push(createPropertyCheck(accessor, ts.createStringLiteral(propertyName), propertyType, optional, visitorContext));
}
}
conditions.push(visitPropertySymbol(property, accessor, visitorContext));
}

@@ -219,2 +229,21 @@ const stringIndexType = visitorContext.checker.getIndexTypeOfType(type, ts.IndexKind.String);

}
function visitIndexedAccessType(type, accessor, visitorContext) {
const typeMapper = visitorContext.typeMapperStack[visitorContext.typeMapperStack.length - 1];
// Using internal TypeScript API, hacky.
let indexedType = type.indexType.type;
if (indexedType === undefined) {
throw new Error('Could not get indexed type of indexed access type.');
}
// Make sure we resolve type parameters.
indexedType = typeMapper(indexedType) || indexedType;
const indexedProperties = visitorContext.checker.getPropertiesOfType(indexedType);
if (indexedProperties.length >= 1) {
return indexedProperties
.map((property) => visitDeclaration(property.valueDeclaration, accessor, false, visitorContext))
.reduce((condition, expression) => ts.createBinary(condition, ts.SyntaxKind.BarBarToken, expression));
}
else {
return ts.createFalse();
}
}
function visitType(type, accessor, visitorContext) {

@@ -277,2 +306,5 @@ if ((ts.TypeFlags.Any & type.flags) !== 0) {

}
else if (tsutils.isIndexedAccessType(type)) {
return visitIndexedAccessType(type, accessor, visitorContext);
}
else {

@@ -279,0 +311,0 @@ throw new Error('Unsupported type with flags: ' + type.flags);

{
"name": "typescript-is",
"version": "0.7.0",
"version": "0.7.1",
"engines": {

@@ -5,0 +5,0 @@ "node": ">=6.14.4"

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