sveld 0.35.1 → 0.35.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -4
- package/cli.js +1 -1
- package/lib/ComponentParser.d.ts +139 -401
- package/lib/ast-guards.d.ts +0 -2
- package/lib/browser.js +203 -225
- package/lib/bundle.d.ts +1 -3
- package/lib/chunk-1p4ka68s.js +2 -0
- package/lib/chunk-72hx9e9w.js +20 -0
- package/lib/chunk-7qz0hzgw.js +217 -0
- package/lib/chunk-8xw75w8t.js +10 -0
- package/lib/chunk-cxrw7gzr.js +2 -0
- package/lib/chunk-jdnsv86e.js +1 -0
- package/lib/chunk-pmj8c3yv.js +6 -0
- package/lib/chunk-s9mzxa4y.js +1 -0
- package/lib/chunk-v4q9vw0y.js +62 -0
- package/lib/chunk-xkrgedm4.js +4 -0
- package/lib/chunk-zva3xjwa.js +13 -0
- package/lib/cli-entry.d.ts +12 -0
- package/lib/cli-entry.js +1 -0
- package/lib/get-svelte-entry.d.ts +0 -1
- package/lib/index.js +1 -343
- package/lib/parse-cache.d.ts +1 -1
- package/lib/parse-entry-exports.d.ts +2 -2
- package/lib/parsed-component-metadata.d.ts +13 -0
- package/lib/parser/bindings.d.ts +0 -2
- package/lib/parser/context.d.ts +7 -49
- package/lib/parser/events.d.ts +0 -2
- package/lib/parser/jsdoc.d.ts +0 -4
- package/lib/parser/prop-shared.d.ts +84 -0
- package/lib/parser/props.d.ts +0 -2
- package/lib/parser/rest-props.d.ts +0 -2
- package/lib/parser/runes-detection.d.ts +1 -4
- package/lib/parser/scopes.d.ts +0 -2
- package/lib/parser/slots.d.ts +0 -5
- package/lib/parser/source-position.d.ts +0 -4
- package/lib/parser/type-resolution.d.ts +0 -15
- package/lib/parser/typescript-casts.d.ts +0 -1
- package/lib/parser/utils.d.ts +1 -0
- package/lib/parser/variable-jsdoc.d.ts +12 -0
- package/lib/parser-stack.d.ts +20 -0
- package/lib/path.d.ts +0 -1
- package/lib/svelte-parse.d.ts +4 -0
- package/lib/svelte-version.d.ts +1 -0
- package/lib/writer/Writer.d.ts +7 -29
- package/lib/writer/WriterMarkdown.d.ts +0 -2
- package/lib/writer/markdown-format-utils.d.ts +0 -84
- package/lib/writer/writer-json.d.ts +2 -12
- package/lib/writer/writer-markdown.d.ts +0 -2
- package/lib/writer/writer-ts-definitions-core.d.ts +1 -9
- package/lib/writer/writer-ts-definitions.d.ts +1 -28
- package/package.json +1 -1
package/lib/parse-cache.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ParsedComponent } from "./ComponentParser";
|
|
2
2
|
/** Default on-disk location for the persistent parse cache, relative to the project root. */
|
|
3
3
|
export declare const DEFAULT_CACHE_FILE: string;
|
|
4
4
|
/** Resolves the effective cache file path for `cache: true | string`. */
|
|
@@ -23,8 +23,8 @@ export type EntryExports = EntryExport[];
|
|
|
23
23
|
* @example
|
|
24
24
|
* ```ts
|
|
25
25
|
* // entry: export { VERSION } from "./constants"; export type { Theme } from "./types";
|
|
26
|
-
* parseEntryExports("/abs/src/index.ts");
|
|
26
|
+
* await parseEntryExports("/abs/src/index.ts");
|
|
27
27
|
* // [{ name: "Theme", kind: "type", isTypeOnly: true, ... }, { name: "VERSION", kind: "const", ... }]
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
|
-
export declare function parseEntryExports(entryFile: string): EntryExports
|
|
30
|
+
export declare function parseEntryExports(entryFile: string): Promise<EntryExports>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime helpers for `ParsedComponent`'s symbol-keyed TypeScript metadata,
|
|
3
|
+
* split out of `./ComponentParser` so callers that only need to read or
|
|
4
|
+
* write this field (`parse-cache.ts`, `writer/writer-ts-definitions-core.ts`,
|
|
5
|
+
* `bundle.ts`) don't have to import the parser stack to get it.
|
|
6
|
+
*/
|
|
7
|
+
import type { ParsedComponent, ParsedComponentTypeScriptMetadata, ResolvedComponentProp } from "./ComponentParser";
|
|
8
|
+
export declare const PARSED_COMPONENT_TYPE_SCRIPT_METADATA: unique symbol;
|
|
9
|
+
export declare function getParsedComponentTypeScriptMetadata(component: {
|
|
10
|
+
[PARSED_COMPONENT_TYPE_SCRIPT_METADATA]?: ParsedComponentTypeScriptMetadata;
|
|
11
|
+
}): ParsedComponentTypeScriptMetadata | undefined;
|
|
12
|
+
/** Append checker-resolved props. Names the AST walker already found are left alone. */
|
|
13
|
+
export declare function applyResolvedProps(component: ParsedComponent, resolved: ResolvedComponentProp[]): void;
|
package/lib/parser/bindings.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type ComponentParser from "../ComponentParser";
|
|
2
2
|
import type { ParserContext } from "./context";
|
|
3
|
-
/** Pull `propName`'s type out of an object type string like `{ value: string; other: number }`. */
|
|
4
3
|
export declare function extractPropertyType(typeStr: string, propName: string): string | undefined;
|
|
5
|
-
/** Resolve `obj.prop` by looking up `obj`'s type and calling {@link extractPropertyType}. */
|
|
6
4
|
export declare function resolveMemberExpressionType(ctx: ParserContext, parser: ComponentParser, expr: unknown): string | undefined;
|
package/lib/parser/context.d.ts
CHANGED
|
@@ -3,111 +3,69 @@ import type { ComponentContext, ComponentElement, ComponentEvent, ComponentGener
|
|
|
3
3
|
import type { SveldDiagnostic } from "../diagnostics";
|
|
4
4
|
/** Per-parse mutable state for {@link ComponentParser}. Reset via {@link createParserContext} on each parse. */
|
|
5
5
|
export interface ParserContext {
|
|
6
|
-
/** Whether the component uses legacy or runes syntax according to compiler metadata */
|
|
7
6
|
syntaxMode: SyntaxMode;
|
|
8
|
-
/** Language used by the component's instance or module script, when supported */
|
|
9
7
|
scriptLanguage?: ScriptLanguage;
|
|
10
|
-
/** Raw source code of the Svelte component being parsed */
|
|
11
8
|
source?: string;
|
|
12
|
-
/** Parsed abstract syntax tree from the Svelte compiler */
|
|
13
9
|
parsed?: LegacyAstRoot;
|
|
14
10
|
/**
|
|
15
|
-
* Explicit `<svelte:options runes={...} />` value
|
|
16
|
-
* runes prop type metadata. When present, overrides rune-reference detection.
|
|
11
|
+
* Explicit `<svelte:options runes={...} />` value. When set, overrides rune-reference detection.
|
|
17
12
|
*/
|
|
18
13
|
runesOptionOverride?: boolean;
|
|
19
|
-
/** Cached `ctx.source` split on newlines */
|
|
20
|
-
sourceLinesCache?: string[];
|
|
21
|
-
/** Cached 0-based source offsets for the start of each line */
|
|
22
14
|
sourceLineStartOffsetsCache?: number[];
|
|
23
|
-
/** Rest props configuration (e.g., `$$restProps`) if present in component */
|
|
24
15
|
rest_props?: RestProps;
|
|
25
|
-
/** Component extension information (e.g., `extends` attribute) */
|
|
26
16
|
extends?: Extends;
|
|
27
|
-
/** Custom-element tag name from `<svelte:options customElement="x-foo" />` (or the object form's `tag`), when present */
|
|
28
17
|
customElementTag?: string;
|
|
29
|
-
/** Component-level description extracted from `@component` HTML comment */
|
|
30
18
|
componentComment?: string;
|
|
31
|
-
/** Source range for the `@component` HTML comment, when available */
|
|
32
19
|
componentCommentSource?: SourceRange;
|
|
33
|
-
/** Component generic type parameters (null if no generics) */
|
|
34
20
|
generics: ComponentGenerics;
|
|
35
21
|
/**
|
|
36
|
-
* Raw `generics` script attribute
|
|
37
|
-
*
|
|
38
|
-
* JSDoc-derived {@link ParserContext.generics}.
|
|
22
|
+
* Raw `generics` script attribute (with `lang="ts"` validated). Held until parse end so it can
|
|
23
|
+
* override JSDoc-derived {@link ParserContext.generics}.
|
|
39
24
|
*/
|
|
40
25
|
scriptGenericsAttribute?: {
|
|
41
26
|
value: string;
|
|
42
27
|
source?: SourceRange;
|
|
43
28
|
};
|
|
44
|
-
/** Diagnostics for the parse in progress. */
|
|
45
29
|
readonly diagnosticRecords: SveldDiagnostic[];
|
|
46
|
-
/** File path tagged onto each diagnostic. */
|
|
47
30
|
componentFilePath: string;
|
|
48
|
-
/** Map of component props keyed by prop name */
|
|
49
31
|
readonly props: Map<string, ComponentProp>;
|
|
50
|
-
/** Map of module exports (functions/variables exported from script) keyed by name */
|
|
51
32
|
readonly moduleExports: Map<string, ComponentProp>;
|
|
52
|
-
/** Maps local binding names back to their public prop names */
|
|
53
33
|
readonly propLocalToPublicName: Map<string, string>;
|
|
54
|
-
/** Set of reactive variable names found in the component */
|
|
55
34
|
readonly reactive_vars: Set<string>;
|
|
56
|
-
/** Function declarations in the component script, by name */
|
|
57
35
|
readonly funcDecls: Map<string, FunctionDeclaration>;
|
|
58
|
-
/** Set of all variable declarations found in the component script */
|
|
59
36
|
readonly vars: Set<VariableDeclaration>;
|
|
60
|
-
/** Per-declarator type metadata extracted from modern AST `$props()` annotations */
|
|
61
37
|
readonly runesPropsDeclarationMetadataByDeclaratorStart: Map<number, RunesPropsDeclarationMetadata>;
|
|
62
|
-
/** Typed `$props()` declarations discovered in source order */
|
|
63
38
|
readonly typedRunesPropsDeclarations: RunesPropsDeclarationMetadata[];
|
|
64
|
-
/** Explicit TypeScript prop annotations for legacy `export let` declarations keyed by local name */
|
|
65
39
|
readonly explicitPropTypesByName: Map<string, string>;
|
|
66
|
-
|
|
40
|
+
readonly explicitVariableTypesByName: Map<string, string>;
|
|
67
41
|
readonly typeImportBindingsByLocalName: Map<string, TypeImportBinding>;
|
|
68
|
-
/** Local interface/type declarations keyed by type name */
|
|
69
42
|
readonly localTypeDeclarationsByName: Map<string, LocalTypeDeclaration>;
|
|
70
|
-
/** Tracks identifier bindings that capture the entire `$props()` object */
|
|
71
43
|
readonly wholePropsLocals: Set<string>;
|
|
72
|
-
/** Tracks `$props()` bindings that are used as spread/rest props */
|
|
73
44
|
readonly restPropLocals: Set<string>;
|
|
74
|
-
/** Component-level lexical scope shared by instance script and template */
|
|
75
45
|
readonly componentScope: LexicalScope;
|
|
76
|
-
/** Precomputed lexical scopes for nested AST nodes */
|
|
77
46
|
scopeDeclarations: WeakMap<object, LexicalScope>;
|
|
78
|
-
/** Active lexical scopes while walking the component AST */
|
|
79
47
|
readonly activeScopes: LexicalScope[];
|
|
80
|
-
/** Map of component slots keyed by slot name (null for default slot) */
|
|
81
48
|
readonly slots: Map<string | null, InternalComponentSlot>;
|
|
82
|
-
/** Tracks prop locals that are used as snippet/render props */
|
|
83
49
|
readonly snippetPropLocals: Set<string>;
|
|
84
|
-
/**
|
|
50
|
+
/** `@template` tags from a `@slot`/`@snippet` block (no `@extends`), held until finalization. */
|
|
85
51
|
deferredSlotBlockGenerics: Array<{
|
|
86
52
|
name: string;
|
|
87
53
|
constraint: string;
|
|
88
54
|
}>;
|
|
89
|
-
/** Map of component events (dispatched events) keyed by event name */
|
|
90
55
|
readonly events: Map<string, ComponentEvent>;
|
|
91
|
-
/** Map of event descriptions extracted from JSDoc comments keyed by event name */
|
|
92
56
|
readonly eventDescriptions: Map<string, string | undefined>;
|
|
93
|
-
/** Map of forwarded events (events forwarded from child components) keyed by event name */
|
|
94
57
|
readonly forwardedEvents: Map<string, ComponentInlineElement | ComponentElement>;
|
|
95
|
-
/** `@event` names from JSDoc, checked against dispatches at end of parse. */
|
|
96
58
|
readonly jsDocEventNames: Set<string>;
|
|
97
|
-
/** Source range
|
|
59
|
+
/** Source range per `@event` JSDoc tag, for `event-no-source` diagnostics. */
|
|
98
60
|
readonly jsDocEventSources: Map<string, SourceRange | undefined>;
|
|
99
|
-
/** Map of prop bindings (e.g., `bind:value`) keyed by prop name */
|
|
100
61
|
readonly bindings: Map<string, ComponentPropBindings>;
|
|
101
|
-
/** Map of component contexts (created with `setContext`) keyed by context name */
|
|
102
62
|
readonly contexts: Map<string, ComponentContext>;
|
|
103
|
-
/** Map of type definitions (typedefs) extracted from JSDoc comments keyed by type name */
|
|
104
63
|
readonly typedefs: Map<string, TypeDef>;
|
|
105
|
-
/** Memoized `findVariableTypeAndDescription` results */
|
|
106
64
|
variableInfoCache: Map<string, {
|
|
107
65
|
type: string;
|
|
108
66
|
description?: string;
|
|
109
67
|
}>;
|
|
110
|
-
/**
|
|
68
|
+
/** True after the per-component variable/JSDoc symbol table has populated {@link variableInfoCache}. */
|
|
111
69
|
variableInfoCacheBuilt: boolean;
|
|
112
70
|
}
|
|
113
71
|
/** Fresh {@link ParserContext}. Keep in sync with new fields on {@link ParserContext}. */
|
package/lib/parser/events.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { CallExpression } from "estree";
|
|
2
2
|
import type { DispatchedEvent } from "../ComponentParser";
|
|
3
3
|
import type { ParserContext } from "./context";
|
|
4
|
-
/** Render a literal event-detail value (from a `dispatch()`/`CustomEvent` argument) as TS type text, quoting strings. */
|
|
5
4
|
export declare function literalDetailToTypeText(value: unknown): string;
|
|
6
5
|
/** Merge or add a dispatched event. Detail defaults to `null` when the dispatch has no argument and no `@event` detail. */
|
|
7
6
|
export declare function addDispatchedEvent(ctx: ParserContext, { name, detail, has_argument, description, deprecated, tags, source, }: Pick<DispatchedEvent, "name" | "description" | "deprecated" | "tags" | "source"> & {
|
|
@@ -13,7 +12,6 @@ export declare function addDispatchedEvent(ctx: ParserContext, { name, detail, h
|
|
|
13
12
|
* record it as a dispatched event, mirroring `createEventDispatcher()` detection.
|
|
14
13
|
*/
|
|
15
14
|
export declare function parseHostDispatchEventCall(ctx: ParserContext, dispatchEventCall: CallExpression): string | undefined;
|
|
16
|
-
/** Build an inline object type (with optional JSDoc per property) for event details or typedefs. */
|
|
17
15
|
export declare function buildEventDetailFromProperties(properties: Array<{
|
|
18
16
|
name: string;
|
|
19
17
|
type: string;
|
package/lib/parser/jsdoc.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import type ComponentParser from "../ComponentParser";
|
|
|
3
3
|
import type { ComponentPropBinding, ComponentPropParam, DeprecatedValue, JsDocPassthroughTag } from "../ComponentParser";
|
|
4
4
|
import type { ParserContext } from "./context";
|
|
5
5
|
export declare function formatComment(comment: string): string;
|
|
6
|
-
/** Split JSDoc tags into type/param/returns/passthrough buckets. */
|
|
7
6
|
export declare function getCommentTags(parsed: ReturnType<typeof parseComment>): {
|
|
8
7
|
type: import("comment-parser").Spec | undefined;
|
|
9
8
|
param: import("comment-parser").Spec[];
|
|
@@ -14,7 +13,6 @@ export declare function getCommentTags(parsed: ReturnType<typeof parseComment>):
|
|
|
14
13
|
passthrough: import("comment-parser").Spec[];
|
|
15
14
|
description: string;
|
|
16
15
|
};
|
|
17
|
-
/** Last leading comment (JSDoc when present). TypeScript directives are stripped first. */
|
|
18
16
|
export declare function findJSDocComment(leadingComments: unknown[]): {
|
|
19
17
|
value: string;
|
|
20
18
|
} | undefined;
|
|
@@ -45,7 +43,6 @@ export declare function processLeadingCommentsJSDoc(ctx: ParserContext, parser:
|
|
|
45
43
|
deprecated?: DeprecatedValue;
|
|
46
44
|
tags?: JsDocPassthroughTag[];
|
|
47
45
|
} | undefined;
|
|
48
|
-
/** Parse adjacent JSDoc into type, params, returns, description, and passthrough tags. */
|
|
49
46
|
export declare function processJSDocComment(parser: ComponentParser, leadingComments: unknown[]): {
|
|
50
47
|
type?: string;
|
|
51
48
|
params?: ComponentPropParam[];
|
|
@@ -55,5 +52,4 @@ export declare function processJSDocComment(parser: ComponentParser, leadingComm
|
|
|
55
52
|
deprecated?: DeprecatedValue;
|
|
56
53
|
tags?: JsDocPassthroughTag[];
|
|
57
54
|
} | undefined;
|
|
58
|
-
/** Scan source JSDoc for events, typedefs, callbacks, slots, extends, and generics. */
|
|
59
55
|
export declare function parseCustomTypes(ctx: ParserContext, parser: ComponentParser): void;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { ComponentPropParam, ComponentPropTypeSource } from "../ComponentParser";
|
|
2
|
+
/**
|
|
3
|
+
* Decides a prop's provenance for docs UIs. Order is fixed and mirrors the
|
|
4
|
+
* precedence used to pick the prop's final `type` text in
|
|
5
|
+
* {@link resolvePropTypeAndDocs}: an explicit TypeScript annotation always
|
|
6
|
+
* wins, then JSDoc `@type`/`@param`/`@returns`, then a type resolved from an
|
|
7
|
+
* identifier default's own JSDoc, and only then a bare inferred/initializer
|
|
8
|
+
* type. `"unknown"` means none of the above produced any type text at all.
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveTypeSource({ hasTypeScriptType, hasJSDocType, inferredType, finalType, }: {
|
|
11
|
+
hasTypeScriptType?: boolean;
|
|
12
|
+
hasJSDocType?: boolean;
|
|
13
|
+
inferredType?: string;
|
|
14
|
+
finalType?: string;
|
|
15
|
+
}): ComponentPropTypeSource;
|
|
16
|
+
export interface ResolvePropTypeAndDocsInput {
|
|
17
|
+
/** Explicit TypeScript type text: a legacy `: T` annotation, or the matching `$props()` type-literal member in runes. */
|
|
18
|
+
explicitType?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Lowest-precedence type text, used only when nothing else applies: the
|
|
21
|
+
* initializer's inferred type, or the literal `"() => any"` seed for a
|
|
22
|
+
* bare `export function` declaration (which has no initializer).
|
|
23
|
+
*/
|
|
24
|
+
typeSeed?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Value fed to {@link resolveTypeSource}'s `inferredType` bucket. Distinct
|
|
27
|
+
* from `typeSeed` for function declarations, which have an initializer-less
|
|
28
|
+
* `typeSeed` placeholder but no actual inferred type.
|
|
29
|
+
*/
|
|
30
|
+
inferredTypeForSource?: string;
|
|
31
|
+
jsdocType?: string;
|
|
32
|
+
jsdocDescription?: string;
|
|
33
|
+
jsdocParams?: ComponentPropParam[];
|
|
34
|
+
jsdocReturnType?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Type/description/params/returnType resolved from an identifier default's
|
|
37
|
+
* own JSDoc (e.g. `export let onClick = defaultHandler;` where
|
|
38
|
+
* `defaultHandler` carries its own doc comment). Callers should gate this
|
|
39
|
+
* to `undefined` whenever `explicitType`/`jsdocType` is already set, so it
|
|
40
|
+
* only ever fills a genuine gap (see {@link resolvePropIsFunction}, which
|
|
41
|
+
* relies on the same gating).
|
|
42
|
+
*/
|
|
43
|
+
resolvedType?: string;
|
|
44
|
+
resolvedDescription?: string;
|
|
45
|
+
resolvedParams?: ComponentPropParam[];
|
|
46
|
+
resolvedReturnType?: string;
|
|
47
|
+
/** True when the initializer itself is an arrow/function expression. */
|
|
48
|
+
initializerIsFunction: boolean;
|
|
49
|
+
/** True for a bare `export function foo() {}` declaration. */
|
|
50
|
+
isFunctionDeclaration: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Runes-only: also treat the prop as a function when its resolved type
|
|
53
|
+
* text looks like a callback signature (`@param`/`@returns`/`=>` from
|
|
54
|
+
* TypeScript, JSDoc, or an identifier default). Legacy `export let` never
|
|
55
|
+
* applies this signature check; the mode difference predates this helper
|
|
56
|
+
* and is preserved here rather than silently converged.
|
|
57
|
+
*/
|
|
58
|
+
inferIsFunctionFromTypeSignature?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Legacy-only: fall back to a `@typedef`'s own description when the prop
|
|
61
|
+
* has none of its own. Runes omits this today (a preserved mode
|
|
62
|
+
* difference); pass `undefined` there.
|
|
63
|
+
*/
|
|
64
|
+
typedefs?: Map<string, {
|
|
65
|
+
description?: string;
|
|
66
|
+
}>;
|
|
67
|
+
}
|
|
68
|
+
export interface ResolvedPropTypeAndDocs {
|
|
69
|
+
type?: string;
|
|
70
|
+
typeSource: ComponentPropTypeSource;
|
|
71
|
+
description?: string;
|
|
72
|
+
params?: ComponentPropParam[];
|
|
73
|
+
returnType?: string;
|
|
74
|
+
isFunction: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Resolves the type/description/params/returnType/isFunction decisions
|
|
78
|
+
* shared by every prop front-end (legacy module exports, legacy instance
|
|
79
|
+
* `export let`/`export function`, and runes `$props()` destructuring). The
|
|
80
|
+
* front-ends differ only in how they extract the raw signals below from
|
|
81
|
+
* their respective AST shapes; once extracted, the decisions are identical
|
|
82
|
+
* except where explicitly parameterized above.
|
|
83
|
+
*/
|
|
84
|
+
export declare function resolvePropTypeAndDocs(input: ResolvePropTypeAndDocsInput): ResolvedPropTypeAndDocs;
|
package/lib/parser/props.d.ts
CHANGED
|
@@ -2,9 +2,7 @@ import type { ArrowFunctionExpression, FunctionDeclaration, FunctionExpression }
|
|
|
2
2
|
import type ComponentParser from "../ComponentParser";
|
|
3
3
|
import type { ComponentProp, ComponentPropParam, ProcessedInitializer } from "../ComponentParser";
|
|
4
4
|
import type { ParserContext } from "./context";
|
|
5
|
-
/** Merge a prop into `ctx.props`, or add it if missing. */
|
|
6
5
|
export declare function addProp(parser: ComponentParser, ctx: ParserContext, prop_name: string, data: ComponentProp): void;
|
|
7
|
-
/** Read value, type, and function-ness from a prop initializer expression. */
|
|
8
6
|
export declare function processInitializer(parser: ComponentParser, ctx: ParserContext, init: unknown, depth?: number): ProcessedInitializer;
|
|
9
7
|
/**
|
|
10
8
|
* Look up a local variable's initializer AST node by name.
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { RestProps } from "../ComponentParser";
|
|
2
2
|
import type { ParserContext } from "./context";
|
|
3
|
-
/** {@link RestProps} for the parent of a `{...$$restProps}` spread. */
|
|
4
3
|
export declare function createRestPropsFromParent(parent: unknown): RestProps;
|
|
5
|
-
/** Record the first `{...$$restProps}` target on `ctx.rest_props`. */
|
|
6
4
|
export declare function maybeSetRestProps(ctx: ParserContext, parent: unknown): void;
|
|
@@ -8,9 +8,6 @@ import type { ParserContext } from "./context";
|
|
|
8
8
|
* mode if any rune name is referenced - and not shadowed by a local declaration of the same name -
|
|
9
9
|
* anywhere in the module script, instance script, or template.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
* outside of any function). No sveld fixture exercises that path, so it's intentionally not
|
|
13
|
-
* replicated here; a component relying solely on top-level `await` to opt into runes mode (with no
|
|
14
|
-
* other rune usage and no explicit `svelte:options`) would be misdetected as legacy.
|
|
11
|
+
* Mirrors svelte analyze runes detection. Omitted: top-level `await` forces runes (no fixture).
|
|
15
12
|
*/
|
|
16
13
|
export declare function detectSyntaxMode(ctx: ParserContext): SyntaxMode;
|
package/lib/parser/scopes.d.ts
CHANGED
|
@@ -2,9 +2,7 @@ import type { ArrowFunctionExpression, Expression, FunctionDeclaration, Function
|
|
|
2
2
|
import type ComponentParser from "../ComponentParser";
|
|
3
3
|
import type { LexicalScope, ScopeBinding, ScopeBindingKind } from "../ComponentParser";
|
|
4
4
|
import type { ParserContext } from "./context";
|
|
5
|
-
/** Declares `name` into `scope` unless it's empty/already bound (first declaration wins). */
|
|
6
5
|
export declare function declareScopeBinding(scope: LexicalScope, name: string, binding: ScopeBinding): void;
|
|
7
|
-
/** Resolves `name` to its public prop name by walking active scopes innermost-first. */
|
|
8
6
|
export declare function resolveIdentifierToReactiveProp(ctx: ParserContext, name: string): string | undefined;
|
|
9
7
|
/** Collects all identifier names bound by a destructuring/assignment pattern (or plain expression). */
|
|
10
8
|
export declare function collectPatternIdentifiers(target: Pattern | Expression | null | undefined, names?: Set<string>): Set<string>;
|
package/lib/parser/slots.d.ts
CHANGED
|
@@ -2,22 +2,17 @@ import type { Expression, ObjectExpression } from "estree";
|
|
|
2
2
|
import type ComponentParser from "../ComponentParser";
|
|
3
3
|
import type { DeprecatedValue, JsDocPassthroughTag, SlotProps, SlotPropValue, SourceRange } from "../ComponentParser";
|
|
4
4
|
import type { ParserContext } from "./context";
|
|
5
|
-
/** Infer a slot prop value/type from an expression (identifier, literal, member access, or source text). */
|
|
6
5
|
export declare function inferSlotPropValueFromExpression(ctx: ParserContext, parser: ComponentParser, expression: unknown): SlotPropValue;
|
|
7
|
-
/** Slot props from an object expression, e.g. `{@render mySnippet({ foo: 1 })}`. */
|
|
8
6
|
export declare function buildSlotPropsFromObjectExpression(ctx: ParserContext, parser: ComponentParser, expression: ObjectExpression): SlotProps;
|
|
9
|
-
/** Snippet prop behind `{@render children()}` or `{@render props.children()}`. */
|
|
10
7
|
export declare function resolveRenderTagPropReference(ctx: ParserContext, callee: unknown): {
|
|
11
8
|
publicName: string;
|
|
12
9
|
trackingName: string;
|
|
13
10
|
} | null;
|
|
14
|
-
/** Callee and arguments from a `{@render ...}` expression (unwraps `ChainExpression` first). */
|
|
15
11
|
export declare function extractRenderTagInfo(ctx: ParserContext, expression: unknown): {
|
|
16
12
|
publicName: string;
|
|
17
13
|
trackingName: string;
|
|
18
14
|
arguments: Array<Expression | unknown>;
|
|
19
15
|
} | null;
|
|
20
|
-
/** Merge or add a slot. Empty `slot_name` is the default slot. */
|
|
21
16
|
export declare function addSlot(ctx: ParserContext, { slot_name, slot_props, slot_fallback, slot_description, slot_deprecated, slot_tags, source, }: {
|
|
22
17
|
slot_name?: string;
|
|
23
18
|
slot_props?: string | SlotProps;
|
|
@@ -5,11 +5,8 @@ import type { ParserContext } from "./context";
|
|
|
5
5
|
* the start of each line in `ctx.source`.
|
|
6
6
|
*/
|
|
7
7
|
export declare function getSourceLineStartOffsets(ctx: ParserContext): number[];
|
|
8
|
-
/** Converts a 0-based source offset into a 1-based line / 0-based column {@link SourcePosition}. */
|
|
9
8
|
export declare function sourcePositionFromOffset(ctx: ParserContext, offset: number): SourcePosition | undefined;
|
|
10
|
-
/** Converts a pair of 0-based source offsets into a {@link SourceRange}. */
|
|
11
9
|
export declare function sourceRangeFromOffsets(ctx: ParserContext, start: number | undefined, end: number | undefined): SourceRange | undefined;
|
|
12
|
-
/** Converts an AST node's `start`/`end` offsets into a {@link SourceRange}. */
|
|
13
10
|
export declare function sourceRangeFromNode(ctx: ParserContext, node: unknown): SourceRange | undefined;
|
|
14
11
|
/**
|
|
15
12
|
* Computes the {@link SourceRange} for a JSDoc tag within a parsed comment
|
|
@@ -26,5 +23,4 @@ export declare function sourceRangeFromCommentTag(ctx: ParserContext, blockSourc
|
|
|
26
23
|
};
|
|
27
24
|
}> | undefined, blockStartOffset: number | undefined): SourceRange | undefined;
|
|
28
25
|
export declare function sourceAtPos(ctx: ParserContext, start: number, end: number): string | undefined;
|
|
29
|
-
/** Source text for an expression, newlines collapsed to one line. */
|
|
30
26
|
export declare function sourceForExpression(ctx: ParserContext, node: unknown): string | undefined;
|
|
@@ -1,32 +1,17 @@
|
|
|
1
1
|
import type { ModernRunesTypeNode, ParsedComponentTypeScriptMetadata } from "../ComponentParser";
|
|
2
2
|
import type { ParserContext } from "./context";
|
|
3
|
-
/**
|
|
4
|
-
* Looks up the modern-runes `$props()` declaration metadata recorded for the
|
|
5
|
-
* declarator starting at `declaratorStart`, if any.
|
|
6
|
-
*/
|
|
7
3
|
export declare function getRunesPropsDeclarationMetadata(ctx: ParserContext, declaratorStart: number | undefined): import("../ComponentParser").RunesPropsDeclarationMetadata | undefined;
|
|
8
|
-
/**
|
|
9
|
-
* Looks up the per-prop type metadata (optionality, source range, type text)
|
|
10
|
-
* for `propName` within the `$props()` declaration starting at `declaratorStart`.
|
|
11
|
-
*/
|
|
12
4
|
export declare function getRunesPropTypeMetadata(ctx: ParserContext, declaratorStart: number | undefined, propName: string): import("../ComponentParser").RunesPropTypeMetadata | undefined;
|
|
13
|
-
/** Rightmost name from a type reference (`Foo` or `NS.Foo`). */
|
|
14
5
|
export declare function getTypeReferenceName(typeName: unknown): string | undefined;
|
|
15
|
-
/** Leftmost name from a type reference, for import/local lookup. */
|
|
16
6
|
export declare function getTypeDependencyName(typeName: unknown): string | undefined;
|
|
17
|
-
/** Returns the trimmed source text spanned by a type annotation node, if positions are available. */
|
|
18
7
|
export declare function getTypeAnnotationText(ctx: ParserContext, typeAnnotation: {
|
|
19
8
|
start?: number;
|
|
20
9
|
end?: number;
|
|
21
10
|
} | undefined): string | undefined;
|
|
22
|
-
/** Returns the trimmed source text spanned by a bare type node (no leading `:`), if positions are available. */
|
|
23
11
|
export declare function getTypeNodeText(ctx: ParserContext, typeNode: {
|
|
24
12
|
start?: number;
|
|
25
13
|
end?: number;
|
|
26
14
|
} | undefined): string | undefined;
|
|
27
|
-
/** Collect imported and local type names referenced by a type AST node. */
|
|
28
15
|
export declare function collectReferencedTypeDependencies(ctx: ParserContext, typeNode: ModernRunesTypeNode | undefined, referencedImportedTypes: Set<string>, referencedLocalTypes: Set<string>, visitedLocalTypes?: Set<string>): void;
|
|
29
|
-
/** Emit `import type` statements for referenced type names, grouped by module. */
|
|
30
16
|
export declare function buildTypeImportStatements(ctx: ParserContext, referencedImportedTypes: Set<string>): string[];
|
|
31
|
-
/** `ParsedComponentTypeScriptMetadata` for a single typed `$props()` declaration, if any. */
|
|
32
17
|
export declare function buildTypeScriptMetadata(ctx: ParserContext): ParsedComponentTypeScriptMetadata | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function assignValueOrUndefined(value?: "" | string): string | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type ComponentParser from "../ComponentParser";
|
|
2
|
+
import type { ParserContext } from "./context";
|
|
3
|
+
/**
|
|
4
|
+
* Maps every top-level variable/function name declared in a component's module and instance
|
|
5
|
+
* scripts to the `@type`/description from its attached JSDoc block. Used by
|
|
6
|
+
* {@link ComponentParser.findVariableTypeAndDescription} to resolve plain identifiers (e.g. a
|
|
7
|
+
* value passed to `setContext`) that aren't otherwise typed by a prop or a TS annotation.
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildVariableJsDocTable(ctx: ParserContext, parser: ComponentParser): Map<string, {
|
|
10
|
+
type: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazily loads the parser stack (`ComponentParser` and the pruned svelte
|
|
3
|
+
* parser in `./svelte-parse`, which together pull in acorn,
|
|
4
|
+
* `@sveltejs/acorn-typescript`, comment-parser, and estree-walker) behind a
|
|
5
|
+
* dynamic import.
|
|
6
|
+
*
|
|
7
|
+
* A fully cached run never needs to parse a single component, so it never
|
|
8
|
+
* has to pay for evaluating any of that. Callers that are about to parse
|
|
9
|
+
* (`bundle.ts`, `parse-entry-exports.ts`, `watch.ts`) await
|
|
10
|
+
* `loadParserStack()` once up front, then read the resolved stack back
|
|
11
|
+
* synchronously via `getParserStack()` for the rest of the (otherwise
|
|
12
|
+
* synchronous) parse path. The load happens at most once per process.
|
|
13
|
+
*/
|
|
14
|
+
export interface ParserStack {
|
|
15
|
+
ComponentParser: typeof import("./ComponentParser").default;
|
|
16
|
+
parseSvelte: typeof import("./svelte-parse").parse;
|
|
17
|
+
}
|
|
18
|
+
export declare function loadParserStack(): Promise<ParserStack>;
|
|
19
|
+
/** Reads back the stack resolved by a prior, already-awaited `loadParserStack()` call. */
|
|
20
|
+
export declare function getParserStack(): ParserStack;
|
package/lib/path.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VERSION: string;
|
package/lib/writer/Writer.d.ts
CHANGED
|
@@ -1,37 +1,19 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base writer class for file system operations.
|
|
3
|
-
*
|
|
4
|
-
* Automatically creates directories as needed before writing.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* const writer = new Writer();
|
|
9
|
-
* await writer.write("./dist/index.d.ts", "export type Props = {};");
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
1
|
export default class Writer {
|
|
13
2
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* Creates the directory structure if needed, then writes the content
|
|
17
|
-
* to the specified file path.
|
|
3
|
+
* Skips the write when `filePath` already contains `raw`, so repeated runs
|
|
4
|
+
* over unchanged sources don't touch the file (or its mtime).
|
|
18
5
|
*
|
|
19
|
-
* @
|
|
20
|
-
* @param raw - The content to write
|
|
6
|
+
* @returns `true` if the file was written, `false` if it was already up to date.
|
|
21
7
|
*
|
|
22
8
|
* @example
|
|
23
9
|
* ```ts
|
|
24
|
-
*
|
|
25
|
-
*
|
|
10
|
+
* const writer = new Writer();
|
|
11
|
+
* await writer.write("./dist/index.d.ts", "export type Props = {};");
|
|
26
12
|
* ```
|
|
27
13
|
*/
|
|
28
|
-
write(filePath: string, raw: string): Promise<
|
|
14
|
+
write(filePath: string, raw: string): Promise<boolean>;
|
|
29
15
|
}
|
|
30
16
|
/**
|
|
31
|
-
* Creates a Writer instance for JSON files.
|
|
32
|
-
*
|
|
33
|
-
* @returns A Writer instance
|
|
34
|
-
*
|
|
35
17
|
* @example
|
|
36
18
|
* ```ts
|
|
37
19
|
* const writer = createJsonWriter();
|
|
@@ -40,14 +22,10 @@ export default class Writer {
|
|
|
40
22
|
*/
|
|
41
23
|
export declare function createJsonWriter(): Writer;
|
|
42
24
|
/**
|
|
43
|
-
* Creates a Writer instance for TypeScript files.
|
|
44
|
-
*
|
|
45
|
-
* @returns A Writer instance
|
|
46
|
-
*
|
|
47
25
|
* @example
|
|
48
26
|
* ```ts
|
|
49
27
|
* const writer = createTypeScriptWriter();
|
|
50
|
-
* await writer.write("index.d.ts", "export type Props={};");
|
|
28
|
+
* await writer.write("index.d.ts", "export type Props = {};");
|
|
51
29
|
* ```
|
|
52
30
|
*/
|
|
53
31
|
export declare function createTypeScriptWriter(): Writer;
|
|
@@ -6,99 +6,15 @@ export declare const PROP_TABLE_HEADER = "| Prop name | Required | Kind | Reacti
|
|
|
6
6
|
export declare const SLOT_TABLE_HEADER = "| Slot name | Default | Props | Fallback | Description |\n| :- | :- | :- | :- | :- |\n";
|
|
7
7
|
export declare const EVENT_TABLE_HEADER = "| Event name | Type | Detail | Description |\n| :- | :- | :- | :- |\n";
|
|
8
8
|
export declare const EXPORT_TABLE_HEADER = "| Name | Kind | Type | Description |\n| :- | :- | :- | :- |\n";
|
|
9
|
-
/**
|
|
10
|
-
* Escape `|` and wrap a prop type for markdown table cells.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* formatPropType("string | number") // Returns: "<code>string | number</code>"
|
|
15
|
-
* formatPropType(undefined) // Returns: "--"
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
9
|
export declare function formatPropType(type?: string): string;
|
|
19
|
-
/**
|
|
20
|
-
* Escape `<` and `>` for markdown output.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* escapeHtml("<div>") // Returns: "<div>"
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
10
|
export declare function escapeHtml(text: string): string;
|
|
28
|
-
/**
|
|
29
|
-
* Format a default value for markdown table cells.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* formatPropValue("'hello'") // Returns: "<code>'hello'</code>"
|
|
34
|
-
* formatPropValue("`test`") // Returns: "<code>\\`test\\`</code>"
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
11
|
export declare function formatPropValue(value: string | undefined): string;
|
|
38
|
-
/**
|
|
39
|
-
* Strike through deprecated prop, slot, and event names in markdown tables.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```ts
|
|
43
|
-
* formatNameWithDeprecation("size", "use width")
|
|
44
|
-
* // Returns: "<s>size</s><br />**Deprecated**: use width"
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
12
|
export declare function formatNameWithDeprecation(name: string, deprecated: DeprecatedValue | undefined): string;
|
|
48
|
-
/**
|
|
49
|
-
* Format a prop description; newlines become `<br />`.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```ts
|
|
53
|
-
* formatPropDescription("Line 1\nLine 2")
|
|
54
|
-
* // Returns: "Line 1<br />Line 2"
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
13
|
export declare function formatPropDescription(description: string | undefined): string;
|
|
58
|
-
/**
|
|
59
|
-
* Format slot props for markdown table cells.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```ts
|
|
63
|
-
* formatSlotProps("{ title: string }") // Returns: "<code>{ title: string }</code>"
|
|
64
|
-
* formatSlotProps("{}") // Returns: "--"
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
14
|
export declare function formatSlotProps(props?: string): string;
|
|
68
|
-
/**
|
|
69
|
-
* Format slot fallback content for markdown table cells.
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```ts
|
|
73
|
-
* formatSlotFallback("<p>Default</p>")
|
|
74
|
-
* // Returns: "<code><p>Default</p></code>"
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
15
|
export declare function formatSlotFallback(fallback?: string): string;
|
|
78
|
-
/**
|
|
79
|
-
* Format a slot/snippet description plus pass-through JSDoc tags for markdown
|
|
80
|
-
* table cells. Newlines become `<br />` and `<`, `>`, `|` are escaped so the
|
|
81
|
-
* content stays inside a single table cell.
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```ts
|
|
85
|
-
* formatSlotDescription("Header content.", [{ name: "since", body: "1.0.0" }])
|
|
86
|
-
* // Returns: "Header content.<br />@since 1.0.0"
|
|
87
|
-
* formatSlotDescription(undefined, [])
|
|
88
|
-
* // Returns: "--"
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
16
|
export declare function formatSlotDescription(description?: string, tags?: Array<{
|
|
92
17
|
name: string;
|
|
93
18
|
body: string;
|
|
94
19
|
}>): string;
|
|
95
|
-
/**
|
|
96
|
-
* Format event detail types for markdown table cells.
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```ts
|
|
100
|
-
* formatEventDetail("{ value: string }")
|
|
101
|
-
* // Returns: "<code>{ value: string }</code>"
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
20
|
export declare function formatEventDetail(detail?: string): string;
|