sveld 0.35.0 → 0.35.1
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 +46 -0
- package/lib/ComponentParser.d.ts +28 -0
- package/lib/ast-guards.d.ts +4 -0
- package/lib/browser.d.ts +39 -0
- package/lib/browser.js +290 -0
- package/lib/bundle.d.ts +8 -1
- package/lib/index.js +231 -372
- package/lib/parse-exports.d.ts +5 -1
- package/lib/parser/context.d.ts +9 -5
- package/lib/parser/props.d.ts +6 -0
- package/lib/parser/runes-detection.d.ts +16 -0
- package/lib/parser/scopes.d.ts +23 -5
- package/lib/parser/slots.d.ts +1 -1
- package/lib/parser/type-resolution.d.ts +5 -0
- package/lib/parser/typescript-casts.d.ts +2 -0
- package/lib/resolve-types.d.ts +1 -1
- package/package.json +6 -1
package/lib/parse-exports.d.ts
CHANGED
|
@@ -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;
|
package/lib/parser/context.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { FunctionDeclaration, VariableDeclaration } from "estree";
|
|
2
|
-
import type {
|
|
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 {
|
|
@@ -10,10 +9,13 @@ export interface ParserContext {
|
|
|
10
9
|
scriptLanguage?: ScriptLanguage;
|
|
11
10
|
/** Raw source code of the Svelte component being parsed */
|
|
12
11
|
source?: string;
|
|
13
|
-
/** Compiled Svelte code containing extracted variables and AST */
|
|
14
|
-
compiled?: ReturnType<typeof compile>;
|
|
15
12
|
/** Parsed abstract syntax tree from the Svelte compiler */
|
|
16
13
|
parsed?: LegacyAstRoot;
|
|
14
|
+
/**
|
|
15
|
+
* Explicit `<svelte:options runes={...} />` value, resolved during the modern-mode parse for
|
|
16
|
+
* runes prop type metadata. When present, overrides rune-reference detection.
|
|
17
|
+
*/
|
|
18
|
+
runesOptionOverride?: boolean;
|
|
17
19
|
/** Cached `ctx.source` split on newlines */
|
|
18
20
|
sourceLinesCache?: string[];
|
|
19
21
|
/** Cached 0-based source offsets for the start of each line */
|
|
@@ -76,7 +78,7 @@ export interface ParserContext {
|
|
|
76
78
|
/** Active lexical scopes while walking the component AST */
|
|
77
79
|
readonly activeScopes: LexicalScope[];
|
|
78
80
|
/** Map of component slots keyed by slot name (null for default slot) */
|
|
79
|
-
readonly slots: Map<string | null,
|
|
81
|
+
readonly slots: Map<string | null, InternalComponentSlot>;
|
|
80
82
|
/** Tracks prop locals that are used as snippet/render props */
|
|
81
83
|
readonly snippetPropLocals: Set<string>;
|
|
82
84
|
/** @template tags in a @slot/@snippet block (no @extends), held until finalization. */
|
|
@@ -105,6 +107,8 @@ export interface ParserContext {
|
|
|
105
107
|
type: string;
|
|
106
108
|
description?: string;
|
|
107
109
|
}>;
|
|
110
|
+
/** Whether {@link variableInfoCache} has been populated by a whole-source scan yet */
|
|
111
|
+
variableInfoCacheBuilt: boolean;
|
|
108
112
|
}
|
|
109
113
|
/** Fresh {@link ParserContext}. Keep in sync with new fields on {@link ParserContext}. */
|
|
110
114
|
export declare function createParserContext(): ParserContext;
|
package/lib/parser/props.d.ts
CHANGED
|
@@ -51,6 +51,12 @@ export declare function inferReturnTypeFromNode(node: FunctionDeclaration | Func
|
|
|
51
51
|
/**
|
|
52
52
|
* Walk a block body and collect each `return`'s argument, skipping nested
|
|
53
53
|
* functions. Bare `return;` becomes `null`.
|
|
54
|
+
*
|
|
55
|
+
* Not fused with the componentRoot walk: this runs from `processInitializer`, called
|
|
56
|
+
* synchronously while the outer walk is still on the ancestor `ExportNamedDeclaration`/
|
|
57
|
+
* `VariableDeclaration` node, so it needs the inferred type before the outer walk would
|
|
58
|
+
* otherwise reach these descendant statements. Deferring it to ride along with the outer
|
|
59
|
+
* traversal would mean computing prop types in a second pass instead of inline.
|
|
54
60
|
*/
|
|
55
61
|
export declare function collectReturnArguments(body: unknown): unknown[];
|
|
56
62
|
/**
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
* Known simplification: svelte also force-enables runes mode on top-level `await` (blocking awaits
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
export declare function detectSyntaxMode(ctx: ParserContext): SyntaxMode;
|
package/lib/parser/scopes.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
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";
|
|
@@ -34,7 +33,26 @@ export declare function declareFunctionLikeScopeBindings(node: FunctionExpressio
|
|
|
34
33
|
export declare function collectDirectBlockDeclarations(parser: ComponentParser, body: unknown, lexicalScope: LexicalScope, varScope: LexicalScope): void;
|
|
35
34
|
/** Declares all component-instance-level (`<script>`) bindings into `ctx.componentScope`. */
|
|
36
35
|
export declare function collectComponentScopeDeclarations(parser: ComponentParser, ctx: ParserContext, instance: unknown): void;
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Resets `ctx.componentScope` / `ctx.scopeDeclarations` / `ctx.activeScopes` and declares the
|
|
38
|
+
* top-level `<script>` bindings. Does not walk the component tree; nested scope declarations are
|
|
39
|
+
* built incrementally by {@link enterNestedScopeDeclarationNode} inside the caller's own traversal
|
|
40
|
+
* of `componentRoot` (fused with prop/slot/event extraction there rather than walked separately).
|
|
41
|
+
*/
|
|
42
|
+
export declare function initComponentScope(parser: ComponentParser, ctx: ParserContext): void;
|
|
43
|
+
/** Mutable stack tracking the enclosing `var`-hoisting scope while walking `componentRoot`. */
|
|
44
|
+
export type ScopeWalkState = {
|
|
45
|
+
varScopeStack: LexicalScope[];
|
|
46
|
+
};
|
|
47
|
+
/** Creates the scope-walk state for a fresh traversal of `componentRoot`, seeded with `ctx.componentScope`. */
|
|
48
|
+
export declare function createScopeWalkState(ctx: ParserContext): ScopeWalkState;
|
|
49
|
+
/**
|
|
50
|
+
* Per-node `enter` step of the (formerly standalone) nested-scope-declaration walk. Declares
|
|
51
|
+
* bindings for `node` if it's a scope owner and pushes it as the active `var` scope for its
|
|
52
|
+
* descendants. Must be called during the same top-down traversal of `componentRoot` that
|
|
53
|
+
* {@link leaveNestedScopeDeclarationNode} tears down, and before any logic that reads
|
|
54
|
+
* `ctx.scopeDeclarations` for `node` itself (its own scope is only created here, on entry).
|
|
55
|
+
*/
|
|
56
|
+
export declare function enterNestedScopeDeclarationNode(parser: ComponentParser, ctx: ParserContext, state: ScopeWalkState, node: unknown): void;
|
|
57
|
+
/** Per-node `leave` step counterpart to {@link enterNestedScopeDeclarationNode}. */
|
|
58
|
+
export declare function leaveNestedScopeDeclarationNode(state: ScopeWalkState, node: unknown): void;
|
package/lib/parser/slots.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare function extractRenderTagInfo(ctx: ParserContext, expression: unk
|
|
|
20
20
|
/** Merge or add a slot. Empty `slot_name` is the default slot. */
|
|
21
21
|
export declare function addSlot(ctx: ParserContext, { slot_name, slot_props, slot_fallback, slot_description, slot_deprecated, slot_tags, source, }: {
|
|
22
22
|
slot_name?: string;
|
|
23
|
-
slot_props?: string;
|
|
23
|
+
slot_props?: string | SlotProps;
|
|
24
24
|
slot_fallback?: string;
|
|
25
25
|
slot_description?: string;
|
|
26
26
|
slot_deprecated?: DeprecatedValue;
|
|
@@ -19,6 +19,11 @@ export declare function getTypeAnnotationText(ctx: ParserContext, typeAnnotation
|
|
|
19
19
|
start?: number;
|
|
20
20
|
end?: number;
|
|
21
21
|
} | undefined): string | undefined;
|
|
22
|
+
/** Returns the trimmed source text spanned by a bare type node (no leading `:`), if positions are available. */
|
|
23
|
+
export declare function getTypeNodeText(ctx: ParserContext, typeNode: {
|
|
24
|
+
start?: number;
|
|
25
|
+
end?: number;
|
|
26
|
+
} | undefined): string | undefined;
|
|
22
27
|
/** Collect imported and local type names referenced by a type AST node. */
|
|
23
28
|
export declare function collectReferencedTypeDependencies(ctx: ParserContext, typeNode: ModernRunesTypeNode | undefined, referencedImportedTypes: Set<string>, referencedLocalTypes: Set<string>, visitedLocalTypes?: Set<string>): void;
|
|
24
29
|
/** Emit `import type` statements for referenced type names, grouped by module. */
|
package/lib/resolve-types.d.ts
CHANGED
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sveld",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Generate TypeScript definitions and component documentation for your Svelte components.",
|
|
6
6
|
"type": "module",
|
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
"types": "./lib/index.d.ts",
|
|
12
12
|
"import": "./lib/index.js",
|
|
13
13
|
"default": "./lib/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./browser": {
|
|
16
|
+
"types": "./lib/browser.d.ts",
|
|
17
|
+
"import": "./lib/browser.js",
|
|
18
|
+
"default": "./lib/browser.js"
|
|
14
19
|
}
|
|
15
20
|
},
|
|
16
21
|
"bin": {
|