sveld 0.35.0 → 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.
Files changed (54) hide show
  1. package/README.md +46 -4
  2. package/cli.js +1 -1
  3. package/lib/ComponentParser.d.ts +164 -398
  4. package/lib/ast-guards.d.ts +2 -0
  5. package/lib/browser.d.ts +39 -0
  6. package/lib/browser.js +268 -0
  7. package/lib/bundle.d.ts +9 -4
  8. package/lib/chunk-1p4ka68s.js +2 -0
  9. package/lib/chunk-72hx9e9w.js +20 -0
  10. package/lib/chunk-7qz0hzgw.js +217 -0
  11. package/lib/chunk-8xw75w8t.js +10 -0
  12. package/lib/chunk-cxrw7gzr.js +2 -0
  13. package/lib/chunk-jdnsv86e.js +1 -0
  14. package/lib/chunk-pmj8c3yv.js +6 -0
  15. package/lib/chunk-s9mzxa4y.js +1 -0
  16. package/lib/chunk-v4q9vw0y.js +62 -0
  17. package/lib/chunk-xkrgedm4.js +4 -0
  18. package/lib/chunk-zva3xjwa.js +13 -0
  19. package/lib/cli-entry.d.ts +12 -0
  20. package/lib/cli-entry.js +1 -0
  21. package/lib/get-svelte-entry.d.ts +0 -1
  22. package/lib/index.js +1 -484
  23. package/lib/parse-cache.d.ts +1 -1
  24. package/lib/parse-entry-exports.d.ts +2 -2
  25. package/lib/parse-exports.d.ts +5 -1
  26. package/lib/parsed-component-metadata.d.ts +13 -0
  27. package/lib/parser/bindings.d.ts +0 -2
  28. package/lib/parser/context.d.ts +13 -51
  29. package/lib/parser/events.d.ts +0 -2
  30. package/lib/parser/jsdoc.d.ts +0 -4
  31. package/lib/parser/prop-shared.d.ts +84 -0
  32. package/lib/parser/props.d.ts +6 -2
  33. package/lib/parser/rest-props.d.ts +0 -2
  34. package/lib/parser/runes-detection.d.ts +13 -0
  35. package/lib/parser/scopes.d.ts +23 -7
  36. package/lib/parser/slots.d.ts +1 -6
  37. package/lib/parser/source-position.d.ts +0 -4
  38. package/lib/parser/type-resolution.d.ts +4 -14
  39. package/lib/parser/typescript-casts.d.ts +1 -0
  40. package/lib/parser/utils.d.ts +1 -0
  41. package/lib/parser/variable-jsdoc.d.ts +12 -0
  42. package/lib/parser-stack.d.ts +20 -0
  43. package/lib/path.d.ts +0 -1
  44. package/lib/resolve-types.d.ts +1 -1
  45. package/lib/svelte-parse.d.ts +4 -0
  46. package/lib/svelte-version.d.ts +1 -0
  47. package/lib/writer/Writer.d.ts +7 -29
  48. package/lib/writer/WriterMarkdown.d.ts +0 -2
  49. package/lib/writer/markdown-format-utils.d.ts +0 -84
  50. package/lib/writer/writer-json.d.ts +2 -12
  51. package/lib/writer/writer-markdown.d.ts +0 -2
  52. package/lib/writer/writer-ts-definitions-core.d.ts +1 -9
  53. package/lib/writer/writer-ts-definitions.d.ts +1 -28
  54. package/package.json +6 -1
@@ -1,4 +1,4 @@
1
- import { type ParsedComponent } from "./ComponentParser";
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>;
@@ -17,5 +17,9 @@ export type ParsedExports = Record<string, {
17
17
  * // App: { source: "./App.svelte", default: true }
18
18
  * // }
19
19
  * ```
20
+ *
21
+ * @param resolving - Absolute paths currently being resolved on this call
22
+ * stack, used to break `export *` cycles between files that re-export
23
+ * each other. Callers should not pass this; it is threaded internally.
20
24
  */
21
- export declare function parseExports(source: string, dir: string): ParsedExports;
25
+ export declare function parseExports(source: string, dir: string, resolving?: Set<string>): ParsedExports;
@@ -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;
@@ -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;
@@ -1,110 +1,72 @@
1
1
  import type { FunctionDeclaration, VariableDeclaration } from "estree";
2
- import type { compile } from "svelte/compiler";
3
- import type { ComponentContext, ComponentElement, ComponentEvent, ComponentGenerics, ComponentInlineElement, ComponentProp, ComponentPropBindings, ComponentSlot, Extends, LegacyAstRoot, LexicalScope, LocalTypeDeclaration, RestProps, RunesPropsDeclarationMetadata, ScriptLanguage, SourceRange, SyntaxMode, TypeDef, TypeImportBinding } from "../ComponentParser";
2
+ import type { ComponentContext, ComponentElement, ComponentEvent, ComponentGenerics, ComponentInlineElement, ComponentProp, ComponentPropBindings, Extends, InternalComponentSlot, LegacyAstRoot, LexicalScope, LocalTypeDeclaration, RestProps, RunesPropsDeclarationMetadata, ScriptLanguage, SourceRange, SyntaxMode, TypeDef, TypeImportBinding } from "../ComponentParser";
4
3
  import type { SveldDiagnostic } from "../diagnostics";
5
4
  /** Per-parse mutable state for {@link ComponentParser}. Reset via {@link createParserContext} on each parse. */
6
5
  export interface ParserContext {
7
- /** Whether the component uses legacy or runes syntax according to compiler metadata */
8
6
  syntaxMode: SyntaxMode;
9
- /** Language used by the component's instance or module script, when supported */
10
7
  scriptLanguage?: ScriptLanguage;
11
- /** Raw source code of the Svelte component being parsed */
12
8
  source?: string;
13
- /** Compiled Svelte code containing extracted variables and AST */
14
- compiled?: ReturnType<typeof compile>;
15
- /** Parsed abstract syntax tree from the Svelte compiler */
16
9
  parsed?: LegacyAstRoot;
17
- /** Cached `ctx.source` split on newlines */
18
- sourceLinesCache?: string[];
19
- /** Cached 0-based source offsets for the start of each line */
10
+ /**
11
+ * Explicit `<svelte:options runes={...} />` value. When set, overrides rune-reference detection.
12
+ */
13
+ runesOptionOverride?: boolean;
20
14
  sourceLineStartOffsetsCache?: number[];
21
- /** Rest props configuration (e.g., `$$restProps`) if present in component */
22
15
  rest_props?: RestProps;
23
- /** Component extension information (e.g., `extends` attribute) */
24
16
  extends?: Extends;
25
- /** Custom-element tag name from `<svelte:options customElement="x-foo" />` (or the object form's `tag`), when present */
26
17
  customElementTag?: string;
27
- /** Component-level description extracted from `@component` HTML comment */
28
18
  componentComment?: string;
29
- /** Source range for the `@component` HTML comment, when available */
30
19
  componentCommentSource?: SourceRange;
31
- /** Component generic type parameters (null if no generics) */
32
20
  generics: ComponentGenerics;
33
21
  /**
34
- * Raw `generics` script attribute value (with `lang="ts"` already validated),
35
- * held until the end of parsing so it can override any `@generics`/`@template`
36
- * 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}.
37
24
  */
38
25
  scriptGenericsAttribute?: {
39
26
  value: string;
40
27
  source?: SourceRange;
41
28
  };
42
- /** Diagnostics for the parse in progress. */
43
29
  readonly diagnosticRecords: SveldDiagnostic[];
44
- /** File path tagged onto each diagnostic. */
45
30
  componentFilePath: string;
46
- /** Map of component props keyed by prop name */
47
31
  readonly props: Map<string, ComponentProp>;
48
- /** Map of module exports (functions/variables exported from script) keyed by name */
49
32
  readonly moduleExports: Map<string, ComponentProp>;
50
- /** Maps local binding names back to their public prop names */
51
33
  readonly propLocalToPublicName: Map<string, string>;
52
- /** Set of reactive variable names found in the component */
53
34
  readonly reactive_vars: Set<string>;
54
- /** Function declarations in the component script, by name */
55
35
  readonly funcDecls: Map<string, FunctionDeclaration>;
56
- /** Set of all variable declarations found in the component script */
57
36
  readonly vars: Set<VariableDeclaration>;
58
- /** Per-declarator type metadata extracted from modern AST `$props()` annotations */
59
37
  readonly runesPropsDeclarationMetadataByDeclaratorStart: Map<number, RunesPropsDeclarationMetadata>;
60
- /** Typed `$props()` declarations discovered in source order */
61
38
  readonly typedRunesPropsDeclarations: RunesPropsDeclarationMetadata[];
62
- /** Explicit TypeScript prop annotations for legacy `export let` declarations keyed by local name */
63
39
  readonly explicitPropTypesByName: Map<string, string>;
64
- /** Type-only imports keyed by their local binding names */
40
+ readonly explicitVariableTypesByName: Map<string, string>;
65
41
  readonly typeImportBindingsByLocalName: Map<string, TypeImportBinding>;
66
- /** Local interface/type declarations keyed by type name */
67
42
  readonly localTypeDeclarationsByName: Map<string, LocalTypeDeclaration>;
68
- /** Tracks identifier bindings that capture the entire `$props()` object */
69
43
  readonly wholePropsLocals: Set<string>;
70
- /** Tracks `$props()` bindings that are used as spread/rest props */
71
44
  readonly restPropLocals: Set<string>;
72
- /** Component-level lexical scope shared by instance script and template */
73
45
  readonly componentScope: LexicalScope;
74
- /** Precomputed lexical scopes for nested AST nodes */
75
46
  scopeDeclarations: WeakMap<object, LexicalScope>;
76
- /** Active lexical scopes while walking the component AST */
77
47
  readonly activeScopes: LexicalScope[];
78
- /** Map of component slots keyed by slot name (null for default slot) */
79
- readonly slots: Map<string | null, ComponentSlot>;
80
- /** Tracks prop locals that are used as snippet/render props */
48
+ readonly slots: Map<string | null, InternalComponentSlot>;
81
49
  readonly snippetPropLocals: Set<string>;
82
- /** @template tags in a @slot/@snippet block (no @extends), held until finalization. */
50
+ /** `@template` tags from a `@slot`/`@snippet` block (no `@extends`), held until finalization. */
83
51
  deferredSlotBlockGenerics: Array<{
84
52
  name: string;
85
53
  constraint: string;
86
54
  }>;
87
- /** Map of component events (dispatched events) keyed by event name */
88
55
  readonly events: Map<string, ComponentEvent>;
89
- /** Map of event descriptions extracted from JSDoc comments keyed by event name */
90
56
  readonly eventDescriptions: Map<string, string | undefined>;
91
- /** Map of forwarded events (events forwarded from child components) keyed by event name */
92
57
  readonly forwardedEvents: Map<string, ComponentInlineElement | ComponentElement>;
93
- /** `@event` names from JSDoc, checked against dispatches at end of parse. */
94
58
  readonly jsDocEventNames: Set<string>;
95
- /** Source range of each `@event` JSDoc tag, keyed by event name, for `event-no-source` diagnostics. */
59
+ /** Source range per `@event` JSDoc tag, for `event-no-source` diagnostics. */
96
60
  readonly jsDocEventSources: Map<string, SourceRange | undefined>;
97
- /** Map of prop bindings (e.g., `bind:value`) keyed by prop name */
98
61
  readonly bindings: Map<string, ComponentPropBindings>;
99
- /** Map of component contexts (created with `setContext`) keyed by context name */
100
62
  readonly contexts: Map<string, ComponentContext>;
101
- /** Map of type definitions (typedefs) extracted from JSDoc comments keyed by type name */
102
63
  readonly typedefs: Map<string, TypeDef>;
103
- /** Memoized `findVariableTypeAndDescription` results */
104
64
  variableInfoCache: Map<string, {
105
65
  type: string;
106
66
  description?: string;
107
67
  }>;
68
+ /** True after the per-component variable/JSDoc symbol table has populated {@link variableInfoCache}. */
69
+ variableInfoCacheBuilt: boolean;
108
70
  }
109
71
  /** Fresh {@link ParserContext}. Keep in sync with new fields on {@link ParserContext}. */
110
72
  export declare function createParserContext(): ParserContext;
@@ -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;
@@ -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;
@@ -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.
@@ -51,6 +49,12 @@ export declare function inferReturnTypeFromNode(node: FunctionDeclaration | Func
51
49
  /**
52
50
  * Walk a block body and collect each `return`'s argument, skipping nested
53
51
  * functions. Bare `return;` becomes `null`.
52
+ *
53
+ * Not fused with the componentRoot walk: this runs from `processInitializer`, called
54
+ * synchronously while the outer walk is still on the ancestor `ExportNamedDeclaration`/
55
+ * `VariableDeclaration` node, so it needs the inferred type before the outer walk would
56
+ * otherwise reach these descendant statements. Deferring it to ride along with the outer
57
+ * traversal would mean computing prop types in a second pass instead of inline.
54
58
  */
55
59
  export declare function collectReturnArguments(body: unknown): unknown[];
56
60
  /**
@@ -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;
@@ -0,0 +1,13 @@
1
+ import type { SyntaxMode } from "../ComponentParser";
2
+ import type { ParserContext } from "./context";
3
+ /**
4
+ * Determines a component's syntax mode without running the svelte compiler's analyze phase.
5
+ *
6
+ * Mirrors `analyze_component`'s own logic (`node_modules/svelte/src/compiler/phases/2-analyze/index.js`):
7
+ * an explicit `<svelte:options runes={...} />` always wins; otherwise the component is in runes
8
+ * mode if any rune name is referenced - and not shadowed by a local declaration of the same name -
9
+ * anywhere in the module script, instance script, or template.
10
+ *
11
+ * Mirrors svelte analyze runes detection. Omitted: top-level `await` forces runes (no fixture).
12
+ */
13
+ export declare function detectSyntaxMode(ctx: ParserContext): SyntaxMode;
@@ -1,11 +1,8 @@
1
1
  import type { ArrowFunctionExpression, Expression, FunctionDeclaration, FunctionExpression, Pattern, VariableDeclaration, VariableDeclarator } from "estree";
2
- import type { Node } from "estree-walker";
3
2
  import type ComponentParser from "../ComponentParser";
4
3
  import type { LexicalScope, ScopeBinding, ScopeBindingKind } from "../ComponentParser";
5
4
  import type { ParserContext } from "./context";
6
- /** Declares `name` into `scope` unless it's empty/already bound (first declaration wins). */
7
5
  export declare function declareScopeBinding(scope: LexicalScope, name: string, binding: ScopeBinding): void;
8
- /** Resolves `name` to its public prop name by walking active scopes innermost-first. */
9
6
  export declare function resolveIdentifierToReactiveProp(ctx: ParserContext, name: string): string | undefined;
10
7
  /** Collects all identifier names bound by a destructuring/assignment pattern (or plain expression). */
11
8
  export declare function collectPatternIdentifiers(target: Pattern | Expression | null | undefined, names?: Set<string>): Set<string>;
@@ -34,7 +31,26 @@ export declare function declareFunctionLikeScopeBindings(node: FunctionExpressio
34
31
  export declare function collectDirectBlockDeclarations(parser: ComponentParser, body: unknown, lexicalScope: LexicalScope, varScope: LexicalScope): void;
35
32
  /** Declares all component-instance-level (`<script>`) bindings into `ctx.componentScope`. */
36
33
  export declare function collectComponentScopeDeclarations(parser: ComponentParser, ctx: ParserContext, instance: unknown): void;
37
- /** Walks the component AST, declaring bindings for every nested lexical/function scope it encounters. */
38
- export declare function collectNestedScopeDeclarations(parser: ComponentParser, ctx: ParserContext, componentRoot: Node): void;
39
- /** Rebuilds `ctx.componentScope` / `ctx.scopeDeclarations` / `ctx.activeScopes` from scratch for `componentRoot`. */
40
- export declare function buildScopeDeclarations(parser: ComponentParser, ctx: ParserContext, componentRoot: Node): void;
34
+ /**
35
+ * Resets `ctx.componentScope` / `ctx.scopeDeclarations` / `ctx.activeScopes` and declares the
36
+ * top-level `<script>` bindings. Does not walk the component tree; nested scope declarations are
37
+ * built incrementally by {@link enterNestedScopeDeclarationNode} inside the caller's own traversal
38
+ * of `componentRoot` (fused with prop/slot/event extraction there rather than walked separately).
39
+ */
40
+ export declare function initComponentScope(parser: ComponentParser, ctx: ParserContext): void;
41
+ /** Mutable stack tracking the enclosing `var`-hoisting scope while walking `componentRoot`. */
42
+ export type ScopeWalkState = {
43
+ varScopeStack: LexicalScope[];
44
+ };
45
+ /** Creates the scope-walk state for a fresh traversal of `componentRoot`, seeded with `ctx.componentScope`. */
46
+ export declare function createScopeWalkState(ctx: ParserContext): ScopeWalkState;
47
+ /**
48
+ * Per-node `enter` step of the (formerly standalone) nested-scope-declaration walk. Declares
49
+ * bindings for `node` if it's a scope owner and pushes it as the active `var` scope for its
50
+ * descendants. Must be called during the same top-down traversal of `componentRoot` that
51
+ * {@link leaveNestedScopeDeclarationNode} tears down, and before any logic that reads
52
+ * `ctx.scopeDeclarations` for `node` itself (its own scope is only created here, on entry).
53
+ */
54
+ export declare function enterNestedScopeDeclarationNode(parser: ComponentParser, ctx: ParserContext, state: ScopeWalkState, node: unknown): void;
55
+ /** Per-node `leave` step counterpart to {@link enterNestedScopeDeclarationNode}. */
56
+ export declare function leaveNestedScopeDeclarationNode(state: ScopeWalkState, node: unknown): void;
@@ -2,25 +2,20 @@ 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
- slot_props?: string;
18
+ slot_props?: string | SlotProps;
24
19
  slot_fallback?: string;
25
20
  slot_description?: string;
26
21
  slot_deprecated?: DeprecatedValue;
@@ -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,27 +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
- /** Collect imported and local type names referenced by a type AST node. */
11
+ export declare function getTypeNodeText(ctx: ParserContext, typeNode: {
12
+ start?: number;
13
+ end?: number;
14
+ } | undefined): string | undefined;
23
15
  export declare function collectReferencedTypeDependencies(ctx: ParserContext, typeNode: ModernRunesTypeNode | undefined, referencedImportedTypes: Set<string>, referencedLocalTypes: Set<string>, visitedLocalTypes?: Set<string>): void;
24
- /** Emit `import type` statements for referenced type names, grouped by module. */
25
16
  export declare function buildTypeImportStatements(ctx: ParserContext, referencedImportedTypes: Set<string>): string[];
26
- /** `ParsedComponentTypeScriptMetadata` for a single typed `$props()` declaration, if any. */
27
17
  export declare function buildTypeScriptMetadata(ctx: ParserContext): ParsedComponentTypeScriptMetadata | undefined;
@@ -0,0 +1 @@
1
+ export declare function stripTypeCastWrappers(root: unknown): void;
@@ -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
@@ -1,3 +1,2 @@
1
1
  import type { NormalizedPath } from "./brands";
2
- /** Normalize path separators to `/`. */
3
2
  export declare function normalizeSeparators(filePath: string): NormalizedPath;
@@ -23,6 +23,7 @@ export interface ExampleCheckDiagnostic {
23
23
  export declare class TypeResolver {
24
24
  private readonly api;
25
25
  private readonly symbolFlags;
26
+ private readonly typeFlags;
26
27
  private readonly tsconfigPath;
27
28
  private readonly overlay;
28
29
  private constructor();
@@ -45,7 +46,6 @@ export declare class TypeResolver {
45
46
  checkExamples(targets: ExampleCheckTarget[]): Promise<Map<string, ExampleCheckDiagnostic[]>>;
46
47
  /** Closes the TypeScript server process. */
47
48
  dispose(): Promise<void>;
48
- private resolveFile;
49
49
  private createFileSystem;
50
50
  private virtualFileName;
51
51
  private exampleFileName;
@@ -0,0 +1,4 @@
1
+ export declare function parse(source: string, { modern, loose }?: {
2
+ modern?: boolean;
3
+ loose?: boolean;
4
+ }): unknown;
@@ -0,0 +1 @@
1
+ export declare const VERSION: string;
@@ -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
- * Writes content to a file.
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
- * @param filePath - The path where the file should be written
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
- * await writer.write("./dist/index.d.ts", "export type Props={}");
25
- * // Creates ./dist/index.d.ts with the given content
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<void>;
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,8 +6,6 @@ interface MarkdownOptions {
6
6
  }
7
7
  export type { AppendType };
8
8
  /**
9
- * Markdown writer with optional append callbacks.
10
- *
11
9
  * @example
12
10
  * ```ts
13
11
  * const writer = new WriterMarkdown({