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

jsdoc-type-pratt-parser

Package Overview
Dependencies
Maintainers
2
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsdoc-type-pratt-parser - npm Package Compare versions

Comparing version 3.2.0-dev.1 to 3.2.0-dev.2

dist/src/parslets/ObjectSquaredPropertyParslet.d.ts

7

dist/src/assertTypes.d.ts

@@ -1,4 +0,4 @@

import { KeyValueResult } from './result/NonRootResult';
import { NameResult, NumberResult, RootResult, VariadicResult } from './result/RootResult';
import { IntermediateResult } from './result/IntermediateResult';
import { type IndexSignatureResult, type KeyValueResult, type MappedTypeResult } from './result/NonRootResult';
import { type NameResult, type NumberResult, type RootResult, type VariadicResult } from './result/RootResult';
import { type IntermediateResult } from './result/IntermediateResult';
/**

@@ -12,1 +12,2 @@ * Throws an error if the provided result is not a {@link RootResult}

export declare function assertNumberOrVariadicNameResult(result: IntermediateResult): NumberResult | NameResult | VariadicResult<NameResult>;
export declare function isSquaredProperty(result: IntermediateResult): result is IndexSignatureResult | MappedTypeResult;

@@ -1,2 +0,2 @@

export type TokenType = '(' | ')' | '[' | ']' | '{' | '}' | '|' | '&' | '<' | '>' | ';' | ',' | '*' | '?' | '!' | '=' | ':' | '.' | '@' | '#' | '~' | '/' | '=>' | '...' | 'null' | 'undefined' | 'function' | 'this' | 'new' | 'module' | 'event' | 'external' | 'typeof' | 'keyof' | 'readonly' | 'import' | 'is' | 'Identifier' | 'StringValue' | 'Number' | 'EOF';
export type TokenType = '(' | ')' | '[' | ']' | '{' | '}' | '|' | '&' | '<' | '>' | ';' | ',' | '*' | '?' | '!' | '=' | ':' | '.' | '@' | '#' | '~' | '/' | '=>' | '...' | 'null' | 'undefined' | 'function' | 'this' | 'new' | 'module' | 'event' | 'external' | 'typeof' | 'keyof' | 'readonly' | 'import' | 'is' | 'in' | 'Identifier' | 'StringValue' | 'Number' | 'EOF';
export interface Token {

@@ -3,0 +3,0 @@ type: TokenType;

import { type ParsletFunction } from './Parslet';
export declare function createObjectFieldParslet({ allowKeyTypes, allowReadonly, allowOptional }: {
export declare function createObjectFieldParslet({ allowSquaredProperties, allowKeyTypes, allowReadonly, allowOptional }: {
allowSquaredProperties: boolean;
allowKeyTypes: boolean;

@@ -4,0 +5,0 @@ allowOptional: boolean;

@@ -1,4 +0,4 @@

import { ParsletFunction } from './Parslet';
import { type ParsletFunction } from './Parslet';
export declare function createTupleParslet({ allowQuestionMark }: {
allowQuestionMark: boolean;
}): ParsletFunction;

@@ -5,6 +5,6 @@ import { type QuoteStyle, type RootResult } from './RootResult';

*/
export type NonRootResult = RootResult | PropertyResult | ObjectFieldResult | JsdocObjectFieldResult | KeyValueResult;
export type NonRootResult = RootResult | PropertyResult | ObjectFieldResult | JsdocObjectFieldResult | KeyValueResult | MappedTypeResult | IndexSignatureResult;
export interface ObjectFieldResult {
type: 'JsdocTypeObjectField';
key: string;
key: string | MappedTypeResult | IndexSignatureResult;
right: RootResult | undefined;

@@ -40,1 +40,11 @@ optional: boolean;

}
export interface IndexSignatureResult {
type: 'JsdocTypeIndexSignature';
key: string;
right: RootResult;
}
export interface MappedTypeResult {
type: 'JsdocTypeMappedType';
key: string;
right: RootResult;
}

@@ -1,2 +0,2 @@

import { RootResult } from '../result/RootResult';
import { type RootResult } from '../result/RootResult';
export declare const reservedWords: string[];

@@ -3,0 +3,0 @@ interface ModifiableResult {

@@ -1,2 +0,2 @@

import { RootResult } from '../result/RootResult';
import { type RootResult } from '../result/RootResult';
export type JtpResult = JtpNameResult | JtpNullableResult | JtpNotNullableResult | JtpOptionalResult | JtpVariadicResult | JtpTypeOfResult | JtpTupleResult | JtpKeyOfResult | JtpStringValueResult | JtpImportResult | JtpAnyResult | JtpUnknownResult | JtpFunctionResult | JtpGenericResult | JtpRecordEntryResult | JtpRecordResult | JtpMemberResult | JtpUnionResult | JtpParenthesisResult | JtpNamedParameterResult | JtpModuleResult | JtpFilePath | JtpIntersectionResult | JtpNumberResult;

@@ -3,0 +3,0 @@ type JtpQuoteStyle = 'single' | 'double' | 'none';

@@ -1,2 +0,2 @@

import { NonRootResult } from './result/NonRootResult';
import { type NonRootResult } from './result/NonRootResult';
export type VisitorKeys = {

@@ -3,0 +3,0 @@ [P in NonRootResult as P['type']]: Array<keyof P>;

{
"name": "jsdoc-type-pratt-parser",
"version": "3.2.0-dev.1",
"version": "3.2.0-dev.2",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -1,5 +0,5 @@

import { KeyValueResult } from './result/NonRootResult'
import { type IndexSignatureResult, type KeyValueResult, type MappedTypeResult } from './result/NonRootResult'
import { UnexpectedTypeError } from './errors'
import { NameResult, NumberResult, RootResult, VariadicResult } from './result/RootResult'
import { IntermediateResult } from './result/IntermediateResult'
import { type NameResult, type NumberResult, type RootResult, type VariadicResult } from './result/RootResult'
import { type IntermediateResult } from './result/IntermediateResult'

@@ -16,3 +16,4 @@ /**

result.type === 'JsdocTypeProperty' || result.type === 'JsdocTypeReadonlyProperty' ||
result.type === 'JsdocTypeObjectField' || result.type === 'JsdocTypeJsdocObjectField'
result.type === 'JsdocTypeObjectField' || result.type === 'JsdocTypeJsdocObjectField' ||
result.type === 'JsdocTypeIndexSignature' || result.type === 'JsdocTypeMappedType'
) {

@@ -57,1 +58,5 @@ throw new UnexpectedTypeError(result)

}
export function isSquaredProperty (result: IntermediateResult): result is IndexSignatureResult | MappedTypeResult {
return result.type === 'JsdocTypeIndexSignature' || result.type === 'JsdocTypeMappedType'
}

@@ -21,3 +21,3 @@ import { baseGrammar } from './baseGrammar'

createNameParslet({
allowedAdditionalTokens: ['module', 'keyof', 'event', 'external']
allowedAdditionalTokens: ['module', 'keyof', 'event', 'external', 'in']
}),

@@ -29,2 +29,3 @@ nullableParslet,

createObjectFieldParslet({
allowSquaredProperties: false,
allowKeyTypes: false,

@@ -43,3 +44,3 @@ allowOptional: false,

createNameParslet({
allowedAdditionalTokens: ['event', 'external']
allowedAdditionalTokens: ['event', 'external', 'in']
}),

@@ -46,0 +47,0 @@ typeOfParslet,

@@ -51,5 +51,6 @@ import { baseGrammar } from './baseGrammar'

createNameParslet({
allowedAdditionalTokens: ['module']
allowedAdditionalTokens: ['module', 'in']
}),
createObjectFieldParslet({
allowSquaredProperties: false,
allowKeyTypes: true,

@@ -56,0 +57,0 @@ allowOptional: false,

@@ -25,2 +25,3 @@ import { baseGrammar } from './baseGrammar'

import { createKeyValueParslet } from '../parslets/KeyValueParslet'
import { objectSquaredPropertyParslet } from '../parslets/ObjectSquaredPropertyParslet'

@@ -30,3 +31,3 @@ const objectFieldGrammar: Grammar = [

createNameParslet({
allowedAdditionalTokens: ['module', 'event', 'keyof', 'event', 'external']
allowedAdditionalTokens: ['module', 'event', 'keyof', 'event', 'external', 'in']
}),

@@ -38,6 +39,8 @@ nullableParslet,

createObjectFieldParslet({
allowSquaredProperties: true,
allowKeyTypes: false,
allowOptional: true,
allowReadonly: true
})
}),
objectSquaredPropertyParslet
]

@@ -69,3 +72,3 @@

createNameParslet({
allowedAdditionalTokens: ['event', 'external']
allowedAdditionalTokens: ['event', 'external', 'in']
}),

@@ -72,0 +75,0 @@ createSpecialNamePathParslet({

@@ -169,2 +169,3 @@ import { type Token, type TokenType } from './Token'

makeKeyWordRule('is'),
makeKeyWordRule('in'),
numberRule,

@@ -171,0 +172,0 @@ identifierRule,

@@ -39,2 +39,3 @@ export type TokenType =

| 'is'
| 'in'
| 'Identifier'

@@ -41,0 +42,0 @@ | 'StringValue'

import { composeParslet, type ParsletFunction } from './Parslet'
import { Precedence } from '../Precedence'
import { UnexpectedTypeError } from '../errors'
import { assertRootResult } from '../assertTypes'
import { assertRootResult, isSquaredProperty } from '../assertTypes'
export function createObjectFieldParslet ({ allowKeyTypes, allowReadonly, allowOptional }: {
export function createObjectFieldParslet ({ allowSquaredProperties, allowKeyTypes, allowReadonly, allowOptional }: {
allowSquaredProperties: boolean
allowKeyTypes: boolean

@@ -33,3 +34,10 @@ allowOptional: boolean

if (left.type === 'JsdocTypeNumber' || left.type === 'JsdocTypeName' || left.type === 'JsdocTypeStringValue') {
if (
left.type === 'JsdocTypeNumber' || left.type === 'JsdocTypeName' || left.type === 'JsdocTypeStringValue' ||
isSquaredProperty(left)
) {
if (isSquaredProperty(left) && !allowSquaredProperties) {
throw new UnexpectedTypeError(left)
}
parentParser.consume(':')

@@ -47,3 +55,3 @@

type: 'JsdocTypeObjectField',
key: left.value.toString(),
key: isSquaredProperty(left) ? left : left.value.toString(),
right,

@@ -50,0 +58,0 @@ optional,

import { assertPlainKeyValueResult, assertRootResult } from '../assertTypes'
import { composeParslet, ParsletFunction } from './Parslet'
import { composeParslet, type ParsletFunction } from './Parslet'
import { Precedence } from '../Precedence'
import { TupleResult } from '../result/RootResult'
import { IntermediateResult } from '../result/IntermediateResult'
import { type TupleResult } from '../result/RootResult'
import { type IntermediateResult } from '../result/IntermediateResult'

@@ -7,0 +7,0 @@ export function createTupleParslet ({ allowQuestionMark }: {

@@ -15,6 +15,8 @@ import {

| KeyValueResult
| MappedTypeResult
| IndexSignatureResult
export interface ObjectFieldResult {
type: 'JsdocTypeObjectField'
key: string
key: string | MappedTypeResult | IndexSignatureResult
right: RootResult | undefined

@@ -53,1 +55,13 @@ optional: boolean

}
export interface IndexSignatureResult {
type: 'JsdocTypeIndexSignature'
key: string
right: RootResult
}
export interface MappedTypeResult {
type: 'JsdocTypeMappedType'
key: string
right: RootResult
}

@@ -1,4 +0,4 @@

import { extractSpecialParams, notAvailableTransform, transform, TransformRules } from './transform'
import { extractSpecialParams, notAvailableTransform, transform, type TransformRules } from './transform'
import { assertRootResult } from '../assertTypes'
import { RootResult } from '../result/RootResult'
import { type RootResult } from '../result/RootResult'
import { quote } from './stringify'

@@ -236,7 +236,12 @@

JsdocTypeObjectField: (result, transform) => ({
type: 'FieldType',
key: makeName(quote(result.key, result.meta.quote)),
value: result.right === undefined ? undefined : transform(result.right)
}),
JsdocTypeObjectField: (result, transform) => {
if (typeof result.key !== 'string') {
throw new Error('Index signatures and mapped types are not supported')
}
return {
type: 'FieldType',
key: makeName(quote(result.key, result.meta.quote)),
value: result.right === undefined ? undefined : transform(result.right)
}
},

@@ -306,2 +311,4 @@ JsdocTypeJsdocObjectField: (result, transform) => ({

JsdocTypeMappedType: notAvailableTransform,
JsdocTypeIndexSignature: notAvailableTransform,
JsdocTypeImport: notAvailableTransform,

@@ -308,0 +315,0 @@ JsdocTypeKeyof: notAvailableTransform,

@@ -183,4 +183,16 @@ import { type TransformRules } from './transform'

right: transform(result.right) as RootResult
}),
JsdocTypeIndexSignature: (result, transform) => ({
type: 'JsdocTypeIndexSignature',
key: result.key,
right: transform(result.right) as RootResult
}),
JsdocTypeMappedType: (result, transform) => ({
type: 'JsdocTypeMappedType',
key: result.key,
right: transform(result.right) as RootResult
})
}
}

@@ -1,5 +0,5 @@

import { extractSpecialParams, notAvailableTransform, transform, TransformRules } from './transform'
import { QuoteStyle, RootResult } from '../result/RootResult'
import { extractSpecialParams, notAvailableTransform, transform, type TransformRules } from './transform'
import { type QuoteStyle, type RootResult } from '../result/RootResult'
import { assertRootResult } from '../assertTypes'
import { NonRootResult } from '../result/NonRootResult'
import { type NonRootResult } from '../result/NonRootResult'

@@ -362,2 +362,6 @@ export type JtpResult =

JsdocTypeObjectField: (result, transform) => {
if (typeof result.key !== 'string') {
throw new Error('Index signatures and mapped types are not supported')
}
if (result.right === undefined) {

@@ -519,3 +523,7 @@ return {

JsdocTypePredicate: notAvailableTransform
JsdocTypePredicate: notAvailableTransform,
JsdocTypeMappedType: notAvailableTransform,
JsdocTypeIndexSignature: notAvailableTransform
}

@@ -522,0 +530,0 @@

@@ -97,3 +97,8 @@ import { transform, type TransformRules } from './transform'

}
text += quote(result.key, result.meta.quote)
if (typeof result.key === 'string') {
text += quote(result.key, result.meta.quote)
} else {
text += transform(result.key)
}
if (result.optional) {

@@ -158,3 +163,7 @@ text += '?'

JsdocTypePredicate: (result, transform) => `${transform(result.left)} is ${transform(result.right)}`
JsdocTypePredicate: (result, transform) => `${transform(result.left)} is ${transform(result.right)}`,
JsdocTypeIndexSignature: (result, transform) => `[${result.key}: ${transform(result.right)}]`,
JsdocTypeMappedType: (result, transform) => `[${result.key} in ${transform(result.right)}]`
}

@@ -161,0 +170,0 @@ }

@@ -1,2 +0,2 @@

import { NonRootResult } from './result/NonRootResult'
import { type NonRootResult } from './result/NonRootResult'

@@ -12,5 +12,7 @@ export type VisitorKeys = {

JsdocTypeImport: [],
JsdocTypeIndexSignature: ['right'],
JsdocTypeIntersection: ['elements'],
JsdocTypeKeyof: ['element'],
JsdocTypeKeyValue: ['right'],
JsdocTypeMappedType: ['right'],
JsdocTypeName: [],

@@ -17,0 +19,0 @@ JsdocTypeNamePath: ['left', 'right'],

Sorry, the diff of this file is too big to display

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