sveld 0.34.0 → 0.35.0

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.
@@ -1,4 +1,4 @@
1
- import type { ArrowFunctionExpression, CallExpression, FunctionDeclaration, FunctionExpression, Identifier, Literal, MemberExpression, ObjectExpression, VariableDeclaration } from "estree";
1
+ import type { ArrowFunctionExpression, CallExpression, FunctionDeclaration, FunctionExpression, Identifier, Literal, MemberExpression, NewExpression, ObjectExpression, VariableDeclaration } from "estree";
2
2
  export declare function isObject(value: unknown): value is Record<string, unknown>;
3
3
  export declare function isVariableDeclaration(node: unknown): node is VariableDeclaration;
4
4
  export declare function isLiteral(node: unknown): node is Literal;
@@ -7,6 +7,8 @@ export declare function isMemberExpression(node: unknown): node is MemberExpress
7
7
  export declare function isObjectExpression(node: unknown): node is ObjectExpression;
8
8
  export declare function isCallExpression(node: unknown): node is CallExpression;
9
9
  export declare function isCallExpressionNamed(node: unknown, calleeName: string): node is CallExpression;
10
+ export declare function isNewExpression(node: unknown): node is NewExpression;
11
+ export declare function isNewExpressionNamed(node: unknown, calleeName: string): node is NewExpression;
10
12
  export declare function isFunctionDeclaration(node: unknown): node is FunctionDeclaration;
11
13
  export declare function isFunctionExpression(node: unknown): node is FunctionExpression;
12
14
  export declare function isArrowFunctionExpression(node: unknown): node is ArrowFunctionExpression;
package/lib/bundle.d.ts CHANGED
@@ -48,8 +48,9 @@ export interface GenerateBundleOptions {
48
48
  documentExports?: boolean;
49
49
  /**
50
50
  * Cache parsed component output to disk. Unchanged files skip re-parsing on
51
- * later runs. `true` uses `node_modules/.cache/sveld/parse-cache.json`; a
52
- * string sets a custom path. Off by default.
51
+ * later runs. On by default, writing to
52
+ * `node_modules/.cache/sveld/parse-cache.json`; a string sets a custom path.
53
+ * Pass `false` to disable.
53
54
  */
54
55
  cache?: boolean | string;
55
56
  /**
@@ -71,7 +72,19 @@ export interface ProcessComponentOptions {
71
72
  onParseError?: (error: ComponentParseError) => void;
72
73
  /** When set, reuse a component's previous parse if its content hash is unchanged. */
73
74
  cache?: ParseCache;
75
+ /** Resolved file path -> sha256, computed once up front so it isn't re-hashed per pass. */
76
+ hashes?: Map<string, string>;
77
+ /**
78
+ * In-run memo of freshly parsed components, keyed by resolved file path and
79
+ * shared across the exported and all-components passes so a component that
80
+ * appears in both is only parsed once. Only fresh parses are stored here
81
+ * (never disk-cache hits), and an entry is cleared wherever the disk cache
82
+ * is invalidated so the `@extends` dependency-invalidation flow still forces
83
+ * a re-parse.
84
+ */
85
+ memo?: Map<string, ParsedComponent>;
74
86
  }
87
+ export declare function stripTopLevelStyleBlock(source: string): string;
75
88
  /**
76
89
  * Discovered component sources for an entry point, before parsing.
77
90
  *
package/lib/check.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { ComponentDocs } from "./bundle";
2
+ import type { SveldRuntimeOptions } from "./load-config";
2
3
  import type { EntryExports } from "./parse-entry-exports";
3
4
  import { type ComponentApiDocument } from "./writer/document-model";
4
5
  export type SemverBump = "major" | "minor" | "patch" | "none";
@@ -26,6 +27,11 @@ export interface RunCheckOptions {
26
27
  /** Entry-barrel exports when `documentExports` is on. */
27
28
  entryExports?: EntryExports;
28
29
  }
30
+ /**
31
+ * Resolves the snapshot path for `check`: an explicit string wins, otherwise
32
+ * it falls back to the `json` writer's `outFile`, or `COMPONENT_API.json`.
33
+ */
34
+ export declare function resolveCheckSnapshotFile(options: Pick<SveldRuntimeOptions, "check" | "jsonOptions">): string;
29
35
  /**
30
36
  * Diffs the current component set against a committed `COMPONENT_API.json`
31
37
  * snapshot and assigns a semver bump to each change. Returns
package/lib/cli.d.ts CHANGED
@@ -1,20 +1,22 @@
1
- import { type PluginSveldOptions } from "./plugin";
2
- /** CLI options layered on top of the shared plugin options. */
3
- interface CliOptions extends PluginSveldOptions {
4
- /** Set exit code 1 when diagnostics are present. */
5
- strict?: boolean;
6
- /**
7
- * Diff the parsed component API against a committed snapshot (default:
8
- * the `json` writer's `outFile`, or `COMPONENT_API.json`) and assign a
9
- * semver bump to each change. Exits `1` on a breaking change. Pass a
10
- * string for a custom snapshot path.
11
- */
12
- check?: boolean | string;
13
- }
14
- export declare function parseCliOptions(argv: string[]): CliOptions;
1
+ import { type SveldRuntimeOptions } from "./load-config";
2
+ /** CLI options: identical surface to the shared runtime options. */
3
+ type CliOptions = SveldRuntimeOptions;
4
+ /** Discriminated result of parsing the full argument list. */
5
+ export type CliParseResult = {
6
+ kind: "options";
7
+ options: CliOptions;
8
+ } | {
9
+ kind: "help";
10
+ } | {
11
+ kind: "version";
12
+ } | {
13
+ kind: "unknown";
14
+ arg: string;
15
+ };
16
+ export declare function parseCliOptions(argv: string[]): CliParseResult;
15
17
  /**
16
- * CLI entry point: parse flags, load any config file, run Rollup, generate
17
- * docs, write outputs.
18
+ * CLI entry point: parse flags, load any config file, generate docs, write
19
+ * outputs.
18
20
  *
19
21
  * @example
20
22
  * ```ts
@@ -1,3 +1,4 @@
1
+ import type { SourceRange } from "./ComponentParser";
1
2
  /**
2
3
  * Why sveld could not pin a type during parsing.
3
4
  *
@@ -5,8 +6,9 @@
5
6
  * - `context-any-type`: `setContext` value inferred as `any`.
6
7
  * - `event-no-source`: `@event` with no dispatch, forward, or callback prop.
7
8
  * - `example-compile-error`: an `@example` block failed to type-check (opt-in, `checkExamples`).
9
+ * - `syntax-skipped`: `$props()`/`{@render}` syntax the parser can't model; omitted from output.
8
10
  */
9
- export type SveldDiagnosticKind = "prop-unknown-type" | "context-any-type" | "event-no-source" | "example-compile-error";
11
+ export type SveldDiagnosticKind = "prop-unknown-type" | "context-any-type" | "event-no-source" | "example-compile-error" | "syntax-skipped";
10
12
  /**
11
13
  * One place sveld had to guess a type instead of inferring it.
12
14
  */
@@ -18,6 +20,8 @@ export interface SveldDiagnostic {
18
20
  name: string;
19
21
  /** What went wrong and what type sveld used. */
20
22
  message: string;
23
+ /** Where in the component source this diagnostic points, when the parser holds a stable position. */
24
+ source?: SourceRange;
21
25
  }
22
26
  /**
23
27
  * Drop duplicates (same component, kind, and name). Each file is parsed twice
@@ -1,4 +1,4 @@
1
- import type { ParsedComponent } from "./ComponentParser";
1
+ import type { ParsedComponent, SourceRange } from "./ComponentParser";
2
2
  /**
3
3
  * One `@example` block worth type-checking, reduced to what `resolve-types.ts`
4
4
  * needs: a declaration for the documented symbol and the example body itself.
@@ -12,6 +12,8 @@ export interface ExampleCheckSource {
12
12
  type: string;
13
13
  /** The `@example` body, stripped of any surrounding code fence. */
14
14
  code: string;
15
+ /** Source range of the documented symbol (prop/export/slot/event), when available. */
16
+ source?: SourceRange;
15
17
  }
16
18
  /**
17
19
  * Collects every `@example` block sveld can type-check for a parsed component: