svelte-effect-runtime 3.2.2 → 3.3.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.
Files changed (47) hide show
  1. package/.dist/chunks/{client-DRjQiULJ.js → client-BYhNKK1i.js} +2 -19
  2. package/.dist/chunks/client-BYhNKK1i.js.map +1 -0
  3. package/.dist/chunks/dispatcher-5WSjtyXR.js +47 -0
  4. package/.dist/chunks/dispatcher-5WSjtyXR.js.map +1 -0
  5. package/.dist/chunks/{dispatcher-CZvLODNK.js → dispatcher-BnitG7p3.js} +155 -24
  6. package/.dist/chunks/dispatcher-BnitG7p3.js.map +1 -0
  7. package/.dist/chunks/{grammars-DwahpmJS.js → grammars-i4CSRxWg.js} +3 -3
  8. package/.dist/chunks/grammars-i4CSRxWg.js.map +1 -0
  9. package/.dist/chunks/{runtime-BgCRz_rL.js → runtime-CPbQxe4W.js} +2 -2
  10. package/.dist/chunks/{runtime-BgCRz_rL.js.map → runtime-CPbQxe4W.js.map} +1 -1
  11. package/.dist/chunks/{transform-B7_CCcvq.js → transform-DHUCirwV.js} +31 -26
  12. package/.dist/chunks/transform-DHUCirwV.js.map +1 -0
  13. package/.dist/dispatcher/fibers.d.ts +2 -0
  14. package/.dist/dispatcher/index.d.ts +27 -2
  15. package/.dist/dispatcher/types.d.ts +140 -0
  16. package/.dist/dispatcher.d.ts +2 -2
  17. package/.dist/dispatcher.js +2 -2
  18. package/.dist/generated/dispatcher.d.ts +49 -2
  19. package/.dist/generators.d.ts +2 -1
  20. package/.dist/grammars.js +1 -1
  21. package/.dist/internal/generators.js +3 -2
  22. package/.dist/internal/remote-client.js +1 -1
  23. package/.dist/markup/promise.js +1 -1
  24. package/.dist/markup/run.js +1 -1
  25. package/.dist/markup/transform/constants.d.ts +2 -3
  26. package/.dist/markup/transform/index.d.ts +5 -4
  27. package/.dist/markup/transform/types.d.ts +27 -3
  28. package/.dist/markup/transform.d.ts +1 -1
  29. package/.dist/markup/transform.js +1 -1
  30. package/.dist/markup/value.js +1 -1
  31. package/.dist/mod.js +2 -2
  32. package/.dist/remote/client/failures.d.ts +1 -16
  33. package/.dist/remote/client.js +1 -1
  34. package/.dist/runtime/transform.d.ts +18 -2
  35. package/.dist/runtime/transform.js +76 -5
  36. package/.dist/runtime/transform.js.map +1 -1
  37. package/.dist/script-transform/types.d.ts +23 -0
  38. package/.dist/server.js +1 -1
  39. package/.dist/vite.js +29 -2
  40. package/.dist/vite.js.map +1 -1
  41. package/package.json +1 -1
  42. package/.dist/chunks/client-DRjQiULJ.js.map +0 -1
  43. package/.dist/chunks/dispatcher-CLSN-Cxn.js +0 -22
  44. package/.dist/chunks/dispatcher-CLSN-Cxn.js.map +0 -1
  45. package/.dist/chunks/dispatcher-CZvLODNK.js.map +0 -1
  46. package/.dist/chunks/grammars-DwahpmJS.js.map +0 -1
  47. package/.dist/chunks/transform-B7_CCcvq.js.map +0 -1
@@ -1,4 +1,37 @@
1
1
  import type { Effect } from "effect";
2
+ /**
3
+ * Stable operation codes used by transform-generated dispatcher events.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * const type = Code.Markup.Promise;
8
+ * ```
9
+ *
10
+ * @since 3.3.0
11
+ * @internal
12
+ */
13
+ export declare const Code: {
14
+ readonly Markup: {
15
+ readonly Promise: "MarkupPromise";
16
+ readonly Run: "MarkupRun";
17
+ readonly Value: "MarkupValue";
18
+ };
19
+ };
20
+ /**
21
+ * Options for markup promise behavior during server rendering.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const options: MarkupPromiseOptions = { ssr: "pending" };
26
+ * ```
27
+ *
28
+ * @since 3.3.0
29
+ * @internal
30
+ */
31
+ export interface MarkupPromiseOptions {
32
+ /** Keep the SSR promise pending so Svelte renders an await block fallback. */
33
+ ssr?: "pending";
34
+ }
2
35
  /**
3
36
  * Minimal cleanup handle returned by dispatcher lifecycle hooks.
4
37
  *
@@ -61,3 +94,110 @@ export interface PromiseOptions<A> {
61
94
  /** Generator function that yields the effect to run. */
62
95
  factory: () => Effect.gen.Return<A, unknown, unknown>;
63
96
  }
97
+ /**
98
+ * Generated event that reads a markup expression through the cached value
99
+ * channel.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * const event: MarkupValueEvent<number, undefined> = {
104
+ * type: Code.Markup.Value,
105
+ * id: "Component.svelte:1:2",
106
+ * deps: [],
107
+ * fallback: undefined,
108
+ * fn: function* () {
109
+ * return yield* Effect.succeed(1);
110
+ * },
111
+ * };
112
+ * ```
113
+ *
114
+ * @since 3.3.0
115
+ * @internal
116
+ */
117
+ export interface MarkupValueEvent<A, F> {
118
+ /** Dispatcher code identifying a markup value read. */
119
+ type: typeof Code.Markup.Value;
120
+ /** Stable identifier generated from the expression's source position. */
121
+ id: string;
122
+ /** Reactive dependency array captured from free identifiers. */
123
+ deps: readonly unknown[];
124
+ /** Value returned synchronously while the effect is pending. */
125
+ fallback: F;
126
+ /** Generator function that yields the effect to run. */
127
+ fn: () => Effect.gen.Return<A, unknown, unknown>;
128
+ }
129
+ /**
130
+ * Generated event that reads a markup expression through the cached promise
131
+ * channel.
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * const event: MarkupPromiseEvent<number> = {
136
+ * type: Code.Markup.Promise,
137
+ * id: "Component.svelte:1:2",
138
+ * deps: [],
139
+ * fn: function* () {
140
+ * return yield* Effect.succeed(1);
141
+ * },
142
+ * };
143
+ * ```
144
+ *
145
+ * @since 3.3.0
146
+ * @internal
147
+ */
148
+ export interface MarkupPromiseEvent<A> {
149
+ /** Dispatcher code identifying a markup promise read. */
150
+ type: typeof Code.Markup.Promise;
151
+ /** Stable identifier generated from the expression's source position. */
152
+ id: string;
153
+ /** Reactive dependency array captured from free identifiers. */
154
+ deps: readonly unknown[];
155
+ /** Generator function that yields the effect to run. */
156
+ fn: () => Effect.gen.Return<A, unknown, unknown>;
157
+ /** Value resolved during SSR when a fallback is required. */
158
+ ssr_fallback?: A;
159
+ /** Optional SSR behavior for await blocks and similar contexts. */
160
+ options?: MarkupPromiseOptions;
161
+ }
162
+ /**
163
+ * Generated event that runs an event-handler Effect.
164
+ *
165
+ * @example
166
+ * ```ts
167
+ * const event: MarkupRunEvent<void> = {
168
+ * type: Code.Markup.Run,
169
+ * fn: function* () {
170
+ * yield* Effect.void;
171
+ * },
172
+ * };
173
+ * ```
174
+ *
175
+ * @since 3.3.0
176
+ * @internal
177
+ */
178
+ export interface MarkupRunEvent<A> {
179
+ /** Dispatcher code identifying a markup event-handler run. */
180
+ type: typeof Code.Markup.Run;
181
+ /** Generator function that yields the effect to run. */
182
+ fn: () => Effect.gen.Return<A, unknown, unknown>;
183
+ }
184
+ /**
185
+ * Union of generated dispatcher events.
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * const event: DispatcherEvent<number, undefined> = {
190
+ * type: Code.Markup.Value,
191
+ * id: "Component.svelte:1:2",
192
+ * deps: [],
193
+ * fallback: undefined,
194
+ * fn: function* () {
195
+ * return yield* Effect.succeed(1);
196
+ * },
197
+ * };
198
+ * ```
199
+ *
200
+ * @since 3.3.0
201
+ * @internal
202
+ */
203
+ export type DispatcherEvent<A, F = A> = MarkupPromiseEvent<A> | MarkupRunEvent<A> | MarkupValueEvent<A, F>;
@@ -1,2 +1,2 @@
1
- export { Dispatcher, get_dispatcher, reset_dispatcher, } from "./dispatcher/index.js";
2
- export type { Dispose, PromiseOptions, ValueOptions, } from "./dispatcher/types.js";
1
+ export { Code, Dispatcher, get_dispatcher, reset_dispatcher, } from "./dispatcher/index.js";
2
+ export type { DispatcherEvent, Dispose, MarkupPromiseEvent, MarkupPromiseOptions, MarkupRunEvent, MarkupValueEvent, PromiseOptions, ValueOptions, } from "./dispatcher/types.js";
@@ -1,2 +1,2 @@
1
- import { n as get_dispatcher, r as reset_dispatcher, t as Dispatcher } from "./chunks/dispatcher-CZvLODNK.js";
2
- export { Dispatcher, get_dispatcher, reset_dispatcher };
1
+ import { i as Code, n as get_dispatcher, r as reset_dispatcher, t as Dispatcher } from "./chunks/dispatcher-BnitG7p3.js";
2
+ export { Code, Dispatcher, get_dispatcher, reset_dispatcher };
@@ -1,4 +1,51 @@
1
- import type { Dispatcher } from "../dispatcher.js";
1
+ import type { Dispatcher as RuntimeDispatcher, DispatcherEvent, MarkupPromiseEvent, MarkupRunEvent, MarkupValueEvent } from "../dispatcher.js";
2
+ export { Code } from "../dispatcher.js";
3
+ export type { DispatcherEvent, MarkupPromiseEvent, MarkupPromiseOptions, MarkupRunEvent, MarkupValueEvent, } from "../dispatcher.js";
4
+ /**
5
+ * Facade used by transform-generated component code to dispatch runtime
6
+ * events through the current client or server dispatcher.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const value = Dispatcher.emit({
11
+ * type: Code.Markup.Value,
12
+ * id: "Component.svelte:1:2",
13
+ * deps: [],
14
+ * fallback: undefined,
15
+ * fn: function* () {
16
+ * return yield* Effect.succeed(1);
17
+ * },
18
+ * });
19
+ * ```
20
+ *
21
+ * @since 3.3.0
22
+ * @internal
23
+ */
24
+ export declare class Dispatcher {
25
+ /**
26
+ * Emits a transform-generated dispatcher event.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const promise = Dispatcher.emit({
31
+ * type: Code.Markup.Promise,
32
+ * id: "Component.svelte:1:2",
33
+ * deps: [],
34
+ * fn: function* () {
35
+ * return yield* Effect.succeed(1);
36
+ * },
37
+ * });
38
+ * ```
39
+ *
40
+ * @since 3.3.0
41
+ * @param event - Generated event describing the dispatcher operation to run.
42
+ * @returns The result produced by the active dispatcher.
43
+ */
44
+ static emit<A, F>(event: MarkupValueEvent<A, F>): A | F;
45
+ static emit<A>(event: MarkupPromiseEvent<A>): Promise<A>;
46
+ static emit<A>(event: MarkupRunEvent<A>): Promise<A>;
47
+ static emit<A, F>(event: DispatcherEvent<A, F>): A | F | Promise<A>;
48
+ }
2
49
  /**
3
50
  * Returns the dispatcher appropriate for generated component code.
4
51
  *
@@ -10,4 +57,4 @@ import type { Dispatcher } from "../dispatcher.js";
10
57
  * @since 3.0.1
11
58
  * @returns The server dispatcher during SSR, otherwise the client dispatcher.
12
59
  */
13
- export declare function get_dispatcher(): Dispatcher;
60
+ export declare function get_dispatcher(): RuntimeDispatcher;
@@ -10,7 +10,8 @@
10
10
  * @since 2.0.0
11
11
  * @internal
12
12
  */
13
- export { get_dispatcher } from "./generated/dispatcher.js";
13
+ export { Code, Dispatcher, get_dispatcher } from "./generated/dispatcher.js";
14
+ export type { DispatcherEvent, MarkupPromiseEvent, MarkupPromiseOptions, MarkupRunEvent, MarkupValueEvent, } from "./generated/dispatcher.js";
14
15
  export { value } from "./markup/value.js";
15
16
  export { promise } from "./markup/promise.js";
16
17
  export { run } from "./markup/run.js";
package/.dist/grammars.js CHANGED
@@ -1,2 +1,2 @@
1
- import { n as textmate, r as textmate_language, t as tree_sitter } from "./chunks/grammars-DwahpmJS.js";
1
+ import { n as textmate, r as textmate_language, t as tree_sitter } from "./chunks/grammars-i4CSRxWg.js";
2
2
  export { textmate as TextMate, textmate, tree_sitter as TreesitterQuery, tree_sitter, textmate_language };
@@ -1,5 +1,6 @@
1
- import { t as get_dispatcher } from "../chunks/dispatcher-CLSN-Cxn.js";
1
+ import { i as Code } from "../chunks/dispatcher-BnitG7p3.js";
2
+ import { n as get_dispatcher, t as Dispatcher } from "../chunks/dispatcher-5WSjtyXR.js";
2
3
  import { value } from "../markup/value.js";
3
4
  import { promise } from "../markup/promise.js";
4
5
  import { run } from "../markup/run.js";
5
- export { get_dispatcher, promise, run, value };
6
+ export { Code, Dispatcher, get_dispatcher, promise, run, value };
@@ -1,2 +1,2 @@
1
- import { i as create_remote_command_adapter, n as create_remote_query_adapter, r as create_remote_form_adapter, t as create_remote_live_query_adapter } from "../chunks/client-DRjQiULJ.js";
1
+ import { i as create_remote_command_adapter, n as create_remote_query_adapter, r as create_remote_form_adapter, t as create_remote_live_query_adapter } from "../chunks/client-BYhNKK1i.js";
2
2
  export { create_remote_command_adapter, create_remote_form_adapter, create_remote_live_query_adapter, create_remote_query_adapter };
@@ -1,4 +1,4 @@
1
- import { t as get_dispatcher } from "../chunks/dispatcher-CLSN-Cxn.js";
1
+ import { n as get_dispatcher } from "../chunks/dispatcher-5WSjtyXR.js";
2
2
  //#region src/markup/promise.ts
3
3
  /**
4
4
  * Runtime helper emitted by the markup transform for
@@ -1,4 +1,4 @@
1
- import { t as get_dispatcher } from "../chunks/dispatcher-CLSN-Cxn.js";
1
+ import { n as get_dispatcher } from "../chunks/dispatcher-5WSjtyXR.js";
2
2
  import { Effect } from "effect";
3
3
  //#region src/markup/run.ts
4
4
  /**
@@ -1,5 +1,4 @@
1
1
  export declare const HELPERS: {
2
- readonly value: "__SER___markup_value";
3
- readonly promise: "__SER___markup_promise";
4
- readonly run: "__SER___markup_run";
2
+ readonly codes: "Code";
3
+ readonly dispatcher: "Dispatcher";
5
4
  };
@@ -1,8 +1,8 @@
1
- import type { MarkupTransformResult } from "./types.js";
2
- export type { MarkupRelocation, MarkupTransformResult } from "./types.js";
1
+ import type { MarkupTransformOptions, MarkupTransformResult } from "./types.js";
2
+ export type { MarkupRelocation, MarkupTransformOptions, MarkupTransformResult, MarkupTransformTarget, } from "./types.js";
3
3
  /**
4
4
  * Transforms Svelte markup containing `{yield* expr}` brace expressions
5
- * into calls to the markup runtime helpers (`value`, `promise`, `run`).
5
+ * into generated dispatcher events.
6
6
  *
7
7
  * Strategy: first find all brace expressions containing `yield*` via
8
8
  * character scanning, replace them with placeholder identifiers, then
@@ -13,7 +13,8 @@ export type { MarkupRelocation, MarkupTransformResult } from "./types.js";
13
13
  * @since 2.0.0
14
14
  * @param content - The raw `.svelte` file content.
15
15
  * @param filename - The source filename, used in error messages.
16
+ * @param options - Optional transform target configuration.
16
17
  * @returns The transformed markup and a flag indicating whether yield* was
17
18
  * found.
18
19
  */
19
- export declare function transform_markup_effect(content: string, filename: string): MarkupTransformResult;
20
+ export declare function transform_markup_effect(content: string, filename: string, options?: MarkupTransformOptions): MarkupTransformResult;
@@ -13,6 +13,31 @@ export interface MarkupTransformResult {
13
13
  /** Offset ranges that preserve hoverable source spans inside lowered code. */
14
14
  relocations?: MarkupRelocation[];
15
15
  }
16
+ /**
17
+ * Runtime environment that controls how markup effect reads are lowered.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const target: MarkupTransformTarget = "client";
22
+ * ```
23
+ *
24
+ * @since 2.5.0
25
+ */
26
+ export type MarkupTransformTarget = "client" | "server" | "editor";
27
+ /**
28
+ * Options accepted by the markup transform.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const options: MarkupTransformOptions = { target: "server" };
33
+ * ```
34
+ *
35
+ * @since 2.5.0
36
+ */
37
+ export interface MarkupTransformOptions {
38
+ /** Legacy emission target retained for compatibility with older callers. */
39
+ target?: MarkupTransformTarget;
40
+ }
16
41
  /** Offset mapping between original markup and generated helper code. */
17
42
  export interface MarkupRelocation {
18
43
  /** Start offset in the original source. */
@@ -63,9 +88,8 @@ export interface Insertion {
63
88
  relocations?: PendingRelocation[];
64
89
  }
65
90
  export interface MarkupHelperBindings {
66
- value: string;
67
- promise: string;
68
- run: string;
91
+ codes: string;
92
+ dispatcher: string;
69
93
  }
70
94
  export interface MarkupNameAllocator {
71
95
  reserve(name: string): string;
@@ -1 +1 @@
1
- export { type MarkupRelocation, type MarkupTransformResult, transform_markup_effect, } from "./transform/index.js";
1
+ export { type MarkupRelocation, type MarkupTransformOptions, type MarkupTransformResult, type MarkupTransformTarget, transform_markup_effect, } from "./transform/index.js";
@@ -1,2 +1,2 @@
1
- import { t as transform_markup_effect } from "../chunks/transform-B7_CCcvq.js";
1
+ import { t as transform_markup_effect } from "../chunks/transform-DHUCirwV.js";
2
2
  export { transform_markup_effect };
@@ -1,4 +1,4 @@
1
- import { t as get_dispatcher } from "../chunks/dispatcher-CLSN-Cxn.js";
1
+ import { n as get_dispatcher } from "../chunks/dispatcher-5WSjtyXR.js";
2
2
  //#region src/markup/value.ts
3
3
  /**
4
4
  * Runtime helper emitted by the markup transform for `{yield* expr}`
package/.dist/mod.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { C as UncheckedPrerenderHandlerMissingError, D as UnsupportedRemoteFormResponseError, E as UnsupportedMarkupEffectPositionError, O as YieldStarInEventCallbackError, S as UncheckedLiveQueryHandlerMissingError, T as UnknownRuntimeError, _ as RuntimeError, a as DispatcherDisposedError, b as UncheckedCommandHandlerMissingError, c as InvalidLiveQueryReturnError, d as PreprocessError, f as RemoteErrorDecodeError, g as RequestEventUnavailableError, h as RemoteHelperError, i as BatchQueryHandlerMissingError, l as InvalidQueryFactoryError, m as RemoteHelperContextError, n as AsyncEffectInSyncRuneError, o as InvalidCommandFactoryError, p as RemoteFormEndpointMissingError, r as AwaitInEffectWorkError, s as InvalidLiveQueryFactoryError, t as AsyncEffectInEventCallbackError, u as InvalidRemoteFormResponseError, v as ServerOnlyImportError, w as UncheckedQueryHandlerMissingError, x as UncheckedFormHandlerMissingError, y as SvelteKitServerExportUnavailableError } from "./chunks/errors-DppSJ83S.js";
2
- import { t as Dispatcher } from "./chunks/dispatcher-CZvLODNK.js";
3
- import { n as textmate, r as textmate_language, t as tree_sitter } from "./chunks/grammars-DwahpmJS.js";
2
+ import { t as Dispatcher } from "./chunks/dispatcher-BnitG7p3.js";
3
+ import { n as textmate, r as textmate_language, t as tree_sitter } from "./chunks/grammars-i4CSRxWg.js";
4
4
  import { is_form_error, is_remote_http_error, is_remote_transport_error, is_remote_validation_error } from "./remote/shared.js";
5
5
  import { effect } from "./vite.js";
6
6
  //#region src/mod.ts
@@ -1,4 +1,4 @@
1
- import type { FormIssue, RemoteFailure } from "../shared.js";
1
+ import type { RemoteFailure } from "../shared.js";
2
2
  /**
3
3
  * Decodes a raw wire value into a remote failure when it uses the runtime
4
4
  * failure envelope.
@@ -27,21 +27,6 @@ export declare function decode_remote_error<ErrorType = never>(raw: unknown, dec
27
27
  * @returns Whether the value carries a `_tag` discriminator.
28
28
  */
29
29
  export declare function is_decoded_remote_failure(value: unknown): value is RemoteFailure<never>;
30
- /**
31
- * Checks whether a response body represents SvelteKit validation issues.
32
- *
33
- * @example
34
- * ```ts
35
- * if (is_validation_body(body)) return body.issues;
36
- * ```
37
- *
38
- * @since 2.0.0
39
- * @param value - Value to inspect.
40
- * @returns Whether the value contains a form issue list.
41
- */
42
- export declare function is_validation_body(value: unknown): value is {
43
- issues: readonly FormIssue[];
44
- };
45
30
  /**
46
31
  * Normalizes native thrown values into the runtime's remote failure model.
47
32
  *
@@ -1,2 +1,2 @@
1
- import { i as create_remote_command_adapter, n as create_remote_query_adapter, r as create_remote_form_adapter, t as create_remote_live_query_adapter } from "../chunks/client-DRjQiULJ.js";
1
+ import { i as create_remote_command_adapter, n as create_remote_query_adapter, r as create_remote_form_adapter, t as create_remote_live_query_adapter } from "../chunks/client-BYhNKK1i.js";
2
2
  export { create_remote_command_adapter, create_remote_form_adapter, create_remote_live_query_adapter, create_remote_query_adapter };
@@ -1,3 +1,4 @@
1
+ import { type MarkupTransformTarget } from "../markup/transform.js";
1
2
  /**
2
3
  * Result returned by the direct whole-file Svelte transform.
3
4
  *
@@ -13,6 +14,20 @@ export interface SvelteTransformResult {
13
14
  /** Transformed Svelte source. */
14
15
  code: string;
15
16
  }
17
+ /**
18
+ * Options accepted by the direct whole-file Svelte transform.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const options: SvelteTransformOptions = { target: "client" };
23
+ * ```
24
+ *
25
+ * @since 2.5.0
26
+ */
27
+ export interface SvelteTransformOptions {
28
+ /** Markup emission target passed through to the markup transform. */
29
+ target?: MarkupTransformTarget;
30
+ }
16
31
  /**
17
32
  * Lowers SER syntax in a complete Svelte component without using Svelte's
18
33
  * adapter API.
@@ -30,8 +45,9 @@ export interface SvelteTransformResult {
30
45
  * it.
31
46
  * @param filename - Component filename used in generated cache identifiers and
32
47
  * diagnostics.
48
+ * @param options - Optional target configuration for markup lowering.
33
49
  * @returns The transformed component source.
34
50
  */
35
- export declare function transform_svelte_effect(content: string, filename?: string): SvelteTransformResult;
36
- export { type MarkupTransformResult, transform_markup_effect, } from "../markup/transform.js";
51
+ export declare function transform_svelte_effect(content: string, filename?: string, options?: SvelteTransformOptions): SvelteTransformResult;
52
+ export { type MarkupTransformOptions, type MarkupTransformResult, type MarkupTransformTarget, transform_markup_effect, } from "../markup/transform.js";
37
53
  export { type BlockRef, type ScriptTransformResult, transform_script_effect, } from "../script-transform/index.js";
@@ -1,5 +1,5 @@
1
1
  import { d as PreprocessError, n as AsyncEffectInSyncRuneError, r as AwaitInEffectWorkError } from "../chunks/errors-DppSJ83S.js";
2
- import { a as find_yield_star_node, c as collect_top_level_binding_names, i as extract_binding_names, l as has_local_import_binding, n as collect_yield_star_nodes, o as is_yield_star_expression, r as contains_top_level_await, s as collect_free_identifiers, t as transform_markup_effect, u as make_imports } from "../chunks/transform-B7_CCcvq.js";
2
+ import { a as find_yield_star_node, c as collect_top_level_binding_names, i as extract_binding_names, l as has_local_import_binding, n as collect_yield_star_nodes, o as is_yield_star_expression, r as contains_top_level_await, s as collect_free_identifiers, t as transform_markup_effect, u as make_imports } from "../chunks/transform-DHUCirwV.js";
3
3
  import { contains_top_level_yield_star } from "../detect.js";
4
4
  import MagicString from "magic-string";
5
5
  import ts from "typescript";
@@ -604,12 +604,82 @@ function transform_script_effect(content, filename, options = {}) {
604
604
  id: filename,
605
605
  kind: "script"
606
606
  });
607
+ const code = magic.toString();
607
608
  return {
608
- code: magic.toString(),
609
+ code,
609
610
  blocks: block_refs,
610
- map: create_source_map(magic, filename)
611
+ map: create_source_map(magic, filename),
612
+ relocations: create_script_relocations(content, code, source_file)
611
613
  };
612
614
  }
615
+ function create_script_relocations(content, code, source_file) {
616
+ const candidates = source_file.statements.flatMap((stmt) => {
617
+ const relocations = [];
618
+ if (contains_top_level_yield_star(stmt) && ts.isVariableStatement(stmt)) for (const decl of stmt.declarationList.declarations) collect_binding_relocation_candidates(decl.name, relocations);
619
+ collect_yield_star_nodes(stmt, (node) => {
620
+ const text = content.slice(node.getStart(), node.end).trim();
621
+ relocations.push({
622
+ originalStart: node.getStart(),
623
+ originalEnd: node.end,
624
+ text,
625
+ match: "exact"
626
+ });
627
+ });
628
+ return relocations;
629
+ });
630
+ const used_ranges = [];
631
+ return candidates.flatMap((candidate) => {
632
+ const generated_start = find_available_generated_text(code, candidate, used_ranges);
633
+ if (generated_start < 0) return [];
634
+ const generated_end = generated_start + candidate.text.length;
635
+ used_ranges.push({
636
+ start: generated_start,
637
+ end: generated_end
638
+ });
639
+ return [{
640
+ originalStart: candidate.originalStart,
641
+ originalEnd: candidate.originalEnd,
642
+ generatedStart: generated_start,
643
+ generatedEnd: generated_end
644
+ }];
645
+ });
646
+ }
647
+ function collect_binding_relocation_candidates(name, candidates) {
648
+ if (ts.isIdentifier(name)) {
649
+ candidates.push({
650
+ originalStart: name.getStart(),
651
+ originalEnd: name.end,
652
+ text: name.text,
653
+ match: "identifier"
654
+ });
655
+ return;
656
+ }
657
+ for (const element of name.elements) {
658
+ if (ts.isOmittedExpression(element)) continue;
659
+ collect_binding_relocation_candidates(element.name, candidates);
660
+ }
661
+ }
662
+ function find_available_generated_text(code, candidate, used_ranges) {
663
+ let search_start = 0;
664
+ while (search_start < code.length) {
665
+ const index = code.indexOf(candidate.text, search_start);
666
+ if (index < 0) return -1;
667
+ const end = index + candidate.text.length;
668
+ const overlaps_used_range = used_ranges.some((range) => index < range.end && end > range.start);
669
+ const is_text_match = candidate.match === "exact" || is_identifier_text_match(code, index, end);
670
+ if (!overlaps_used_range && is_text_match) return index;
671
+ search_start = candidate.match === "identifier" ? index + 1 : end;
672
+ }
673
+ return -1;
674
+ }
675
+ function is_identifier_text_match(code, start, end) {
676
+ const before = start === 0 ? 0 : code.charCodeAt(start - 1);
677
+ const after = end >= code.length ? 0 : code.charCodeAt(end);
678
+ return !is_identifier_part(before) && !is_identifier_part(after);
679
+ }
680
+ function is_identifier_part(char_code) {
681
+ return char_code >= 65 && char_code <= 90 || char_code >= 97 && char_code <= 122 || char_code >= 48 && char_code <= 57 || char_code === 36 || char_code === 95;
682
+ }
613
683
  function validate_script_yield_boundaries(stmt, content, filename) {
614
684
  const bad_member = find_class_member_with_yield_star(stmt);
615
685
  if (!bad_member) return;
@@ -670,16 +740,17 @@ function make_generated_name(hint, suffix) {
670
740
  * it.
671
741
  * @param filename - Component filename used in generated cache identifiers and
672
742
  * diagnostics.
743
+ * @param options - Optional target configuration for markup lowering.
673
744
  * @returns The transformed component source.
674
745
  */
675
- function transform_svelte_effect(content, filename = "unknown.svelte") {
746
+ function transform_svelte_effect(content, filename = "unknown.svelte", options = {}) {
676
747
  const script = find_script(content);
677
748
  let combined = content;
678
749
  if (script?.has_effect) {
679
750
  const result = transform_script_effect(script.text, filename, { emit_types: script.is_typescript });
680
751
  combined = content.slice(0, script.effect_attr_start) + content.slice(script.effect_attr_end, script.open_end) + result.code + content.slice(script.close_start);
681
752
  }
682
- return { code: transform_markup_effect(combined, filename).code };
753
+ return { code: transform_markup_effect(combined, filename, { target: options.target }).code };
683
754
  }
684
755
  function find_script(content) {
685
756
  for (const match of content.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script\s*>/gi)) {