jsdoc-type-pratt-parser
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -7,6 +7,7 @@ import { ParsletFunction } from './Parslet'; | ||
export declare function getUnnamedParameters(value: IntermediateResult): RootResult[]; | ||
export declare function createFunctionParslet({ allowNamedParameters, allowNoReturnType, allowWithoutParenthesis }: { | ||
export declare function createFunctionParslet({ allowNamedParameters, allowNoReturnType, allowWithoutParenthesis, allowNewAsFunctionKeyword }: { | ||
allowNamedParameters?: string[]; | ||
allowWithoutParenthesis: boolean; | ||
allowNoReturnType: boolean; | ||
allowNewAsFunctionKeyword: boolean; | ||
}): ParsletFunction; |
import { ParsletFunction } from './Parslet'; | ||
export declare function createKeyValueParslet({ allowKeyTypes, allowReadonly, allowOptional }: { | ||
export declare function createKeyValueParslet({ allowKeyTypes, allowReadonly, allowOptional, allowVariadic }: { | ||
allowKeyTypes: boolean; | ||
allowOptional: boolean; | ||
allowReadonly: boolean; | ||
allowVariadic: boolean; | ||
}): ParsletFunction; |
@@ -17,2 +17,3 @@ import { QuoteStyle, RootResult } from './RootResult'; | ||
readonly: boolean; | ||
variadic: boolean; | ||
meta: { | ||
@@ -19,0 +20,0 @@ quote: QuoteStyle | undefined; |
@@ -123,2 +123,3 @@ import { JsdocObjectKeyValueResult, KeyValueResult, PropertyResult } from './NonRootResult'; | ||
returnType?: RootResult; | ||
constructor: boolean; | ||
arrow: boolean; | ||
@@ -125,0 +126,0 @@ parenthesis: boolean; |
@@ -6,3 +6,3 @@ import 'mocha'; | ||
export declare type CompareMode = ParseMode | 'fail' | 'differ'; | ||
export interface Fixture { | ||
interface BaseFixture { | ||
/** | ||
@@ -12,6 +12,2 @@ * The input that should be parsed | ||
input: string; | ||
/** | ||
* The {@link ParseMode}s that the expression is expected to get parsed in. In all other modes it is expected to fail. | ||
*/ | ||
modes?: ParseMode[]; | ||
jtp?: { | ||
@@ -28,6 +24,2 @@ [K in JtpMode]: CompareMode; | ||
expected?: RootResult; | ||
error?: string; | ||
errors?: { | ||
[K in ParseMode]?: string; | ||
}; | ||
/** | ||
@@ -45,2 +37,16 @@ * The expected parse results objects for different modes. If a mode is included in `modes` and as a key of | ||
} | ||
declare type SuccessFixture = BaseFixture & { | ||
/** | ||
* The {@link ParseMode}s that the expression is expected to get parsed in. In all other modes it is expected to fail. | ||
*/ | ||
modes: ParseMode[]; | ||
}; | ||
declare type ErrorFixture = BaseFixture & ({ | ||
error: string; | ||
} | { | ||
errors: { | ||
[K in ParseMode]?: string; | ||
}; | ||
}); | ||
export declare type Fixture = SuccessFixture | ErrorFixture; | ||
/** | ||
@@ -50,1 +56,2 @@ * Function to run all relevant tests for a {@link Fixture}. | ||
export declare function testFixture(fixture: Fixture): void; | ||
export {}; |
{ | ||
"name": "jsdoc-type-pratt-parser", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -29,3 +29,4 @@ import { baseGrammar } from './baseGrammar' | ||
allowOptional: false, | ||
allowReadonly: false | ||
allowReadonly: false, | ||
allowVariadic: false | ||
}) | ||
@@ -47,3 +48,4 @@ ] | ||
allowNamedParameters: ['this', 'new'], | ||
allowNoReturnType: true | ||
allowNoReturnType: true, | ||
allowNewAsFunctionKeyword: false | ||
}), | ||
@@ -69,5 +71,6 @@ createVariadicParslet({ | ||
allowOptional: false, | ||
allowReadonly: false | ||
allowReadonly: false, | ||
allowVariadic: false | ||
}), | ||
symbolParslet | ||
] |
@@ -20,3 +20,4 @@ import { baseGrammar } from './baseGrammar' | ||
allowNamedParameters: ['this', 'new'], | ||
allowNoReturnType: true | ||
allowNoReturnType: true, | ||
allowNewAsFunctionKeyword: false | ||
}), | ||
@@ -44,3 +45,4 @@ stringValueParslet, | ||
allowOptional: false, | ||
allowReadonly: false | ||
allowReadonly: false, | ||
allowVariadic: false | ||
}) | ||
@@ -47,0 +49,0 @@ ] |
@@ -37,3 +37,4 @@ import { baseGrammar } from './baseGrammar' | ||
allowOptional: true, | ||
allowReadonly: true | ||
allowReadonly: true, | ||
allowVariadic: false | ||
}) | ||
@@ -55,3 +56,4 @@ ] | ||
allowNoReturnType: false, | ||
allowNamedParameters: ['this', 'new'] | ||
allowNamedParameters: ['this', 'new', 'args'], | ||
allowNewAsFunctionKeyword: true | ||
}), | ||
@@ -81,3 +83,4 @@ createTupleParslet({ | ||
allowOptional: true, | ||
allowReadonly: true | ||
allowReadonly: true, | ||
allowVariadic: true | ||
}), | ||
@@ -84,0 +87,0 @@ intersectionParslet, |
@@ -16,2 +16,3 @@ import { composeParslet } from './Parslet' | ||
arrow: true, | ||
constructor: false, | ||
parenthesis: true, | ||
@@ -18,0 +19,0 @@ returnType: parser.parseType(Precedence.OBJECT) |
@@ -30,11 +30,13 @@ import { composeParslet, ParsletFunction } from './Parslet' | ||
export function createFunctionParslet ({ allowNamedParameters, allowNoReturnType, allowWithoutParenthesis }: { | ||
export function createFunctionParslet ({ allowNamedParameters, allowNoReturnType, allowWithoutParenthesis, allowNewAsFunctionKeyword }: { | ||
allowNamedParameters?: string[] | ||
allowWithoutParenthesis: boolean | ||
allowNoReturnType: boolean | ||
allowNewAsFunctionKeyword: boolean | ||
}): ParsletFunction { | ||
return composeParslet({ | ||
name: 'functionParslet', | ||
accept: type => type === 'function', | ||
accept: (type, next) => type === 'function' || (allowNewAsFunctionKeyword && type === 'new' && next === '('), | ||
parsePrefix: parser => { | ||
const newKeyword = parser.consume('new') | ||
parser.consume('function') | ||
@@ -55,6 +57,7 @@ | ||
const result: FunctionResult = { | ||
let result: FunctionResult = { | ||
type: 'JsdocTypeFunction', | ||
parameters: [], | ||
arrow: false, | ||
constructor: newKeyword, | ||
parenthesis: hasParenthesis | ||
@@ -67,2 +70,6 @@ } | ||
result.parameters = getUnnamedParameters(value) | ||
} else if (newKeyword && value.type === 'JsdocTypeFunction' && value.arrow) { | ||
result = value | ||
result.constructor = true | ||
return result | ||
} else { | ||
@@ -69,0 +76,0 @@ result.parameters = getParameters(value) |
@@ -6,6 +6,7 @@ import { composeParslet, ParsletFunction } from './Parslet' | ||
export function createKeyValueParslet ({ allowKeyTypes, allowReadonly, allowOptional }: { | ||
export function createKeyValueParslet ({ allowKeyTypes, allowReadonly, allowOptional, allowVariadic }: { | ||
allowKeyTypes: boolean | ||
allowOptional: boolean | ||
allowReadonly: boolean | ||
allowVariadic: boolean | ||
}): ParsletFunction { | ||
@@ -19,2 +20,3 @@ return composeParslet({ | ||
let readonlyProperty = false | ||
let variadic = false | ||
@@ -31,2 +33,7 @@ if (allowOptional && left.type === 'JsdocTypeNullable') { | ||
if (allowVariadic && left.type === 'JsdocTypeVariadic' && left.element !== undefined) { | ||
variadic = true | ||
left = left.element | ||
} | ||
// object parslet uses a special grammar and for the value we want to switch back to the parent | ||
@@ -50,5 +57,6 @@ const parentParser = parser.parent ?? parser | ||
key: left.value.toString(), | ||
right: right, | ||
optional: optional, | ||
right, | ||
optional, | ||
readonly: readonlyProperty, | ||
variadic, | ||
meta: { | ||
@@ -55,0 +63,0 @@ quote, |
@@ -57,2 +57,3 @@ import { composeParslet, ParsletFunction } from './Parslet' | ||
readonly: false, | ||
variadic: false, | ||
meta: { | ||
@@ -59,0 +60,0 @@ quote, |
@@ -23,2 +23,3 @@ import { QuoteStyle, RootResult } from './RootResult' | ||
readonly: boolean | ||
variadic: boolean | ||
meta: { | ||
@@ -25,0 +26,0 @@ quote: QuoteStyle | undefined |
@@ -163,2 +163,3 @@ import { JsdocObjectKeyValueResult, KeyValueResult, PropertyResult } from './NonRootResult' | ||
returnType?: RootResult | ||
constructor: boolean | ||
arrow: boolean | ||
@@ -165,0 +166,0 @@ parenthesis: boolean |
@@ -100,2 +100,3 @@ import { TransformRules } from './transform' | ||
readonly: result.readonly, | ||
variadic: result.variadic, | ||
meta: result.meta | ||
@@ -152,2 +153,3 @@ } | ||
parameters: result.parameters.map(transform) as RootResult[], | ||
constructor: result.constructor, | ||
parenthesis: result.parenthesis | ||
@@ -154,0 +156,0 @@ } |
@@ -29,3 +29,3 @@ import { transform, TransformRules } from './transform' | ||
if (!result.arrow) { | ||
let stringified = 'function' | ||
let stringified = result.constructor ? 'new' : 'function' | ||
if (!result.parenthesis) { | ||
@@ -43,3 +43,7 @@ return stringified | ||
} | ||
return `(${result.parameters.map(transform).join(', ')}) => ${transform(result.returnType)}` | ||
let stringified = `(${result.parameters.map(transform).join(', ')}) => ${transform(result.returnType)}` | ||
if (result.constructor) { | ||
stringified = 'new ' + stringified | ||
} | ||
return stringified | ||
} | ||
@@ -101,2 +105,5 @@ }, | ||
} | ||
if (result.variadic) { | ||
text = '...' + text | ||
} | ||
@@ -103,0 +110,0 @@ if (result.right === undefined) { |
Sorry, the diff of this file is too big to display
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
229471
6341