From 9609d5a68ce5c4a77fbc33147e13761632bb87c4 Mon Sep 17 00:00:00 2001 From: "Alexey Mulyukin (alexprey)" Date: Fri, 12 Feb 2021 19:10:43 +0300 Subject: [PATCH] Describe module exports in typings.d.ts --- index.js | 4 +++ typings.d.ts | 83 +++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 67 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index dc5cfd9..1a7f813 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ const { loadFileStructureFromOptions } = require('./lib/helpers'); const { validate, retrieveFileOptions } = require('./lib/options'); const SvelteVersionDetector = require('./lib/detector'); +const { SVELTE_VERSION_2, SVELTE_VERSION_3 } = require('./lib/detector'); /** * @typedef {import("./typings").SvelteParserOptions} SvelteParserOptions @@ -215,3 +216,6 @@ module.exports.detectVersion = (options) => { return SvelteVersionDetector.detectVersionFromOptions(options); }; + +module.exports.SVELTE_VERSION_2 = SVELTE_VERSION_2; +module.exports.SVELTE_VERSION_3 = SVELTE_VERSION_3; diff --git a/typings.d.ts b/typings.d.ts index 81861a2..aa9f23b 100644 --- a/typings.d.ts +++ b/typings.d.ts @@ -18,35 +18,35 @@ export interface JSDocTypeBase { /** * The text representation of this type. */ - text: string, + text: string; } export interface JSDocTypeElement extends JSDocTypeBase { - kind: 'type', + kind: 'type'; /** * The name of JS type. */ - type: string, + type: string; } export interface JSDocTypeConst extends JSDocTypeBase { - kind: 'const', + kind: 'const'; /** * The name of JS type. */ - type: string, + type: string; /** * The constant value related to this type, if can be provided. */ - value?: any, + value?: any; } export interface JSDocTypeUnion extends JSDocTypeBase { - kind: 'union', + kind: 'union'; /** * The list of possible types. */ - type: JSDocType[] + type: JSDocType[]; } export type JSDocType = JSDocTypeElement | JSDocTypeConst | JSDocTypeUnion; @@ -177,7 +177,7 @@ export interface SvelteComputedItem extends ISvelteItem { /** * The list of data or computed properties names, marked as depended to this property. */ - dependencies: string[] + dependencies: string[]; } export interface SvelteMethodParamItem { @@ -255,12 +255,18 @@ export interface SvelteComponentItem extends ISvelteItem { /** * Represents the event modificators. - * + * * @since Svelte V2.5 * @since Svelte V3 * @since {2.0.0} */ -export type SvelteEventModificator = 'preventDefault'|'stopPropagation'|'passive'|'capture'|'once'|'nonpassive'; +export type SvelteEventModificator = + | 'preventDefault' + | 'stopPropagation' + | 'passive' + | 'capture' + | 'once' + | 'nonpassive'; export interface SvelteEventItem extends ISvelteItem { /** @@ -279,9 +285,7 @@ export interface SvelteEventItem extends ISvelteItem { * @since Svelte V3 * @since {2.0.0} */ -export interface SvelteSlotParameter extends ISvelteItem { - -} +export interface SvelteSlotParameter extends ISvelteItem {} export interface SvelteSlotItem extends ISvelteItem { /** @@ -310,7 +314,7 @@ export interface SvelteComponentDoc { /** * The Svelte compiler version that used for this document. */ - version?: number, + version?: number; /** * The component description. */ @@ -401,7 +405,7 @@ export enum Svelte3Feature { events = 'events', slots = 'slots', refs = 'refs', -}; +} type Svelte2FeatureKeys = keyof typeof Svelte2Feature; type Svelte3FeatureKeys = keyof typeof Svelte3Feature; @@ -414,7 +418,10 @@ type Svelte3ExclusiveFeature = Exclude; */ export type SvelteVersion = 2 | 3; -interface BaseParserOptions { +interface BaseParserOptions< + V extends SvelteVersion, + F extends SvelteFeatureKeys +> { /** * The filename to parse. Required unless fileContent is passed. */ @@ -449,7 +456,7 @@ interface BaseParserOptions | BaseParserOptions<2, Svelte2FeatureKeys>; + +declare module 'sveltedoc-parser' { + /** + * Parse the svelte source file to structured object. + * + * @param options The parser options + * @example + * ```js + * const { parse } = require('sveltedoc-parser'); + * // basic usage only requires 'filename' to be set. + * const doc = await parse({ + * filename: 'main.svelte', + * encoding: 'ascii', + * features: ['data', 'computed', 'methods'], + * ignoredVisibilities: ['private'], + * includeSourceLocations: true, + * version: 3 + * }); + * ``` + * @return Promise with parsed document structure. + */ + export function parse( + options: SvelteParserOptions + ): Promise; + + /** + * Try to detect svelte source file version. + * + * @param options The parser options + * @return The detected version of svelte source file. + */ + export function detectVersion(options: SvelteParserOptions): number; + + export const SVELTE_VERSION_2: number; + export const SVELTE_VERSION_3: number; +}